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

Unified Diff: mojo/common/data_pipe_utils_unittest.cc

Issue 696543003: Mojo content handler shebang support (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: For now, we'll block waiting for 7 characters (#!mojo: or not) Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/common/data_pipe_utils.cc ('k') | mojo/shell/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/common/data_pipe_utils_unittest.cc
diff --git a/mojo/common/data_pipe_utils_unittest.cc b/mojo/common/data_pipe_utils_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..61f0afa5ccfdb205660cbe3ab686318fd1c763bf
--- /dev/null
+++ b/mojo/common/data_pipe_utils_unittest.cc
@@ -0,0 +1,109 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mojo/common/data_pipe_utils.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace mojo {
+namespace common {
+namespace {
+
+ /*
+TEST(DataPipePeek, PeekNBytes) {
+ DataPipe data_pipe;
+ DataPipeConsumerHandle consumer(data_pipe.consumer_handle.get());
+ DataPipeProducerHandle producer(data_pipe.producer_handle.get());
+
+ // Inialize the pipe with 4 bytes.
+
+ const char* s4 = "1234";
+ uint32_t num_bytes4 = 4;
+ EXPECT_EQ(MOJO_RESULT_OK,
+ WriteDataRaw(producer, s4, &num_bytes4, MOJO_WRITE_DATA_FLAG_NONE));
+ EXPECT_EQ(4u, num_bytes4);
+
+ // We're not consuming data, so peeking for 4 bytes should always succeed.
+
+ std::string bytes;
+ MojoDeadline timeout = 0;
+ EXPECT_TRUE(BlockingPeekNBytes(consumer, &bytes, num_bytes4, timeout));
+ EXPECT_EQ(bytes, std::string(s4));
+
+ timeout = 1000; // 1ms
+ EXPECT_TRUE(BlockingPeekNBytes(consumer, &bytes, num_bytes4, timeout));
+ EXPECT_EQ(bytes, std::string(s4));
+
+ timeout = MOJO_DEADLINE_INDEFINITE;
+ EXPECT_TRUE(BlockingPeekNBytes(consumer, &bytes, num_bytes4, timeout));
+ EXPECT_EQ(bytes, std::string(s4));
+
+ // Peeking for 5 bytes should fail, until another byte is written.
+
+ uint32_t bytes1 = 1;
+ uint32_t num_bytes5 = 5;
+ const char* s1 = "5";
+ const char* s5 = "12345";
+
+ timeout = 0;
+ EXPECT_FALSE(BlockingPeekNBytes(consumer, &bytes, num_bytes5, timeout));
+
+ timeout = 500; // Should cause peek to timeout after about 0.5ms.
+ EXPECT_FALSE(BlockingPeekNBytes(consumer, &bytes, num_bytes5, timeout));
+
+ EXPECT_EQ(MOJO_RESULT_OK,
+ WriteDataRaw(producer, s1, &bytes1, MOJO_WRITE_DATA_FLAG_NONE));
+ EXPECT_EQ(1u, bytes1);
+
+ EXPECT_TRUE(BlockingPeekNBytes(consumer, &bytes, num_bytes5, timeout));
+ EXPECT_EQ(bytes, std::string(s5));
+
+ // If the consumer side of the pipe is closed, peek should fail.
+
+ data_pipe.consumer_handle.reset();
+ timeout = 0;
+ EXPECT_FALSE(BlockingPeekNBytes(consumer, &bytes, num_bytes5, timeout));
+}
+
+TEST(DataPipePeek, PeekLine) {
+ DataPipe data_pipe;
+ DataPipeConsumerHandle consumer(data_pipe.consumer_handle.get());
+ DataPipeProducerHandle producer(data_pipe.producer_handle.get());
+
+ // Inialize the pipe with 4 bytes and no newline.
+
+ const char* s4 = "1234";
+ uint32_t num_bytes4 = 4;
+ EXPECT_EQ(MOJO_RESULT_OK,
+ WriteDataRaw(producer, s4, &num_bytes4, MOJO_WRITE_DATA_FLAG_NONE));
+ EXPECT_EQ(4u, num_bytes4);
+
+ // Peeking for a line should fail.
+
+ std::string str;
+ size_t max_str_length = 5;
+ MojoDeadline timeout = 0;
+ EXPECT_FALSE(BlockingPeekLine(consumer, &str, max_str_length, timeout));
+
+ // Writing a newline should cause PeekLine to succeed.
+
+ uint32_t bytes1 = 1;
+ const char* s1 = "\n";
+ EXPECT_EQ(MOJO_RESULT_OK,
+ WriteDataRaw(producer, s1, &bytes1, MOJO_WRITE_DATA_FLAG_NONE));
+ EXPECT_EQ(1u, bytes1);
+
+ EXPECT_TRUE(BlockingPeekLine(consumer, &str, max_str_length, timeout));
+ EXPECT_EQ(str, std::string(s4) + "\n");
+
+ // If the max_line_length parameter is less than the length of the
+ // newline terminated string, then peek should fail.
+
+ max_str_length = 3;
+ EXPECT_FALSE(BlockingPeekLine(consumer, &str, max_str_length, timeout));
+}
+ */
+} // namespace
+} // namespace common
+} // namespace mojo
« no previous file with comments | « mojo/common/data_pipe_utils.cc ('k') | mojo/shell/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698