| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "mojo/public/cpp/environment/environment.h" | |
| 6 #include "mojo/public/interfaces/bindings/tests/test_structs.mojom.h" | 5 #include "mojo/public/interfaces/bindings/tests/test_structs.mojom.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
| 8 | 7 |
| 9 namespace mojo { | 8 namespace mojo { |
| 10 namespace test { | 9 namespace test { |
| 11 | 10 |
| 12 namespace { | 11 namespace { |
| 13 | 12 |
| 14 RectPtr CreateRect() { | 13 RectPtr CreateRect() { |
| 15 RectPtr r = Rect::New(); | 14 RectPtr r = Rect::New(); |
| 16 r->x = 1; | 15 r->x = 1; |
| 17 r->y = 2; | 16 r->y = 2; |
| 18 r->width = 3; | 17 r->width = 3; |
| 19 r->height = 4; | 18 r->height = 4; |
| 20 return r; | 19 return r; |
| 21 } | 20 } |
| 22 | 21 |
| 23 class EqualsTest : public testing::Test { | 22 } // namespace |
| 24 public: | |
| 25 ~EqualsTest() override {} | |
| 26 | 23 |
| 27 private: | 24 TEST(EqualsTest, Null) { |
| 28 Environment env_; | |
| 29 }; | |
| 30 } | |
| 31 | |
| 32 TEST_F(EqualsTest, Null) { | |
| 33 RectPtr r1; | 25 RectPtr r1; |
| 34 RectPtr r2; | 26 RectPtr r2; |
| 35 EXPECT_TRUE(r1.Equals(r2)); | 27 EXPECT_TRUE(r1.Equals(r2)); |
| 36 EXPECT_TRUE(r2.Equals(r1)); | 28 EXPECT_TRUE(r2.Equals(r1)); |
| 37 | 29 |
| 38 r1 = CreateRect(); | 30 r1 = CreateRect(); |
| 39 EXPECT_FALSE(r1.Equals(r2)); | 31 EXPECT_FALSE(r1.Equals(r2)); |
| 40 EXPECT_FALSE(r2.Equals(r1)); | 32 EXPECT_FALSE(r2.Equals(r1)); |
| 41 } | 33 } |
| 42 | 34 |
| 43 TEST_F(EqualsTest, EqualsStruct) { | 35 TEST(EqualsTest, EqualsStruct) { |
| 44 RectPtr r1(CreateRect()); | 36 RectPtr r1(CreateRect()); |
| 45 RectPtr r2(r1.Clone()); | 37 RectPtr r2(r1.Clone()); |
| 46 EXPECT_TRUE(r1.Equals(r2)); | 38 EXPECT_TRUE(r1.Equals(r2)); |
| 47 r2->y = 1; | 39 r2->y = 1; |
| 48 EXPECT_FALSE(r1.Equals(r2)); | 40 EXPECT_FALSE(r1.Equals(r2)); |
| 49 r2.reset(); | 41 r2.reset(); |
| 50 EXPECT_FALSE(r1.Equals(r2)); | 42 EXPECT_FALSE(r1.Equals(r2)); |
| 51 } | 43 } |
| 52 | 44 |
| 53 TEST_F(EqualsTest, EqualsStructNested) { | 45 TEST(EqualsTest, EqualsStructNested) { |
| 54 RectPairPtr p1(RectPair::New()); | 46 RectPairPtr p1(RectPair::New()); |
| 55 p1->first = CreateRect(); | 47 p1->first = CreateRect(); |
| 56 p1->second = CreateRect(); | 48 p1->second = CreateRect(); |
| 57 RectPairPtr p2(p1.Clone()); | 49 RectPairPtr p2(p1.Clone()); |
| 58 EXPECT_TRUE(p1.Equals(p2)); | 50 EXPECT_TRUE(p1.Equals(p2)); |
| 59 p2->second->width = 0; | 51 p2->second->width = 0; |
| 60 EXPECT_FALSE(p1.Equals(p2)); | 52 EXPECT_FALSE(p1.Equals(p2)); |
| 61 p2->second.reset(); | 53 p2->second.reset(); |
| 62 EXPECT_FALSE(p1.Equals(p2)); | 54 EXPECT_FALSE(p1.Equals(p2)); |
| 63 } | 55 } |
| 64 | 56 |
| 65 TEST_F(EqualsTest, EqualsArray) { | 57 TEST(EqualsTest, EqualsArray) { |
| 66 NamedRegionPtr n1(NamedRegion::New()); | 58 NamedRegionPtr n1(NamedRegion::New()); |
| 67 n1->name = "n1"; | 59 n1->name = "n1"; |
| 68 n1->rects.push_back(CreateRect()); | 60 n1->rects.push_back(CreateRect()); |
| 69 NamedRegionPtr n2(n1.Clone()); | 61 NamedRegionPtr n2(n1.Clone()); |
| 70 EXPECT_TRUE(n1.Equals(n2)); | 62 EXPECT_TRUE(n1.Equals(n2)); |
| 71 | 63 |
| 72 n2->rects.reset(); | 64 n2->rects.reset(); |
| 73 EXPECT_FALSE(n1.Equals(n2)); | 65 EXPECT_FALSE(n1.Equals(n2)); |
| 74 n2->rects.resize(0); | 66 n2->rects.resize(0); |
| 75 EXPECT_FALSE(n1.Equals(n2)); | 67 EXPECT_FALSE(n1.Equals(n2)); |
| 76 | 68 |
| 77 n2->rects.push_back(CreateRect()); | 69 n2->rects.push_back(CreateRect()); |
| 78 n2->rects.push_back(CreateRect()); | 70 n2->rects.push_back(CreateRect()); |
| 79 EXPECT_FALSE(n1.Equals(n2)); | 71 EXPECT_FALSE(n1.Equals(n2)); |
| 80 | 72 |
| 81 n2->rects.resize(1); | 73 n2->rects.resize(1); |
| 82 n2->rects[0]->width = 0; | 74 n2->rects[0]->width = 0; |
| 83 EXPECT_FALSE(n1.Equals(n2)); | 75 EXPECT_FALSE(n1.Equals(n2)); |
| 84 | 76 |
| 85 n2->rects[0] = CreateRect(); | 77 n2->rects[0] = CreateRect(); |
| 86 EXPECT_TRUE(n1.Equals(n2)); | 78 EXPECT_TRUE(n1.Equals(n2)); |
| 87 } | 79 } |
| 88 | 80 |
| 89 TEST_F(EqualsTest, EqualsMap) { | 81 TEST(EqualsTest, EqualsMap) { |
| 90 auto n1(NamedRegion::New()); | 82 auto n1(NamedRegion::New()); |
| 91 n1->name = "foo"; | 83 n1->name = "foo"; |
| 92 n1->rects.push_back(CreateRect()); | 84 n1->rects.push_back(CreateRect()); |
| 93 | 85 |
| 94 Map<std::string, NamedRegionPtr> m1; | 86 Map<std::string, NamedRegionPtr> m1; |
| 95 m1.insert("foo", n1.Pass()); | 87 m1.insert("foo", n1.Pass()); |
| 96 | 88 |
| 97 decltype(m1) m2; | 89 decltype(m1) m2; |
| 98 EXPECT_FALSE(m1.Equals(m2)); | 90 EXPECT_FALSE(m1.Equals(m2)); |
| 99 | 91 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 111 m2.at("foo")->rects.resize(1); | 103 m2.at("foo")->rects.resize(1); |
| 112 m2.at("foo")->rects[0]->width = 1; | 104 m2.at("foo")->rects[0]->width = 1; |
| 113 EXPECT_FALSE(m1.Equals(m2)); | 105 EXPECT_FALSE(m1.Equals(m2)); |
| 114 | 106 |
| 115 m2 = m1.Clone(); | 107 m2 = m1.Clone(); |
| 116 EXPECT_TRUE(m1.Equals(m2)); | 108 EXPECT_TRUE(m1.Equals(m2)); |
| 117 } | 109 } |
| 118 | 110 |
| 119 } // test | 111 } // test |
| 120 } // mojo | 112 } // mojo |
| OLD | NEW |