Home | History | Annotate | Download | only in test
      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 SetUp() override {
     35     base::CommandLine::Reset();
     36   }
     37 
     38   void TearDown() override {
     39     base::CommandLine::Reset();
     40   }
     41 
     42  protected:
     43   base::AtExitManager exit_manager_;
     44   Settings settings_;
     45 
     46  private:
     47   DISALLOW_COPY_AND_ASSIGN(SettingsTest);
     48 };
     49 
     50 TEST_F(SettingsTest, EmptyCommandLine) {
     51   const base::CommandLine::CharType* argv[] = { "program" };
     52   EXPECT_TRUE(base::CommandLine::Init(arraysize(argv), argv));
     53   EXPECT_TRUE(settings_.Init());
     54 }
     55 
     56 TEST_F(SettingsTest, UnexpectedSwitches1) {
     57   const base::CommandLine::CharType* argv[] = {
     58     "program", "--create-ipc-socket=foobar", "--foobarbaz"
     59   };
     60   EXPECT_TRUE(base::CommandLine::Init(arraysize(argv), argv));
     61   EXPECT_FALSE(settings_.Init());
     62 }
     63 
     64 TEST_F(SettingsTest, UnexpectedSwitches2) {
     65   const base::CommandLine::CharType* argv[] = {
     66     "program", "--foobarbaz"
     67   };
     68   EXPECT_TRUE(base::CommandLine::Init(arraysize(argv), argv));
     69   EXPECT_FALSE(settings_.Init());
     70 }
     71 
     72 TEST_F(SettingsTest, UnexpectedArguments1) {
     73   const base::CommandLine::CharType* argv[] = {
     74     "program", "foobarbaz"
     75   };
     76   EXPECT_TRUE(base::CommandLine::Init(arraysize(argv), argv));
     77   EXPECT_FALSE(settings_.Init());
     78 }
     79 
     80 TEST_F(SettingsTest, UnexpectedArguments2) {
     81   const base::CommandLine::CharType* argv[] = {
     82     "program", "--create-ipc-socket=foobar", "foobarbaz"
     83   };
     84   EXPECT_TRUE(base::CommandLine::Init(arraysize(argv), argv));
     85   EXPECT_FALSE(settings_.Init());
     86 }
     87 
     88 TEST_F(SettingsTest, TooManyIpcOptions) {
     89   const base::CommandLine::CharType* argv[] = {
     90       "program", "--create-ipc-socket=foobar",
     91       "--android-ipc-socket-suffix=foobar"};
     92   EXPECT_TRUE(base::CommandLine::Init(arraysize(argv), argv));
     93   EXPECT_FALSE(settings_.Init());
     94 }
     95 
     96 TEST_F(SettingsTest, GoodArgumentsCreateIpc) {
     97   const base::CommandLine::CharType* argv[] = {
     98     "program", "--create-ipc-socket=foobar"
     99   };
    100   EXPECT_TRUE(base::CommandLine::Init(arraysize(argv), argv));
    101   EXPECT_TRUE(settings_.Init());
    102 }
    103 
    104 TEST_F(SettingsTest, GoodArgumentsAndroidIpc) {
    105   const base::CommandLine::CharType* argv[] = {
    106     "program", "--android-ipc-socket-suffix=foobar"
    107   };
    108   EXPECT_TRUE(base::CommandLine::Init(arraysize(argv), argv));
    109   EXPECT_TRUE(settings_.Init());
    110 }
    111 
    112 }  // namespace
    113