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