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

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

Issue 1618963006: Mojo C++ bindings: support enum validation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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"
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 internal::PodUnion_Data* data = internal::PodUnion_Data::New(&buf); 257 internal::PodUnion_Data* data = internal::PodUnion_Data::New(&buf);
258 data->tag = static_cast<internal::PodUnion_Data::PodUnion_Tag>(0xFFFFFF); 258 data->tag = static_cast<internal::PodUnion_Data::PodUnion_Tag>(0xFFFFFF);
259 mojo::internal::BoundsChecker bounds_checker(data, 259 mojo::internal::BoundsChecker bounds_checker(data,
260 static_cast<uint32_t>(size), 0); 260 static_cast<uint32_t>(size), 0);
261 void* raw_buf = buf.Leak(); 261 void* raw_buf = buf.Leak();
262 EXPECT_FALSE( 262 EXPECT_FALSE(
263 internal::PodUnion_Data::Validate(raw_buf, &bounds_checker, false)); 263 internal::PodUnion_Data::Validate(raw_buf, &bounds_checker, false));
264 free(raw_buf); 264 free(raw_buf);
265 } 265 }
266 266
267 TEST(UnionTest, UnknownEnumValueValidation) {
268 PodUnionPtr pod(PodUnion::New());
269 pod->set_f_enum(static_cast<AnEnum>(0xFFFF));
270
271 size_t size = GetSerializedSize_(pod, false);
272 EXPECT_EQ(16U, size);
273
274 mojo::internal::FixedBufferForTesting buf(size);
275 internal::PodUnion_Data* data = nullptr;
276 SerializeUnion_(std::move(pod), &buf, &data, false);
277
278 void* raw_buf = buf.Leak();
279 mojo::internal::BoundsChecker bounds_checker(data,
280 static_cast<uint32_t>(size), 0);
281 EXPECT_FALSE(
282 internal::PodUnion_Data::Validate(raw_buf, &bounds_checker, false));
283 free(raw_buf);
284 }
285
286 TEST(UnionTest, UnknownExtensibleEnumValueValidation) {
287 PodUnionPtr pod(PodUnion::New());
288 pod->set_f_extensible_enum(static_cast<AnExtensibleEnum>(0xFFFF));
289
290 size_t size = GetSerializedSize_(pod, false);
291 EXPECT_EQ(16U, size);
292
293 mojo::internal::FixedBufferForTesting buf(size);
294 internal::PodUnion_Data* data = nullptr;
295 SerializeUnion_(std::move(pod), &buf, &data, false);
296
297 void* raw_buf = buf.Leak();
298 mojo::internal::BoundsChecker bounds_checker(data,
299 static_cast<uint32_t>(size), 0);
300 EXPECT_TRUE(
301 internal::PodUnion_Data::Validate(raw_buf, &bounds_checker, false));
302 free(raw_buf);
303 }
304
267 TEST(UnionTest, StringGetterSetter) { 305 TEST(UnionTest, StringGetterSetter) {
268 ObjectUnionPtr pod(ObjectUnion::New()); 306 ObjectUnionPtr pod(ObjectUnion::New());
269 307
270 String hello("hello world"); 308 String hello("hello world");
271 pod->set_f_string(hello); 309 pod->set_f_string(hello);
272 EXPECT_EQ(hello, pod->get_f_string()); 310 EXPECT_EQ(hello, pod->get_f_string());
273 EXPECT_TRUE(pod->is_f_string()); 311 EXPECT_TRUE(pod->is_f_string());
274 EXPECT_EQ(pod->which(), ObjectUnion::Tag::F_STRING); 312 EXPECT_EQ(pod->which(), ObjectUnion::Tag::F_STRING);
275 } 313 }
276 314
(...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after
1133 PodUnionPtr pod(PodUnion::New()); 1171 PodUnionPtr pod(PodUnion::New());
1134 pod->set_f_int16(16); 1172 pod->set_f_int16(16);
1135 1173
1136 ptr->Echo(std::move(pod), 1174 ptr->Echo(std::move(pod),
1137 [](PodUnionPtr out) { EXPECT_EQ(16, out->get_f_int16()); }); 1175 [](PodUnionPtr out) { EXPECT_EQ(16, out->get_f_int16()); });
1138 run_loop.RunUntilIdle(); 1176 run_loop.RunUntilIdle();
1139 } 1177 }
1140 1178
1141 } // namespace test 1179 } // namespace test
1142 } // namespace mojo 1180 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/validation_util.h ('k') | mojo/public/cpp/bindings/tests/validation_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698