| OLD | NEW |
| (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 "gtest/gtest.h" | |
| 6 #include "mojo/public/interfaces/bindings/tests/test_structs.mojom.h" | |
| 7 | |
| 8 namespace mojo { | |
| 9 namespace test { | |
| 10 | |
| 11 namespace { | |
| 12 | |
| 13 RectPtr CreateRect() { | |
| 14 RectPtr r = Rect::New(); | |
| 15 r->x = 1; | |
| 16 r->y = 2; | |
| 17 r->width = 3; | |
| 18 r->height = 4; | |
| 19 return r; | |
| 20 } | |
| 21 | |
| 22 } // namespace | |
| 23 | |
| 24 TEST(EqualsTest, Null) { | |
| 25 RectPtr r1; | |
| 26 RectPtr r2; | |
| 27 EXPECT_TRUE(r1.Equals(r2)); | |
| 28 EXPECT_TRUE(r2.Equals(r1)); | |
| 29 | |
| 30 r1 = CreateRect(); | |
| 31 EXPECT_FALSE(r1.Equals(r2)); | |
| 32 EXPECT_FALSE(r2.Equals(r1)); | |
| 33 } | |
| 34 | |
| 35 TEST(EqualsTest, EqualsStruct) { | |
| 36 RectPtr r1(CreateRect()); | |
| 37 RectPtr r2(r1.Clone()); | |
| 38 EXPECT_TRUE(r1.Equals(r2)); | |
| 39 r2->y = 1; | |
| 40 EXPECT_FALSE(r1.Equals(r2)); | |
| 41 r2.reset(); | |
| 42 EXPECT_FALSE(r1.Equals(r2)); | |
| 43 } | |
| 44 | |
| 45 TEST(EqualsTest, EqualsStructNested) { | |
| 46 RectPairPtr p1(RectPair::New()); | |
| 47 p1->first = CreateRect(); | |
| 48 p1->second = CreateRect(); | |
| 49 RectPairPtr p2(p1.Clone()); | |
| 50 EXPECT_TRUE(p1.Equals(p2)); | |
| 51 p2->second->width = 0; | |
| 52 EXPECT_FALSE(p1.Equals(p2)); | |
| 53 p2->second.reset(); | |
| 54 EXPECT_FALSE(p1.Equals(p2)); | |
| 55 } | |
| 56 | |
| 57 TEST(EqualsTest, EqualsArray) { | |
| 58 NamedRegionPtr n1(NamedRegion::New()); | |
| 59 n1->name = "n1"; | |
| 60 n1->rects.push_back(CreateRect()); | |
| 61 NamedRegionPtr n2(n1.Clone()); | |
| 62 EXPECT_TRUE(n1.Equals(n2)); | |
| 63 | |
| 64 n2->rects.reset(); | |
| 65 EXPECT_FALSE(n1.Equals(n2)); | |
| 66 n2->rects.resize(0); | |
| 67 EXPECT_FALSE(n1.Equals(n2)); | |
| 68 | |
| 69 n2->rects.push_back(CreateRect()); | |
| 70 n2->rects.push_back(CreateRect()); | |
| 71 EXPECT_FALSE(n1.Equals(n2)); | |
| 72 | |
| 73 n2->rects.resize(1); | |
| 74 n2->rects[0]->width = 0; | |
| 75 EXPECT_FALSE(n1.Equals(n2)); | |
| 76 | |
| 77 n2->rects[0] = CreateRect(); | |
| 78 EXPECT_TRUE(n1.Equals(n2)); | |
| 79 } | |
| 80 | |
| 81 TEST(EqualsTest, EqualsMap) { | |
| 82 auto n1(NamedRegion::New()); | |
| 83 n1->name = "foo"; | |
| 84 n1->rects.push_back(CreateRect()); | |
| 85 | |
| 86 Map<std::string, NamedRegionPtr> m1; | |
| 87 m1.insert("foo", n1.Pass()); | |
| 88 | |
| 89 decltype(m1) m2; | |
| 90 EXPECT_FALSE(m1.Equals(m2)); | |
| 91 | |
| 92 m2.insert("bar", m1.at("foo").Clone()); | |
| 93 EXPECT_FALSE(m1.Equals(m2)); | |
| 94 | |
| 95 m2 = m1.Clone(); | |
| 96 m2.at("foo")->name = "monkey"; | |
| 97 EXPECT_FALSE(m1.Equals(m2)); | |
| 98 | |
| 99 m2 = m1.Clone(); | |
| 100 m2.at("foo")->rects.push_back(Rect::New()); | |
| 101 EXPECT_FALSE(m1.Equals(m2)); | |
| 102 | |
| 103 m2.at("foo")->rects.resize(1); | |
| 104 m2.at("foo")->rects[0]->width = 1; | |
| 105 EXPECT_FALSE(m1.Equals(m2)); | |
| 106 | |
| 107 m2 = m1.Clone(); | |
| 108 EXPECT_TRUE(m1.Equals(m2)); | |
| 109 } | |
| 110 | |
| 111 } // test | |
| 112 } // mojo | |
| OLD | NEW |