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

Unified Diff: mojo/edk/test/mojo_test_base.cc

Issue 1748503002: [mojo-edk] Add MojoWatch and MojoCancelWatch APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: revert RequestContext usage, nits Created 4 years, 10 months 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/edk/test/mojo_test_base.h ('k') | mojo/mojo_edk.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/edk/test/mojo_test_base.cc
diff --git a/mojo/edk/test/mojo_test_base.cc b/mojo/edk/test/mojo_test_base.cc
index 27c92bb9b2e01384c6ccfab76595613bc76f7bc9..7ec067aeae6742fe27c8f3ee33341536270d99bf 100644
--- a/mojo/edk/test/mojo_test_base.cc
+++ b/mojo/edk/test/mojo_test_base.cc
@@ -9,6 +9,7 @@
#include "mojo/edk/embedder/embedder.h"
#include "mojo/edk/system/handle_signals_state.h"
#include "mojo/public/c/system/buffer.h"
+#include "mojo/public/c/system/data_pipe.h"
#include "mojo/public/c/system/functions.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -221,6 +222,48 @@ void MojoTestBase::ExpectBufferContents(MojoHandle h,
EXPECT_EQ(MOJO_RESULT_OK, MojoUnmapBuffer(static_cast<void*>(data)));
}
+// static
+void MojoTestBase::CreateDataPipe(MojoHandle *p0,
+ MojoHandle* p1,
+ size_t capacity) {
+ MojoCreateDataPipeOptions options;
+ options.struct_size = static_cast<uint32_t>(sizeof(options));
+ options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE;
+ options.element_num_bytes = 1;
+ options.capacity_num_bytes = static_cast<uint32_t>(capacity);
+
+ MojoCreateDataPipe(&options, p0, p1);
+ CHECK_NE(*p0, MOJO_HANDLE_INVALID);
+ CHECK_NE(*p1, MOJO_HANDLE_INVALID);
+}
+
+// static
+void MojoTestBase::WriteData(MojoHandle producer, const std::string& data) {
+ CHECK_EQ(MojoWait(producer, MOJO_HANDLE_SIGNAL_WRITABLE,
+ MOJO_DEADLINE_INDEFINITE, nullptr),
+ MOJO_RESULT_OK);
+ uint32_t num_bytes = static_cast<uint32_t>(data.size());
+ CHECK_EQ(MojoWriteData(producer, data.data(), &num_bytes,
+ MOJO_WRITE_DATA_FLAG_ALL_OR_NONE),
+ MOJO_RESULT_OK);
+ CHECK_EQ(num_bytes, static_cast<uint32_t>(data.size()));
+}
+
+// static
+std::string MojoTestBase::ReadData(MojoHandle consumer, size_t size) {
+ CHECK_EQ(MojoWait(consumer, MOJO_HANDLE_SIGNAL_READABLE,
+ MOJO_DEADLINE_INDEFINITE, nullptr),
+ MOJO_RESULT_OK);
+ std::vector<char> buffer(size);
+ uint32_t num_bytes = static_cast<uint32_t>(size);
+ CHECK_EQ(MojoReadData(consumer, buffer.data(), &num_bytes,
+ MOJO_WRITE_DATA_FLAG_ALL_OR_NONE),
+ MOJO_RESULT_OK);
+ CHECK_EQ(num_bytes, static_cast<uint32_t>(size));
+
+ return std::string(buffer.data(), buffer.size());
+}
+
} // namespace test
} // namespace edk
} // namespace mojo
« no previous file with comments | « mojo/edk/test/mojo_test_base.h ('k') | mojo/mojo_edk.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698