Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Side by Side Diff: mojo/public/cpp/bindings/tests/union_unittest.cc

Issue 1552983003: Fix a bunch of mojo_public_*_unittests with the new EDK. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 #include <utility> 7 #include <utility>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/run_loop.h"
11 #include "mojo/message_pump/message_pump_mojo.h" 12 #include "mojo/message_pump/message_pump_mojo.h"
12 #include "mojo/public/cpp/bindings/array.h" 13 #include "mojo/public/cpp/bindings/array.h"
13 #include "mojo/public/cpp/bindings/binding.h" 14 #include "mojo/public/cpp/bindings/binding.h"
14 #include "mojo/public/cpp/bindings/lib/array_internal.h" 15 #include "mojo/public/cpp/bindings/lib/array_internal.h"
15 #include "mojo/public/cpp/bindings/lib/array_serialization.h" 16 #include "mojo/public/cpp/bindings/lib/array_serialization.h"
16 #include "mojo/public/cpp/bindings/lib/bounds_checker.h" 17 #include "mojo/public/cpp/bindings/lib/bounds_checker.h"
17 #include "mojo/public/cpp/bindings/lib/fixed_buffer.h" 18 #include "mojo/public/cpp/bindings/lib/fixed_buffer.h"
18 #include "mojo/public/cpp/bindings/string.h" 19 #include "mojo/public/cpp/bindings/string.h"
19 #include "mojo/public/cpp/test_support/test_utils.h" 20 #include "mojo/public/cpp/test_support/test_utils.h"
20 #include "mojo/public/interfaces/bindings/tests/test_structs.mojom.h" 21 #include "mojo/public/interfaces/bindings/tests/test_structs.mojom.h"
(...skipping 1022 matching lines...) Expand 10 before | Expand all | Expand 10 after
1043 void* raw_buf = buf.Leak(); 1044 void* raw_buf = buf.Leak();
1044 mojo::internal::BoundsChecker bounds_checker(data, 1045 mojo::internal::BoundsChecker bounds_checker(data,
1045 static_cast<uint32_t>(size), 1); 1046 static_cast<uint32_t>(size), 1);
1046 EXPECT_FALSE( 1047 EXPECT_FALSE(
1047 internal::HandleUnion_Data::Validate(raw_buf, &bounds_checker, false)); 1048 internal::HandleUnion_Data::Validate(raw_buf, &bounds_checker, false));
1048 free(raw_buf); 1049 free(raw_buf);
1049 } 1050 }
1050 1051
1051 class SmallCacheImpl : public SmallCache { 1052 class SmallCacheImpl : public SmallCache {
1052 public: 1053 public:
1053 SmallCacheImpl() : int_value_(0) {} 1054 explicit SmallCacheImpl(const base::Closure& closure)
1055 : int_value_(0), closure_(closure) {}
1054 ~SmallCacheImpl() override {} 1056 ~SmallCacheImpl() override {}
1055 int64_t int_value() const { return int_value_; } 1057 int64_t int_value() const { return int_value_; }
1056 1058
1057 private: 1059 private:
1058 void SetIntValue(int64_t int_value) override { int_value_ = int_value; } 1060 void SetIntValue(int64_t int_value) override {
1061 int_value_ = int_value;
1062 closure_.Run();
1063 }
1059 void GetIntValue(const GetIntValueCallback& callback) override { 1064 void GetIntValue(const GetIntValueCallback& callback) override {
1060 callback.Run(int_value_); 1065 callback.Run(int_value_);
1061 } 1066 }
1062 1067
1063 int64_t int_value_; 1068 int64_t int_value_;
1069 base::Closure closure_;
1064 }; 1070 };
1065 1071
1066 TEST(UnionTest, InterfaceInUnion) { 1072 TEST(UnionTest, InterfaceInUnion) {
1067 base::MessageLoop run_loop(common::MessagePumpMojo::Create()); 1073 base::MessageLoop message_loop(common::MessagePumpMojo::Create());
1068 SmallCacheImpl impl; 1074 base::RunLoop run_loop;
1075 SmallCacheImpl impl(run_loop.QuitClosure());
1069 SmallCachePtr ptr; 1076 SmallCachePtr ptr;
1070 Binding<SmallCache> bindings(&impl, GetProxy(&ptr)); 1077 Binding<SmallCache> bindings(&impl, GetProxy(&ptr));
1071 1078
1072 HandleUnionPtr handle(HandleUnion::New()); 1079 HandleUnionPtr handle(HandleUnion::New());
1073 handle->set_f_small_cache(std::move(ptr)); 1080 handle->set_f_small_cache(std::move(ptr));
1074 1081
1075 handle->get_f_small_cache()->SetIntValue(10); 1082 handle->get_f_small_cache()->SetIntValue(10);
1076 run_loop.RunUntilIdle(); 1083 run_loop.Run();
1077 EXPECT_EQ(10, impl.int_value()); 1084 EXPECT_EQ(10, impl.int_value());
1078 } 1085 }
1079 1086
1080 TEST(UnionTest, InterfaceInUnionSerialization) { 1087 TEST(UnionTest, InterfaceInUnionSerialization) {
1081 base::MessageLoop run_loop(common::MessagePumpMojo::Create()); 1088 base::MessageLoop message_loop(common::MessagePumpMojo::Create());
1082 SmallCacheImpl impl; 1089 base::RunLoop run_loop;
1090 SmallCacheImpl impl(run_loop.QuitClosure());
1083 SmallCachePtr ptr; 1091 SmallCachePtr ptr;
1084 Binding<SmallCache> bindings(&impl, GetProxy(&ptr)); 1092 Binding<SmallCache> bindings(&impl, GetProxy(&ptr));
1085 1093
1086 HandleUnionPtr handle(HandleUnion::New()); 1094 HandleUnionPtr handle(HandleUnion::New());
1087 handle->set_f_small_cache(std::move(ptr)); 1095 handle->set_f_small_cache(std::move(ptr));
1088 size_t size = GetSerializedSize_(handle, false); 1096 size_t size = GetSerializedSize_(handle, false);
1089 EXPECT_EQ(16U, size); 1097 EXPECT_EQ(16U, size);
1090 1098
1091 mojo::internal::FixedBufferForTesting buf(size); 1099 mojo::internal::FixedBufferForTesting buf(size);
1092 internal::HandleUnion_Data* data = nullptr; 1100 internal::HandleUnion_Data* data = nullptr;
1093 SerializeUnion_(std::move(handle), &buf, &data, false); 1101 SerializeUnion_(std::move(handle), &buf, &data, false);
1094 1102
1095 std::vector<Handle> handles; 1103 std::vector<Handle> handles;
1096 data->EncodePointersAndHandles(&handles); 1104 data->EncodePointersAndHandles(&handles);
1097 EXPECT_EQ(1U, handles.size()); 1105 EXPECT_EQ(1U, handles.size());
1098 data->DecodePointersAndHandles(&handles); 1106 data->DecodePointersAndHandles(&handles);
1099 1107
1100 HandleUnionPtr handle2(HandleUnion::New()); 1108 HandleUnionPtr handle2(HandleUnion::New());
1101 Deserialize_(data, &handle2, nullptr); 1109 Deserialize_(data, &handle2, nullptr);
1102 1110
1103 handle2->get_f_small_cache()->SetIntValue(10); 1111 handle2->get_f_small_cache()->SetIntValue(10);
1104 run_loop.RunUntilIdle(); 1112 run_loop.Run();
1105 EXPECT_EQ(10, impl.int_value()); 1113 EXPECT_EQ(10, impl.int_value());
1106 } 1114 }
1107 1115
1108 class UnionInterfaceImpl : public UnionInterface { 1116 class UnionInterfaceImpl : public UnionInterface {
1109 public: 1117 public:
1110 UnionInterfaceImpl() {} 1118 UnionInterfaceImpl() {}
1111 ~UnionInterfaceImpl() override {} 1119 ~UnionInterfaceImpl() override {}
1112 1120
1113 private: 1121 private:
1114 void Echo(PodUnionPtr in, const EchoCallback& callback) override { 1122 void Echo(PodUnionPtr in, const EchoCallback& callback) override {
(...skipping 10 matching lines...) Expand all
1125 PodUnionPtr pod(PodUnion::New()); 1133 PodUnionPtr pod(PodUnion::New());
1126 pod->set_f_int16(16); 1134 pod->set_f_int16(16);
1127 1135
1128 ptr->Echo(std::move(pod), 1136 ptr->Echo(std::move(pod),
1129 [](PodUnionPtr out) { EXPECT_EQ(16, out->get_f_int16()); }); 1137 [](PodUnionPtr out) { EXPECT_EQ(16, out->get_f_int16()); });
1130 run_loop.RunUntilIdle(); 1138 run_loop.RunUntilIdle();
1131 } 1139 }
1132 1140
1133 } // namespace test 1141 } // namespace test
1134 } // namespace mojo 1142 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/tests/router_unittest.cc ('k') | mojo/public/cpp/bindings/tests/validation_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698