OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "shell/application_manager/data_pipe_peek.h" | 5 #include "shell/application_manager/data_pipe_peek.h" |
6 | 6 |
7 #include "shell/context.h" | 7 #include "shell/context.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 namespace mojo { | |
11 namespace shell { | 10 namespace shell { |
12 namespace { | 11 namespace { |
13 | 12 |
14 TEST(DataPipePeek, PeekNBytes) { | 13 TEST(DataPipePeek, PeekNBytes) { |
15 Context::EnsureEmbedderIsInitialized(); | 14 Context::EnsureEmbedderIsInitialized(); |
16 | 15 |
17 DataPipe data_pipe; | 16 mojo::DataPipe data_pipe; |
18 DataPipeConsumerHandle consumer(data_pipe.consumer_handle.get()); | 17 mojo::DataPipeConsumerHandle consumer(data_pipe.consumer_handle.get()); |
19 DataPipeProducerHandle producer(data_pipe.producer_handle.get()); | 18 mojo::DataPipeProducerHandle producer(data_pipe.producer_handle.get()); |
20 | 19 |
21 // Inialize the pipe with 4 bytes. | 20 // Inialize the pipe with 4 bytes. |
22 | 21 |
23 const char* s4 = "1234"; | 22 const char* s4 = "1234"; |
24 uint32_t num_bytes4 = 4; | 23 uint32_t num_bytes4 = 4; |
25 EXPECT_EQ(MOJO_RESULT_OK, | 24 EXPECT_EQ(MOJO_RESULT_OK, |
26 WriteDataRaw(producer, s4, &num_bytes4, MOJO_WRITE_DATA_FLAG_NONE)); | 25 WriteDataRaw(producer, s4, &num_bytes4, MOJO_WRITE_DATA_FLAG_NONE)); |
27 EXPECT_EQ(4u, num_bytes4); | 26 EXPECT_EQ(4u, num_bytes4); |
28 | 27 |
29 // We're not consuming data, so peeking for 4 bytes should always succeed. | 28 // We're not consuming data, so peeking for 4 bytes should always succeed. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 // If the consumer side of the pipe is closed, peek should fail. | 63 // If the consumer side of the pipe is closed, peek should fail. |
65 | 64 |
66 data_pipe.consumer_handle.reset(); | 65 data_pipe.consumer_handle.reset(); |
67 timeout = 0; | 66 timeout = 0; |
68 EXPECT_FALSE(BlockingPeekNBytes(consumer, &bytes, num_bytes5, timeout)); | 67 EXPECT_FALSE(BlockingPeekNBytes(consumer, &bytes, num_bytes5, timeout)); |
69 } | 68 } |
70 | 69 |
71 TEST(DataPipePeek, PeekLine) { | 70 TEST(DataPipePeek, PeekLine) { |
72 Context::EnsureEmbedderIsInitialized(); | 71 Context::EnsureEmbedderIsInitialized(); |
73 | 72 |
74 DataPipe data_pipe; | 73 mojo::DataPipe data_pipe; |
75 DataPipeConsumerHandle consumer(data_pipe.consumer_handle.get()); | 74 mojo::DataPipeConsumerHandle consumer(data_pipe.consumer_handle.get()); |
76 DataPipeProducerHandle producer(data_pipe.producer_handle.get()); | 75 mojo::DataPipeProducerHandle producer(data_pipe.producer_handle.get()); |
77 | 76 |
78 // Inialize the pipe with 4 bytes and no newline. | 77 // Inialize the pipe with 4 bytes and no newline. |
79 | 78 |
80 const char* s4 = "1234"; | 79 const char* s4 = "1234"; |
81 uint32_t num_bytes4 = 4; | 80 uint32_t num_bytes4 = 4; |
82 EXPECT_EQ(MOJO_RESULT_OK, | 81 EXPECT_EQ(MOJO_RESULT_OK, |
83 WriteDataRaw(producer, s4, &num_bytes4, MOJO_WRITE_DATA_FLAG_NONE)); | 82 WriteDataRaw(producer, s4, &num_bytes4, MOJO_WRITE_DATA_FLAG_NONE)); |
84 EXPECT_EQ(4u, num_bytes4); | 83 EXPECT_EQ(4u, num_bytes4); |
85 | 84 |
86 // Peeking for a line should fail. | 85 // Peeking for a line should fail. |
(...skipping 16 matching lines...) Expand all Loading... |
103 | 102 |
104 // If the max_line_length parameter is less than the length of the | 103 // If the max_line_length parameter is less than the length of the |
105 // newline terminated string, then peek should fail. | 104 // newline terminated string, then peek should fail. |
106 | 105 |
107 max_str_length = 3; | 106 max_str_length = 3; |
108 EXPECT_FALSE(BlockingPeekLine(consumer, &str, max_str_length, timeout)); | 107 EXPECT_FALSE(BlockingPeekLine(consumer, &str, max_str_length, timeout)); |
109 } | 108 } |
110 | 109 |
111 } // namespace | 110 } // namespace |
112 } // namespace shell | 111 } // namespace shell |
113 } // namespace mojo | |
OLD | NEW |