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

Unified Diff: mojo/edk/system/wait_set_dispatcher_unittest.cc

Issue 1880823005: [mojo-edk] Add explicit message object APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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/system/message_pipe_unittest.cc ('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/system/wait_set_dispatcher_unittest.cc
diff --git a/mojo/edk/system/wait_set_dispatcher_unittest.cc b/mojo/edk/system/wait_set_dispatcher_unittest.cc
index 2a42be164523a718a506bcfb3434061b47099145..40ac2ac9a7089f83660f60e81c41b46b317e91d3 100644
--- a/mojo/edk/system/wait_set_dispatcher_unittest.cc
+++ b/mojo/edk/system/wait_set_dispatcher_unittest.cc
@@ -13,6 +13,7 @@
#include "base/memory/ref_counted.h"
#include "mojo/edk/embedder/embedder_internal.h"
#include "mojo/edk/system/core.h"
+#include "mojo/edk/system/message_for_transit.h"
#include "mojo/edk/system/message_pipe_dispatcher.h"
#include "mojo/edk/system/request_context.h"
#include "mojo/edk/system/test_utils.h"
@@ -74,6 +75,35 @@ class WaitSetDispatcherTest : public ::testing::Test {
dispatchers_to_close_.push_back(dispatcher);
}
+ void WriteMessage(MessagePipeDispatcher* dispatcher,
+ const void* bytes,
+ size_t num_bytes) {
+ Core* core = mojo::edk::internal::g_core;
+ MojoMessageHandle msg;
+ ASSERT_EQ(MOJO_RESULT_OK,
+ core->AllocMessage(static_cast<uint32_t>(num_bytes), nullptr, 0,
+ MOJO_ALLOC_MESSAGE_FLAG_NONE, &msg));
+ void* buffer;
+ ASSERT_EQ(MOJO_RESULT_OK, core->GetMessageBuffer(msg, &buffer));
+ memcpy(buffer, bytes, num_bytes);
+
+ std::unique_ptr<MessageForTransit> message(
+ reinterpret_cast<MessageForTransit*>(msg));
+ ASSERT_EQ(MOJO_RESULT_OK,
+ dispatcher->WriteMessage(std::move(message),
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
+ }
+
+ void ReadMessage(MessagePipeDispatcher* dispatcher,
+ void* bytes,
+ uint32_t* num_bytes) {
+ std::unique_ptr<MessageForTransit> message;
+ ASSERT_EQ(MOJO_RESULT_OK,
+ dispatcher->ReadMessage(&message, num_bytes, nullptr, 0,
+ MOJO_READ_MESSAGE_FLAG_NONE, false));
+ memcpy(bytes, message->bytes(), *num_bytes);
+ }
+
protected:
scoped_refptr<MessagePipeDispatcher> dispatcher0_;
scoped_refptr<MessagePipeDispatcher> dispatcher1_;
@@ -140,9 +170,7 @@ TEST_F(WaitSetDispatcherTest, Basic) {
// Write to |dispatcher1_|, which should make |dispatcher0_| readable.
char buffer[] = "abcd";
w.Init();
- ASSERT_EQ(MOJO_RESULT_OK,
- dispatcher1_->WriteMessage(buffer, sizeof(buffer), nullptr, 0,
- MOJO_WRITE_MESSAGE_FLAG_NONE));
+ WriteMessage(dispatcher1_.get(), buffer, sizeof(buffer));
EXPECT_EQ(MOJO_RESULT_OK, w.Wait(MOJO_DEADLINE_INDEFINITE, nullptr));
woken_dispatcher = nullptr;
context = 0;
@@ -187,9 +215,7 @@ TEST_F(WaitSetDispatcherTest, HandleWithoutRemoving) {
// Write to |dispatcher1_|, which should make |dispatcher0_| readable.
char buffer[] = "abcd";
w.Init();
- ASSERT_EQ(MOJO_RESULT_OK,
- dispatcher1_->WriteMessage(buffer, sizeof(buffer), nullptr, 0,
- MOJO_WRITE_MESSAGE_FLAG_NONE));
+ WriteMessage(dispatcher1_.get(), buffer, sizeof(buffer));
EXPECT_EQ(MOJO_RESULT_OK, w.Wait(MOJO_DEADLINE_INDEFINITE, nullptr));
woken_dispatcher = nullptr;
context = 0;
@@ -201,9 +227,7 @@ TEST_F(WaitSetDispatcherTest, HandleWithoutRemoving) {
// Read from |dispatcher0_| which should change it's state to non-readable.
char read_buffer[sizeof(buffer) + 5];
uint32_t num_bytes = sizeof(read_buffer);
- ASSERT_EQ(MOJO_RESULT_OK,
- dispatcher0_->ReadMessage(read_buffer, &num_bytes, nullptr,
- nullptr, MOJO_READ_MESSAGE_FLAG_NONE));
+ ReadMessage(dispatcher0_.get(), read_buffer, &num_bytes);
EXPECT_EQ(sizeof(buffer), num_bytes);
// No dispatchers are ready.
@@ -314,9 +338,7 @@ TEST_F(WaitSetDispatcherTest, MultipleReady) {
// Write to |dispatcher1_|, which should make |dispatcher0_| readable.
char buffer[] = "abcd";
w.Init();
- ASSERT_EQ(MOJO_RESULT_OK,
- dispatcher1_->WriteMessage(buffer, sizeof(buffer), nullptr, 0,
- MOJO_WRITE_MESSAGE_FLAG_NONE));
+ WriteMessage(dispatcher1_.get(), buffer, sizeof(buffer));
{
Waiter mp_w;
mp_w.Init();
« no previous file with comments | « mojo/edk/system/message_pipe_unittest.cc ('k') | mojo/mojo_edk.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698