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

Side by Side Diff: mojo/public/cpp/test_support/lib/test_utils.cc

Issue 2250183003: Make the fuchsia mojo/public repo the source of truth. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 4 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 unified diff | Download patch
« no previous file with comments | « mojo/public/cpp/test_support/BUILD.gn ('k') | mojo/public/cpp/test_support/test_support.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "mojo/public/cpp/test_support/test_utils.h"
6
7 #include "mojo/public/cpp/system/handle.h"
8 #include "mojo/public/cpp/system/message_pipe.h"
9 #include "mojo/public/cpp/system/wait.h"
10
11 namespace mojo {
12 namespace test {
13
14 bool WriteTextMessage(const MessagePipeHandle& handle,
15 const std::string& text) {
16 MojoResult rv =
17 WriteMessageRaw(handle, text.data(), static_cast<uint32_t>(text.size()),
18 nullptr, 0u, MOJO_WRITE_MESSAGE_FLAG_NONE);
19 return rv == MOJO_RESULT_OK;
20 }
21
22 bool ReadTextMessage(const MessagePipeHandle& handle, std::string* text) {
23 MojoResult rv;
24 bool did_wait = false;
25
26 uint32_t num_bytes = 0u;
27 uint32_t num_handles = 0u;
28 for (;;) {
29 rv = ReadMessageRaw(handle, nullptr, &num_bytes, nullptr, &num_handles,
30 MOJO_READ_MESSAGE_FLAG_NONE);
31 if (rv == MOJO_RESULT_SHOULD_WAIT) {
32 if (did_wait) {
33 assert(false); // Looping endlessly!?
34 return false;
35 }
36 rv = Wait(handle, MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE,
37 nullptr);
38 if (rv != MOJO_RESULT_OK)
39 return false;
40 did_wait = true;
41 } else {
42 assert(!num_handles);
43 break;
44 }
45 }
46
47 text->resize(num_bytes);
48 rv = ReadMessageRaw(handle, &text->at(0), &num_bytes, nullptr, &num_handles,
49 MOJO_READ_MESSAGE_FLAG_NONE);
50 return rv == MOJO_RESULT_OK;
51 }
52
53 bool DiscardMessage(const MessagePipeHandle& handle) {
54 MojoResult rv = ReadMessageRaw(handle, nullptr, nullptr, nullptr, nullptr,
55 MOJO_READ_MESSAGE_FLAG_MAY_DISCARD);
56 return rv == MOJO_RESULT_OK;
57 }
58
59 } // namespace test
60 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/test_support/BUILD.gn ('k') | mojo/public/cpp/test_support/test_support.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698