summaryrefslogtreecommitdiffstats
path: root/base/command_line_unittest.cc
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-15 21:59:08 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-15 21:59:08 +0000
commit10e42bf623bcc526e25d5b22760cce3d0766039b (patch)
tree6630df4ba59b7e65622625f64e60dc2b958eb57c /base/command_line_unittest.cc
parent22717d1e33abe98ff8f628a5f1c404115f70cdc6 (diff)
downloadchromium_src-10e42bf623bcc526e25d5b22760cce3d0766039b.zip
chromium_src-10e42bf623bcc526e25d5b22760cce3d0766039b.tar.gz
chromium_src-10e42bf623bcc526e25d5b22760cce3d0766039b.tar.bz2
Store the command line in a more convenient format on non-windows platforms.
Review URL: http://codereview.chromium.org/7249 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@3426 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/command_line_unittest.cc')
-rw-r--r--base/command_line_unittest.cc29
1 files changed, 24 insertions, 5 deletions
diff --git a/base/command_line_unittest.cc b/base/command_line_unittest.cc
index a6364ec..504c852 100644
--- a/base/command_line_unittest.cc
+++ b/base/command_line_unittest.cc
@@ -8,6 +8,7 @@
#include "base/command_line.h"
#include "base/basictypes.h"
#include "base/logging.h"
+#include "base/string_util.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
@@ -74,6 +75,13 @@ TEST(CommandLineTest, CommandLineConstructor) {
EXPECT_EQ(L"in the time of submarines...", *iter);
++iter;
EXPECT_TRUE(iter == cl.GetLooseValuesEnd());
+#if defined(OS_POSIX)
+ std::vector<std::string> argvec = cl.argv();
+
+ for (size_t i = 0; i < argvec.size(); i++) {
+ EXPECT_EQ(0, argvec[i].compare(argv[i]));
+ }
+#endif
}
// These test the command line used to invoke the unit test.
@@ -89,6 +97,7 @@ TEST(CommandLineTest, EmptyString) {
CommandLine cl(L"");
#elif defined(OS_POSIX)
CommandLine cl(0, NULL);
+ EXPECT_TRUE(cl.argv().size() == 0);
#endif
EXPECT_TRUE(cl.command_line_string().empty());
EXPECT_TRUE(cl.program().empty());
@@ -96,11 +105,7 @@ TEST(CommandLineTest, EmptyString) {
}
// Test static functions for appending switches to a command line.
-// TODO(pinkerton): non-windows platforms don't have the requisite ctor here, so
-// we need something that tests AppendSwitches in another way (if even desired).
-#if defined(OS_WIN)
TEST(CommandLineTest, AppendSwitches) {
- std::wstring cl_string = L"Program";
std::wstring switch1 = L"switch1";
std::wstring switch2 = L"switch2";
std::wstring value = L"value";
@@ -109,11 +114,25 @@ TEST(CommandLineTest, AppendSwitches) {
std::wstring switch4 = L"switch4";
std::wstring value4 = L"\"a value with quotes\"";
+#if defined(OS_WIN)
+ std::wstring cl_string = L"Program";
CommandLine::AppendSwitch(&cl_string, switch1);
CommandLine::AppendSwitchWithValue(&cl_string, switch2, value);
CommandLine::AppendSwitchWithValue(&cl_string, switch3, value3);
CommandLine::AppendSwitchWithValue(&cl_string, switch4, value4);
CommandLine cl(cl_string);
+#elif defined(OS_POSIX)
+ std::vector<std::string> argv;
+ argv.push_back(std::string("Program"));
+ argv.push_back(WideToUTF8(CommandLine::PrefixedSwitchString(switch1)));
+ argv.push_back(WideToUTF8(CommandLine::PrefixedSwitchStringWithValue(
+ switch2, value)));
+ argv.push_back(WideToUTF8(CommandLine::PrefixedSwitchStringWithValue(
+ switch3, value3)));
+ argv.push_back(WideToUTF8(CommandLine::PrefixedSwitchStringWithValue(
+ switch4, value4.substr(1, value4.length() - 2))));
+ CommandLine cl(argv);
+#endif
EXPECT_TRUE(cl.HasSwitch(switch1));
EXPECT_TRUE(cl.HasSwitch(switch2));
@@ -123,4 +142,4 @@ TEST(CommandLineTest, AppendSwitches) {
EXPECT_TRUE(cl.HasSwitch(switch4));
EXPECT_EQ(value4.substr(1, value4.length() - 2), cl.GetSwitchValue(switch4));
}
-#endif
+