OLD | NEW |
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/local_data_pipe_impl.h" | 5 #include "mojo/edk/system/local_data_pipe_impl.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "mojo/edk/system/data_pipe.h" | 11 #include "mojo/edk/system/data_pipe.h" |
12 #include "mojo/edk/system/waiter.h" | 12 #include "mojo/edk/system/waiter.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 kSizeOfOptions = | 19 const uint32_t kSizeOfOptions = |
20 static_cast<uint32_t>(sizeof(MojoCreateDataPipeOptions)); | 20 static_cast<uint32_t>(sizeof(MojoCreateDataPipeOptions)); |
21 | 21 |
22 // Validate options. | 22 // Validate options. |
23 TEST(LocalDataPipeImplTest, Creation) { | 23 TEST(LocalDataPipeImplTest, Creation) { |
24 // Create using default options. | 24 // Create using default options. |
25 { | 25 { |
26 // Get default options. | 26 // Get default options. |
27 MojoCreateDataPipeOptions default_options = {0}; | 27 MojoCreateDataPipeOptions default_options = {0}; |
28 EXPECT_EQ(MOJO_RESULT_OK, DataPipe::ValidateCreateOptions( | 28 EXPECT_EQ(MOJO_RESULT_OK, DataPipe::ValidateCreateOptions( |
29 NullUserPointer(), &default_options)); | 29 NullUserPointer(), &default_options)); |
30 scoped_refptr<LocalDataPipeImpl> dp(new LocalDataPipeImpl(default_options)); | 30 scoped_refptr<DataPipe> dp(DataPipe::CreateLocal(default_options)); |
31 dp->ProducerClose(); | 31 dp->ProducerClose(); |
32 dp->ConsumerClose(); | 32 dp->ConsumerClose(); |
33 } | 33 } |
34 | 34 |
35 // Create using non-default options. | 35 // Create using non-default options. |
36 { | 36 { |
37 const MojoCreateDataPipeOptions options = { | 37 const MojoCreateDataPipeOptions options = { |
38 kSizeOfOptions, // |struct_size|. | 38 kSizeOfOptions, // |struct_size|. |
39 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|. | 39 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|. |
40 1, // |element_num_bytes|. | 40 1, // |element_num_bytes|. |
41 1000 // |capacity_num_bytes|. | 41 1000 // |capacity_num_bytes|. |
42 }; | 42 }; |
43 MojoCreateDataPipeOptions validated_options = {0}; | 43 MojoCreateDataPipeOptions validated_options = {0}; |
44 EXPECT_EQ(MOJO_RESULT_OK, | 44 EXPECT_EQ(MOJO_RESULT_OK, |
45 DataPipe::ValidateCreateOptions(MakeUserPointer(&options), | 45 DataPipe::ValidateCreateOptions(MakeUserPointer(&options), |
46 &validated_options)); | 46 &validated_options)); |
47 scoped_refptr<LocalDataPipeImpl> dp( | 47 scoped_refptr<DataPipe> dp(DataPipe::CreateLocal(validated_options)); |
48 new LocalDataPipeImpl(validated_options)); | |
49 dp->ProducerClose(); | 48 dp->ProducerClose(); |
50 dp->ConsumerClose(); | 49 dp->ConsumerClose(); |
51 } | 50 } |
52 { | 51 { |
53 const MojoCreateDataPipeOptions options = { | 52 const MojoCreateDataPipeOptions options = { |
54 kSizeOfOptions, // |struct_size|. | 53 kSizeOfOptions, // |struct_size|. |
55 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|. | 54 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|. |
56 4, // |element_num_bytes|. | 55 4, // |element_num_bytes|. |
57 4000 // |capacity_num_bytes|. | 56 4000 // |capacity_num_bytes|. |
58 }; | 57 }; |
59 MojoCreateDataPipeOptions validated_options = {0}; | 58 MojoCreateDataPipeOptions validated_options = {0}; |
60 EXPECT_EQ(MOJO_RESULT_OK, | 59 EXPECT_EQ(MOJO_RESULT_OK, |
61 DataPipe::ValidateCreateOptions(MakeUserPointer(&options), | 60 DataPipe::ValidateCreateOptions(MakeUserPointer(&options), |
62 &validated_options)); | 61 &validated_options)); |
63 scoped_refptr<LocalDataPipeImpl> dp( | 62 scoped_refptr<DataPipe> dp(DataPipe::CreateLocal(validated_options)); |
64 new LocalDataPipeImpl(validated_options)); | |
65 dp->ProducerClose(); | 63 dp->ProducerClose(); |
66 dp->ConsumerClose(); | 64 dp->ConsumerClose(); |
67 } | 65 } |
68 { | 66 { |
69 const MojoCreateDataPipeOptions options = { | 67 const MojoCreateDataPipeOptions options = { |
70 kSizeOfOptions, // |struct_size|. | 68 kSizeOfOptions, // |struct_size|. |
71 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_MAY_DISCARD, // |flags|. | 69 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_MAY_DISCARD, // |flags|. |
72 7, // |element_num_bytes|. | 70 7, // |element_num_bytes|. |
73 7000000 // |capacity_num_bytes|. | 71 7000000 // |capacity_num_bytes|. |
74 }; | 72 }; |
75 MojoCreateDataPipeOptions validated_options = {0}; | 73 MojoCreateDataPipeOptions validated_options = {0}; |
76 EXPECT_EQ(MOJO_RESULT_OK, | 74 EXPECT_EQ(MOJO_RESULT_OK, |
77 DataPipe::ValidateCreateOptions(MakeUserPointer(&options), | 75 DataPipe::ValidateCreateOptions(MakeUserPointer(&options), |
78 &validated_options)); | 76 &validated_options)); |
79 scoped_refptr<LocalDataPipeImpl> dp( | 77 scoped_refptr<DataPipe> dp(DataPipe::CreateLocal(validated_options)); |
80 new LocalDataPipeImpl(validated_options)); | |
81 dp->ProducerClose(); | 78 dp->ProducerClose(); |
82 dp->ConsumerClose(); | 79 dp->ConsumerClose(); |
83 } | 80 } |
84 // Default capacity. | 81 // Default capacity. |
85 { | 82 { |
86 const MojoCreateDataPipeOptions options = { | 83 const MojoCreateDataPipeOptions options = { |
87 kSizeOfOptions, // |struct_size|. | 84 kSizeOfOptions, // |struct_size|. |
88 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_MAY_DISCARD, // |flags|. | 85 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_MAY_DISCARD, // |flags|. |
89 100, // |element_num_bytes|. | 86 100, // |element_num_bytes|. |
90 0 // |capacity_num_bytes|. | 87 0 // |capacity_num_bytes|. |
91 }; | 88 }; |
92 MojoCreateDataPipeOptions validated_options = {0}; | 89 MojoCreateDataPipeOptions validated_options = {0}; |
93 EXPECT_EQ(MOJO_RESULT_OK, | 90 EXPECT_EQ(MOJO_RESULT_OK, |
94 DataPipe::ValidateCreateOptions(MakeUserPointer(&options), | 91 DataPipe::ValidateCreateOptions(MakeUserPointer(&options), |
95 &validated_options)); | 92 &validated_options)); |
96 scoped_refptr<LocalDataPipeImpl> dp( | 93 scoped_refptr<DataPipe> dp(DataPipe::CreateLocal(validated_options)); |
97 new LocalDataPipeImpl(validated_options)); | |
98 dp->ProducerClose(); | 94 dp->ProducerClose(); |
99 dp->ConsumerClose(); | 95 dp->ConsumerClose(); |
100 } | 96 } |
101 } | 97 } |
102 | 98 |
103 TEST(LocalDataPipeImplTest, SimpleReadWrite) { | 99 TEST(LocalDataPipeImplTest, SimpleReadWrite) { |
104 const MojoCreateDataPipeOptions options = { | 100 const MojoCreateDataPipeOptions options = { |
105 kSizeOfOptions, // |struct_size|. | 101 kSizeOfOptions, // |struct_size|. |
106 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|. | 102 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|. |
107 static_cast<uint32_t>(sizeof(int32_t)), // |element_num_bytes|. | 103 static_cast<uint32_t>(sizeof(int32_t)), // |element_num_bytes|. |
108 1000 * sizeof(int32_t) // |capacity_num_bytes|. | 104 1000 * sizeof(int32_t) // |capacity_num_bytes|. |
109 }; | 105 }; |
110 MojoCreateDataPipeOptions validated_options = {0}; | 106 MojoCreateDataPipeOptions validated_options = {0}; |
111 EXPECT_EQ(MOJO_RESULT_OK, DataPipe::ValidateCreateOptions( | 107 EXPECT_EQ(MOJO_RESULT_OK, DataPipe::ValidateCreateOptions( |
112 MakeUserPointer(&options), &validated_options)); | 108 MakeUserPointer(&options), &validated_options)); |
113 | 109 |
114 scoped_refptr<LocalDataPipeImpl> dp(new LocalDataPipeImpl(validated_options)); | 110 scoped_refptr<DataPipe> dp(DataPipe::CreateLocal(validated_options)); |
115 | 111 |
116 int32_t elements[10] = {0}; | 112 int32_t elements[10] = {0}; |
117 uint32_t num_bytes = 0; | 113 uint32_t num_bytes = 0; |
118 | 114 |
119 // Try reading; nothing there yet. | 115 // Try reading; nothing there yet. |
120 num_bytes = static_cast<uint32_t>(arraysize(elements) * sizeof(elements[0])); | 116 num_bytes = static_cast<uint32_t>(arraysize(elements) * sizeof(elements[0])); |
121 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT, | 117 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT, |
122 dp->ConsumerReadData(UserPointer<void>(elements), | 118 dp->ConsumerReadData(UserPointer<void>(elements), |
123 MakeUserPointer(&num_bytes), false, false)); | 119 MakeUserPointer(&num_bytes), false, false)); |
124 | 120 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 const MojoCreateDataPipeOptions options = { | 220 const MojoCreateDataPipeOptions options = { |
225 kSizeOfOptions, // |struct_size|. | 221 kSizeOfOptions, // |struct_size|. |
226 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|. | 222 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|. |
227 static_cast<uint32_t>(sizeof(int32_t)), // |element_num_bytes|. | 223 static_cast<uint32_t>(sizeof(int32_t)), // |element_num_bytes|. |
228 2 * sizeof(int32_t) // |capacity_num_bytes|. | 224 2 * sizeof(int32_t) // |capacity_num_bytes|. |
229 }; | 225 }; |
230 MojoCreateDataPipeOptions validated_options = {0}; | 226 MojoCreateDataPipeOptions validated_options = {0}; |
231 EXPECT_EQ(MOJO_RESULT_OK, DataPipe::ValidateCreateOptions( | 227 EXPECT_EQ(MOJO_RESULT_OK, DataPipe::ValidateCreateOptions( |
232 MakeUserPointer(&options), &validated_options)); | 228 MakeUserPointer(&options), &validated_options)); |
233 | 229 |
234 scoped_refptr<LocalDataPipeImpl> dp(new LocalDataPipeImpl(validated_options)); | 230 scoped_refptr<DataPipe> dp(DataPipe::CreateLocal(validated_options)); |
235 Waiter waiter; | 231 Waiter waiter; |
236 uint32_t context = 0; | 232 uint32_t context = 0; |
237 HandleSignalsState hss; | 233 HandleSignalsState hss; |
238 | 234 |
239 // Never readable. | 235 // Never readable. |
240 waiter.Init(); | 236 waiter.Init(); |
241 hss = HandleSignalsState(); | 237 hss = HandleSignalsState(); |
242 EXPECT_EQ( | 238 EXPECT_EQ( |
243 MOJO_RESULT_FAILED_PRECONDITION, | 239 MOJO_RESULT_FAILED_PRECONDITION, |
244 dp->ProducerAddAwakable(&waiter, MOJO_HANDLE_SIGNAL_READABLE, 12, &hss)); | 240 dp->ProducerAddAwakable(&waiter, MOJO_HANDLE_SIGNAL_READABLE, 12, &hss)); |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 }; | 401 }; |
406 MojoCreateDataPipeOptions validated_options = {0}; | 402 MojoCreateDataPipeOptions validated_options = {0}; |
407 EXPECT_EQ(MOJO_RESULT_OK, DataPipe::ValidateCreateOptions( | 403 EXPECT_EQ(MOJO_RESULT_OK, DataPipe::ValidateCreateOptions( |
408 MakeUserPointer(&options), &validated_options)); | 404 MakeUserPointer(&options), &validated_options)); |
409 | 405 |
410 Waiter waiter; | 406 Waiter waiter; |
411 HandleSignalsState hss; | 407 HandleSignalsState hss; |
412 | 408 |
413 // Check MOJO_HANDLE_SIGNAL_PEER_CLOSED on producer. | 409 // Check MOJO_HANDLE_SIGNAL_PEER_CLOSED on producer. |
414 { | 410 { |
415 scoped_refptr<LocalDataPipeImpl> dp( | 411 scoped_refptr<DataPipe> dp(DataPipe::CreateLocal(validated_options)); |
416 new LocalDataPipeImpl(validated_options)); | |
417 // Add a waiter. | 412 // Add a waiter. |
418 waiter.Init(); | 413 waiter.Init(); |
419 ASSERT_EQ(MOJO_RESULT_OK, | 414 ASSERT_EQ(MOJO_RESULT_OK, |
420 dp->ProducerAddAwakable(&waiter, MOJO_HANDLE_SIGNAL_PEER_CLOSED, | 415 dp->ProducerAddAwakable(&waiter, MOJO_HANDLE_SIGNAL_PEER_CLOSED, |
421 12, nullptr)); | 416 12, nullptr)); |
422 | 417 |
423 // Close the consumer. | 418 // Close the consumer. |
424 dp->ConsumerClose(); | 419 dp->ConsumerClose(); |
425 | 420 |
426 // It should be signaled. | 421 // It should be signaled. |
427 uint32_t context = 0; | 422 uint32_t context = 0; |
428 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(1000, &context)); | 423 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(1000, &context)); |
429 EXPECT_EQ(12u, context); | 424 EXPECT_EQ(12u, context); |
430 hss = HandleSignalsState(); | 425 hss = HandleSignalsState(); |
431 dp->ProducerRemoveAwakable(&waiter, &hss); | 426 dp->ProducerRemoveAwakable(&waiter, &hss); |
432 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfied_signals); | 427 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfied_signals); |
433 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfiable_signals); | 428 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfiable_signals); |
434 | 429 |
435 dp->ProducerClose(); | 430 dp->ProducerClose(); |
436 } | 431 } |
437 | 432 |
438 // Check MOJO_HANDLE_SIGNAL_PEER_CLOSED on consumer. | 433 // Check MOJO_HANDLE_SIGNAL_PEER_CLOSED on consumer. |
439 { | 434 { |
440 scoped_refptr<LocalDataPipeImpl> dp( | 435 scoped_refptr<DataPipe> dp(DataPipe::CreateLocal(validated_options)); |
441 new LocalDataPipeImpl(validated_options)); | |
442 // Add a waiter. | 436 // Add a waiter. |
443 waiter.Init(); | 437 waiter.Init(); |
444 ASSERT_EQ(MOJO_RESULT_OK, | 438 ASSERT_EQ(MOJO_RESULT_OK, |
445 dp->ConsumerAddAwakable(&waiter, MOJO_HANDLE_SIGNAL_PEER_CLOSED, | 439 dp->ConsumerAddAwakable(&waiter, MOJO_HANDLE_SIGNAL_PEER_CLOSED, |
446 12, nullptr)); | 440 12, nullptr)); |
447 | 441 |
448 // Close the producer. | 442 // Close the producer. |
449 dp->ProducerClose(); | 443 dp->ProducerClose(); |
450 | 444 |
451 // It should be signaled. | 445 // It should be signaled. |
(...skipping 14 matching lines...) Expand all Loading... |
466 kSizeOfOptions, // |struct_size|. | 460 kSizeOfOptions, // |struct_size|. |
467 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|. | 461 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|. |
468 static_cast<uint32_t>(sizeof(int32_t)), // |element_num_bytes|. | 462 static_cast<uint32_t>(sizeof(int32_t)), // |element_num_bytes|. |
469 1000 * sizeof(int32_t) // |capacity_num_bytes|. | 463 1000 * sizeof(int32_t) // |capacity_num_bytes|. |
470 }; | 464 }; |
471 MojoCreateDataPipeOptions validated_options = {0}; | 465 MojoCreateDataPipeOptions validated_options = {0}; |
472 EXPECT_EQ(MOJO_RESULT_OK, DataPipe::ValidateCreateOptions( | 466 EXPECT_EQ(MOJO_RESULT_OK, DataPipe::ValidateCreateOptions( |
473 MakeUserPointer(&options), &validated_options)); | 467 MakeUserPointer(&options), &validated_options)); |
474 | 468 |
475 { | 469 { |
476 scoped_refptr<LocalDataPipeImpl> dp( | 470 scoped_refptr<DataPipe> dp(DataPipe::CreateLocal(validated_options)); |
477 new LocalDataPipeImpl(validated_options)); | |
478 Waiter waiter; | 471 Waiter waiter; |
479 uint32_t context = 0; | 472 uint32_t context = 0; |
480 HandleSignalsState hss; | 473 HandleSignalsState hss; |
481 | 474 |
482 // Never writable. | 475 // Never writable. |
483 waiter.Init(); | 476 waiter.Init(); |
484 hss = HandleSignalsState(); | 477 hss = HandleSignalsState(); |
485 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, | 478 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, |
486 dp->ConsumerAddAwakable(&waiter, MOJO_HANDLE_SIGNAL_WRITABLE, 12, | 479 dp->ConsumerAddAwakable(&waiter, MOJO_HANDLE_SIGNAL_WRITABLE, 12, |
487 &hss)); | 480 &hss)); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 &hss)); | 615 &hss)); |
623 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfied_signals); | 616 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfied_signals); |
624 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfiable_signals); | 617 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfiable_signals); |
625 | 618 |
626 dp->ConsumerClose(); | 619 dp->ConsumerClose(); |
627 } | 620 } |
628 | 621 |
629 // Test with two-phase APIs and closing the producer with an active consumer | 622 // Test with two-phase APIs and closing the producer with an active consumer |
630 // waiter. | 623 // waiter. |
631 { | 624 { |
632 scoped_refptr<LocalDataPipeImpl> dp( | 625 scoped_refptr<DataPipe> dp(DataPipe::CreateLocal(validated_options)); |
633 new LocalDataPipeImpl(validated_options)); | |
634 Waiter waiter; | 626 Waiter waiter; |
635 uint32_t context = 0; | 627 uint32_t context = 0; |
636 HandleSignalsState hss; | 628 HandleSignalsState hss; |
637 | 629 |
638 // Write two elements. | 630 // Write two elements. |
639 int32_t* elements = nullptr; | 631 int32_t* elements = nullptr; |
640 void* buffer = nullptr; | 632 void* buffer = nullptr; |
641 // Request room for three (but we'll only write two). | 633 // Request room for three (but we'll only write two). |
642 uint32_t num_bytes = static_cast<uint32_t>(3u * sizeof(elements[0])); | 634 uint32_t num_bytes = static_cast<uint32_t>(3u * sizeof(elements[0])); |
643 EXPECT_EQ(MOJO_RESULT_OK, | 635 EXPECT_EQ(MOJO_RESULT_OK, |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 const MojoCreateDataPipeOptions options = { | 717 const MojoCreateDataPipeOptions options = { |
726 kSizeOfOptions, // |struct_size|. | 718 kSizeOfOptions, // |struct_size|. |
727 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|. | 719 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|. |
728 static_cast<uint32_t>(sizeof(int32_t)), // |element_num_bytes|. | 720 static_cast<uint32_t>(sizeof(int32_t)), // |element_num_bytes|. |
729 1000 * sizeof(int32_t) // |capacity_num_bytes|. | 721 1000 * sizeof(int32_t) // |capacity_num_bytes|. |
730 }; | 722 }; |
731 MojoCreateDataPipeOptions validated_options = {0}; | 723 MojoCreateDataPipeOptions validated_options = {0}; |
732 EXPECT_EQ(MOJO_RESULT_OK, DataPipe::ValidateCreateOptions( | 724 EXPECT_EQ(MOJO_RESULT_OK, DataPipe::ValidateCreateOptions( |
733 MakeUserPointer(&options), &validated_options)); | 725 MakeUserPointer(&options), &validated_options)); |
734 | 726 |
735 scoped_refptr<LocalDataPipeImpl> dp(new LocalDataPipeImpl(validated_options)); | 727 scoped_refptr<DataPipe> dp(DataPipe::CreateLocal(validated_options)); |
736 Waiter waiter; | 728 Waiter waiter; |
737 HandleSignalsState hss; | 729 HandleSignalsState hss; |
738 | 730 |
739 // It should be writable. | 731 // It should be writable. |
740 waiter.Init(); | 732 waiter.Init(); |
741 hss = HandleSignalsState(); | 733 hss = HandleSignalsState(); |
742 EXPECT_EQ( | 734 EXPECT_EQ( |
743 MOJO_RESULT_ALREADY_EXISTS, | 735 MOJO_RESULT_ALREADY_EXISTS, |
744 dp->ProducerAddAwakable(&waiter, MOJO_HANDLE_SIGNAL_WRITABLE, 0, &hss)); | 736 dp->ProducerAddAwakable(&waiter, MOJO_HANDLE_SIGNAL_WRITABLE, 0, &hss)); |
745 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals); | 737 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals); |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
878 const MojoCreateDataPipeOptions options = { | 870 const MojoCreateDataPipeOptions options = { |
879 kSizeOfOptions, // |struct_size|. | 871 kSizeOfOptions, // |struct_size|. |
880 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_MAY_DISCARD, // |flags|. | 872 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_MAY_DISCARD, // |flags|. |
881 static_cast<uint32_t>(sizeof(int32_t)), // |element_num_bytes|. | 873 static_cast<uint32_t>(sizeof(int32_t)), // |element_num_bytes|. |
882 1 * sizeof(int32_t) // |capacity_num_bytes|. | 874 1 * sizeof(int32_t) // |capacity_num_bytes|. |
883 }; | 875 }; |
884 MojoCreateDataPipeOptions validated_options = {0}; | 876 MojoCreateDataPipeOptions validated_options = {0}; |
885 EXPECT_EQ(MOJO_RESULT_OK, DataPipe::ValidateCreateOptions( | 877 EXPECT_EQ(MOJO_RESULT_OK, DataPipe::ValidateCreateOptions( |
886 MakeUserPointer(&options), &validated_options)); | 878 MakeUserPointer(&options), &validated_options)); |
887 | 879 |
888 scoped_refptr<LocalDataPipeImpl> dp(new LocalDataPipeImpl(validated_options)); | 880 scoped_refptr<DataPipe> dp(DataPipe::CreateLocal(validated_options)); |
889 Waiter waiter; | 881 Waiter waiter; |
890 HandleSignalsState hss; | 882 HandleSignalsState hss; |
891 | 883 |
892 // Writable. | 884 // Writable. |
893 waiter.Init(); | 885 waiter.Init(); |
894 hss = HandleSignalsState(); | 886 hss = HandleSignalsState(); |
895 EXPECT_EQ( | 887 EXPECT_EQ( |
896 MOJO_RESULT_ALREADY_EXISTS, | 888 MOJO_RESULT_ALREADY_EXISTS, |
897 dp->ProducerAddAwakable(&waiter, MOJO_HANDLE_SIGNAL_WRITABLE, 0, &hss)); | 889 dp->ProducerAddAwakable(&waiter, MOJO_HANDLE_SIGNAL_WRITABLE, 0, &hss)); |
898 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals); | 890 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1010 const MojoCreateDataPipeOptions options = { | 1002 const MojoCreateDataPipeOptions options = { |
1011 kSizeOfOptions, // |struct_size|. | 1003 kSizeOfOptions, // |struct_size|. |
1012 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_MAY_DISCARD, // |flags|. | 1004 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_MAY_DISCARD, // |flags|. |
1013 static_cast<uint32_t>(sizeof(int32_t)), // |element_num_bytes|. | 1005 static_cast<uint32_t>(sizeof(int32_t)), // |element_num_bytes|. |
1014 10 * sizeof(int32_t) // |capacity_num_bytes|. | 1006 10 * sizeof(int32_t) // |capacity_num_bytes|. |
1015 }; | 1007 }; |
1016 MojoCreateDataPipeOptions validated_options = {0}; | 1008 MojoCreateDataPipeOptions validated_options = {0}; |
1017 EXPECT_EQ(MOJO_RESULT_OK, DataPipe::ValidateCreateOptions( | 1009 EXPECT_EQ(MOJO_RESULT_OK, DataPipe::ValidateCreateOptions( |
1018 MakeUserPointer(&options), &validated_options)); | 1010 MakeUserPointer(&options), &validated_options)); |
1019 | 1011 |
1020 scoped_refptr<LocalDataPipeImpl> dp(new LocalDataPipeImpl(validated_options)); | 1012 scoped_refptr<DataPipe> dp(DataPipe::CreateLocal(validated_options)); |
1021 | 1013 |
1022 int32_t buffer[100] = {0}; | 1014 int32_t buffer[100] = {0}; |
1023 uint32_t num_bytes = 0; | 1015 uint32_t num_bytes = 0; |
1024 | 1016 |
1025 num_bytes = 20u * sizeof(int32_t); | 1017 num_bytes = 20u * sizeof(int32_t); |
1026 Seq(0, arraysize(buffer), buffer); | 1018 Seq(0, arraysize(buffer), buffer); |
1027 // Try writing more than capacity. (This test relies on the implementation | 1019 // Try writing more than capacity. (This test relies on the implementation |
1028 // enforcing the capacity strictly.) | 1020 // enforcing the capacity strictly.) |
1029 EXPECT_EQ(MOJO_RESULT_OK, | 1021 EXPECT_EQ(MOJO_RESULT_OK, |
1030 dp->ProducerWriteData(UserPointer<const void>(buffer), | 1022 dp->ProducerWriteData(UserPointer<const void>(buffer), |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1203 const MojoCreateDataPipeOptions options = { | 1195 const MojoCreateDataPipeOptions options = { |
1204 kSizeOfOptions, // |struct_size|. | 1196 kSizeOfOptions, // |struct_size|. |
1205 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|. | 1197 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|. |
1206 static_cast<uint32_t>(sizeof(int32_t)), // |element_num_bytes|. | 1198 static_cast<uint32_t>(sizeof(int32_t)), // |element_num_bytes|. |
1207 10 * sizeof(int32_t) // |capacity_num_bytes|. | 1199 10 * sizeof(int32_t) // |capacity_num_bytes|. |
1208 }; | 1200 }; |
1209 MojoCreateDataPipeOptions validated_options = {0}; | 1201 MojoCreateDataPipeOptions validated_options = {0}; |
1210 EXPECT_EQ(MOJO_RESULT_OK, DataPipe::ValidateCreateOptions( | 1202 EXPECT_EQ(MOJO_RESULT_OK, DataPipe::ValidateCreateOptions( |
1211 MakeUserPointer(&options), &validated_options)); | 1203 MakeUserPointer(&options), &validated_options)); |
1212 | 1204 |
1213 scoped_refptr<LocalDataPipeImpl> dp(new LocalDataPipeImpl(validated_options)); | 1205 scoped_refptr<DataPipe> dp(DataPipe::CreateLocal(validated_options)); |
1214 | 1206 |
1215 // Try writing way too much. | 1207 // Try writing way too much. |
1216 uint32_t num_bytes = 20u * sizeof(int32_t); | 1208 uint32_t num_bytes = 20u * sizeof(int32_t); |
1217 int32_t buffer[100]; | 1209 int32_t buffer[100]; |
1218 Seq(0, arraysize(buffer), buffer); | 1210 Seq(0, arraysize(buffer), buffer); |
1219 EXPECT_EQ(MOJO_RESULT_OUT_OF_RANGE, | 1211 EXPECT_EQ(MOJO_RESULT_OUT_OF_RANGE, |
1220 dp->ProducerWriteData(UserPointer<const void>(buffer), | 1212 dp->ProducerWriteData(UserPointer<const void>(buffer), |
1221 MakeUserPointer(&num_bytes), true)); | 1213 MakeUserPointer(&num_bytes), true)); |
1222 | 1214 |
1223 // Should still be empty. | 1215 // Should still be empty. |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1363 const MojoCreateDataPipeOptions options = { | 1355 const MojoCreateDataPipeOptions options = { |
1364 kSizeOfOptions, // |struct_size|. | 1356 kSizeOfOptions, // |struct_size|. |
1365 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_MAY_DISCARD, // |flags|. | 1357 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_MAY_DISCARD, // |flags|. |
1366 static_cast<uint32_t>(sizeof(int32_t)), // |element_num_bytes|. | 1358 static_cast<uint32_t>(sizeof(int32_t)), // |element_num_bytes|. |
1367 10 * sizeof(int32_t) // |capacity_num_bytes|. | 1359 10 * sizeof(int32_t) // |capacity_num_bytes|. |
1368 }; | 1360 }; |
1369 MojoCreateDataPipeOptions validated_options = {0}; | 1361 MojoCreateDataPipeOptions validated_options = {0}; |
1370 EXPECT_EQ(MOJO_RESULT_OK, DataPipe::ValidateCreateOptions( | 1362 EXPECT_EQ(MOJO_RESULT_OK, DataPipe::ValidateCreateOptions( |
1371 MakeUserPointer(&options), &validated_options)); | 1363 MakeUserPointer(&options), &validated_options)); |
1372 | 1364 |
1373 scoped_refptr<LocalDataPipeImpl> dp(new LocalDataPipeImpl(validated_options)); | 1365 scoped_refptr<DataPipe> dp(DataPipe::CreateLocal(validated_options)); |
1374 | 1366 |
1375 // Try writing way too much. | 1367 // Try writing way too much. |
1376 uint32_t num_bytes = 20u * sizeof(int32_t); | 1368 uint32_t num_bytes = 20u * sizeof(int32_t); |
1377 int32_t buffer[100]; | 1369 int32_t buffer[100]; |
1378 Seq(0, arraysize(buffer), buffer); | 1370 Seq(0, arraysize(buffer), buffer); |
1379 EXPECT_EQ(MOJO_RESULT_OUT_OF_RANGE, | 1371 EXPECT_EQ(MOJO_RESULT_OUT_OF_RANGE, |
1380 dp->ProducerWriteData(UserPointer<const void>(buffer), | 1372 dp->ProducerWriteData(UserPointer<const void>(buffer), |
1381 MakeUserPointer(&num_bytes), true)); | 1373 MakeUserPointer(&num_bytes), true)); |
1382 | 1374 |
1383 // Write some stuff. | 1375 // Write some stuff. |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1462 const MojoCreateDataPipeOptions options = { | 1454 const MojoCreateDataPipeOptions options = { |
1463 kSizeOfOptions, // |struct_size|. | 1455 kSizeOfOptions, // |struct_size|. |
1464 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|. | 1456 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|. |
1465 static_cast<uint32_t>(sizeof(int32_t)), // |element_num_bytes|. | 1457 static_cast<uint32_t>(sizeof(int32_t)), // |element_num_bytes|. |
1466 10 * sizeof(int32_t) // |capacity_num_bytes|. | 1458 10 * sizeof(int32_t) // |capacity_num_bytes|. |
1467 }; | 1459 }; |
1468 MojoCreateDataPipeOptions validated_options = {0}; | 1460 MojoCreateDataPipeOptions validated_options = {0}; |
1469 EXPECT_EQ(MOJO_RESULT_OK, DataPipe::ValidateCreateOptions( | 1461 EXPECT_EQ(MOJO_RESULT_OK, DataPipe::ValidateCreateOptions( |
1470 MakeUserPointer(&options), &validated_options)); | 1462 MakeUserPointer(&options), &validated_options)); |
1471 | 1463 |
1472 scoped_refptr<LocalDataPipeImpl> dp(new LocalDataPipeImpl(validated_options)); | 1464 scoped_refptr<DataPipe> dp(DataPipe::CreateLocal(validated_options)); |
1473 | 1465 |
1474 // Try writing way too much (two-phase). | 1466 // Try writing way too much (two-phase). |
1475 uint32_t num_bytes = 20u * sizeof(int32_t); | 1467 uint32_t num_bytes = 20u * sizeof(int32_t); |
1476 void* write_ptr = nullptr; | 1468 void* write_ptr = nullptr; |
1477 EXPECT_EQ(MOJO_RESULT_OUT_OF_RANGE, | 1469 EXPECT_EQ(MOJO_RESULT_OUT_OF_RANGE, |
1478 dp->ProducerBeginWriteData(MakeUserPointer(&write_ptr), | 1470 dp->ProducerBeginWriteData(MakeUserPointer(&write_ptr), |
1479 MakeUserPointer(&num_bytes), true)); | 1471 MakeUserPointer(&num_bytes), true)); |
1480 | 1472 |
1481 // Try writing an amount which isn't a multiple of the element size | 1473 // Try writing an amount which isn't a multiple of the element size |
1482 // (two-phase). | 1474 // (two-phase). |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1604 1u, // |element_num_bytes|. | 1596 1u, // |element_num_bytes|. |
1605 100u // |capacity_num_bytes|. | 1597 100u // |capacity_num_bytes|. |
1606 }; | 1598 }; |
1607 MojoCreateDataPipeOptions validated_options = {0}; | 1599 MojoCreateDataPipeOptions validated_options = {0}; |
1608 EXPECT_EQ(MOJO_RESULT_OK, DataPipe::ValidateCreateOptions( | 1600 EXPECT_EQ(MOJO_RESULT_OK, DataPipe::ValidateCreateOptions( |
1609 MakeUserPointer(&options), &validated_options)); | 1601 MakeUserPointer(&options), &validated_options)); |
1610 // This test won't be valid if |ValidateCreateOptions()| decides to give the | 1602 // This test won't be valid if |ValidateCreateOptions()| decides to give the |
1611 // pipe more space. | 1603 // pipe more space. |
1612 ASSERT_EQ(100u, validated_options.capacity_num_bytes); | 1604 ASSERT_EQ(100u, validated_options.capacity_num_bytes); |
1613 | 1605 |
1614 scoped_refptr<LocalDataPipeImpl> dp(new LocalDataPipeImpl(validated_options)); | 1606 scoped_refptr<DataPipe> dp(DataPipe::CreateLocal(validated_options)); |
1615 | 1607 |
1616 // Write 20 bytes. | 1608 // Write 20 bytes. |
1617 uint32_t num_bytes = 20u; | 1609 uint32_t num_bytes = 20u; |
1618 EXPECT_EQ(MOJO_RESULT_OK, | 1610 EXPECT_EQ(MOJO_RESULT_OK, |
1619 dp->ProducerWriteData(UserPointer<const void>(&test_data[0]), | 1611 dp->ProducerWriteData(UserPointer<const void>(&test_data[0]), |
1620 MakeUserPointer(&num_bytes), false)); | 1612 MakeUserPointer(&num_bytes), false)); |
1621 EXPECT_EQ(20u, num_bytes); | 1613 EXPECT_EQ(20u, num_bytes); |
1622 | 1614 |
1623 // Read 10 bytes. | 1615 // Read 10 bytes. |
1624 unsigned char read_buffer[1000] = {0}; | 1616 unsigned char read_buffer[1000] = {0}; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1687 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|. | 1679 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|. |
1688 1u, // |element_num_bytes|. | 1680 1u, // |element_num_bytes|. |
1689 1000u // |capacity_num_bytes|. | 1681 1000u // |capacity_num_bytes|. |
1690 }; | 1682 }; |
1691 MojoCreateDataPipeOptions validated_options = {0}; | 1683 MojoCreateDataPipeOptions validated_options = {0}; |
1692 EXPECT_EQ(MOJO_RESULT_OK, DataPipe::ValidateCreateOptions( | 1684 EXPECT_EQ(MOJO_RESULT_OK, DataPipe::ValidateCreateOptions( |
1693 MakeUserPointer(&options), &validated_options)); | 1685 MakeUserPointer(&options), &validated_options)); |
1694 | 1686 |
1695 // Close producer first, then consumer. | 1687 // Close producer first, then consumer. |
1696 { | 1688 { |
1697 scoped_refptr<LocalDataPipeImpl> dp( | 1689 scoped_refptr<DataPipe> dp(DataPipe::CreateLocal(validated_options)); |
1698 new LocalDataPipeImpl(validated_options)); | |
1699 | 1690 |
1700 // Write some data, so we'll have something to read. | 1691 // Write some data, so we'll have something to read. |
1701 uint32_t num_bytes = kTestDataSize; | 1692 uint32_t num_bytes = kTestDataSize; |
1702 EXPECT_EQ(MOJO_RESULT_OK, | 1693 EXPECT_EQ(MOJO_RESULT_OK, |
1703 dp->ProducerWriteData(UserPointer<const void>(kTestData), | 1694 dp->ProducerWriteData(UserPointer<const void>(kTestData), |
1704 MakeUserPointer(&num_bytes), false)); | 1695 MakeUserPointer(&num_bytes), false)); |
1705 EXPECT_EQ(kTestDataSize, num_bytes); | 1696 EXPECT_EQ(kTestDataSize, num_bytes); |
1706 | 1697 |
1707 // Write it again, so we'll have something left over. | 1698 // Write it again, so we'll have something left over. |
1708 num_bytes = kTestDataSize; | 1699 num_bytes = kTestDataSize; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1744 MakeUserPointer(&num_bytes), false)); | 1735 MakeUserPointer(&num_bytes), false)); |
1745 EXPECT_TRUE(read_buffer_ptr); | 1736 EXPECT_TRUE(read_buffer_ptr); |
1746 EXPECT_EQ(kTestDataSize, num_bytes); | 1737 EXPECT_EQ(kTestDataSize, num_bytes); |
1747 | 1738 |
1748 // Close the consumer, which cancels the two-phase read. | 1739 // Close the consumer, which cancels the two-phase read. |
1749 dp->ConsumerClose(); | 1740 dp->ConsumerClose(); |
1750 } | 1741 } |
1751 | 1742 |
1752 // Close consumer first, then producer. | 1743 // Close consumer first, then producer. |
1753 { | 1744 { |
1754 scoped_refptr<LocalDataPipeImpl> dp( | 1745 scoped_refptr<DataPipe> dp(DataPipe::CreateLocal(validated_options)); |
1755 new LocalDataPipeImpl(validated_options)); | |
1756 | 1746 |
1757 // Write some data, so we'll have something to read. | 1747 // Write some data, so we'll have something to read. |
1758 uint32_t num_bytes = kTestDataSize; | 1748 uint32_t num_bytes = kTestDataSize; |
1759 EXPECT_EQ(MOJO_RESULT_OK, | 1749 EXPECT_EQ(MOJO_RESULT_OK, |
1760 dp->ProducerWriteData(UserPointer<const void>(kTestData), | 1750 dp->ProducerWriteData(UserPointer<const void>(kTestData), |
1761 MakeUserPointer(&num_bytes), false)); | 1751 MakeUserPointer(&num_bytes), false)); |
1762 EXPECT_EQ(kTestDataSize, num_bytes); | 1752 EXPECT_EQ(kTestDataSize, num_bytes); |
1763 | 1753 |
1764 // Start two-phase write. | 1754 // Start two-phase write. |
1765 void* write_buffer_ptr = nullptr; | 1755 void* write_buffer_ptr = nullptr; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1801 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, | 1791 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, |
1802 dp->ProducerBeginWriteData(MakeUserPointer(&write_buffer_ptr), | 1792 dp->ProducerBeginWriteData(MakeUserPointer(&write_buffer_ptr), |
1803 MakeUserPointer(&num_bytes), false)); | 1793 MakeUserPointer(&num_bytes), false)); |
1804 | 1794 |
1805 dp->ProducerClose(); | 1795 dp->ProducerClose(); |
1806 } | 1796 } |
1807 | 1797 |
1808 // Test closing the consumer first, then the producer, with an active | 1798 // Test closing the consumer first, then the producer, with an active |
1809 // two-phase write. | 1799 // two-phase write. |
1810 { | 1800 { |
1811 scoped_refptr<LocalDataPipeImpl> dp( | 1801 scoped_refptr<DataPipe> dp(DataPipe::CreateLocal(validated_options)); |
1812 new LocalDataPipeImpl(validated_options)); | |
1813 | 1802 |
1814 // Start two-phase write. | 1803 // Start two-phase write. |
1815 void* write_buffer_ptr = nullptr; | 1804 void* write_buffer_ptr = nullptr; |
1816 uint32_t num_bytes = 0u; | 1805 uint32_t num_bytes = 0u; |
1817 EXPECT_EQ(MOJO_RESULT_OK, | 1806 EXPECT_EQ(MOJO_RESULT_OK, |
1818 dp->ProducerBeginWriteData(MakeUserPointer(&write_buffer_ptr), | 1807 dp->ProducerBeginWriteData(MakeUserPointer(&write_buffer_ptr), |
1819 MakeUserPointer(&num_bytes), false)); | 1808 MakeUserPointer(&num_bytes), false)); |
1820 EXPECT_TRUE(write_buffer_ptr); | 1809 EXPECT_TRUE(write_buffer_ptr); |
1821 ASSERT_GT(num_bytes, kTestDataSize); | 1810 ASSERT_GT(num_bytes, kTestDataSize); |
1822 | 1811 |
1823 dp->ConsumerClose(); | 1812 dp->ConsumerClose(); |
1824 dp->ProducerClose(); | 1813 dp->ProducerClose(); |
1825 } | 1814 } |
1826 | 1815 |
1827 // Test closing the producer and then trying to read (with no data). | 1816 // Test closing the producer and then trying to read (with no data). |
1828 { | 1817 { |
1829 scoped_refptr<LocalDataPipeImpl> dp( | 1818 scoped_refptr<DataPipe> dp(DataPipe::CreateLocal(validated_options)); |
1830 new LocalDataPipeImpl(validated_options)); | |
1831 | 1819 |
1832 // Write some data, so we'll have something to read. | 1820 // Write some data, so we'll have something to read. |
1833 uint32_t num_bytes = kTestDataSize; | 1821 uint32_t num_bytes = kTestDataSize; |
1834 EXPECT_EQ(MOJO_RESULT_OK, | 1822 EXPECT_EQ(MOJO_RESULT_OK, |
1835 dp->ProducerWriteData(UserPointer<const void>(kTestData), | 1823 dp->ProducerWriteData(UserPointer<const void>(kTestData), |
1836 MakeUserPointer(&num_bytes), false)); | 1824 MakeUserPointer(&num_bytes), false)); |
1837 EXPECT_EQ(kTestDataSize, num_bytes); | 1825 EXPECT_EQ(kTestDataSize, num_bytes); |
1838 | 1826 |
1839 // Close the producer. | 1827 // Close the producer. |
1840 dp->ProducerClose(); | 1828 dp->ProducerClose(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1883 const MojoCreateDataPipeOptions options = { | 1871 const MojoCreateDataPipeOptions options = { |
1884 kSizeOfOptions, // |struct_size|. | 1872 kSizeOfOptions, // |struct_size|. |
1885 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|. | 1873 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|. |
1886 static_cast<uint32_t>(sizeof(int32_t)), // |element_num_bytes|. | 1874 static_cast<uint32_t>(sizeof(int32_t)), // |element_num_bytes|. |
1887 10 * sizeof(int32_t) // |capacity_num_bytes|. | 1875 10 * sizeof(int32_t) // |capacity_num_bytes|. |
1888 }; | 1876 }; |
1889 MojoCreateDataPipeOptions validated_options = {0}; | 1877 MojoCreateDataPipeOptions validated_options = {0}; |
1890 EXPECT_EQ(MOJO_RESULT_OK, DataPipe::ValidateCreateOptions( | 1878 EXPECT_EQ(MOJO_RESULT_OK, DataPipe::ValidateCreateOptions( |
1891 MakeUserPointer(&options), &validated_options)); | 1879 MakeUserPointer(&options), &validated_options)); |
1892 | 1880 |
1893 scoped_refptr<LocalDataPipeImpl> dp(new LocalDataPipeImpl(validated_options)); | 1881 scoped_refptr<DataPipe> dp(DataPipe::CreateLocal(validated_options)); |
1894 | 1882 |
1895 // No data. | 1883 // No data. |
1896 uint32_t num_bytes = 1000u; | 1884 uint32_t num_bytes = 1000u; |
1897 EXPECT_EQ(MOJO_RESULT_OK, dp->ConsumerQueryData(MakeUserPointer(&num_bytes))); | 1885 EXPECT_EQ(MOJO_RESULT_OK, dp->ConsumerQueryData(MakeUserPointer(&num_bytes))); |
1898 EXPECT_EQ(0u, num_bytes); | 1886 EXPECT_EQ(0u, num_bytes); |
1899 | 1887 |
1900 // Try "ending" a two-phase write when one isn't active. | 1888 // Try "ending" a two-phase write when one isn't active. |
1901 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, | 1889 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, |
1902 dp->ProducerEndWriteData(1u * sizeof(int32_t))); | 1890 dp->ProducerEndWriteData(1u * sizeof(int32_t))); |
1903 | 1891 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2009 const MojoCreateDataPipeOptions options = { | 1997 const MojoCreateDataPipeOptions options = { |
2010 kSizeOfOptions, // |struct_size|. | 1998 kSizeOfOptions, // |struct_size|. |
2011 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_MAY_DISCARD, // |flags|. | 1999 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_MAY_DISCARD, // |flags|. |
2012 1, // |element_num_bytes|. | 2000 1, // |element_num_bytes|. |
2013 2 // |capacity_num_bytes|. | 2001 2 // |capacity_num_bytes|. |
2014 }; | 2002 }; |
2015 MojoCreateDataPipeOptions validated_options = {0}; | 2003 MojoCreateDataPipeOptions validated_options = {0}; |
2016 EXPECT_EQ(MOJO_RESULT_OK, DataPipe::ValidateCreateOptions( | 2004 EXPECT_EQ(MOJO_RESULT_OK, DataPipe::ValidateCreateOptions( |
2017 MakeUserPointer(&options), &validated_options)); | 2005 MakeUserPointer(&options), &validated_options)); |
2018 | 2006 |
2019 scoped_refptr<LocalDataPipeImpl> dp(new LocalDataPipeImpl(validated_options)); | 2007 scoped_refptr<DataPipe> dp(DataPipe::CreateLocal(validated_options)); |
2020 | 2008 |
2021 // Write some elements. | 2009 // Write some elements. |
2022 char elements[2] = {'a', 'b'}; | 2010 char elements[2] = {'a', 'b'}; |
2023 uint32_t num_bytes = 2u; | 2011 uint32_t num_bytes = 2u; |
2024 EXPECT_EQ(MOJO_RESULT_OK, | 2012 EXPECT_EQ(MOJO_RESULT_OK, |
2025 dp->ProducerWriteData(UserPointer<const void>(elements), | 2013 dp->ProducerWriteData(UserPointer<const void>(elements), |
2026 MakeUserPointer(&num_bytes), false)); | 2014 MakeUserPointer(&num_bytes), false)); |
2027 EXPECT_EQ(2u, num_bytes); | 2015 EXPECT_EQ(2u, num_bytes); |
2028 | 2016 |
2029 // Begin reading. | 2017 // Begin reading. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2074 // End reading. | 2062 // End reading. |
2075 EXPECT_EQ(MOJO_RESULT_OK, dp->ConsumerEndReadData(2u)); | 2063 EXPECT_EQ(MOJO_RESULT_OK, dp->ConsumerEndReadData(2u)); |
2076 | 2064 |
2077 dp->ProducerClose(); | 2065 dp->ProducerClose(); |
2078 dp->ConsumerClose(); | 2066 dp->ConsumerClose(); |
2079 } | 2067 } |
2080 | 2068 |
2081 } // namespace | 2069 } // namespace |
2082 } // namespace system | 2070 } // namespace system |
2083 } // namespace mojo | 2071 } // namespace mojo |
OLD | NEW |