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

Side by Side Diff: mojo/public/cpp/system/tests/wait_unittest.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/system/tests/time_unittest.cc ('k') | mojo/public/cpp/system/time.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 2016 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 // This file tests the C++ wrappers in mojo/public/cpp/system/wait.h.
6
7 #include "mojo/public/cpp/system/wait.h"
8
9 #include <vector>
10
11 #include "gtest/gtest.h"
12 #include "mojo/public/cpp/system/handle.h"
13 #include "mojo/public/cpp/system/message_pipe.h"
14
15 namespace mojo {
16 namespace {
17
18 TEST(WaitTest, InvalidArgs) {
19 ScopedHandle h;
20
21 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
22 Wait(h.get(), ~MOJO_HANDLE_SIGNAL_NONE, 1000000, nullptr));
23
24 std::vector<Handle> wh;
25 wh.push_back(h.get());
26 std::vector<MojoHandleSignals> sigs;
27 sigs.push_back(~MOJO_HANDLE_SIGNAL_NONE);
28 WaitManyResult wait_many_result =
29 WaitMany(wh, sigs, MOJO_DEADLINE_INDEFINITE, nullptr);
30 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, wait_many_result.result);
31 EXPECT_TRUE(wait_many_result.IsIndexValid());
32 EXPECT_FALSE(wait_many_result.AreSignalsStatesValid());
33 }
34
35 TEST(WaitTest, TimeOut) {
36 // |Wait()|:
37 {
38 // Need a valid handle to wait on for |Wait()|.
39 MessagePipe mp;
40 EXPECT_EQ(
41 MOJO_RESULT_DEADLINE_EXCEEDED,
42 Wait(mp.handle0.get(), MOJO_HANDLE_SIGNAL_READABLE, 100u, nullptr));
43 }
44
45 // |WaitMany()|:
46 {
47 std::vector<Handle> wh;
48 std::vector<MojoHandleSignals> sigs;
49 WaitManyResult wait_many_result = WaitMany(wh, sigs, 100u, nullptr);
50 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, wait_many_result.result);
51 EXPECT_FALSE(wait_many_result.IsIndexValid());
52 EXPECT_TRUE(wait_many_result.AreSignalsStatesValid());
53 }
54 }
55
56 TEST(WaitTest, WaitManyResult) {
57 {
58 WaitManyResult wmr(MOJO_RESULT_OK);
59 EXPECT_FALSE(wmr.IsIndexValid());
60 EXPECT_TRUE(wmr.AreSignalsStatesValid());
61 EXPECT_EQ(MOJO_RESULT_OK, wmr.result);
62 }
63
64 {
65 WaitManyResult wmr(MOJO_RESULT_FAILED_PRECONDITION);
66 EXPECT_FALSE(wmr.IsIndexValid());
67 EXPECT_TRUE(wmr.AreSignalsStatesValid());
68 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, wmr.result);
69 }
70
71 {
72 WaitManyResult wmr(MOJO_RESULT_INVALID_ARGUMENT);
73 EXPECT_FALSE(wmr.IsIndexValid());
74 EXPECT_FALSE(wmr.AreSignalsStatesValid());
75 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, wmr.result);
76 }
77
78 // These should be like "invalid argument".
79 EXPECT_FALSE(
80 WaitManyResult(MOJO_RESULT_RESOURCE_EXHAUSTED).AreSignalsStatesValid());
81 EXPECT_FALSE(WaitManyResult(MOJO_RESULT_BUSY).AreSignalsStatesValid());
82
83 {
84 WaitManyResult wmr(MOJO_RESULT_OK, 5u);
85 EXPECT_TRUE(wmr.IsIndexValid());
86 EXPECT_TRUE(wmr.AreSignalsStatesValid());
87 EXPECT_EQ(MOJO_RESULT_OK, wmr.result);
88 EXPECT_EQ(5u, wmr.index);
89 }
90
91 {
92 WaitManyResult wmr(MOJO_RESULT_FAILED_PRECONDITION, 5u);
93 EXPECT_TRUE(wmr.IsIndexValid());
94 EXPECT_TRUE(wmr.AreSignalsStatesValid());
95 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, wmr.result);
96 EXPECT_EQ(5u, wmr.index);
97 }
98 }
99
100 } // namespace
101 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/system/tests/time_unittest.cc ('k') | mojo/public/cpp/system/time.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698