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

Side by Side Diff: mojo/edk/system/data_pipe_unittest.cc

Issue 728553002: Update mojo sdk to rev afb4440fd5a10cba980878c326180b7ad7960480 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « mojo/edk/system/data_pipe_consumer_dispatcher.cc ('k') | mojo/edk/system/dispatcher.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/edk/system/data_pipe.h" 5 #include "mojo/edk/system/data_pipe.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <limits> 10 #include <limits>
11 11
12 #include "mojo/edk/system/constants.h" 12 #include "mojo/edk/system/configuration.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 namespace mojo { 15 namespace mojo {
16 namespace system { 16 namespace system {
17 namespace { 17 namespace {
18 18
19 const uint32_t kSizeOfCreateOptions = 19 const uint32_t kSizeOfCreateOptions =
20 static_cast<uint32_t>(sizeof(MojoCreateDataPipeOptions)); 20 static_cast<uint32_t>(sizeof(MojoCreateDataPipeOptions));
21 21
22 // Does a cursory sanity check of |validated_options|. Calls 22 // Does a cursory sanity check of |validated_options|. Calls
23 // |ValidateCreateOptions()| on already-validated options. The validated options 23 // |ValidateCreateOptions()| on already-validated options. The validated options
24 // should be valid, and the revalidated copy should be the same. 24 // should be valid, and the revalidated copy should be the same.
25 void RevalidateCreateOptions( 25 void RevalidateCreateOptions(
26 const MojoCreateDataPipeOptions& validated_options) { 26 const MojoCreateDataPipeOptions& validated_options) {
27 EXPECT_EQ(kSizeOfCreateOptions, validated_options.struct_size); 27 EXPECT_EQ(kSizeOfCreateOptions, validated_options.struct_size);
28 // Nothing to check for flags. 28 // Nothing to check for flags.
29 EXPECT_GT(validated_options.element_num_bytes, 0u); 29 EXPECT_GT(validated_options.element_num_bytes, 0u);
30 EXPECT_GT(validated_options.capacity_num_bytes, 0u); 30 EXPECT_GT(validated_options.capacity_num_bytes, 0u);
31 EXPECT_EQ(0u, 31 EXPECT_EQ(0u, validated_options.capacity_num_bytes %
32 validated_options.capacity_num_bytes % 32 validated_options.element_num_bytes);
33 validated_options.element_num_bytes);
34 33
35 MojoCreateDataPipeOptions revalidated_options = {}; 34 MojoCreateDataPipeOptions revalidated_options = {};
36 EXPECT_EQ(MOJO_RESULT_OK, 35 EXPECT_EQ(MOJO_RESULT_OK,
37 DataPipe::ValidateCreateOptions(MakeUserPointer(&validated_options), 36 DataPipe::ValidateCreateOptions(MakeUserPointer(&validated_options),
38 &revalidated_options)); 37 &revalidated_options));
39 EXPECT_EQ(validated_options.struct_size, revalidated_options.struct_size); 38 EXPECT_EQ(validated_options.struct_size, revalidated_options.struct_size);
40 EXPECT_EQ(validated_options.element_num_bytes, 39 EXPECT_EQ(validated_options.element_num_bytes,
41 revalidated_options.element_num_bytes); 40 revalidated_options.element_num_bytes);
42 EXPECT_EQ(validated_options.capacity_num_bytes, 41 EXPECT_EQ(validated_options.capacity_num_bytes,
43 revalidated_options.capacity_num_bytes); 42 revalidated_options.capacity_num_bytes);
44 EXPECT_EQ(validated_options.flags, revalidated_options.flags); 43 EXPECT_EQ(validated_options.flags, revalidated_options.flags);
45 } 44 }
46 45
47 // Checks that a default-computed capacity is correct. (Does not duplicate the 46 // Checks that a default-computed capacity is correct. (Does not duplicate the
48 // checks done by |RevalidateCreateOptions()|.) 47 // checks done by |RevalidateCreateOptions()|.)
49 void CheckDefaultCapacity(const MojoCreateDataPipeOptions& validated_options) { 48 void CheckDefaultCapacity(const MojoCreateDataPipeOptions& validated_options) {
50 EXPECT_LE(validated_options.capacity_num_bytes, 49 EXPECT_LE(validated_options.capacity_num_bytes,
51 kDefaultDataPipeCapacityBytes); 50 GetConfiguration().default_data_pipe_capacity_bytes);
52 EXPECT_GT(validated_options.capacity_num_bytes + 51 EXPECT_GT(validated_options.capacity_num_bytes +
53 validated_options.element_num_bytes, 52 validated_options.element_num_bytes,
54 kDefaultDataPipeCapacityBytes); 53 GetConfiguration().default_data_pipe_capacity_bytes);
55 } 54 }
56 55
57 // Tests valid inputs to |ValidateCreateOptions()|. 56 // Tests valid inputs to |ValidateCreateOptions()|.
58 TEST(DataPipeTest, ValidateCreateOptionsValid) { 57 TEST(DataPipeTest, ValidateCreateOptionsValid) {
59 // Default options. 58 // Default options.
60 { 59 {
61 MojoCreateDataPipeOptions validated_options = {}; 60 MojoCreateDataPipeOptions validated_options = {};
62 EXPECT_EQ( 61 EXPECT_EQ(MOJO_RESULT_OK, DataPipe::ValidateCreateOptions(
63 MOJO_RESULT_OK, 62 NullUserPointer(), &validated_options));
64 DataPipe::ValidateCreateOptions(NullUserPointer(), &validated_options));
65 RevalidateCreateOptions(validated_options); 63 RevalidateCreateOptions(validated_options);
66 CheckDefaultCapacity(validated_options); 64 CheckDefaultCapacity(validated_options);
67 } 65 }
68 66
69 // Size member, but nothing beyond. 67 // Size member, but nothing beyond.
70 { 68 {
71 MojoCreateDataPipeOptions options = { 69 MojoCreateDataPipeOptions options = {
72 offsetof(MojoCreateDataPipeOptions, flags) // |struct_size|. 70 offsetof(MojoCreateDataPipeOptions, flags) // |struct_size|.
73 }; 71 };
74 MojoCreateDataPipeOptions validated_options = {}; 72 MojoCreateDataPipeOptions validated_options = {};
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 MojoCreateDataPipeOptions unused; 366 MojoCreateDataPipeOptions unused;
369 EXPECT_EQ( 367 EXPECT_EQ(
370 MOJO_RESULT_RESOURCE_EXHAUSTED, 368 MOJO_RESULT_RESOURCE_EXHAUSTED,
371 DataPipe::ValidateCreateOptions(MakeUserPointer(&options), &unused)); 369 DataPipe::ValidateCreateOptions(MakeUserPointer(&options), &unused));
372 } 370 }
373 } 371 }
374 372
375 } // namespace 373 } // namespace
376 } // namespace system 374 } // namespace system
377 } // namespace mojo 375 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/data_pipe_consumer_dispatcher.cc ('k') | mojo/edk/system/dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698