OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "base/macros.h" | 5 #include "base/macros.h" |
6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "mojo/public/cpp/bindings/binding.h" | 8 #include "mojo/public/cpp/bindings/binding.h" |
9 #include "mojo/public/cpp/bindings/lib/fixed_buffer.h" | 9 #include "mojo/public/cpp/bindings/lib/fixed_buffer.h" |
10 #include "mojo/public/cpp/bindings/lib/serialization.h" | 10 #include "mojo/public/cpp/bindings/lib/serialization.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 TEST_F(WTFTypesTest, Serialization_WTFArrayToWTFArray) { | 67 TEST_F(WTFTypesTest, Serialization_WTFArrayToWTFArray) { |
68 WTFArray<WTF::String> strs = ConstructStringArray(); | 68 WTFArray<WTF::String> strs = ConstructStringArray(); |
69 WTFArray<WTF::String> cloned_strs = strs.Clone(); | 69 WTFArray<WTF::String> cloned_strs = strs.Clone(); |
70 | 70 |
71 mojo::internal::SerializationContext context; | 71 mojo::internal::SerializationContext context; |
72 size_t size = mojo::internal::PrepareToSerialize<Array<mojo::String>>( | 72 size_t size = mojo::internal::PrepareToSerialize<Array<mojo::String>>( |
73 cloned_strs, &context); | 73 cloned_strs, &context); |
74 | 74 |
75 mojo::internal::FixedBufferForTesting buf(size); | 75 mojo::internal::FixedBufferForTesting buf(size); |
76 mojo::internal::Array_Data<mojo::internal::String_Data*>* data; | 76 mojo::internal::Array_Data<mojo::internal::String_Data*>* data; |
77 mojo::internal::ArrayValidateParams validate_params( | 77 mojo::internal::ContainerValidateParams validate_params( |
78 0, true, new mojo::internal::ArrayValidateParams(0, false, nullptr)); | 78 0, true, new mojo::internal::ContainerValidateParams(0, false, nullptr)); |
79 mojo::internal::Serialize<Array<mojo::String>>(cloned_strs, &buf, &data, | 79 mojo::internal::Serialize<Array<mojo::String>>(cloned_strs, &buf, &data, |
80 &validate_params, &context); | 80 &validate_params, &context); |
81 | 81 |
82 WTFArray<WTF::String> strs2; | 82 WTFArray<WTF::String> strs2; |
83 mojo::internal::Deserialize<Array<mojo::String>>(data, &strs2, nullptr); | 83 mojo::internal::Deserialize<Array<mojo::String>>(data, &strs2, nullptr); |
84 | 84 |
85 EXPECT_TRUE(strs.Equals(strs2)); | 85 EXPECT_TRUE(strs.Equals(strs2)); |
86 } | 86 } |
87 | 87 |
88 TEST_F(WTFTypesTest, Serialization_WTFVectorToWTFVector) { | 88 TEST_F(WTFTypesTest, Serialization_WTFVectorToWTFVector) { |
89 WTF::Vector<WTF::String> strs = ConstructStringArray().PassStorage(); | 89 WTF::Vector<WTF::String> strs = ConstructStringArray().PassStorage(); |
90 WTF::Vector<WTF::String> cloned_strs = strs; | 90 WTF::Vector<WTF::String> cloned_strs = strs; |
91 | 91 |
92 mojo::internal::SerializationContext context; | 92 mojo::internal::SerializationContext context; |
93 size_t size = mojo::internal::PrepareToSerialize<Array<mojo::String>>( | 93 size_t size = mojo::internal::PrepareToSerialize<Array<mojo::String>>( |
94 cloned_strs, &context); | 94 cloned_strs, &context); |
95 | 95 |
96 mojo::internal::FixedBufferForTesting buf(size); | 96 mojo::internal::FixedBufferForTesting buf(size); |
97 mojo::internal::Array_Data<mojo::internal::String_Data*>* data; | 97 mojo::internal::Array_Data<mojo::internal::String_Data*>* data; |
98 mojo::internal::ArrayValidateParams validate_params( | 98 mojo::internal::ContainerValidateParams validate_params( |
99 0, true, new mojo::internal::ArrayValidateParams(0, false, nullptr)); | 99 0, true, new mojo::internal::ContainerValidateParams(0, false, nullptr)); |
100 mojo::internal::Serialize<Array<mojo::String>>(cloned_strs, &buf, &data, | 100 mojo::internal::Serialize<Array<mojo::String>>(cloned_strs, &buf, &data, |
101 &validate_params, &context); | 101 &validate_params, &context); |
102 | 102 |
103 WTF::Vector<WTF::String> strs2; | 103 WTF::Vector<WTF::String> strs2; |
104 mojo::internal::Deserialize<Array<mojo::String>>(data, &strs2, nullptr); | 104 mojo::internal::Deserialize<Array<mojo::String>>(data, &strs2, nullptr); |
105 | 105 |
106 EXPECT_EQ(strs, strs2); | 106 EXPECT_EQ(strs, strs2); |
107 } | 107 } |
108 | 108 |
109 TEST_F(WTFTypesTest, Serialization_WTFArrayToMojoArray) { | 109 TEST_F(WTFTypesTest, Serialization_WTFArrayToMojoArray) { |
110 WTFArray<WTF::String> strs = ConstructStringArray(); | 110 WTFArray<WTF::String> strs = ConstructStringArray(); |
111 | 111 |
112 mojo::internal::SerializationContext context; | 112 mojo::internal::SerializationContext context; |
113 size_t size = | 113 size_t size = |
114 mojo::internal::PrepareToSerialize<Array<mojo::String>>(strs, &context); | 114 mojo::internal::PrepareToSerialize<Array<mojo::String>>(strs, &context); |
115 | 115 |
116 mojo::internal::FixedBufferForTesting buf(size); | 116 mojo::internal::FixedBufferForTesting buf(size); |
117 mojo::internal::Array_Data<mojo::internal::String_Data*>* data; | 117 mojo::internal::Array_Data<mojo::internal::String_Data*>* data; |
118 mojo::internal::ArrayValidateParams validate_params( | 118 mojo::internal::ContainerValidateParams validate_params( |
119 0, true, new mojo::internal::ArrayValidateParams(0, false, nullptr)); | 119 0, true, new mojo::internal::ContainerValidateParams(0, false, nullptr)); |
120 mojo::internal::Serialize<Array<mojo::String>>(strs, &buf, &data, | 120 mojo::internal::Serialize<Array<mojo::String>>(strs, &buf, &data, |
121 &validate_params, &context); | 121 &validate_params, &context); |
122 | 122 |
123 Array<mojo::String> strs2; | 123 Array<mojo::String> strs2; |
124 mojo::internal::Deserialize<Array<mojo::String>>(data, &strs2, nullptr); | 124 mojo::internal::Deserialize<Array<mojo::String>>(data, &strs2, nullptr); |
125 | 125 |
126 ASSERT_EQ(4u, strs2.size()); | 126 ASSERT_EQ(4u, strs2.size()); |
127 EXPECT_TRUE(strs2[0].is_null()); | 127 EXPECT_TRUE(strs2[0].is_null()); |
128 EXPECT_TRUE("" == strs2[1]); | 128 EXPECT_TRUE("" == strs2[1]); |
129 EXPECT_TRUE(kHelloWorld == strs2[2]); | 129 EXPECT_TRUE(kHelloWorld == strs2[2]); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 [&loop, &expected_arr, &i](WTFArray<WTF::String> arr) { | 174 [&loop, &expected_arr, &i](WTFArray<WTF::String> arr) { |
175 EXPECT_TRUE(expected_arr.Equals(arr)); | 175 EXPECT_TRUE(expected_arr.Equals(arr)); |
176 loop.Quit(); | 176 loop.Quit(); |
177 }); | 177 }); |
178 loop.Run(); | 178 loop.Run(); |
179 } | 179 } |
180 } | 180 } |
181 | 181 |
182 } // namespace test | 182 } // namespace test |
183 } // namespace mojo | 183 } // namespace mojo |
OLD | NEW |