| OLD | NEW | 
|    1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |    1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 
|    2 // Use of this source code is governed by a BSD-style license that can be |    2 // Use of this source code is governed by a BSD-style license that can be | 
|    3 // found in the LICENSE file. |    3 // found in the LICENSE file. | 
|    4  |    4  | 
|    5 #include <string> |    5 #include <string> | 
|    6 #include <vector> |    6 #include <vector> | 
|    7  |    7  | 
|    8 #include "base/command_line.h" |    8 #include "base/command_line.h" | 
|    9 #include "base/basictypes.h" |    9 #include "base/basictypes.h" | 
|   10 #include "base/string_util.h" |   10 #include "base/string_util.h" | 
|   11 #include "testing/gtest/include/gtest/gtest.h" |   11 #include "testing/gtest/include/gtest/gtest.h" | 
|   12  |   12  | 
|   13 TEST(CommandLineTest, CommandLineConstructor) { |   13 TEST(CommandLineTest, CommandLineConstructor) { | 
|   14 #if defined(OS_WIN) |   14 #if defined(OS_WIN) | 
|   15   CommandLine cl(L""); |   15   CommandLine cl = CommandLine::FromString( | 
|   16   cl.ParseFromString(L"program --foo= -bAr  /Spaetzel=pierogi /Baz flim " |   16                      L"program --foo= -bAr  /Spaetzel=pierogi /Baz flim " | 
|   17                      L"--other-switches=\"--dog=canine --cat=feline\" " |   17                      L"--other-switches=\"--dog=canine --cat=feline\" " | 
|   18                      L"-spaetzle=Crepe   -=loosevalue  flan " |   18                      L"-spaetzle=Crepe   -=loosevalue  flan " | 
|   19                      L"--input-translation=\"45\"--output-rotation " |   19                      L"--input-translation=\"45\"--output-rotation " | 
|   20                      L"-- -- --not-a-switch " |   20                      L"-- -- --not-a-switch " | 
|   21                      L"\"in the time of submarines...\""); |   21                      L"\"in the time of submarines...\""); | 
|   22   EXPECT_FALSE(cl.command_line_string().empty()); |   22   EXPECT_FALSE(cl.command_line_string().empty()); | 
|   23 #elif defined(OS_POSIX) |   23 #elif defined(OS_POSIX) | 
|   24   const char* argv[] = {"program", "--foo=", "-bar", |   24   const char* argv[] = {"program", "--foo=", "-bar", | 
|   25                         "-spaetzel=pierogi", "-baz", "flim", |   25                         "-spaetzel=pierogi", "-baz", "flim", | 
|   26                         "--other-switches=--dog=canine --cat=feline", |   26                         "--other-switches=--dog=canine --cat=feline", | 
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   78  |   78  | 
|   79   for (size_t i = 0; i < argvec.size(); i++) { |   79   for (size_t i = 0; i < argvec.size(); i++) { | 
|   80     EXPECT_EQ(0, argvec[i].compare(argv[i])); |   80     EXPECT_EQ(0, argvec[i].compare(argv[i])); | 
|   81   } |   81   } | 
|   82 #endif |   82 #endif | 
|   83 } |   83 } | 
|   84  |   84  | 
|   85 // Tests behavior with an empty input string. |   85 // Tests behavior with an empty input string. | 
|   86 TEST(CommandLineTest, EmptyString) { |   86 TEST(CommandLineTest, EmptyString) { | 
|   87 #if defined(OS_WIN) |   87 #if defined(OS_WIN) | 
|   88   CommandLine cl(L""); |   88   CommandLine cl = CommandLine::FromString(L""); | 
|   89   EXPECT_TRUE(cl.command_line_string().empty()); |   89   EXPECT_TRUE(cl.command_line_string().empty()); | 
|   90   EXPECT_TRUE(cl.program().empty()); |   90   EXPECT_TRUE(cl.program().empty()); | 
|   91 #elif defined(OS_POSIX) |   91 #elif defined(OS_POSIX) | 
|   92   CommandLine cl(0, NULL); |   92   CommandLine cl(0, NULL); | 
|   93   EXPECT_TRUE(cl.argv().size() == 0); |   93   EXPECT_TRUE(cl.argv().size() == 0); | 
|   94 #endif |   94 #endif | 
|   95   EXPECT_EQ(0U, cl.GetLooseValues().size()); |   95   EXPECT_EQ(0U, cl.GetLooseValues().size()); | 
|   96 } |   96 } | 
|   97  |   97  | 
|   98 // Test methods for appending switches to a command line. |   98 // Test methods for appending switches to a command line. | 
|   99 TEST(CommandLineTest, AppendSwitches) { |   99 TEST(CommandLineTest, AppendSwitches) { | 
|  100   std::string switch1 = "switch1"; |  100   std::string switch1 = "switch1"; | 
|  101   std::string switch2 = "switch2"; |  101   std::string switch2 = "switch2"; | 
|  102   std::wstring value = L"value"; |  102   std::wstring value = L"value"; | 
|  103   std::string switch3 = "switch3"; |  103   std::string switch3 = "switch3"; | 
|  104   std::wstring value3 = L"a value with spaces"; |  104   std::wstring value3 = L"a value with spaces"; | 
|  105   std::string switch4 = "switch4"; |  105   std::string switch4 = "switch4"; | 
|  106   std::wstring value4 = L"\"a value with quotes\""; |  106   std::wstring value4 = L"\"a value with quotes\""; | 
|  107  |  107  | 
|  108 #if defined(OS_WIN) |  108   CommandLine cl(FilePath(FILE_PATH_LITERAL("Program"))); | 
|  109   CommandLine cl(L"Program"); |  | 
|  110 #elif defined(OS_POSIX) |  | 
|  111   std::vector<std::string> argv; |  | 
|  112   argv.push_back(std::string("Program")); |  | 
|  113   CommandLine cl(argv); |  | 
|  114 #endif |  | 
|  115  |  109  | 
|  116   cl.AppendSwitch(switch1); |  110   cl.AppendSwitch(switch1); | 
|  117   cl.AppendSwitchWithValue(switch2, value); |  111   cl.AppendSwitchWithValue(switch2, value); | 
|  118   cl.AppendSwitchWithValue(switch3, value3); |  112   cl.AppendSwitchWithValue(switch3, value3); | 
|  119   cl.AppendSwitchWithValue(switch4, value4); |  113   cl.AppendSwitchWithValue(switch4, value4); | 
|  120  |  114  | 
|  121   EXPECT_TRUE(cl.HasSwitch(switch1)); |  115   EXPECT_TRUE(cl.HasSwitch(switch1)); | 
|  122   EXPECT_TRUE(cl.HasSwitch(switch2)); |  116   EXPECT_TRUE(cl.HasSwitch(switch2)); | 
|  123   EXPECT_EQ(value, cl.GetSwitchValue(switch2)); |  117   EXPECT_EQ(value, cl.GetSwitchValue(switch2)); | 
|  124   EXPECT_TRUE(cl.HasSwitch(switch3)); |  118   EXPECT_TRUE(cl.HasSwitch(switch3)); | 
|  125   EXPECT_EQ(value3, cl.GetSwitchValue(switch3)); |  119   EXPECT_EQ(value3, cl.GetSwitchValue(switch3)); | 
|  126   EXPECT_TRUE(cl.HasSwitch(switch4)); |  120   EXPECT_TRUE(cl.HasSwitch(switch4)); | 
|  127   EXPECT_EQ(value4, cl.GetSwitchValue(switch4)); |  121   EXPECT_EQ(value4, cl.GetSwitchValue(switch4)); | 
|  128 } |  122 } | 
| OLD | NEW |