diff options
author | gab@chromium.org <gab@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-29 21:31:31 +0000 |
---|---|---|
committer | gab@chromium.org <gab@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-29 21:31:31 +0000 |
commit | 45f982ef3e2267388089826ca1c875f7436f7e82 (patch) | |
tree | 03a7e390ab53d311c4438898fca2843b2421757c /base/command_line_unittest.cc | |
parent | 3642e2dc31e87fb1445f586acd8707732042bdf2 (diff) | |
download | chromium_src-45f982ef3e2267388089826ca1c875f7436f7e82.zip chromium_src-45f982ef3e2267388089826ca1c875f7436f7e82.tar.gz chromium_src-45f982ef3e2267388089826ca1c875f7436f7e82.tar.bz2 |
Extract arguments reconstruction logic out of GetCommandLineString() into GetArgumentsString().
BUG=To get arguments we had to GetCommandLineString() and piece out the program: http://code.google.com/searchframe#OAMlx_jo-ck/src/chrome/installer/util/install_util.cc&exact_package=chromium&q=GetCommandLineString&type=cs&l=125
TEST=base_unittests.exe --gtest_filter=CommandLineTest*
Review URL: https://chromiumcodereview.appspot.com/11305010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@164740 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/command_line_unittest.cc')
-rw-r--r-- | base/command_line_unittest.cc | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/base/command_line_unittest.cc b/base/command_line_unittest.cc index d93ffb8..372af37 100644 --- a/base/command_line_unittest.cc +++ b/base/command_line_unittest.cc @@ -178,6 +178,64 @@ TEST(CommandLineTest, EmptyString) { EXPECT_TRUE(cl_from_argv.GetArgs().empty()); } +TEST(CommandLineTest, GetArgumentsString) { + static const FilePath::CharType kPath1[] = + FILE_PATH_LITERAL("C:\\Some File\\With Spaces.ggg"); + static const FilePath::CharType kPath2[] = + FILE_PATH_LITERAL("C:\\no\\spaces.ggg"); + + static const char kFirstArgName[] = "first-arg"; + static const char kSecondArgName[] = "arg2"; + static const char kThirdArgName[] = "arg with space"; + static const char kFourthArgName[] = "nospace"; + + CommandLine cl(CommandLine::NO_PROGRAM); + cl.AppendSwitchPath(kFirstArgName, FilePath(kPath1)); + cl.AppendSwitchPath(kSecondArgName, FilePath(kPath2)); + cl.AppendArg(kThirdArgName); + cl.AppendArg(kFourthArgName); + +#if defined(OS_WIN) + CommandLine::StringType expected_first_arg(UTF8ToUTF16(kFirstArgName)); + CommandLine::StringType expected_second_arg(UTF8ToUTF16(kSecondArgName)); + CommandLine::StringType expected_third_arg(UTF8ToUTF16(kThirdArgName)); + CommandLine::StringType expected_fourth_arg(UTF8ToUTF16(kFourthArgName)); +#elif defined(OS_POSIX) + CommandLine::StringType expected_first_arg(kFirstArgName); + CommandLine::StringType expected_second_arg(kSecondArgName); + CommandLine::StringType expected_third_arg(kThirdArgName); + CommandLine::StringType expected_fourth_arg(kFourthArgName); +#endif + +#if defined(OS_WIN) +#define QUOTE_ON_WIN FILE_PATH_LITERAL("\"") +#else +#define QUOTE_ON_WIN FILE_PATH_LITERAL("") +#endif // OS_WIN + + CommandLine::StringType expected_str; + expected_str.append(FILE_PATH_LITERAL("--")) + .append(expected_first_arg) + .append(FILE_PATH_LITERAL("=")) + .append(QUOTE_ON_WIN) + .append(kPath1) + .append(QUOTE_ON_WIN) + .append(FILE_PATH_LITERAL(" ")) + .append(FILE_PATH_LITERAL("--")) + .append(expected_second_arg) + .append(FILE_PATH_LITERAL("=")) + .append(QUOTE_ON_WIN) + .append(kPath2) + .append(QUOTE_ON_WIN) + .append(FILE_PATH_LITERAL(" ")) + .append(QUOTE_ON_WIN) + .append(expected_third_arg) + .append(QUOTE_ON_WIN) + .append(FILE_PATH_LITERAL(" ")) + .append(expected_fourth_arg); + EXPECT_EQ(expected_str, cl.GetArgumentsString()); +} + // Test methods for appending switches to a command line. TEST(CommandLineTest, AppendSwitches) { std::string switch1 = "switch1"; |