2 // Copyright (C) 2015 Google, Inc.
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:
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include <base/at_exit.h>
18 #include <base/command_line.h>
19 #include <base/macros.h>
20 #include <gtest/gtest.h>
22 #include "service/settings.h"
23 #include "service/switches.h"
25 using bluetooth::Settings;
26 using namespace bluetooth::switches;
30 class SettingsTest : public ::testing::Test {
32 SettingsTest() = default;
34 void TearDown() override {
35 base::CommandLine::Reset();
39 base::AtExitManager exit_manager_;
43 DISALLOW_COPY_AND_ASSIGN(SettingsTest);
46 TEST_F(SettingsTest, EmptyCommandLine) {
47 const base::CommandLine::CharType* argv[] = { "program" };
48 base::CommandLine::Init(arraysize(argv), argv);
49 EXPECT_TRUE(settings_.Init());
52 TEST_F(SettingsTest, UnexpectedSwitches1) {
53 const base::CommandLine::CharType* argv[] = {
54 "program", "--create-ipc-socket=foobar", "--foobarbaz"
56 base::CommandLine::Init(arraysize(argv), argv);
57 EXPECT_FALSE(settings_.Init());
60 TEST_F(SettingsTest, UnexpectedSwitches2) {
61 const base::CommandLine::CharType* argv[] = {
62 "program", "--foobarbaz"
64 base::CommandLine::Init(arraysize(argv), argv);
65 EXPECT_FALSE(settings_.Init());
68 TEST_F(SettingsTest, UnexpectedArguments1) {
69 const base::CommandLine::CharType* argv[] = {
70 "program", "foobarbaz"
72 base::CommandLine::Init(arraysize(argv), argv);
73 EXPECT_FALSE(settings_.Init());
76 TEST_F(SettingsTest, UnexpectedArguments2) {
77 const base::CommandLine::CharType* argv[] = {
78 "program", "--create-ipc-socket=foobar", "foobarbaz"
80 base::CommandLine::Init(arraysize(argv), argv);
81 EXPECT_FALSE(settings_.Init());
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());
92 TEST_F(SettingsTest, GoodArgumentsCreateIpc) {
93 const base::CommandLine::CharType* argv[] = {
94 "program", "--create-ipc-socket=foobar"
96 base::CommandLine::Init(arraysize(argv), argv);
97 EXPECT_TRUE(settings_.Init());
100 TEST_F(SettingsTest, GoodArgumentsAndroidIpc) {
101 const base::CommandLine::CharType* argv[] = {
102 "program", "--android-ipc-socket-suffix=foobar"
104 base::CommandLine::Init(arraysize(argv), argv);
105 EXPECT_TRUE(settings_.Init());