OSDN Git Service

resolved conflicts for b8cc54d1 to mnc-dr-dev-plus-aosp
[android-x86/system-bt.git] / service / test / settings_unittest.cpp
1 //
2 //  Copyright (C) 2015 Google, Inc.
3 //
4 //  Licensed under the Apache License, Version 2.0 (the "License");
5 //  you may not use this file except in compliance with the License.
6 //  You may obtain a copy of the License at:
7 //
8 //  http://www.apache.org/licenses/LICENSE-2.0
9 //
10 //  Unless required by applicable law or agreed to in writing, software
11 //  distributed under the License is distributed on an "AS IS" BASIS,
12 //  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 //  See the License for the specific language governing permissions and
14 //  limitations under the License.
15 //
16
17 #include <base/at_exit.h>
18 #include <base/command_line.h>
19 #include <base/macros.h>
20 #include <gtest/gtest.h>
21
22 #include "service/settings.h"
23 #include "service/switches.h"
24
25 using bluetooth::Settings;
26 using namespace bluetooth::switches;
27
28 namespace {
29
30 class SettingsTest : public ::testing::Test {
31  public:
32   SettingsTest() = default;
33
34   void TearDown() override {
35     base::CommandLine::Reset();
36   }
37
38  protected:
39   base::AtExitManager exit_manager_;
40   Settings settings_;
41
42  private:
43   DISALLOW_COPY_AND_ASSIGN(SettingsTest);
44 };
45
46 TEST_F(SettingsTest, EmptyCommandLine) {
47   const base::CommandLine::CharType* argv[] = { "program" };
48   base::CommandLine::Init(arraysize(argv), argv);
49   EXPECT_TRUE(settings_.Init());
50 }
51
52 TEST_F(SettingsTest, UnexpectedSwitches1) {
53   const base::CommandLine::CharType* argv[] = {
54     "program", "--create-ipc-socket=foobar", "--foobarbaz"
55   };
56   base::CommandLine::Init(arraysize(argv), argv);
57   EXPECT_FALSE(settings_.Init());
58 }
59
60 TEST_F(SettingsTest, UnexpectedSwitches2) {
61   const base::CommandLine::CharType* argv[] = {
62     "program", "--foobarbaz"
63   };
64   base::CommandLine::Init(arraysize(argv), argv);
65   EXPECT_FALSE(settings_.Init());
66 }
67
68 TEST_F(SettingsTest, UnexpectedArguments1) {
69   const base::CommandLine::CharType* argv[] = {
70     "program", "foobarbaz"
71   };
72   base::CommandLine::Init(arraysize(argv), argv);
73   EXPECT_FALSE(settings_.Init());
74 }
75
76 TEST_F(SettingsTest, UnexpectedArguments2) {
77   const base::CommandLine::CharType* argv[] = {
78     "program", "--create-ipc-socket=foobar", "foobarbaz"
79   };
80   base::CommandLine::Init(arraysize(argv), argv);
81   EXPECT_FALSE(settings_.Init());
82 }
83
84 TEST_F(SettingsTest, TooManyIpcOptions) {
85   const base::CommandLine::CharType* argv[] = {
86       "program", "--create-ipc-socket=foobar",
87       "--android-ipc-socket-suffix=foobar"};
88   base::CommandLine::Init(arraysize(argv), argv);
89   EXPECT_FALSE(settings_.Init());
90 }
91
92 TEST_F(SettingsTest, GoodArgumentsCreateIpc) {
93   const base::CommandLine::CharType* argv[] = {
94     "program", "--create-ipc-socket=foobar"
95   };
96   base::CommandLine::Init(arraysize(argv), argv);
97   EXPECT_TRUE(settings_.Init());
98 }
99
100 TEST_F(SettingsTest, GoodArgumentsAndroidIpc) {
101   const base::CommandLine::CharType* argv[] = {
102     "program", "--android-ipc-socket-suffix=foobar"
103   };
104   base::CommandLine::Init(arraysize(argv), argv);
105   EXPECT_TRUE(settings_.Init());
106 }
107
108 }  // namespace