| 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 <utility> | 5 #include <utility> |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "mojo/public/interfaces/bindings/tests/test_structs.mojom.h" | 8 #include "mojo/public/interfaces/bindings/tests/test_structs.mojom.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| 11 namespace mojo { | 11 namespace mojo { |
| 12 namespace test { | 12 namespace test { |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 RectPtr CreateRect() { | 16 RectPtr CreateRect() { |
| 17 RectPtr r = Rect::New(); | 17 return Rect::New(1, 2, 3, 4); |
| 18 r->x = 1; | |
| 19 r->y = 2; | |
| 20 r->width = 3; | |
| 21 r->height = 4; | |
| 22 return r; | |
| 23 } | 18 } |
| 24 | 19 |
| 25 using EqualsTest = testing::Test; | 20 using EqualsTest = testing::Test; |
| 26 | 21 |
| 27 } // namespace | 22 } // namespace |
| 28 | 23 |
| 29 TEST_F(EqualsTest, NullStruct) { | 24 TEST_F(EqualsTest, NullStruct) { |
| 30 RectPtr r1; | 25 RectPtr r1; |
| 31 RectPtr r2; | 26 RectPtr r2; |
| 32 EXPECT_TRUE(r1.Equals(r2)); | 27 EXPECT_TRUE(r1.Equals(r2)); |
| 33 EXPECT_TRUE(r2.Equals(r1)); | 28 EXPECT_TRUE(r2.Equals(r1)); |
| 34 | 29 |
| 35 r1 = CreateRect(); | 30 r1 = CreateRect(); |
| 36 EXPECT_FALSE(r1.Equals(r2)); | 31 EXPECT_FALSE(r1.Equals(r2)); |
| 37 EXPECT_FALSE(r2.Equals(r1)); | 32 EXPECT_FALSE(r2.Equals(r1)); |
| 38 } | 33 } |
| 39 | 34 |
| 40 TEST_F(EqualsTest, Struct) { | 35 TEST_F(EqualsTest, Struct) { |
| 41 RectPtr r1(CreateRect()); | 36 RectPtr r1(CreateRect()); |
| 42 RectPtr r2(r1.Clone()); | 37 RectPtr r2(r1.Clone()); |
| 43 EXPECT_TRUE(r1.Equals(r2)); | 38 EXPECT_TRUE(r1.Equals(r2)); |
| 44 r2->y = 1; | 39 r2->y = 1; |
| 45 EXPECT_FALSE(r1.Equals(r2)); | 40 EXPECT_FALSE(r1.Equals(r2)); |
| 46 r2.reset(); | 41 r2.reset(); |
| 47 EXPECT_FALSE(r1.Equals(r2)); | 42 EXPECT_FALSE(r1.Equals(r2)); |
| 48 } | 43 } |
| 49 | 44 |
| 50 TEST_F(EqualsTest, StructNested) { | 45 TEST_F(EqualsTest, StructNested) { |
| 51 RectPairPtr p1(RectPair::New()); | 46 RectPairPtr p1(RectPair::New(CreateRect(), CreateRect())); |
| 52 p1->first = CreateRect(); | |
| 53 p1->second = CreateRect(); | |
| 54 RectPairPtr p2(p1.Clone()); | 47 RectPairPtr p2(p1.Clone()); |
| 55 EXPECT_TRUE(p1.Equals(p2)); | 48 EXPECT_TRUE(p1.Equals(p2)); |
| 56 p2->second->width = 0; | 49 p2->second->width = 0; |
| 57 EXPECT_FALSE(p1.Equals(p2)); | 50 EXPECT_FALSE(p1.Equals(p2)); |
| 58 p2->second.reset(); | 51 p2->second.reset(); |
| 59 EXPECT_FALSE(p1.Equals(p2)); | 52 EXPECT_FALSE(p1.Equals(p2)); |
| 60 } | 53 } |
| 61 | 54 |
| 62 TEST_F(EqualsTest, Array) { | 55 TEST_F(EqualsTest, Array) { |
| 63 NamedRegionPtr n1(NamedRegion::New()); | 56 std::vector<RectPtr> rects; |
| 64 n1->name.emplace("n1"); | 57 rects.push_back(CreateRect()); |
| 65 n1->rects.emplace(); | 58 NamedRegionPtr n1(NamedRegion::New(std::string("n1"), std::move(rects))); |
| 66 n1->rects->push_back(CreateRect()); | |
| 67 NamedRegionPtr n2(n1.Clone()); | 59 NamedRegionPtr n2(n1.Clone()); |
| 68 EXPECT_TRUE(n1.Equals(n2)); | 60 EXPECT_TRUE(n1.Equals(n2)); |
| 69 | 61 |
| 70 n2->rects = base::nullopt; | 62 n2->rects = base::nullopt; |
| 71 EXPECT_FALSE(n1.Equals(n2)); | 63 EXPECT_FALSE(n1.Equals(n2)); |
| 72 n2->rects.emplace(); | 64 n2->rects.emplace(); |
| 73 EXPECT_FALSE(n1.Equals(n2)); | 65 EXPECT_FALSE(n1.Equals(n2)); |
| 74 | 66 |
| 75 n2->rects->push_back(CreateRect()); | 67 n2->rects->push_back(CreateRect()); |
| 76 n2->rects->push_back(CreateRect()); | 68 n2->rects->push_back(CreateRect()); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 EXPECT_FALSE(req1.Equals(req2)); | 113 EXPECT_FALSE(req1.Equals(req2)); |
| 122 | 114 |
| 123 SomeInterfacePtr inf2; | 115 SomeInterfacePtr inf2; |
| 124 req2 = MakeRequest(&inf2); | 116 req2 = MakeRequest(&inf2); |
| 125 | 117 |
| 126 EXPECT_FALSE(req1.Equals(req2)); | 118 EXPECT_FALSE(req1.Equals(req2)); |
| 127 } | 119 } |
| 128 | 120 |
| 129 } // test | 121 } // test |
| 130 } // mojo | 122 } // mojo |
| OLD | NEW |