| 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/bindings/lib/fixed_buffer.h" | 5 #include "mojo/public/cpp/bindings/lib/fixed_buffer.h" |
| 6 #include "mojo/public/cpp/environment/environment.h" | 6 #include "mojo/public/cpp/environment/environment.h" |
| 7 #include "mojo/public/interfaces/bindings/tests/test_structs.mojom.h" | 7 #include "mojo/public/interfaces/bindings/tests/test_structs.mojom.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 namespace mojo { | 10 namespace mojo { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 EXPECT_FALSE(rect); | 44 EXPECT_FALSE(rect); |
| 45 | 45 |
| 46 rect = MakeRect(); | 46 rect = MakeRect(); |
| 47 EXPECT_FALSE(rect.is_null()); | 47 EXPECT_FALSE(rect.is_null()); |
| 48 EXPECT_FALSE(!rect); | 48 EXPECT_FALSE(!rect); |
| 49 EXPECT_TRUE(rect); | 49 EXPECT_TRUE(rect); |
| 50 | 50 |
| 51 CheckRect(*rect); | 51 CheckRect(*rect); |
| 52 } | 52 } |
| 53 | 53 |
| 54 TEST_F(StructTest, Clone) { |
| 55 NamedRegionPtr region; |
| 56 |
| 57 NamedRegionPtr clone_region = region.Clone(); |
| 58 EXPECT_TRUE(clone_region.is_null()); |
| 59 |
| 60 region = NamedRegion::New(); |
| 61 clone_region = region.Clone(); |
| 62 EXPECT_TRUE(clone_region->name.is_null()); |
| 63 EXPECT_TRUE(clone_region->rects.is_null()); |
| 64 |
| 65 region->name = "hello world"; |
| 66 clone_region = region.Clone(); |
| 67 EXPECT_EQ(region->name, clone_region->name); |
| 68 |
| 69 region->rects = Array<RectPtr>(2); |
| 70 region->rects[1] = MakeRect(); |
| 71 clone_region = region.Clone(); |
| 72 EXPECT_EQ(2u, clone_region->rects.size()); |
| 73 EXPECT_TRUE(clone_region->rects[0].is_null()); |
| 74 CheckRect(*clone_region->rects[1]); |
| 75 |
| 76 // NoDefaultFieldValues contains handles, so Clone() is not available, but |
| 77 // NoDefaultFieldValuesPtr should still compile. |
| 78 NoDefaultFieldValuesPtr no_default_field_values(NoDefaultFieldValues::New()); |
| 79 EXPECT_FALSE(no_default_field_values->f13.is_valid()); |
| 80 } |
| 81 |
| 54 // Serialization test of a struct with no pointer or handle members. | 82 // Serialization test of a struct with no pointer or handle members. |
| 55 TEST_F(StructTest, Serialization_Basic) { | 83 TEST_F(StructTest, Serialization_Basic) { |
| 56 RectPtr rect(MakeRect()); | 84 RectPtr rect(MakeRect()); |
| 57 | 85 |
| 58 size_t size = GetSerializedSize_(rect); | 86 size_t size = GetSerializedSize_(rect); |
| 59 EXPECT_EQ(8U + 16U, size); | 87 EXPECT_EQ(8U + 16U, size); |
| 60 | 88 |
| 61 mojo::internal::FixedBuffer buf(size); | 89 mojo::internal::FixedBuffer buf(size); |
| 62 internal::Rect_Data* data; | 90 internal::Rect_Data* data; |
| 63 Serialize_(rect.Pass(), &buf, &data); | 91 Serialize_(rect.Pass(), &buf, &data); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 | 168 |
| 141 NamedRegionPtr region2; | 169 NamedRegionPtr region2; |
| 142 Deserialize_(data, ®ion2); | 170 Deserialize_(data, ®ion2); |
| 143 | 171 |
| 144 EXPECT_TRUE(region2->name.is_null()); | 172 EXPECT_TRUE(region2->name.is_null()); |
| 145 EXPECT_TRUE(region2->rects.is_null()); | 173 EXPECT_TRUE(region2->rects.is_null()); |
| 146 } | 174 } |
| 147 | 175 |
| 148 } // namespace test | 176 } // namespace test |
| 149 } // namespace mojo | 177 } // namespace mojo |
| OLD | NEW |