diff options
author | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-10 23:17:12 +0000 |
---|---|---|
committer | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-10 23:17:12 +0000 |
commit | 517d8b4a4b51d75b58bd0def382a819f9e0d9306 (patch) | |
tree | a759cfdb95473e1f75345ebb48210e32a81f2c42 /mojo/public | |
parent | 1d9bdfa02acadf1bc3e63f62ee408bfe1f2fb589 (diff) | |
download | chromium_src-517d8b4a4b51d75b58bd0def382a819f9e0d9306.zip chromium_src-517d8b4a4b51d75b58bd0def382a819f9e0d9306.tar.gz chromium_src-517d8b4a4b51d75b58bd0def382a819f9e0d9306.tar.bz2 |
Mojo: Small cleanup of public/tests/test_support.h.
R=sky@chromium.org
Review URL: https://codereview.chromium.org/159303002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@250235 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo/public')
-rw-r--r-- | mojo/public/environment/tests/async_waiter_unittest.cc | 13 | ||||
-rw-r--r-- | mojo/public/tests/test_support.cc | 21 | ||||
-rw-r--r-- | mojo/public/tests/test_support.h | 17 | ||||
-rw-r--r-- | mojo/public/utility/tests/run_loop_unittest.cc | 6 |
4 files changed, 31 insertions, 26 deletions
diff --git a/mojo/public/environment/tests/async_waiter_unittest.cc b/mojo/public/environment/tests/async_waiter_unittest.cc index 9dfbecc..a0f39ef 100644 --- a/mojo/public/environment/tests/async_waiter_unittest.cc +++ b/mojo/public/environment/tests/async_waiter_unittest.cc @@ -4,6 +4,8 @@ #include "mojo/public/environment/default_async_waiter.h" +#include <string> + #include "mojo/public/environment/environment.h" #include "mojo/public/system/core_cpp.h" #include "mojo/public/system/macros.h" @@ -70,8 +72,7 @@ class AsyncWaiterTest : public testing::Test { TEST_F(AsyncWaiterTest, CallbackNotified) { TestAsyncWaitCallback callback; MessagePipe test_pipe; - EXPECT_EQ(MOJO_RESULT_OK, - test::WriteEmptyMessage(test_pipe.handle1.get())); + EXPECT_TRUE(test::WriteTextMessage(test_pipe.handle1.get(), std::string())); CallAsyncWait(test_pipe.handle0.get(), MOJO_WAIT_FLAG_READABLE, @@ -87,10 +88,8 @@ TEST_F(AsyncWaiterTest, TwoCallbacksNotified) { TestAsyncWaitCallback callback2; MessagePipe test_pipe1; MessagePipe test_pipe2; - EXPECT_EQ(MOJO_RESULT_OK, - test::WriteEmptyMessage(test_pipe1.handle1.get())); - EXPECT_EQ(MOJO_RESULT_OK, - test::WriteEmptyMessage(test_pipe2.handle1.get())); + EXPECT_TRUE(test::WriteTextMessage(test_pipe1.handle1.get(), std::string())); + EXPECT_TRUE(test::WriteTextMessage(test_pipe2.handle1.get(), std::string())); CallAsyncWait(test_pipe1.handle0.get(), MOJO_WAIT_FLAG_READABLE, &callback1); CallAsyncWait(test_pipe2.handle0.get(), MOJO_WAIT_FLAG_READABLE, &callback2); @@ -106,7 +105,7 @@ TEST_F(AsyncWaiterTest, TwoCallbacksNotified) { TEST_F(AsyncWaiterTest, CancelCallback) { TestAsyncWaitCallback callback; MessagePipe test_pipe; - EXPECT_EQ(MOJO_RESULT_OK, test::WriteEmptyMessage(test_pipe.handle1.get())); + EXPECT_TRUE(test::WriteTextMessage(test_pipe.handle1.get(), std::string())); CallCancelWait( CallAsyncWait(test_pipe.handle0.get(), diff --git a/mojo/public/tests/test_support.cc b/mojo/public/tests/test_support.cc index de3e01e..c9cb169 100644 --- a/mojo/public/tests/test_support.cc +++ b/mojo/public/tests/test_support.cc @@ -10,7 +10,8 @@ namespace mojo { namespace test { -bool WriteTextMessage(MessagePipeHandle handle, const std::string& text) { +bool WriteTextMessage(const MessagePipeHandle& handle, + const std::string& text) { MojoResult rv = WriteMessageRaw(handle, text.data(), static_cast<uint32_t>(text.size()), @@ -20,7 +21,7 @@ bool WriteTextMessage(MessagePipeHandle handle, const std::string& text) { return rv == MOJO_RESULT_OK; } -bool ReadTextMessage(MessagePipeHandle handle, std::string* text) { +bool ReadTextMessage(const MessagePipeHandle& handle, std::string* text) { MojoResult rv; bool did_wait = false; @@ -57,6 +58,12 @@ bool ReadTextMessage(MessagePipeHandle handle, std::string* text) { return rv == MOJO_RESULT_OK; } +bool DiscardMessage(const MessagePipeHandle& handle) { + MojoResult rv = ReadMessageRaw(handle, NULL, NULL, NULL, NULL, + MOJO_READ_MESSAGE_FLAG_MAY_DISCARD); + return rv == MOJO_RESULT_OK; +} + void IterateAndReportPerf(const char* test_name, PerfTestSingleIteration single_iteration, void* closure) { @@ -80,15 +87,5 @@ void IterateAndReportPerf(const char* test_name, "iterations/second"); } -MojoResult WriteEmptyMessage(const MessagePipeHandle& handle) { - return WriteMessageRaw(handle, NULL, 0, NULL, 0, - MOJO_WRITE_MESSAGE_FLAG_NONE); -} - -MojoResult ReadEmptyMessage(const MessagePipeHandle& handle) { - return ReadMessageRaw(handle, NULL, NULL, NULL, NULL, - MOJO_READ_MESSAGE_FLAG_MAY_DISCARD); -} - } // namespace test } // namespace mojo diff --git a/mojo/public/tests/test_support.h b/mojo/public/tests/test_support.h index a75ba1e..0cc98c4 100644 --- a/mojo/public/tests/test_support.h +++ b/mojo/public/tests/test_support.h @@ -12,8 +12,18 @@ namespace mojo { namespace test { -bool WriteTextMessage(MessagePipeHandle handle, const std::string& text); -bool ReadTextMessage(MessagePipeHandle handle, std::string* text); +// Writes a message to |handle| with message data |text|. Returns true on +// success. +bool WriteTextMessage(const MessagePipeHandle& handle, const std::string& text); + +// Reads a message from |handle|, putting its contents into |*text|. Returns +// true on success. (This blocks if necessary and will call |MojoReadMessage()| +// multiple times, e.g., to query the size of the message.) +bool ReadTextMessage(const MessagePipeHandle& handle, std::string* text); + +// Discards a message from |handle|. Returns true on success. (This does not +// block. It will fail if no message is available to discard.) +bool DiscardMessage(const MessagePipeHandle& handle); // Run |single_iteration| an appropriate number of times and report its // performance appropriately. (This actually runs |single_iteration| for a fixed @@ -23,9 +33,6 @@ void IterateAndReportPerf(const char* test_name, PerfTestSingleIteration single_iteration, void* closure); -MojoResult WriteEmptyMessage(const MessagePipeHandle& handle); -MojoResult ReadEmptyMessage(const MessagePipeHandle& handle); - } // namespace test } // namespace mojo diff --git a/mojo/public/utility/tests/run_loop_unittest.cc b/mojo/public/utility/tests/run_loop_unittest.cc index 9899695..6a592663 100644 --- a/mojo/public/utility/tests/run_loop_unittest.cc +++ b/mojo/public/utility/tests/run_loop_unittest.cc @@ -4,6 +4,8 @@ #include "mojo/public/utility/run_loop.h" +#include <string> + #include "mojo/public/system/core_cpp.h" #include "mojo/public/tests/test_support.h" #include "mojo/public/utility/run_loop_handler.h" @@ -94,7 +96,7 @@ class RemoveOnReadyRunLoopHandler : public TestRunLoopHandler { TEST_F(RunLoopTest, HandleReady) { RemoveOnReadyRunLoopHandler handler; MessagePipe test_pipe; - EXPECT_EQ(MOJO_RESULT_OK, test::WriteEmptyMessage(test_pipe.handle1.get())); + EXPECT_TRUE(test::WriteTextMessage(test_pipe.handle1.get(), std::string())); RunLoop run_loop; handler.set_run_loop(&run_loop); @@ -130,7 +132,7 @@ class QuitOnReadyRunLoopHandler : public TestRunLoopHandler { TEST_F(RunLoopTest, QuitFromReady) { QuitOnReadyRunLoopHandler handler; MessagePipe test_pipe; - EXPECT_EQ(MOJO_RESULT_OK, test::WriteEmptyMessage(test_pipe.handle1.get())); + EXPECT_TRUE(test::WriteTextMessage(test_pipe.handle1.get(), std::string())); RunLoop run_loop; handler.set_run_loop(&run_loop); |