1 //
2 // Copyright 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 <gtest/gtest.h>
20
21 #include "array_utils.h"
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 SettingsTest(const SettingsTest&) = delete;
34 SettingsTest& operator=(const SettingsTest&) = delete;
35
SetUp()36 void SetUp() override { base::CommandLine::Reset(); }
37
TearDown()38 void TearDown() override { base::CommandLine::Reset(); }
39
40 protected:
41 base::AtExitManager exit_manager_;
42 Settings settings_;
43 };
44
TEST_F(SettingsTest,EmptyCommandLine)45 TEST_F(SettingsTest, EmptyCommandLine) {
46 const base::CommandLine::CharType* argv[] = {"program"};
47 EXPECT_TRUE(base::CommandLine::Init(ARRAY_SIZE(argv), argv));
48 EXPECT_TRUE(settings_.Init());
49 }
50
TEST_F(SettingsTest,UnexpectedSwitches1)51 TEST_F(SettingsTest, UnexpectedSwitches1) {
52 const base::CommandLine::CharType* argv[] = {
53 "program", "--create-ipc-socket=foobar", "--foobarbaz"};
54 EXPECT_TRUE(base::CommandLine::Init(ARRAY_SIZE(argv), argv));
55 EXPECT_FALSE(settings_.Init());
56 }
57
TEST_F(SettingsTest,UnexpectedSwitches2)58 TEST_F(SettingsTest, UnexpectedSwitches2) {
59 const base::CommandLine::CharType* argv[] = {"program", "--foobarbaz"};
60 EXPECT_TRUE(base::CommandLine::Init(ARRAY_SIZE(argv), argv));
61 EXPECT_FALSE(settings_.Init());
62 }
63
TEST_F(SettingsTest,UnexpectedArguments1)64 TEST_F(SettingsTest, UnexpectedArguments1) {
65 const base::CommandLine::CharType* argv[] = {"program", "foobarbaz"};
66 EXPECT_TRUE(base::CommandLine::Init(ARRAY_SIZE(argv), argv));
67 EXPECT_FALSE(settings_.Init());
68 }
69
TEST_F(SettingsTest,UnexpectedArguments2)70 TEST_F(SettingsTest, UnexpectedArguments2) {
71 const base::CommandLine::CharType* argv[] = {
72 "program", "--create-ipc-socket=foobar", "foobarbaz"};
73 EXPECT_TRUE(base::CommandLine::Init(ARRAY_SIZE(argv), argv));
74 EXPECT_FALSE(settings_.Init());
75 }
76
TEST_F(SettingsTest,TooManyIpcOptions)77 TEST_F(SettingsTest, TooManyIpcOptions) {
78 const base::CommandLine::CharType* argv[] = {
79 "program", "--create-ipc-socket=foobar",
80 "--android-ipc-socket-suffix=foobar"};
81 EXPECT_TRUE(base::CommandLine::Init(ARRAY_SIZE(argv), argv));
82 EXPECT_FALSE(settings_.Init());
83 }
84
TEST_F(SettingsTest,GoodArgumentsCreateIpc)85 TEST_F(SettingsTest, GoodArgumentsCreateIpc) {
86 const base::CommandLine::CharType* argv[] = {"program",
87 "--create-ipc-socket=foobar"};
88 EXPECT_TRUE(base::CommandLine::Init(ARRAY_SIZE(argv), argv));
89 EXPECT_TRUE(settings_.Init());
90 }
91
TEST_F(SettingsTest,GoodArgumentsAndroidIpc)92 TEST_F(SettingsTest, GoodArgumentsAndroidIpc) {
93 const base::CommandLine::CharType* argv[] = {
94 "program", "--android-ipc-socket-suffix=foobar"};
95 EXPECT_TRUE(base::CommandLine::Init(ARRAY_SIZE(argv), argv));
96 EXPECT_TRUE(settings_.Init());
97 }
98
99 } // namespace
100