| Index: chromeos/dbus/dbus_command_line_helper_unittest.cc
|
| diff --git a/chromeos/dbus/dbus_command_line_helper_unittest.cc b/chromeos/dbus/dbus_command_line_helper_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..483357b76153c7c722ed690979da83cc247f8c4a
|
| --- /dev/null
|
| +++ b/chromeos/dbus/dbus_command_line_helper_unittest.cc
|
| @@ -0,0 +1,99 @@
|
| +// Copyright (c) 2014 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chromeos/dbus/dbus_command_line_helper.h"
|
| +
|
| +#include <utility>
|
| +
|
| +#include "base/bind.h"
|
| +#include "base/command_line.h"
|
| +#include "chromeos/chromeos_switches.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +namespace {
|
| +
|
| +class DbusCommandLineHelperTests : public testing::Test {
|
| + public:
|
| + DbusCommandLineHelperTests() {}
|
| +
|
| + protected:
|
| + bool ParseOption(const std::string& arg0, const std::string& arg1) {
|
| + results_.push_back(std::make_pair(arg0, arg1));
|
| + return true;
|
| + }
|
| +
|
| + bool CallParseOption(const std::string& option) {
|
| + results_.clear();
|
| + return dbus_command_line_helper::ParseOptions(
|
| + option,
|
| + base::Bind(&DbusCommandLineHelperTests::ParseOption,
|
| + base::Unretained(this)));
|
| + }
|
| +
|
| + std::vector<std::pair<std::string, std::string> > results_;
|
| +};
|
| +
|
| +const char kTestSwitch[] = "test-switch";
|
| +
|
| +} // namespace
|
| +
|
| +TEST_F(DbusCommandLineHelperTests, TestParseOptionBasic) {
|
| + CommandLine* command_line = CommandLine::ForCurrentProcess();
|
| + command_line->AppendSwitchASCII(kTestSwitch, "foo");
|
| + EXPECT_TRUE(CallParseOption(kTestSwitch));
|
| + ASSERT_EQ(1u, results_.size());
|
| + EXPECT_EQ("foo", results_[0].first);
|
| + EXPECT_EQ("", results_[0].second);
|
| +
|
| + command_line->AppendSwitchASCII(kTestSwitch, "foo=");
|
| + EXPECT_TRUE(CallParseOption(kTestSwitch));
|
| + ASSERT_EQ(1u, results_.size());
|
| + EXPECT_EQ("foo", results_[0].first);
|
| + EXPECT_EQ("", results_[0].second);
|
| +
|
| + command_line->AppendSwitchASCII(kTestSwitch, "foo=1");
|
| + EXPECT_TRUE(CallParseOption(kTestSwitch));
|
| + ASSERT_EQ(1u, results_.size());
|
| + EXPECT_EQ("foo", results_[0].first);
|
| + EXPECT_EQ("1", results_[0].second);
|
| +}
|
| +
|
| +TEST_F(DbusCommandLineHelperTests, TestParseOptionMultiple) {
|
| + CommandLine* command_line = CommandLine::ForCurrentProcess();
|
| + command_line->AppendSwitchASCII(kTestSwitch, "foo,bar");
|
| + EXPECT_TRUE(CallParseOption(kTestSwitch));
|
| + ASSERT_EQ(2u, results_.size());
|
| + EXPECT_EQ("foo", results_[0].first);
|
| + EXPECT_EQ("", results_[0].second);
|
| + EXPECT_EQ("bar", results_[1].first);
|
| + EXPECT_EQ("", results_[1].second);
|
| +
|
| + command_line->AppendSwitchASCII(kTestSwitch, "foo=bar,bar=foo");
|
| + EXPECT_TRUE(CallParseOption(kTestSwitch));
|
| + ASSERT_EQ(2u, results_.size());
|
| + EXPECT_EQ("foo", results_[0].first);
|
| + EXPECT_EQ("bar", results_[0].second);
|
| + EXPECT_EQ("bar", results_[1].first);
|
| + EXPECT_EQ("foo", results_[1].second);
|
| +
|
| + command_line->AppendSwitchASCII(kTestSwitch, "foo=bar,bar=,car");
|
| + EXPECT_TRUE(CallParseOption(kTestSwitch));
|
| + ASSERT_EQ(3u, results_.size());
|
| + EXPECT_EQ("foo", results_[0].first);
|
| + EXPECT_EQ("bar", results_[0].second);
|
| + EXPECT_EQ("bar", results_[1].first);
|
| + EXPECT_EQ("", results_[1].second);
|
| + EXPECT_EQ("car", results_[2].first);
|
| + EXPECT_EQ("", results_[2].second);
|
| +
|
| + command_line->AppendSwitchASCII(kTestSwitch, "foo,");
|
| + EXPECT_TRUE(CallParseOption(kTestSwitch));
|
| + ASSERT_EQ(1u, results_.size());
|
| + EXPECT_EQ("foo", results_[0].first);
|
| + EXPECT_EQ("", results_[0].second);
|
| +}
|
| +
|
| +TEST_F(DbusCommandLineHelperTests, TestParseOptionFail) {
|
| + EXPECT_FALSE(CallParseOption(kTestSwitch));
|
| +}
|
|
|