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

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: reorder 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.
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, Null) {
33 RectPtr r1;
34 RectPtr r2;
35 EXPECT_TRUE(r1.Equals(r2));
36 EXPECT_TRUE(r2.Equals(r1));
37
38 r1 = CreateRect();
39 EXPECT_FALSE(r1.Equals(r2));
40 EXPECT_FALSE(r2.Equals(r1));
41 }
42
43 TEST_F(EqualsTest, EqualsStruct) {
44 RectPtr r1(CreateRect());
45 RectPtr r2(r1.Clone());
46 EXPECT_TRUE(r1.Equals(r2));
47 r2->y = 1;
48 EXPECT_FALSE(r1.Equals(r2));
49 r2.reset();
50 EXPECT_FALSE(r1.Equals(r2));
51 }
52
53 TEST_F(EqualsTest, EqualsStructNested) {
54 RectPairPtr p1(RectPair::New());
55 p1->first = CreateRect();
56 p1->second = CreateRect();
57 RectPairPtr p2(p1.Clone());
58 EXPECT_TRUE(p1.Equals(p2));
59 p2->second->width = 0;
60 EXPECT_FALSE(p1.Equals(p2));
61 p2->second.reset();
62 EXPECT_FALSE(p1.Equals(p2));
63 }
64
65 TEST_F(EqualsTest, EqualsArray) {
66 NamedRegionPtr n1(NamedRegion::New());
67 n1->name = "n1";
68 n1->rects.push_back(CreateRect());
69 NamedRegionPtr n2(n1.Clone());
70 EXPECT_TRUE(n1.Equals(n2));
71
72 n2->rects.reset();
73 EXPECT_FALSE(n1.Equals(n2));
74 n2->rects.resize(0);
75 EXPECT_FALSE(n1.Equals(n2));
76
77 n2->rects.push_back(CreateRect());
78 n2->rects.push_back(CreateRect());
79 EXPECT_FALSE(n1.Equals(n2));
80
81 n2->rects.resize(1);
82 n2->rects[0]->width = 0;
83 EXPECT_FALSE(n1.Equals(n2));
84
85 n2->rects[0] = CreateRect();
86 EXPECT_TRUE(n1.Equals(n2));
87 }
88
89 TEST_F(EqualsTest, EqualsMap) {
90 auto n1(NamedRegion::New());
91 n1->name = "foo";
92 n1->rects.push_back(CreateRect());
93
94 Map<std::string, NamedRegionPtr> m1;
95 m1.insert("foo", n1.Pass());
96
97 decltype(m1) m2;
98 EXPECT_FALSE(m1.Equals(m2));
99
100 m2.insert("bar", m1.at("foo").Clone());
101 EXPECT_FALSE(m1.Equals(m2));
102
103 m2 = m1.Clone();
104 m2.at("foo")->name = "monkey";
105 EXPECT_FALSE(m1.Equals(m2));
106
107 m2 = m1.Clone();
108 m2.at("foo")->rects.push_back(Rect::New());
109 EXPECT_FALSE(m1.Equals(m2));
110
111 m2.at("foo")->rects.resize(1);
112 m2.at("foo")->rects[0]->width = 1;
113 EXPECT_FALSE(m1.Equals(m2));
114
115 m2 = m1.Clone();
116 EXPECT_TRUE(m1.Equals(m2));
117 }
118
119 } // test
120 } // mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698