From b4a159a1da74dc7519b00acabe7d824bcb6cb87c Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Thu, 3 Dec 2015 17:13:14 -0500 Subject: [PATCH] Add CommandLineTest.IgnorePrefixes unit test to verify prefix removal behavior (issue #1778) --- tests/unittests/command_line_unittest.cc | 28 +++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/tests/unittests/command_line_unittest.cc b/tests/unittests/command_line_unittest.cc index da303beb4..6c4ce0710 100644 --- a/tests/unittests/command_line_unittest.cc +++ b/tests/unittests/command_line_unittest.cc @@ -10,7 +10,9 @@ namespace { -void VerifyCommandLine(CefRefPtr command_line) { +void VerifyCommandLine(CefRefPtr command_line, + const char* expected_arg1 = "arg1", + const char* expected_arg2 = "arg 2") { std::string program = command_line->GetProgram(); EXPECT_EQ("test.exe", program); @@ -67,9 +69,9 @@ void VerifyCommandLine(CefRefPtr command_line) { command_line->GetArguments(args); EXPECT_EQ((size_t)2, args.size()); std::string arg0 = args[0]; - EXPECT_EQ("arg1", arg0); + EXPECT_EQ(expected_arg1, arg0); std::string arg1 = args[1]; - EXPECT_EQ("arg 2", arg1); + EXPECT_EQ(expected_arg2, arg1); command_line->Reset(); EXPECT_FALSE(command_line->HasSwitches()); @@ -119,3 +121,23 @@ TEST(CommandLineTest, Manual) { VerifyCommandLine(command_line); } + +// Test that any prefixes included with the switches are ignored. +TEST(CommandLineTest, IgnorePrefixes) { + CefRefPtr command_line = CefCommandLine::CreateCommandLine(); + EXPECT_TRUE(command_line.get() != NULL); + + command_line->SetProgram("test.exe"); + command_line->AppendSwitch("-switch1"); + command_line->AppendSwitchWithValue("--switch2", "val2"); + command_line->AppendSwitchWithValue("-switch3", "val3"); + command_line->AppendSwitchWithValue("-switch4", "val 4"); + + // Prefixes will not be removed from arguments. + const char arg1[] = "-arg1"; + const char arg2[] = "--arg 2"; + command_line->AppendArgument(arg1); + command_line->AppendArgument(arg2); + + VerifyCommandLine(command_line, arg1, arg2); +}