blob: ae67ab34b8a99404d498a87b71690a14e66f976d [file] [log] [blame]
hashimoto9aaf6362015-12-15 06:48:121// Copyright 2015 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 <unistd.h>
6#include <linux/android/binder.h>
7
8#include "chromeos/binder/command_stream.h"
9#include "chromeos/binder/driver.h"
10#include "testing/gtest/include/gtest/gtest.h"
11
12namespace binder {
13
14namespace {
15
16// TODO(hashimoto): Add tests for Fetch() and ProcessCommand().
17class BinderCommandStreamTest : public ::testing::Test,
18 public CommandStream::IncomingCommandHandler {
19 public:
20 BinderCommandStreamTest() : command_stream_(&driver_, this) {}
21 ~BinderCommandStreamTest() override {}
22
23 void SetUp() override { ASSERT_TRUE(driver_.Initialize()); }
24
25 protected:
26 Driver driver_;
27 CommandStream command_stream_;
28};
29
30} // namespace
31
32TEST_F(BinderCommandStreamTest, EnterLooper) {
33 command_stream_.AppendOutgoingCommand(BC_ENTER_LOOPER, nullptr, 0);
34 EXPECT_TRUE(command_stream_.Flush());
35 command_stream_.AppendOutgoingCommand(BC_EXIT_LOOPER, nullptr, 0);
36 EXPECT_TRUE(command_stream_.Flush());
37}
38
39TEST_F(BinderCommandStreamTest, Error) {
40 // Kernel's binder.h says BC_ATTEMPT_ACQUIRE is not currently supported.
41 binder_pri_desc params = {};
42 command_stream_.AppendOutgoingCommand(BC_ATTEMPT_ACQUIRE, &params,
43 sizeof(params));
44 EXPECT_FALSE(command_stream_.Flush());
45}
46
47} // namespace binder