This source file includes following definitions.
- TEST
- TEST
- TEST
#include "win8/delegate_execute/delegate_execute_util.h"
#include <algorithm>
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
static const char kSomeSwitch[] = "some-switch";
}
TEST(DelegateExecuteUtil, CommandLineFromParametersTest) {
CommandLine cl(CommandLine::NO_PROGRAM);
cl = delegate_execute::CommandLineFromParameters(NULL);
EXPECT_EQ(std::wstring(), cl.GetProgram().value());
EXPECT_EQ(CommandLine::StringType(), cl.GetCommandLineString());
cl = delegate_execute::CommandLineFromParameters(
base::StringPrintf(L"--%ls",
base::ASCIIToWide(kSomeSwitch).c_str()).c_str());
EXPECT_EQ(std::wstring(), cl.GetProgram().value());
EXPECT_TRUE(cl.HasSwitch(kSomeSwitch));
}
TEST(DelegateExecuteUtil, MakeChromeCommandLineTest) {
static const wchar_t kSomeArgument[] = L"http://some.url/";
static const wchar_t kOtherArgument[] = L"http://some.other.url/";
const base::FilePath this_exe(CommandLine::ForCurrentProcess()->GetProgram());
CommandLine cl(CommandLine::NO_PROGRAM);
cl = delegate_execute::MakeChromeCommandLine(
this_exe,
delegate_execute::CommandLineFromParameters(NULL),
base::string16());
EXPECT_EQ(1, cl.argv().size());
EXPECT_EQ(this_exe.value(), cl.GetProgram().value());
cl = delegate_execute::MakeChromeCommandLine(
this_exe, delegate_execute::CommandLineFromParameters(NULL),
base::string16(kSomeArgument));
EXPECT_EQ(2, cl.argv().size());
EXPECT_EQ(this_exe.value(), cl.GetProgram().value());
EXPECT_EQ(1, cl.GetArgs().size());
EXPECT_EQ(base::string16(kSomeArgument), cl.GetArgs()[0]);
cl = delegate_execute::MakeChromeCommandLine(
this_exe, delegate_execute::CommandLineFromParameters(
base::StringPrintf(L"--%ls -- %ls",
base::ASCIIToWide(kSomeSwitch).c_str(),
kOtherArgument).c_str()),
base::string16(kSomeArgument));
EXPECT_EQ(5, cl.argv().size());
EXPECT_EQ(this_exe.value(), cl.GetProgram().value());
EXPECT_TRUE(cl.HasSwitch(kSomeSwitch));
CommandLine::StringVector args(cl.GetArgs());
EXPECT_EQ(2, args.size());
EXPECT_NE(
args.end(),
std::find(args.begin(), args.end(), base::string16(kOtherArgument)));
EXPECT_NE(args.end(),
std::find(args.begin(), args.end(), base::string16(kSomeArgument)));
}
TEST(DelegateExecuteUtil, ParametersFromSwitchTest) {
EXPECT_EQ(base::string16(), delegate_execute::ParametersFromSwitch(NULL));
EXPECT_EQ(base::string16(L"--some-switch"),
delegate_execute::ParametersFromSwitch(kSomeSwitch));
}