| 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 <vector> | 6 #include <vector> |
| 7 |
| 6 #include "mojo/public/cpp/bindings/array.h" | 8 #include "mojo/public/cpp/bindings/array.h" |
| 7 #include "mojo/public/cpp/bindings/binding.h" | 9 #include "mojo/public/cpp/bindings/binding.h" |
| 8 #include "mojo/public/cpp/bindings/lib/array_internal.h" | 10 #include "mojo/public/cpp/bindings/lib/array_internal.h" |
| 9 #include "mojo/public/cpp/bindings/lib/array_serialization.h" | 11 #include "mojo/public/cpp/bindings/lib/array_serialization.h" |
| 10 #include "mojo/public/cpp/bindings/lib/bounds_checker.h" | 12 #include "mojo/public/cpp/bindings/lib/bounds_checker.h" |
| 11 #include "mojo/public/cpp/bindings/lib/fixed_buffer.h" | 13 #include "mojo/public/cpp/bindings/lib/fixed_buffer.h" |
| 12 #include "mojo/public/cpp/bindings/lib/map_serialization.h" | 14 #include "mojo/public/cpp/bindings/lib/map_serialization.h" |
| 13 #include "mojo/public/cpp/bindings/string.h" | 15 #include "mojo/public/cpp/bindings/string.h" |
| 14 #include "mojo/public/cpp/environment/environment.h" | 16 #include "mojo/public/cpp/environment/environment.h" |
| 15 #include "mojo/public/cpp/test_support/test_utils.h" | 17 #include "mojo/public/cpp/test_support/test_utils.h" |
| (...skipping 1201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1217 TEST(UnionTest, InterfaceInUnion) { | 1219 TEST(UnionTest, InterfaceInUnion) { |
| 1218 Environment env; | 1220 Environment env; |
| 1219 RunLoop run_loop; | 1221 RunLoop run_loop; |
| 1220 SmallCacheImpl impl; | 1222 SmallCacheImpl impl; |
| 1221 SmallCachePtr ptr; | 1223 SmallCachePtr ptr; |
| 1222 Binding<SmallCache> bindings(&impl, GetProxy(&ptr)); | 1224 Binding<SmallCache> bindings(&impl, GetProxy(&ptr)); |
| 1223 | 1225 |
| 1224 HandleUnionPtr handle(HandleUnion::New()); | 1226 HandleUnionPtr handle(HandleUnion::New()); |
| 1225 handle->set_f_small_cache(ptr.Pass()); | 1227 handle->set_f_small_cache(ptr.Pass()); |
| 1226 | 1228 |
| 1227 handle->get_f_small_cache()->SetIntValue(10); | 1229 auto small_cache = |
| 1230 SmallCachePtr::Create(std::move(handle->get_f_small_cache())); |
| 1231 small_cache->SetIntValue(10); |
| 1228 run_loop.RunUntilIdle(); | 1232 run_loop.RunUntilIdle(); |
| 1229 EXPECT_EQ(10, impl.int_value()); | 1233 EXPECT_EQ(10, impl.int_value()); |
| 1230 } | 1234 } |
| 1231 | 1235 |
| 1232 TEST(UnionTest, InterfaceInUnionSerialization) { | 1236 TEST(UnionTest, InterfaceInUnionSerialization) { |
| 1233 Environment env; | 1237 Environment env; |
| 1234 RunLoop run_loop; | 1238 RunLoop run_loop; |
| 1235 SmallCacheImpl impl; | 1239 SmallCacheImpl impl; |
| 1236 SmallCachePtr ptr; | 1240 SmallCachePtr ptr; |
| 1237 Binding<SmallCache> bindings(&impl, GetProxy(&ptr)); | 1241 Binding<SmallCache> bindings(&impl, GetProxy(&ptr)); |
| 1238 | 1242 |
| 1239 HandleUnionPtr handle(HandleUnion::New()); | 1243 HandleUnionPtr handle(HandleUnion::New()); |
| 1240 handle->set_f_small_cache(ptr.Pass()); | 1244 handle->set_f_small_cache(ptr.Pass()); |
| 1241 size_t size = GetSerializedSize_(handle, false); | 1245 size_t size = GetSerializedSize_(handle, false); |
| 1242 EXPECT_EQ(16U, size); | 1246 EXPECT_EQ(16U, size); |
| 1243 | 1247 |
| 1244 mojo::internal::FixedBufferForTesting buf(size); | 1248 mojo::internal::FixedBufferForTesting buf(size); |
| 1245 internal::HandleUnion_Data* data = nullptr; | 1249 internal::HandleUnion_Data* data = nullptr; |
| 1246 SerializeUnion_(handle.get(), &buf, &data, false); | 1250 SerializeUnion_(handle.get(), &buf, &data, false); |
| 1247 | 1251 |
| 1248 std::vector<Handle> handles; | 1252 std::vector<Handle> handles; |
| 1249 data->EncodePointersAndHandles(&handles); | 1253 data->EncodePointersAndHandles(&handles); |
| 1250 EXPECT_EQ(1U, handles.size()); | 1254 EXPECT_EQ(1U, handles.size()); |
| 1251 data->DecodePointersAndHandles(&handles); | 1255 data->DecodePointersAndHandles(&handles); |
| 1252 | 1256 |
| 1253 HandleUnionPtr handle2(HandleUnion::New()); | 1257 HandleUnionPtr handle2(HandleUnion::New()); |
| 1254 Deserialize_(data, handle2.get()); | 1258 Deserialize_(data, handle2.get()); |
| 1255 | 1259 |
| 1256 handle2->get_f_small_cache()->SetIntValue(10); | 1260 auto small_cache = |
| 1261 SmallCachePtr::Create(std::move(handle2->get_f_small_cache())); |
| 1262 small_cache->SetIntValue(10); |
| 1257 run_loop.RunUntilIdle(); | 1263 run_loop.RunUntilIdle(); |
| 1258 EXPECT_EQ(10, impl.int_value()); | 1264 EXPECT_EQ(10, impl.int_value()); |
| 1259 } | 1265 } |
| 1260 | 1266 |
| 1261 class UnionInterfaceImpl : public UnionInterface { | 1267 class UnionInterfaceImpl : public UnionInterface { |
| 1262 public: | 1268 public: |
| 1263 UnionInterfaceImpl() {} | 1269 UnionInterfaceImpl() {} |
| 1264 ~UnionInterfaceImpl() override {} | 1270 ~UnionInterfaceImpl() override {} |
| 1265 | 1271 |
| 1266 private: | 1272 private: |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1279 PodUnionPtr pod(PodUnion::New()); | 1285 PodUnionPtr pod(PodUnion::New()); |
| 1280 pod->set_f_int16(16); | 1286 pod->set_f_int16(16); |
| 1281 | 1287 |
| 1282 ptr->Echo(pod.Pass(), | 1288 ptr->Echo(pod.Pass(), |
| 1283 [](PodUnionPtr out) { EXPECT_EQ(16, out->get_f_int16()); }); | 1289 [](PodUnionPtr out) { EXPECT_EQ(16, out->get_f_int16()); }); |
| 1284 run_loop.RunUntilIdle(); | 1290 run_loop.RunUntilIdle(); |
| 1285 } | 1291 } |
| 1286 | 1292 |
| 1287 } // namespace test | 1293 } // namespace test |
| 1288 } // namespace mojo | 1294 } // namespace mojo |
| OLD | NEW |