• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 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/c/system/core.h"
6 #include "testing/gtest/include/gtest/gtest.h"
7 
8 namespace {
9 
TEST(MojoCoreTest,SanityCheck)10 TEST(MojoCoreTest, SanityCheck) {
11   // Exercises some APIs against the mojo_core library and expects them to work
12   // as intended.
13 
14   MojoHandle a, b;
15   EXPECT_EQ(MOJO_RESULT_OK, MojoCreateMessagePipe(nullptr, &a, &b));
16 
17   MojoMessageHandle m;
18   EXPECT_EQ(MOJO_RESULT_OK, MojoCreateMessage(nullptr, &m));
19   EXPECT_EQ(MOJO_RESULT_OK,
20             MojoSetMessageContext(m, 42, nullptr, nullptr, nullptr));
21   EXPECT_EQ(MOJO_RESULT_OK, MojoWriteMessage(a, m, nullptr));
22   m = MOJO_MESSAGE_HANDLE_INVALID;
23 
24   MojoHandleSignalsState state;
25   EXPECT_EQ(MOJO_RESULT_OK, MojoQueryHandleSignalsState(b, &state));
26   EXPECT_TRUE(state.satisfied_signals & MOJO_HANDLE_SIGNAL_READABLE);
27 
28   EXPECT_EQ(MOJO_RESULT_OK, MojoReadMessage(b, nullptr, &m));
29 
30   uintptr_t context = 0;
31   EXPECT_EQ(MOJO_RESULT_OK, MojoGetMessageContext(m, nullptr, &context));
32   EXPECT_EQ(42u, context);
33 
34   EXPECT_EQ(MOJO_RESULT_OK, MojoDestroyMessage(m));
35   EXPECT_EQ(MOJO_RESULT_OK, MojoClose(b));
36   EXPECT_EQ(MOJO_RESULT_OK, MojoClose(a));
37 }
38 
39 }  // namespace
40