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/system/local_data_pipe.h" | 5 #include "mojo/system/local_data_pipe.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 num_bytes = sizeof(elements[0]) + 1; | 129 num_bytes = sizeof(elements[0]) + 1; |
130 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, | 130 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, |
131 dp->ConsumerReadData(UserPointer<void>(elements), | 131 dp->ConsumerReadData(UserPointer<void>(elements), |
132 MakeUserPointer(&num_bytes), false)); | 132 MakeUserPointer(&num_bytes), false)); |
133 | 133 |
134 // Write two elements. | 134 // Write two elements. |
135 elements[0] = 123; | 135 elements[0] = 123; |
136 elements[1] = 456; | 136 elements[1] = 456; |
137 num_bytes = static_cast<uint32_t>(2u * sizeof(elements[0])); | 137 num_bytes = static_cast<uint32_t>(2u * sizeof(elements[0])); |
138 EXPECT_EQ(MOJO_RESULT_OK, | 138 EXPECT_EQ(MOJO_RESULT_OK, |
139 dp->ProducerWriteData(elements, &num_bytes, false)); | 139 dp->ProducerWriteData(UserPointer<const void>(elements), |
| 140 MakeUserPointer(&num_bytes), false)); |
140 // It should have written everything (even without "all or none"). | 141 // It should have written everything (even without "all or none"). |
141 EXPECT_EQ(2u * sizeof(elements[0]), num_bytes); | 142 EXPECT_EQ(2u * sizeof(elements[0]), num_bytes); |
142 | 143 |
143 // Query. | 144 // Query. |
144 num_bytes = 0; | 145 num_bytes = 0; |
145 EXPECT_EQ(MOJO_RESULT_OK, dp->ConsumerQueryData(MakeUserPointer(&num_bytes))); | 146 EXPECT_EQ(MOJO_RESULT_OK, dp->ConsumerQueryData(MakeUserPointer(&num_bytes))); |
146 EXPECT_EQ(2 * sizeof(elements[0]), num_bytes); | 147 EXPECT_EQ(2 * sizeof(elements[0]), num_bytes); |
147 | 148 |
148 // Read one element. | 149 // Read one element. |
149 elements[0] = -1; | 150 elements[0] = -1; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 dp->ProducerAddWaiter(&waiter, MOJO_HANDLE_SIGNAL_READABLE, 12)); | 218 dp->ProducerAddWaiter(&waiter, MOJO_HANDLE_SIGNAL_READABLE, 12)); |
218 | 219 |
219 // Already writable. | 220 // Already writable. |
220 waiter.Init(); | 221 waiter.Init(); |
221 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, | 222 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, |
222 dp->ProducerAddWaiter(&waiter, MOJO_HANDLE_SIGNAL_WRITABLE, 34)); | 223 dp->ProducerAddWaiter(&waiter, MOJO_HANDLE_SIGNAL_WRITABLE, 34)); |
223 | 224 |
224 // Write two elements. | 225 // Write two elements. |
225 int32_t elements[2] = { 123, 456 }; | 226 int32_t elements[2] = { 123, 456 }; |
226 uint32_t num_bytes = static_cast<uint32_t>(2u * sizeof(elements[0])); | 227 uint32_t num_bytes = static_cast<uint32_t>(2u * sizeof(elements[0])); |
227 EXPECT_EQ(MOJO_RESULT_OK, dp->ProducerWriteData(elements, &num_bytes, true)); | 228 EXPECT_EQ(MOJO_RESULT_OK, |
| 229 dp->ProducerWriteData(UserPointer<const void>(elements), |
| 230 MakeUserPointer(&num_bytes), true)); |
228 EXPECT_EQ(static_cast<uint32_t>(2u * sizeof(elements[0])), num_bytes); | 231 EXPECT_EQ(static_cast<uint32_t>(2u * sizeof(elements[0])), num_bytes); |
229 | 232 |
230 // Adding a waiter should now succeed. | 233 // Adding a waiter should now succeed. |
231 waiter.Init(); | 234 waiter.Init(); |
232 ASSERT_EQ(MOJO_RESULT_OK, | 235 ASSERT_EQ(MOJO_RESULT_OK, |
233 dp->ProducerAddWaiter(&waiter, MOJO_HANDLE_SIGNAL_WRITABLE, 56)); | 236 dp->ProducerAddWaiter(&waiter, MOJO_HANDLE_SIGNAL_WRITABLE, 56)); |
234 // And it shouldn't be writable yet. | 237 // And it shouldn't be writable yet. |
235 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, waiter.Wait(0, NULL)); | 238 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, waiter.Wait(0, NULL)); |
236 dp->ProducerRemoveWaiter(&waiter); | 239 dp->ProducerRemoveWaiter(&waiter); |
237 | 240 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 static_cast<uint32_t>(1u * sizeof(elements[0])))); | 295 static_cast<uint32_t>(1u * sizeof(elements[0])))); |
293 | 296 |
294 // Waiting should succeed. | 297 // Waiting should succeed. |
295 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(1000, &context)); | 298 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(1000, &context)); |
296 EXPECT_EQ(90u, context); | 299 EXPECT_EQ(90u, context); |
297 dp->ProducerRemoveWaiter(&waiter); | 300 dp->ProducerRemoveWaiter(&waiter); |
298 | 301 |
299 // Write one element. | 302 // Write one element. |
300 elements[0] = 123; | 303 elements[0] = 123; |
301 num_bytes = static_cast<uint32_t>(1u * sizeof(elements[0])); | 304 num_bytes = static_cast<uint32_t>(1u * sizeof(elements[0])); |
302 EXPECT_EQ(MOJO_RESULT_OK, dp->ProducerWriteData(elements, &num_bytes, false)); | 305 EXPECT_EQ(MOJO_RESULT_OK, |
| 306 dp->ProducerWriteData(UserPointer<const void>(elements), |
| 307 MakeUserPointer(&num_bytes), false)); |
303 EXPECT_EQ(static_cast<uint32_t>(1u * sizeof(elements[0])), num_bytes); | 308 EXPECT_EQ(static_cast<uint32_t>(1u * sizeof(elements[0])), num_bytes); |
304 | 309 |
305 // Add a waiter. | 310 // Add a waiter. |
306 waiter.Init(); | 311 waiter.Init(); |
307 ASSERT_EQ(MOJO_RESULT_OK, | 312 ASSERT_EQ(MOJO_RESULT_OK, |
308 dp->ProducerAddWaiter(&waiter, MOJO_HANDLE_SIGNAL_WRITABLE, 12)); | 313 dp->ProducerAddWaiter(&waiter, MOJO_HANDLE_SIGNAL_WRITABLE, 12)); |
309 | 314 |
310 // Close the consumer. | 315 // Close the consumer. |
311 dp->ConsumerClose(); | 316 dp->ConsumerClose(); |
312 | 317 |
(...skipping 30 matching lines...) Expand all Loading... |
343 waiter.Init(); | 348 waiter.Init(); |
344 ASSERT_EQ(MOJO_RESULT_OK, | 349 ASSERT_EQ(MOJO_RESULT_OK, |
345 dp->ConsumerAddWaiter(&waiter, MOJO_HANDLE_SIGNAL_READABLE, 34)); | 350 dp->ConsumerAddWaiter(&waiter, MOJO_HANDLE_SIGNAL_READABLE, 34)); |
346 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, waiter.Wait(0, NULL)); | 351 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, waiter.Wait(0, NULL)); |
347 dp->ConsumerRemoveWaiter(&waiter); | 352 dp->ConsumerRemoveWaiter(&waiter); |
348 | 353 |
349 // Write two elements. | 354 // Write two elements. |
350 int32_t elements[2] = { 123, 456 }; | 355 int32_t elements[2] = { 123, 456 }; |
351 uint32_t num_bytes = static_cast<uint32_t>(2u * sizeof(elements[0])); | 356 uint32_t num_bytes = static_cast<uint32_t>(2u * sizeof(elements[0])); |
352 EXPECT_EQ(MOJO_RESULT_OK, | 357 EXPECT_EQ(MOJO_RESULT_OK, |
353 dp->ProducerWriteData(elements, &num_bytes, true)); | 358 dp->ProducerWriteData(UserPointer<const void>(elements), |
| 359 MakeUserPointer(&num_bytes), true)); |
354 | 360 |
355 // Should already be readable. | 361 // Should already be readable. |
356 waiter.Init(); | 362 waiter.Init(); |
357 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, | 363 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, |
358 dp->ConsumerAddWaiter(&waiter, MOJO_HANDLE_SIGNAL_READABLE, 56)); | 364 dp->ConsumerAddWaiter(&waiter, MOJO_HANDLE_SIGNAL_READABLE, 56)); |
359 | 365 |
360 // Discard one element. | 366 // Discard one element. |
361 num_bytes = static_cast<uint32_t>(1u * sizeof(elements[0])); | 367 num_bytes = static_cast<uint32_t>(1u * sizeof(elements[0])); |
362 EXPECT_EQ(MOJO_RESULT_OK, | 368 EXPECT_EQ(MOJO_RESULT_OK, |
363 dp->ConsumerDiscardData(MakeUserPointer(&num_bytes), true)); | 369 dp->ConsumerDiscardData(MakeUserPointer(&num_bytes), true)); |
(...skipping 18 matching lines...) Expand all Loading... |
382 // Adding a waiter should now succeed. | 388 // Adding a waiter should now succeed. |
383 waiter.Init(); | 389 waiter.Init(); |
384 ASSERT_EQ(MOJO_RESULT_OK, | 390 ASSERT_EQ(MOJO_RESULT_OK, |
385 dp->ConsumerAddWaiter(&waiter, MOJO_HANDLE_SIGNAL_READABLE, 90)); | 391 dp->ConsumerAddWaiter(&waiter, MOJO_HANDLE_SIGNAL_READABLE, 90)); |
386 | 392 |
387 // Write one element. | 393 // Write one element. |
388 elements[0] = 789; | 394 elements[0] = 789; |
389 elements[1] = -1; | 395 elements[1] = -1; |
390 num_bytes = static_cast<uint32_t>(1u * sizeof(elements[0])); | 396 num_bytes = static_cast<uint32_t>(1u * sizeof(elements[0])); |
391 EXPECT_EQ(MOJO_RESULT_OK, | 397 EXPECT_EQ(MOJO_RESULT_OK, |
392 dp->ProducerWriteData(elements, &num_bytes, true)); | 398 dp->ProducerWriteData(UserPointer<const void>(elements), |
| 399 MakeUserPointer(&num_bytes), true)); |
393 | 400 |
394 // Waiting should now succeed. | 401 // Waiting should now succeed. |
395 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(1000, &context)); | 402 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(1000, &context)); |
396 EXPECT_EQ(90u, context); | 403 EXPECT_EQ(90u, context); |
397 dp->ConsumerRemoveWaiter(&waiter); | 404 dp->ConsumerRemoveWaiter(&waiter); |
398 | 405 |
399 // Close the producer. | 406 // Close the producer. |
400 dp->ProducerClose(); | 407 dp->ProducerClose(); |
401 | 408 |
402 // Should still be readable. | 409 // Should still be readable. |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 // Not readable. | 642 // Not readable. |
636 waiter.Init(); | 643 waiter.Init(); |
637 ASSERT_EQ(MOJO_RESULT_OK, | 644 ASSERT_EQ(MOJO_RESULT_OK, |
638 dp->ConsumerAddWaiter(&waiter, MOJO_HANDLE_SIGNAL_READABLE, 1)); | 645 dp->ConsumerAddWaiter(&waiter, MOJO_HANDLE_SIGNAL_READABLE, 1)); |
639 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, waiter.Wait(0, NULL)); | 646 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, waiter.Wait(0, NULL)); |
640 dp->ConsumerRemoveWaiter(&waiter); | 647 dp->ConsumerRemoveWaiter(&waiter); |
641 | 648 |
642 uint32_t num_bytes = static_cast<uint32_t>(sizeof(int32_t)); | 649 uint32_t num_bytes = static_cast<uint32_t>(sizeof(int32_t)); |
643 int32_t element = 123; | 650 int32_t element = 123; |
644 EXPECT_EQ(MOJO_RESULT_OK, | 651 EXPECT_EQ(MOJO_RESULT_OK, |
645 dp->ProducerWriteData(&element, &num_bytes, false)); | 652 dp->ProducerWriteData(UserPointer<const void>(&element), |
| 653 MakeUserPointer(&num_bytes), false)); |
646 EXPECT_EQ(static_cast<uint32_t>(sizeof(int32_t)), num_bytes); | 654 EXPECT_EQ(static_cast<uint32_t>(sizeof(int32_t)), num_bytes); |
647 | 655 |
648 // Still writable (even though it's full). | 656 // Still writable (even though it's full). |
649 waiter.Init(); | 657 waiter.Init(); |
650 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, | 658 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, |
651 dp->ProducerAddWaiter(&waiter, MOJO_HANDLE_SIGNAL_WRITABLE, 2)); | 659 dp->ProducerAddWaiter(&waiter, MOJO_HANDLE_SIGNAL_WRITABLE, 2)); |
652 | 660 |
653 // Now readable. | 661 // Now readable. |
654 waiter.Init(); | 662 waiter.Init(); |
655 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, | 663 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, |
656 dp->ConsumerAddWaiter(&waiter, MOJO_HANDLE_SIGNAL_READABLE, 3)); | 664 dp->ConsumerAddWaiter(&waiter, MOJO_HANDLE_SIGNAL_READABLE, 3)); |
657 | 665 |
658 // Overwrite that element. | 666 // Overwrite that element. |
659 num_bytes = static_cast<uint32_t>(sizeof(int32_t)); | 667 num_bytes = static_cast<uint32_t>(sizeof(int32_t)); |
660 element = 456; | 668 element = 456; |
661 EXPECT_EQ(MOJO_RESULT_OK, | 669 EXPECT_EQ(MOJO_RESULT_OK, |
662 dp->ProducerWriteData(&element, &num_bytes, false)); | 670 dp->ProducerWriteData(UserPointer<const void>(&element), |
| 671 MakeUserPointer(&num_bytes), false)); |
663 EXPECT_EQ(static_cast<uint32_t>(sizeof(int32_t)), num_bytes); | 672 EXPECT_EQ(static_cast<uint32_t>(sizeof(int32_t)), num_bytes); |
664 | 673 |
665 // Still writable. | 674 // Still writable. |
666 waiter.Init(); | 675 waiter.Init(); |
667 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, | 676 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, |
668 dp->ProducerAddWaiter(&waiter, MOJO_HANDLE_SIGNAL_WRITABLE, 4)); | 677 dp->ProducerAddWaiter(&waiter, MOJO_HANDLE_SIGNAL_WRITABLE, 4)); |
669 | 678 |
670 // And still readable. | 679 // And still readable. |
671 waiter.Init(); | 680 waiter.Init(); |
672 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, | 681 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
715 | 724 |
716 scoped_refptr<LocalDataPipe> dp(new LocalDataPipe(validated_options)); | 725 scoped_refptr<LocalDataPipe> dp(new LocalDataPipe(validated_options)); |
717 | 726 |
718 int32_t buffer[100] = { 0 }; | 727 int32_t buffer[100] = { 0 }; |
719 uint32_t num_bytes = 0; | 728 uint32_t num_bytes = 0; |
720 | 729 |
721 num_bytes = 20u * sizeof(int32_t); | 730 num_bytes = 20u * sizeof(int32_t); |
722 Seq(0, arraysize(buffer), buffer); | 731 Seq(0, arraysize(buffer), buffer); |
723 // Try writing more than capacity. (This test relies on the implementation | 732 // Try writing more than capacity. (This test relies on the implementation |
724 // enforcing the capacity strictly.) | 733 // enforcing the capacity strictly.) |
725 EXPECT_EQ(MOJO_RESULT_OK, dp->ProducerWriteData(buffer, &num_bytes, false)); | 734 EXPECT_EQ(MOJO_RESULT_OK, |
| 735 dp->ProducerWriteData(UserPointer<const void>(buffer), |
| 736 MakeUserPointer(&num_bytes), false)); |
726 EXPECT_EQ(10u * sizeof(int32_t), num_bytes); | 737 EXPECT_EQ(10u * sizeof(int32_t), num_bytes); |
727 | 738 |
728 // Read half of what we wrote. | 739 // Read half of what we wrote. |
729 num_bytes = 5u * sizeof(int32_t); | 740 num_bytes = 5u * sizeof(int32_t); |
730 memset(buffer, 0xab, sizeof(buffer)); | 741 memset(buffer, 0xab, sizeof(buffer)); |
731 EXPECT_EQ(MOJO_RESULT_OK, | 742 EXPECT_EQ(MOJO_RESULT_OK, |
732 dp->ConsumerReadData(UserPointer<void>(buffer), | 743 dp->ConsumerReadData(UserPointer<void>(buffer), |
733 MakeUserPointer(&num_bytes), false)); | 744 MakeUserPointer(&num_bytes), false)); |
734 EXPECT_EQ(5u * sizeof(int32_t), num_bytes); | 745 EXPECT_EQ(5u * sizeof(int32_t), num_bytes); |
735 int32_t expected_buffer[100]; | 746 int32_t expected_buffer[100]; |
736 memset(expected_buffer, 0xab, sizeof(expected_buffer)); | 747 memset(expected_buffer, 0xab, sizeof(expected_buffer)); |
737 Seq(0, 5u, expected_buffer); | 748 Seq(0, 5u, expected_buffer); |
738 EXPECT_EQ(0, memcmp(buffer, expected_buffer, sizeof(buffer))); | 749 EXPECT_EQ(0, memcmp(buffer, expected_buffer, sizeof(buffer))); |
739 // Internally, a circular buffer would now look like: | 750 // Internally, a circular buffer would now look like: |
740 // -, -, -, -, -, 5, 6, 7, 8, 9 | 751 // -, -, -, -, -, 5, 6, 7, 8, 9 |
741 | 752 |
742 // Write a bit more than the space that's available. | 753 // Write a bit more than the space that's available. |
743 num_bytes = 8u * sizeof(int32_t); | 754 num_bytes = 8u * sizeof(int32_t); |
744 Seq(100, arraysize(buffer), buffer); | 755 Seq(100, arraysize(buffer), buffer); |
745 EXPECT_EQ(MOJO_RESULT_OK, dp->ProducerWriteData(buffer, &num_bytes, false)); | 756 EXPECT_EQ(MOJO_RESULT_OK, |
| 757 dp->ProducerWriteData(UserPointer<const void>(buffer), |
| 758 MakeUserPointer(&num_bytes), false)); |
746 EXPECT_EQ(8u * sizeof(int32_t), num_bytes); | 759 EXPECT_EQ(8u * sizeof(int32_t), num_bytes); |
747 // Internally, a circular buffer would now look like: | 760 // Internally, a circular buffer would now look like: |
748 // 100, 101, 102, 103, 104, 105, 106, 107, 8, 9 | 761 // 100, 101, 102, 103, 104, 105, 106, 107, 8, 9 |
749 | 762 |
750 // Read half of what's available. | 763 // Read half of what's available. |
751 num_bytes = 5u * sizeof(int32_t); | 764 num_bytes = 5u * sizeof(int32_t); |
752 memset(buffer, 0xab, sizeof(buffer)); | 765 memset(buffer, 0xab, sizeof(buffer)); |
753 EXPECT_EQ(MOJO_RESULT_OK, | 766 EXPECT_EQ(MOJO_RESULT_OK, |
754 dp->ConsumerReadData(UserPointer<void>(buffer), | 767 dp->ConsumerReadData(UserPointer<void>(buffer), |
755 MakeUserPointer(&num_bytes), false)); | 768 MakeUserPointer(&num_bytes), false)); |
756 EXPECT_EQ(5u * sizeof(int32_t), num_bytes); | 769 EXPECT_EQ(5u * sizeof(int32_t), num_bytes); |
757 memset(expected_buffer, 0xab, sizeof(expected_buffer)); | 770 memset(expected_buffer, 0xab, sizeof(expected_buffer)); |
758 expected_buffer[0] = 8; | 771 expected_buffer[0] = 8; |
759 expected_buffer[1] = 9; | 772 expected_buffer[1] = 9; |
760 expected_buffer[2] = 100; | 773 expected_buffer[2] = 100; |
761 expected_buffer[3] = 101; | 774 expected_buffer[3] = 101; |
762 expected_buffer[4] = 102; | 775 expected_buffer[4] = 102; |
763 EXPECT_EQ(0, memcmp(buffer, expected_buffer, sizeof(buffer))); | 776 EXPECT_EQ(0, memcmp(buffer, expected_buffer, sizeof(buffer))); |
764 // Internally, a circular buffer would now look like: | 777 // Internally, a circular buffer would now look like: |
765 // -, -, -, 103, 104, 105, 106, 107, -, - | 778 // -, -, -, 103, 104, 105, 106, 107, -, - |
766 | 779 |
767 // Write one integer. | 780 // Write one integer. |
768 num_bytes = 1u * sizeof(int32_t); | 781 num_bytes = 1u * sizeof(int32_t); |
769 Seq(200, arraysize(buffer), buffer); | 782 Seq(200, arraysize(buffer), buffer); |
770 EXPECT_EQ(MOJO_RESULT_OK, dp->ProducerWriteData(buffer, &num_bytes, false)); | 783 EXPECT_EQ(MOJO_RESULT_OK, |
| 784 dp->ProducerWriteData(UserPointer<const void>(buffer), |
| 785 MakeUserPointer(&num_bytes), false)); |
771 EXPECT_EQ(1u * sizeof(int32_t), num_bytes); | 786 EXPECT_EQ(1u * sizeof(int32_t), num_bytes); |
772 // Internally, a circular buffer would now look like: | 787 // Internally, a circular buffer would now look like: |
773 // -, -, -, 103, 104, 105, 106, 107, 200, - | 788 // -, -, -, 103, 104, 105, 106, 107, 200, - |
774 | 789 |
775 // Write five more. | 790 // Write five more. |
776 num_bytes = 5u * sizeof(int32_t); | 791 num_bytes = 5u * sizeof(int32_t); |
777 Seq(300, arraysize(buffer), buffer); | 792 Seq(300, arraysize(buffer), buffer); |
778 EXPECT_EQ(MOJO_RESULT_OK, dp->ProducerWriteData(buffer, &num_bytes, false)); | 793 EXPECT_EQ(MOJO_RESULT_OK, |
| 794 dp->ProducerWriteData(UserPointer<const void>(buffer), |
| 795 MakeUserPointer(&num_bytes), false)); |
779 EXPECT_EQ(5u * sizeof(int32_t), num_bytes); | 796 EXPECT_EQ(5u * sizeof(int32_t), num_bytes); |
780 // Internally, a circular buffer would now look like: | 797 // Internally, a circular buffer would now look like: |
781 // 301, 302, 303, 304, 104, 105, 106, 107, 200, 300 | 798 // 301, 302, 303, 304, 104, 105, 106, 107, 200, 300 |
782 | 799 |
783 // Read it all. | 800 // Read it all. |
784 num_bytes = sizeof(buffer); | 801 num_bytes = sizeof(buffer); |
785 memset(buffer, 0xab, sizeof(buffer)); | 802 memset(buffer, 0xab, sizeof(buffer)); |
786 EXPECT_EQ(MOJO_RESULT_OK, | 803 EXPECT_EQ(MOJO_RESULT_OK, |
787 dp->ConsumerReadData(UserPointer<void>(buffer), | 804 dp->ConsumerReadData(UserPointer<void>(buffer), |
788 MakeUserPointer(&num_bytes), false)); | 805 MakeUserPointer(&num_bytes), false)); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
898 EXPECT_EQ(MOJO_RESULT_OK, | 915 EXPECT_EQ(MOJO_RESULT_OK, |
899 DataPipe::ValidateCreateOptions(&options, &validated_options)); | 916 DataPipe::ValidateCreateOptions(&options, &validated_options)); |
900 | 917 |
901 scoped_refptr<LocalDataPipe> dp(new LocalDataPipe(validated_options)); | 918 scoped_refptr<LocalDataPipe> dp(new LocalDataPipe(validated_options)); |
902 | 919 |
903 // Try writing way too much. | 920 // Try writing way too much. |
904 uint32_t num_bytes = 20u * sizeof(int32_t); | 921 uint32_t num_bytes = 20u * sizeof(int32_t); |
905 int32_t buffer[100]; | 922 int32_t buffer[100]; |
906 Seq(0, arraysize(buffer), buffer); | 923 Seq(0, arraysize(buffer), buffer); |
907 EXPECT_EQ(MOJO_RESULT_OUT_OF_RANGE, | 924 EXPECT_EQ(MOJO_RESULT_OUT_OF_RANGE, |
908 dp->ProducerWriteData(buffer, &num_bytes, true)); | 925 dp->ProducerWriteData(UserPointer<const void>(buffer), |
| 926 MakeUserPointer(&num_bytes), true)); |
909 | 927 |
910 // Should still be empty. | 928 // Should still be empty. |
911 num_bytes = ~0u; | 929 num_bytes = ~0u; |
912 EXPECT_EQ(MOJO_RESULT_OK, dp->ConsumerQueryData(MakeUserPointer(&num_bytes))); | 930 EXPECT_EQ(MOJO_RESULT_OK, dp->ConsumerQueryData(MakeUserPointer(&num_bytes))); |
913 EXPECT_EQ(0u, num_bytes); | 931 EXPECT_EQ(0u, num_bytes); |
914 | 932 |
915 // Write some data. | 933 // Write some data. |
916 num_bytes = 5u * sizeof(int32_t); | 934 num_bytes = 5u * sizeof(int32_t); |
917 Seq(100, arraysize(buffer), buffer); | 935 Seq(100, arraysize(buffer), buffer); |
918 EXPECT_EQ(MOJO_RESULT_OK, dp->ProducerWriteData(buffer, &num_bytes, true)); | 936 EXPECT_EQ(MOJO_RESULT_OK, |
| 937 dp->ProducerWriteData(UserPointer<const void>(buffer), |
| 938 MakeUserPointer(&num_bytes), true)); |
919 EXPECT_EQ(5u * sizeof(int32_t), num_bytes); | 939 EXPECT_EQ(5u * sizeof(int32_t), num_bytes); |
920 | 940 |
921 // Half full. | 941 // Half full. |
922 num_bytes = 0u; | 942 num_bytes = 0u; |
923 EXPECT_EQ(MOJO_RESULT_OK, dp->ConsumerQueryData(MakeUserPointer(&num_bytes))); | 943 EXPECT_EQ(MOJO_RESULT_OK, dp->ConsumerQueryData(MakeUserPointer(&num_bytes))); |
924 EXPECT_EQ(5u * sizeof(int32_t), num_bytes); | 944 EXPECT_EQ(5u * sizeof(int32_t), num_bytes); |
925 | 945 |
926 // Too much. | 946 // Too much. |
927 num_bytes = 6u * sizeof(int32_t); | 947 num_bytes = 6u * sizeof(int32_t); |
928 Seq(200, arraysize(buffer), buffer); | 948 Seq(200, arraysize(buffer), buffer); |
929 EXPECT_EQ(MOJO_RESULT_OUT_OF_RANGE, | 949 EXPECT_EQ(MOJO_RESULT_OUT_OF_RANGE, |
930 dp->ProducerWriteData(buffer, &num_bytes, true)); | 950 dp->ProducerWriteData(UserPointer<const void>(buffer), |
| 951 MakeUserPointer(&num_bytes), true)); |
931 | 952 |
932 // Try reading too much. | 953 // Try reading too much. |
933 num_bytes = 11u * sizeof(int32_t); | 954 num_bytes = 11u * sizeof(int32_t); |
934 memset(buffer, 0xab, sizeof(buffer)); | 955 memset(buffer, 0xab, sizeof(buffer)); |
935 EXPECT_EQ(MOJO_RESULT_OUT_OF_RANGE, | 956 EXPECT_EQ(MOJO_RESULT_OUT_OF_RANGE, |
936 dp->ConsumerReadData(UserPointer<void>(buffer), | 957 dp->ConsumerReadData(UserPointer<void>(buffer), |
937 MakeUserPointer(&num_bytes), true)); | 958 MakeUserPointer(&num_bytes), true)); |
938 int32_t expected_buffer[100]; | 959 int32_t expected_buffer[100]; |
939 memset(expected_buffer, 0xab, sizeof(expected_buffer)); | 960 memset(expected_buffer, 0xab, sizeof(expected_buffer)); |
940 EXPECT_EQ(0, memcmp(buffer, expected_buffer, sizeof(buffer))); | 961 EXPECT_EQ(0, memcmp(buffer, expected_buffer, sizeof(buffer))); |
941 | 962 |
942 // Try discarding too much. | 963 // Try discarding too much. |
943 num_bytes = 11u * sizeof(int32_t); | 964 num_bytes = 11u * sizeof(int32_t); |
944 EXPECT_EQ(MOJO_RESULT_OUT_OF_RANGE, | 965 EXPECT_EQ(MOJO_RESULT_OUT_OF_RANGE, |
945 dp->ConsumerDiscardData(MakeUserPointer(&num_bytes), true)); | 966 dp->ConsumerDiscardData(MakeUserPointer(&num_bytes), true)); |
946 | 967 |
947 // Just a little. | 968 // Just a little. |
948 num_bytes = 2u * sizeof(int32_t); | 969 num_bytes = 2u * sizeof(int32_t); |
949 Seq(300, arraysize(buffer), buffer); | 970 Seq(300, arraysize(buffer), buffer); |
950 EXPECT_EQ(MOJO_RESULT_OK, dp->ProducerWriteData(buffer, &num_bytes, true)); | 971 EXPECT_EQ(MOJO_RESULT_OK, |
| 972 dp->ProducerWriteData(UserPointer<const void>(buffer), |
| 973 MakeUserPointer(&num_bytes), true)); |
951 EXPECT_EQ(2u * sizeof(int32_t), num_bytes); | 974 EXPECT_EQ(2u * sizeof(int32_t), num_bytes); |
952 | 975 |
953 // Just right. | 976 // Just right. |
954 num_bytes = 3u * sizeof(int32_t); | 977 num_bytes = 3u * sizeof(int32_t); |
955 Seq(400, arraysize(buffer), buffer); | 978 Seq(400, arraysize(buffer), buffer); |
956 EXPECT_EQ(MOJO_RESULT_OK, dp->ProducerWriteData(buffer, &num_bytes, true)); | 979 EXPECT_EQ(MOJO_RESULT_OK, |
| 980 dp->ProducerWriteData(UserPointer<const void>(buffer), |
| 981 MakeUserPointer(&num_bytes), true)); |
957 EXPECT_EQ(3u * sizeof(int32_t), num_bytes); | 982 EXPECT_EQ(3u * sizeof(int32_t), num_bytes); |
958 | 983 |
959 // Exactly full. | 984 // Exactly full. |
960 num_bytes = 0u; | 985 num_bytes = 0u; |
961 EXPECT_EQ(MOJO_RESULT_OK, dp->ConsumerQueryData(MakeUserPointer(&num_bytes))); | 986 EXPECT_EQ(MOJO_RESULT_OK, dp->ConsumerQueryData(MakeUserPointer(&num_bytes))); |
962 EXPECT_EQ(10u * sizeof(int32_t), num_bytes); | 987 EXPECT_EQ(10u * sizeof(int32_t), num_bytes); |
963 | 988 |
964 // Read half. | 989 // Read half. |
965 num_bytes = 5u * sizeof(int32_t); | 990 num_bytes = 5u * sizeof(int32_t); |
966 memset(buffer, 0xab, sizeof(buffer)); | 991 memset(buffer, 0xab, sizeof(buffer)); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1050 EXPECT_EQ(MOJO_RESULT_OK, | 1075 EXPECT_EQ(MOJO_RESULT_OK, |
1051 DataPipe::ValidateCreateOptions(&options, &validated_options)); | 1076 DataPipe::ValidateCreateOptions(&options, &validated_options)); |
1052 | 1077 |
1053 scoped_refptr<LocalDataPipe> dp(new LocalDataPipe(validated_options)); | 1078 scoped_refptr<LocalDataPipe> dp(new LocalDataPipe(validated_options)); |
1054 | 1079 |
1055 // Try writing way too much. | 1080 // Try writing way too much. |
1056 uint32_t num_bytes = 20u * sizeof(int32_t); | 1081 uint32_t num_bytes = 20u * sizeof(int32_t); |
1057 int32_t buffer[100]; | 1082 int32_t buffer[100]; |
1058 Seq(0, arraysize(buffer), buffer); | 1083 Seq(0, arraysize(buffer), buffer); |
1059 EXPECT_EQ(MOJO_RESULT_OUT_OF_RANGE, | 1084 EXPECT_EQ(MOJO_RESULT_OUT_OF_RANGE, |
1060 dp->ProducerWriteData(buffer, &num_bytes, true)); | 1085 dp->ProducerWriteData(UserPointer<const void>(buffer), |
| 1086 MakeUserPointer(&num_bytes), true)); |
1061 | 1087 |
1062 // Write some stuff. | 1088 // Write some stuff. |
1063 num_bytes = 5u * sizeof(int32_t); | 1089 num_bytes = 5u * sizeof(int32_t); |
1064 Seq(100, arraysize(buffer), buffer); | 1090 Seq(100, arraysize(buffer), buffer); |
1065 EXPECT_EQ(MOJO_RESULT_OK, dp->ProducerWriteData(buffer, &num_bytes, true)); | 1091 EXPECT_EQ(MOJO_RESULT_OK, |
| 1092 dp->ProducerWriteData(UserPointer<const void>(buffer), |
| 1093 MakeUserPointer(&num_bytes), true)); |
1066 EXPECT_EQ(5u * sizeof(int32_t), num_bytes); | 1094 EXPECT_EQ(5u * sizeof(int32_t), num_bytes); |
1067 | 1095 |
1068 // Write lots of stuff (discarding all but "104"). | 1096 // Write lots of stuff (discarding all but "104"). |
1069 num_bytes = 9u * sizeof(int32_t); | 1097 num_bytes = 9u * sizeof(int32_t); |
1070 Seq(200, arraysize(buffer), buffer); | 1098 Seq(200, arraysize(buffer), buffer); |
1071 EXPECT_EQ(MOJO_RESULT_OK, dp->ProducerWriteData(buffer, &num_bytes, true)); | 1099 EXPECT_EQ(MOJO_RESULT_OK, |
| 1100 dp->ProducerWriteData(UserPointer<const void>(buffer), |
| 1101 MakeUserPointer(&num_bytes), true)); |
1072 EXPECT_EQ(9u * sizeof(int32_t), num_bytes); | 1102 EXPECT_EQ(9u * sizeof(int32_t), num_bytes); |
1073 | 1103 |
1074 // Read one. | 1104 // Read one. |
1075 num_bytes = 1u * sizeof(int32_t); | 1105 num_bytes = 1u * sizeof(int32_t); |
1076 memset(buffer, 0xab, sizeof(buffer)); | 1106 memset(buffer, 0xab, sizeof(buffer)); |
1077 EXPECT_EQ(MOJO_RESULT_OK, | 1107 EXPECT_EQ(MOJO_RESULT_OK, |
1078 dp->ConsumerReadData(UserPointer<void>(buffer), | 1108 dp->ConsumerReadData(UserPointer<void>(buffer), |
1079 MakeUserPointer(&num_bytes), true)); | 1109 MakeUserPointer(&num_bytes), true)); |
1080 EXPECT_EQ(1u * sizeof(int32_t), num_bytes); | 1110 EXPECT_EQ(1u * sizeof(int32_t), num_bytes); |
1081 int32_t expected_buffer[100]; | 1111 int32_t expected_buffer[100]; |
(...skipping 21 matching lines...) Expand all Loading... |
1103 dp->ConsumerDiscardData(MakeUserPointer(&num_bytes), true)); | 1133 dp->ConsumerDiscardData(MakeUserPointer(&num_bytes), true)); |
1104 | 1134 |
1105 // Half full. | 1135 // Half full. |
1106 num_bytes = 0u; | 1136 num_bytes = 0u; |
1107 EXPECT_EQ(MOJO_RESULT_OK, dp->ConsumerQueryData(MakeUserPointer(&num_bytes))); | 1137 EXPECT_EQ(MOJO_RESULT_OK, dp->ConsumerQueryData(MakeUserPointer(&num_bytes))); |
1108 EXPECT_EQ(5u * sizeof(int32_t), num_bytes); | 1138 EXPECT_EQ(5u * sizeof(int32_t), num_bytes); |
1109 | 1139 |
1110 // Write as much as possible. | 1140 // Write as much as possible. |
1111 num_bytes = 10u * sizeof(int32_t); | 1141 num_bytes = 10u * sizeof(int32_t); |
1112 Seq(300, arraysize(buffer), buffer); | 1142 Seq(300, arraysize(buffer), buffer); |
1113 EXPECT_EQ(MOJO_RESULT_OK, dp->ProducerWriteData(buffer, &num_bytes, true)); | 1143 EXPECT_EQ(MOJO_RESULT_OK, |
| 1144 dp->ProducerWriteData(UserPointer<const void>(buffer), |
| 1145 MakeUserPointer(&num_bytes), true)); |
1114 EXPECT_EQ(10u * sizeof(int32_t), num_bytes); | 1146 EXPECT_EQ(10u * sizeof(int32_t), num_bytes); |
1115 | 1147 |
1116 // Read everything. | 1148 // Read everything. |
1117 num_bytes = 10u * sizeof(int32_t); | 1149 num_bytes = 10u * sizeof(int32_t); |
1118 memset(buffer, 0xab, sizeof(buffer)); | 1150 memset(buffer, 0xab, sizeof(buffer)); |
1119 EXPECT_EQ(MOJO_RESULT_OK, | 1151 EXPECT_EQ(MOJO_RESULT_OK, |
1120 dp->ConsumerReadData(UserPointer<void>(buffer), | 1152 dp->ConsumerReadData(UserPointer<void>(buffer), |
1121 MakeUserPointer(&num_bytes), true)); | 1153 MakeUserPointer(&num_bytes), true)); |
1122 memset(expected_buffer, 0xab, sizeof(expected_buffer)); | 1154 memset(expected_buffer, 0xab, sizeof(expected_buffer)); |
1123 EXPECT_EQ(10u * sizeof(int32_t), num_bytes); | 1155 EXPECT_EQ(10u * sizeof(int32_t), num_bytes); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1207 num_bytes = 6u * sizeof(int32_t); | 1239 num_bytes = 6u * sizeof(int32_t); |
1208 write_ptr = NULL; | 1240 write_ptr = NULL; |
1209 EXPECT_EQ(MOJO_RESULT_OUT_OF_RANGE, | 1241 EXPECT_EQ(MOJO_RESULT_OUT_OF_RANGE, |
1210 dp->ProducerBeginWriteData(MakeUserPointer(&write_ptr), | 1242 dp->ProducerBeginWriteData(MakeUserPointer(&write_ptr), |
1211 MakeUserPointer(&num_bytes), true)); | 1243 MakeUserPointer(&num_bytes), true)); |
1212 | 1244 |
1213 // Write six elements (simple), filling the buffer. | 1245 // Write six elements (simple), filling the buffer. |
1214 num_bytes = 6u * sizeof(int32_t); | 1246 num_bytes = 6u * sizeof(int32_t); |
1215 int32_t buffer[100]; | 1247 int32_t buffer[100]; |
1216 Seq(100, 6, buffer); | 1248 Seq(100, 6, buffer); |
1217 EXPECT_EQ(MOJO_RESULT_OK, dp->ProducerWriteData(buffer, &num_bytes, true)); | 1249 EXPECT_EQ(MOJO_RESULT_OK, |
| 1250 dp->ProducerWriteData(UserPointer<const void>(buffer), |
| 1251 MakeUserPointer(&num_bytes), true)); |
1218 EXPECT_EQ(6u * sizeof(int32_t), num_bytes); | 1252 EXPECT_EQ(6u * sizeof(int32_t), num_bytes); |
1219 | 1253 |
1220 // We have ten. | 1254 // We have ten. |
1221 num_bytes = 0u; | 1255 num_bytes = 0u; |
1222 EXPECT_EQ(MOJO_RESULT_OK, dp->ConsumerQueryData(MakeUserPointer(&num_bytes))); | 1256 EXPECT_EQ(MOJO_RESULT_OK, dp->ConsumerQueryData(MakeUserPointer(&num_bytes))); |
1223 EXPECT_EQ(10u * sizeof(int32_t), num_bytes); | 1257 EXPECT_EQ(10u * sizeof(int32_t), num_bytes); |
1224 | 1258 |
1225 // But a two-phase read of ten should fail. | 1259 // But a two-phase read of ten should fail. |
1226 num_bytes = 10u * sizeof(int32_t); | 1260 num_bytes = 10u * sizeof(int32_t); |
1227 read_ptr = NULL; | 1261 read_ptr = NULL; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1280 DataPipe::ValidateCreateOptions(&options, &validated_options)); | 1314 DataPipe::ValidateCreateOptions(&options, &validated_options)); |
1281 // This test won't be valid if |ValidateCreateOptions()| decides to give the | 1315 // This test won't be valid if |ValidateCreateOptions()| decides to give the |
1282 // pipe more space. | 1316 // pipe more space. |
1283 ASSERT_EQ(100u, validated_options.capacity_num_bytes); | 1317 ASSERT_EQ(100u, validated_options.capacity_num_bytes); |
1284 | 1318 |
1285 scoped_refptr<LocalDataPipe> dp(new LocalDataPipe(validated_options)); | 1319 scoped_refptr<LocalDataPipe> dp(new LocalDataPipe(validated_options)); |
1286 | 1320 |
1287 // Write 20 bytes. | 1321 // Write 20 bytes. |
1288 uint32_t num_bytes = 20u; | 1322 uint32_t num_bytes = 20u; |
1289 EXPECT_EQ(MOJO_RESULT_OK, | 1323 EXPECT_EQ(MOJO_RESULT_OK, |
1290 dp->ProducerWriteData(&test_data[0], &num_bytes, false)); | 1324 dp->ProducerWriteData(UserPointer<const void>(&test_data[0]), |
| 1325 MakeUserPointer(&num_bytes), false)); |
1291 EXPECT_EQ(20u, num_bytes); | 1326 EXPECT_EQ(20u, num_bytes); |
1292 | 1327 |
1293 // Read 10 bytes. | 1328 // Read 10 bytes. |
1294 unsigned char read_buffer[1000] = { 0 }; | 1329 unsigned char read_buffer[1000] = { 0 }; |
1295 num_bytes = 10u; | 1330 num_bytes = 10u; |
1296 EXPECT_EQ(MOJO_RESULT_OK, | 1331 EXPECT_EQ(MOJO_RESULT_OK, |
1297 dp->ConsumerReadData(UserPointer<void>(read_buffer), | 1332 dp->ConsumerReadData(UserPointer<void>(read_buffer), |
1298 MakeUserPointer(&num_bytes), false)); | 1333 MakeUserPointer(&num_bytes), false)); |
1299 EXPECT_EQ(10u, num_bytes); | 1334 EXPECT_EQ(10u, num_bytes); |
1300 EXPECT_EQ(0, memcmp(read_buffer, &test_data[0], 10u)); | 1335 EXPECT_EQ(0, memcmp(read_buffer, &test_data[0], 10u)); |
1301 | 1336 |
1302 // Check that a two-phase write can now only write (at most) 80 bytes. (This | 1337 // Check that a two-phase write can now only write (at most) 80 bytes. (This |
1303 // checks an implementation detail; this behavior is not guaranteed, but we | 1338 // checks an implementation detail; this behavior is not guaranteed, but we |
1304 // need it for this test.) | 1339 // need it for this test.) |
1305 void* write_buffer_ptr = NULL; | 1340 void* write_buffer_ptr = NULL; |
1306 num_bytes = 0u; | 1341 num_bytes = 0u; |
1307 EXPECT_EQ(MOJO_RESULT_OK, | 1342 EXPECT_EQ(MOJO_RESULT_OK, |
1308 dp->ProducerBeginWriteData(MakeUserPointer(&write_buffer_ptr), | 1343 dp->ProducerBeginWriteData(MakeUserPointer(&write_buffer_ptr), |
1309 MakeUserPointer(&num_bytes), false)); | 1344 MakeUserPointer(&num_bytes), false)); |
1310 EXPECT_TRUE(write_buffer_ptr != NULL); | 1345 EXPECT_TRUE(write_buffer_ptr != NULL); |
1311 EXPECT_EQ(80u, num_bytes); | 1346 EXPECT_EQ(80u, num_bytes); |
1312 EXPECT_EQ(MOJO_RESULT_OK, dp->ProducerEndWriteData(0u)); | 1347 EXPECT_EQ(MOJO_RESULT_OK, dp->ProducerEndWriteData(0u)); |
1313 | 1348 |
1314 // Write as much data as we can (using |ProducerWriteData()|). We should write | 1349 // Write as much data as we can (using |ProducerWriteData()|). We should write |
1315 // 90 bytes. | 1350 // 90 bytes. |
1316 num_bytes = 200u; | 1351 num_bytes = 200u; |
1317 EXPECT_EQ(MOJO_RESULT_OK, | 1352 EXPECT_EQ(MOJO_RESULT_OK, |
1318 dp->ProducerWriteData(&test_data[20], &num_bytes, false)); | 1353 dp->ProducerWriteData(UserPointer<const void>(&test_data[20]), |
| 1354 MakeUserPointer(&num_bytes), false)); |
1319 EXPECT_EQ(90u, num_bytes); | 1355 EXPECT_EQ(90u, num_bytes); |
1320 | 1356 |
1321 // Check that a two-phase read can now only read (at most) 90 bytes. (This | 1357 // Check that a two-phase read can now only read (at most) 90 bytes. (This |
1322 // checks an implementation detail; this behavior is not guaranteed, but we | 1358 // checks an implementation detail; this behavior is not guaranteed, but we |
1323 // need it for this test.) | 1359 // need it for this test.) |
1324 const void* read_buffer_ptr = NULL; | 1360 const void* read_buffer_ptr = NULL; |
1325 num_bytes = 0u; | 1361 num_bytes = 0u; |
1326 EXPECT_EQ(MOJO_RESULT_OK, | 1362 EXPECT_EQ(MOJO_RESULT_OK, |
1327 dp->ConsumerBeginReadData(MakeUserPointer(&read_buffer_ptr), | 1363 dp->ConsumerBeginReadData(MakeUserPointer(&read_buffer_ptr), |
1328 MakeUserPointer(&num_bytes), false)); | 1364 MakeUserPointer(&num_bytes), false)); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1361 EXPECT_EQ(MOJO_RESULT_OK, | 1397 EXPECT_EQ(MOJO_RESULT_OK, |
1362 DataPipe::ValidateCreateOptions(&options, &validated_options)); | 1398 DataPipe::ValidateCreateOptions(&options, &validated_options)); |
1363 | 1399 |
1364 // Close producer first, then consumer. | 1400 // Close producer first, then consumer. |
1365 { | 1401 { |
1366 scoped_refptr<LocalDataPipe> dp(new LocalDataPipe(validated_options)); | 1402 scoped_refptr<LocalDataPipe> dp(new LocalDataPipe(validated_options)); |
1367 | 1403 |
1368 // Write some data, so we'll have something to read. | 1404 // Write some data, so we'll have something to read. |
1369 uint32_t num_bytes = kTestDataSize; | 1405 uint32_t num_bytes = kTestDataSize; |
1370 EXPECT_EQ(MOJO_RESULT_OK, | 1406 EXPECT_EQ(MOJO_RESULT_OK, |
1371 dp->ProducerWriteData(kTestData, &num_bytes, false)); | 1407 dp->ProducerWriteData(UserPointer<const void>(kTestData), |
| 1408 MakeUserPointer(&num_bytes), false)); |
1372 EXPECT_EQ(kTestDataSize, num_bytes); | 1409 EXPECT_EQ(kTestDataSize, num_bytes); |
1373 | 1410 |
1374 // Write it again, so we'll have something left over. | 1411 // Write it again, so we'll have something left over. |
1375 num_bytes = kTestDataSize; | 1412 num_bytes = kTestDataSize; |
1376 EXPECT_EQ(MOJO_RESULT_OK, | 1413 EXPECT_EQ(MOJO_RESULT_OK, |
1377 dp->ProducerWriteData(kTestData, &num_bytes, false)); | 1414 dp->ProducerWriteData(UserPointer<const void>(kTestData), |
| 1415 MakeUserPointer(&num_bytes), false)); |
1378 EXPECT_EQ(kTestDataSize, num_bytes); | 1416 EXPECT_EQ(kTestDataSize, num_bytes); |
1379 | 1417 |
1380 // Start two-phase write. | 1418 // Start two-phase write. |
1381 void* write_buffer_ptr = NULL; | 1419 void* write_buffer_ptr = NULL; |
1382 num_bytes = 0u; | 1420 num_bytes = 0u; |
1383 EXPECT_EQ(MOJO_RESULT_OK, | 1421 EXPECT_EQ(MOJO_RESULT_OK, |
1384 dp->ProducerBeginWriteData(MakeUserPointer(&write_buffer_ptr), | 1422 dp->ProducerBeginWriteData(MakeUserPointer(&write_buffer_ptr), |
1385 MakeUserPointer(&num_bytes), false)); | 1423 MakeUserPointer(&num_bytes), false)); |
1386 EXPECT_TRUE(write_buffer_ptr != NULL); | 1424 EXPECT_TRUE(write_buffer_ptr != NULL); |
1387 EXPECT_GT(num_bytes, 0u); | 1425 EXPECT_GT(num_bytes, 0u); |
(...skipping 27 matching lines...) Expand all Loading... |
1415 dp->ConsumerClose(); | 1453 dp->ConsumerClose(); |
1416 } | 1454 } |
1417 | 1455 |
1418 // Close consumer first, then producer. | 1456 // Close consumer first, then producer. |
1419 { | 1457 { |
1420 scoped_refptr<LocalDataPipe> dp(new LocalDataPipe(validated_options)); | 1458 scoped_refptr<LocalDataPipe> dp(new LocalDataPipe(validated_options)); |
1421 | 1459 |
1422 // Write some data, so we'll have something to read. | 1460 // Write some data, so we'll have something to read. |
1423 uint32_t num_bytes = kTestDataSize; | 1461 uint32_t num_bytes = kTestDataSize; |
1424 EXPECT_EQ(MOJO_RESULT_OK, | 1462 EXPECT_EQ(MOJO_RESULT_OK, |
1425 dp->ProducerWriteData(kTestData, &num_bytes, false)); | 1463 dp->ProducerWriteData(UserPointer<const void>(kTestData), |
| 1464 MakeUserPointer(&num_bytes), false)); |
1426 EXPECT_EQ(kTestDataSize, num_bytes); | 1465 EXPECT_EQ(kTestDataSize, num_bytes); |
1427 | 1466 |
1428 // Start two-phase write. | 1467 // Start two-phase write. |
1429 void* write_buffer_ptr = NULL; | 1468 void* write_buffer_ptr = NULL; |
1430 num_bytes = 0u; | 1469 num_bytes = 0u; |
1431 EXPECT_EQ(MOJO_RESULT_OK, | 1470 EXPECT_EQ(MOJO_RESULT_OK, |
1432 dp->ProducerBeginWriteData(MakeUserPointer(&write_buffer_ptr), | 1471 dp->ProducerBeginWriteData(MakeUserPointer(&write_buffer_ptr), |
1433 MakeUserPointer(&num_bytes), false)); | 1472 MakeUserPointer(&num_bytes), false)); |
1434 EXPECT_TRUE(write_buffer_ptr != NULL); | 1473 EXPECT_TRUE(write_buffer_ptr != NULL); |
1435 ASSERT_GT(num_bytes, kTestDataSize); | 1474 ASSERT_GT(num_bytes, kTestDataSize); |
(...skipping 13 matching lines...) Expand all Loading... |
1449 // Actually write some data. (Note: Premature freeing of the buffer would | 1488 // Actually write some data. (Note: Premature freeing of the buffer would |
1450 // probably only be detected under ASAN or similar.) | 1489 // probably only be detected under ASAN or similar.) |
1451 memcpy(write_buffer_ptr, kTestData, kTestDataSize); | 1490 memcpy(write_buffer_ptr, kTestData, kTestDataSize); |
1452 // Note: Even though the consumer has been closed, ending the two-phase | 1491 // Note: Even though the consumer has been closed, ending the two-phase |
1453 // write will report success. | 1492 // write will report success. |
1454 EXPECT_EQ(MOJO_RESULT_OK, dp->ProducerEndWriteData(kTestDataSize)); | 1493 EXPECT_EQ(MOJO_RESULT_OK, dp->ProducerEndWriteData(kTestDataSize)); |
1455 | 1494 |
1456 // But trying to write should result in failure. | 1495 // But trying to write should result in failure. |
1457 num_bytes = kTestDataSize; | 1496 num_bytes = kTestDataSize; |
1458 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, | 1497 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, |
1459 dp->ProducerWriteData(kTestData, &num_bytes, false)); | 1498 dp->ProducerWriteData(UserPointer<const void>(kTestData), |
| 1499 MakeUserPointer(&num_bytes), false)); |
1460 | 1500 |
1461 // As will trying to start another two-phase write. | 1501 // As will trying to start another two-phase write. |
1462 write_buffer_ptr = NULL; | 1502 write_buffer_ptr = NULL; |
1463 num_bytes = 0u; | 1503 num_bytes = 0u; |
1464 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, | 1504 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, |
1465 dp->ProducerBeginWriteData(MakeUserPointer(&write_buffer_ptr), | 1505 dp->ProducerBeginWriteData(MakeUserPointer(&write_buffer_ptr), |
1466 MakeUserPointer(&num_bytes), false)); | 1506 MakeUserPointer(&num_bytes), false)); |
1467 | 1507 |
1468 dp->ProducerClose(); | 1508 dp->ProducerClose(); |
1469 } | 1509 } |
(...skipping 16 matching lines...) Expand all Loading... |
1486 dp->ProducerClose(); | 1526 dp->ProducerClose(); |
1487 } | 1527 } |
1488 | 1528 |
1489 // Test closing the producer and then trying to read (with no data). | 1529 // Test closing the producer and then trying to read (with no data). |
1490 { | 1530 { |
1491 scoped_refptr<LocalDataPipe> dp(new LocalDataPipe(validated_options)); | 1531 scoped_refptr<LocalDataPipe> dp(new LocalDataPipe(validated_options)); |
1492 | 1532 |
1493 // Write some data, so we'll have something to read. | 1533 // Write some data, so we'll have something to read. |
1494 uint32_t num_bytes = kTestDataSize; | 1534 uint32_t num_bytes = kTestDataSize; |
1495 EXPECT_EQ(MOJO_RESULT_OK, | 1535 EXPECT_EQ(MOJO_RESULT_OK, |
1496 dp->ProducerWriteData(kTestData, &num_bytes, false)); | 1536 dp->ProducerWriteData(UserPointer<const void>(kTestData), |
| 1537 MakeUserPointer(&num_bytes), false)); |
1497 EXPECT_EQ(kTestDataSize, num_bytes); | 1538 EXPECT_EQ(kTestDataSize, num_bytes); |
1498 | 1539 |
1499 // Close the producer. | 1540 // Close the producer. |
1500 dp->ProducerClose(); | 1541 dp->ProducerClose(); |
1501 | 1542 |
1502 // Read that data. | 1543 // Read that data. |
1503 char buffer[1000]; | 1544 char buffer[1000]; |
1504 num_bytes = static_cast<uint32_t>(sizeof(buffer)); | 1545 num_bytes = static_cast<uint32_t>(sizeof(buffer)); |
1505 EXPECT_EQ(MOJO_RESULT_OK, | 1546 EXPECT_EQ(MOJO_RESULT_OK, |
1506 dp->ConsumerReadData(UserPointer<void>(buffer), | 1547 dp->ConsumerReadData(UserPointer<void>(buffer), |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1589 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, dp->ProducerEndWriteData(0u)); | 1630 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, dp->ProducerEndWriteData(0u)); |
1590 | 1631 |
1591 // Still no data. | 1632 // Still no data. |
1592 num_bytes = 1000u; | 1633 num_bytes = 1000u; |
1593 EXPECT_EQ(MOJO_RESULT_OK, dp->ConsumerQueryData(MakeUserPointer(&num_bytes))); | 1634 EXPECT_EQ(MOJO_RESULT_OK, dp->ConsumerQueryData(MakeUserPointer(&num_bytes))); |
1594 EXPECT_EQ(0u, num_bytes); | 1635 EXPECT_EQ(0u, num_bytes); |
1595 | 1636 |
1596 // Now write some data, so we'll be able to try reading. | 1637 // Now write some data, so we'll be able to try reading. |
1597 int32_t element = 123; | 1638 int32_t element = 123; |
1598 num_bytes = 1u * sizeof(int32_t); | 1639 num_bytes = 1u * sizeof(int32_t); |
1599 EXPECT_EQ(MOJO_RESULT_OK, dp->ProducerWriteData(&element, &num_bytes, false)); | 1640 EXPECT_EQ(MOJO_RESULT_OK, |
| 1641 dp->ProducerWriteData(UserPointer<const void>(&element), |
| 1642 MakeUserPointer(&num_bytes), false)); |
1600 | 1643 |
1601 // One element available. | 1644 // One element available. |
1602 num_bytes = 0u; | 1645 num_bytes = 0u; |
1603 EXPECT_EQ(MOJO_RESULT_OK, dp->ConsumerQueryData(MakeUserPointer(&num_bytes))); | 1646 EXPECT_EQ(MOJO_RESULT_OK, dp->ConsumerQueryData(MakeUserPointer(&num_bytes))); |
1604 EXPECT_EQ(1u * sizeof(int32_t), num_bytes); | 1647 EXPECT_EQ(1u * sizeof(int32_t), num_bytes); |
1605 | 1648 |
1606 // Try "ending" a two-phase read when one isn't active. | 1649 // Try "ending" a two-phase read when one isn't active. |
1607 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, | 1650 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, |
1608 dp->ConsumerEndReadData(1u * sizeof(int32_t))); | 1651 dp->ConsumerEndReadData(1u * sizeof(int32_t))); |
1609 | 1652 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1663 }; | 1706 }; |
1664 MojoCreateDataPipeOptions validated_options = { 0 }; | 1707 MojoCreateDataPipeOptions validated_options = { 0 }; |
1665 EXPECT_EQ(MOJO_RESULT_OK, | 1708 EXPECT_EQ(MOJO_RESULT_OK, |
1666 DataPipe::ValidateCreateOptions(&options, &validated_options)); | 1709 DataPipe::ValidateCreateOptions(&options, &validated_options)); |
1667 | 1710 |
1668 scoped_refptr<LocalDataPipe> dp(new LocalDataPipe(validated_options)); | 1711 scoped_refptr<LocalDataPipe> dp(new LocalDataPipe(validated_options)); |
1669 | 1712 |
1670 // Write some elements. | 1713 // Write some elements. |
1671 char elements[2] = { 'a', 'b' }; | 1714 char elements[2] = { 'a', 'b' }; |
1672 uint32_t num_bytes = 2u; | 1715 uint32_t num_bytes = 2u; |
1673 EXPECT_EQ(MOJO_RESULT_OK, dp->ProducerWriteData(elements, &num_bytes, false)); | 1716 EXPECT_EQ(MOJO_RESULT_OK, |
| 1717 dp->ProducerWriteData(UserPointer<const void>(elements), |
| 1718 MakeUserPointer(&num_bytes), false)); |
1674 EXPECT_EQ(2u, num_bytes); | 1719 EXPECT_EQ(2u, num_bytes); |
1675 | 1720 |
1676 // Begin reading. | 1721 // Begin reading. |
1677 const void* read_ptr = NULL; | 1722 const void* read_ptr = NULL; |
1678 num_bytes = 2u; | 1723 num_bytes = 2u; |
1679 EXPECT_EQ(MOJO_RESULT_OK, | 1724 EXPECT_EQ(MOJO_RESULT_OK, |
1680 dp->ConsumerBeginReadData(MakeUserPointer(&read_ptr), | 1725 dp->ConsumerBeginReadData(MakeUserPointer(&read_ptr), |
1681 MakeUserPointer(&num_bytes), false)); | 1726 MakeUserPointer(&num_bytes), false)); |
1682 EXPECT_EQ(2u, num_bytes); | 1727 EXPECT_EQ(2u, num_bytes); |
1683 EXPECT_EQ('a', static_cast<const char*>(read_ptr)[0]); | 1728 EXPECT_EQ('a', static_cast<const char*>(read_ptr)[0]); |
1684 EXPECT_EQ('b', static_cast<const char*>(read_ptr)[1]); | 1729 EXPECT_EQ('b', static_cast<const char*>(read_ptr)[1]); |
1685 | 1730 |
1686 // Try to write some more. But nothing should be discardable right now. | 1731 // Try to write some more. But nothing should be discardable right now. |
1687 elements[0] = 'x'; | 1732 elements[0] = 'x'; |
1688 elements[1] = 'y'; | 1733 elements[1] = 'y'; |
1689 num_bytes = 2u; | 1734 num_bytes = 2u; |
1690 // TODO(vtl): This should be: | 1735 // TODO(vtl): This should be: |
1691 // EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT, | 1736 // EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT, |
1692 // dp->ProducerWriteData(elements, &num_bytes, false)); | 1737 // dp->ProducerWriteData(elements, &num_bytes, false)); |
1693 // but we incorrectly think that the bytes being read are discardable. Letting | 1738 // but we incorrectly think that the bytes being read are discardable. Letting |
1694 // this through reveals the significant consequence. | 1739 // this through reveals the significant consequence. |
1695 EXPECT_EQ(MOJO_RESULT_OK, dp->ProducerWriteData(elements, &num_bytes, false)); | 1740 EXPECT_EQ(MOJO_RESULT_OK, |
| 1741 dp->ProducerWriteData(UserPointer<const void>(elements), |
| 1742 MakeUserPointer(&num_bytes), false)); |
1696 | 1743 |
1697 // Check that our read buffer hasn't changed underneath us. | 1744 // Check that our read buffer hasn't changed underneath us. |
1698 EXPECT_EQ('a', static_cast<const char*>(read_ptr)[0]); | 1745 EXPECT_EQ('a', static_cast<const char*>(read_ptr)[0]); |
1699 EXPECT_EQ('b', static_cast<const char*>(read_ptr)[1]); | 1746 EXPECT_EQ('b', static_cast<const char*>(read_ptr)[1]); |
1700 | 1747 |
1701 // End reading. | 1748 // End reading. |
1702 EXPECT_EQ(MOJO_RESULT_OK, dp->ConsumerEndReadData(2u)); | 1749 EXPECT_EQ(MOJO_RESULT_OK, dp->ConsumerEndReadData(2u)); |
1703 | 1750 |
1704 // Now writing should succeed. | 1751 // Now writing should succeed. |
1705 EXPECT_EQ(MOJO_RESULT_OK, dp->ProducerWriteData(elements, &num_bytes, false)); | 1752 EXPECT_EQ(MOJO_RESULT_OK, |
| 1753 dp->ProducerWriteData(UserPointer<const void>(elements), |
| 1754 MakeUserPointer(&num_bytes), false)); |
1706 | 1755 |
1707 // And if we read, we should get the new values. | 1756 // And if we read, we should get the new values. |
1708 read_ptr = NULL; | 1757 read_ptr = NULL; |
1709 num_bytes = 2u; | 1758 num_bytes = 2u; |
1710 EXPECT_EQ(MOJO_RESULT_OK, | 1759 EXPECT_EQ(MOJO_RESULT_OK, |
1711 dp->ConsumerBeginReadData(MakeUserPointer(&read_ptr), | 1760 dp->ConsumerBeginReadData(MakeUserPointer(&read_ptr), |
1712 MakeUserPointer(&num_bytes), false)); | 1761 MakeUserPointer(&num_bytes), false)); |
1713 EXPECT_EQ(2u, num_bytes); | 1762 EXPECT_EQ(2u, num_bytes); |
1714 EXPECT_EQ('x', static_cast<const char*>(read_ptr)[0]); | 1763 EXPECT_EQ('x', static_cast<const char*>(read_ptr)[0]); |
1715 EXPECT_EQ('y', static_cast<const char*>(read_ptr)[1]); | 1764 EXPECT_EQ('y', static_cast<const char*>(read_ptr)[1]); |
1716 | 1765 |
1717 // End reading. | 1766 // End reading. |
1718 EXPECT_EQ(MOJO_RESULT_OK, dp->ConsumerEndReadData(2u)); | 1767 EXPECT_EQ(MOJO_RESULT_OK, dp->ConsumerEndReadData(2u)); |
1719 | 1768 |
1720 dp->ProducerClose(); | 1769 dp->ProducerClose(); |
1721 dp->ConsumerClose(); | 1770 dp->ConsumerClose(); |
1722 } | 1771 } |
1723 | 1772 |
1724 } // namespace | 1773 } // namespace |
1725 } // namespace system | 1774 } // namespace system |
1726 } // namespace mojo | 1775 } // namespace mojo |
OLD | NEW |