Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Side by Side Diff: mojo/public/cpp/bindings/tests/equals_unittest.cc

Issue 649633003: Add Equals() to mojom structs and related types. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cleanup Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
yzshen1 2014/10/14 21:47:21 It seems currently we divide test cases by the obj
Aaron Boodman 2014/10/14 22:30:12 In this case, it seemed less clean to do that beca
yzshen1 2014/10/14 22:47:39 Okay.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "mojo/public/cpp/environment/environment.h"
6 #include "mojo/public/interfaces/bindings/tests/test_structs.mojom.h"
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 namespace mojo {
10 namespace test {
11
12 namespace {
13
14 RectPtr CreateRect() {
15 RectPtr r = Rect::New();
16 r->x = 1;
17 r->y = 2;
18 r->width = 3;
19 r->height = 4;
20 return r.Pass();
21 }
22
23 class EqualsTest : public testing::Test {
24 public:
25 virtual ~EqualsTest() {}
26
27 private:
28 Environment env_;
29 };
30 }
31
32 TEST_F(EqualsTest, EqualsStruct) {
33 RectPtr r1(CreateRect());
34 RectPtr r2(r1.Clone());
35 EXPECT_TRUE(r1.Equals(r2));
36 r2->y = 1;
37 EXPECT_FALSE(r1.Equals(r2));
38 r2.reset();
39 EXPECT_FALSE(r1.Equals(r2));
40 }
41
42 TEST_F(EqualsTest, EqualsStructNested) {
43 RectPairPtr p1(RectPair::New());
44 p1->first = CreateRect();
45 p1->second = CreateRect();
46 RectPairPtr p2(p1.Clone());
47 EXPECT_TRUE(p1.Equals(p2));
48 p2->second->width = 0;
49 EXPECT_FALSE(p1.Equals(p2));
50 p2->second.reset();
51 EXPECT_FALSE(p1.Equals(p2));
52 }
53
54 TEST_F(EqualsTest, EqualsArray) {
55 NamedRegionPtr n1(NamedRegion::New());
56 n1->name = "n1";
57 n1->rects.push_back(CreateRect());
58 NamedRegionPtr n2(n1.Clone());
59 EXPECT_TRUE(n1.Equals(n2));
60
61 n2->rects.reset();
62 EXPECT_FALSE(n1.Equals(n2));
63 n2->rects.resize(0);
64 EXPECT_FALSE(n1.Equals(n2));
65
66 n2->rects.push_back(CreateRect());
67 n2->rects.push_back(CreateRect());
68 EXPECT_FALSE(n1.Equals(n2));
69
70 n2->rects.resize(1);
71 n2->rects[0]->width = 0;
72 EXPECT_FALSE(n1.Equals(n2));
73
74 n2->rects[0] = CreateRect();
75 EXPECT_TRUE(n1.Equals(n2));
76 }
77
78 TEST_F(EqualsTest, EqualsMap) {
79 auto n1(NamedRegion::New());
80 n1->name = "foo";
81 n1->rects.push_back(CreateRect());
82
83 Map<std::string, NamedRegionPtr> m1;
84 m1.insert("foo", n1.Pass());
85
86 decltype(m1) m2;
87 EXPECT_FALSE(m1.Equals(m2));
88
89 m2.insert("bar", m1.at("foo").Clone());
90 EXPECT_FALSE(m1.Equals(m2));
91
92 m2 = m1.Clone();
93 m2.at("foo")->name = "monkey";
94 EXPECT_FALSE(m1.Equals(m2));
95
96 m2 = m1.Clone();
97 m2.at("foo")->rects.push_back(Rect::New());
98 EXPECT_FALSE(m1.Equals(m2));
99
100 m2.at("foo")->rects.resize(1);
101 m2.at("foo")->rects[0]->width = 1;
102 EXPECT_FALSE(m1.Equals(m2));
103
104 m2 = m1.Clone();
105 EXPECT_TRUE(m1.Equals(m2));
106 }
107
108 } // test
109 } // mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698