|
|
@ -58,14 +58,14 @@ TEST(AppParametersTest, null) { |
|
|
|
app_parameters parameters{ 0, static_cast<const char**>(nullptr) }; |
|
|
|
app_parameters parameters2{ 1234, static_cast<const char**>(nullptr) }; |
|
|
|
|
|
|
|
EXPECT_TRUE(parameters.path().empty()); |
|
|
|
EXPECT_TRUE(parameters.name().empty()); |
|
|
|
EXPECT_TRUE(parameters.arguments().empty()); |
|
|
|
EXPECT_TRUE(parameters.switches().empty()); |
|
|
|
EXPECT_TRUE(parameters.switches_set().empty()); |
|
|
|
EXPECT_TRUE(parameters.values().empty()); |
|
|
|
EXPECT_TRUE(parameters.as_object().null()); |
|
|
|
|
|
|
|
EXPECT_TRUE(parameters2.path().empty()); |
|
|
|
EXPECT_TRUE(parameters2.name().empty()); |
|
|
|
EXPECT_TRUE(parameters2.arguments().empty()); |
|
|
|
EXPECT_TRUE(parameters2.switches().empty()); |
|
|
|
EXPECT_TRUE(parameters2.switches_set().empty()); |
|
|
@ -73,11 +73,11 @@ TEST(AppParametersTest, null) { |
|
|
|
EXPECT_TRUE(parameters2.as_object().null()); |
|
|
|
} |
|
|
|
|
|
|
|
TEST(AppParametersTest, path_only) { |
|
|
|
TEST(AppParametersTest, name_only) { |
|
|
|
ArgWrapper args{ "/path/to/exe" }; |
|
|
|
app_parameters parameters{ args.argc(), args.argv() }; |
|
|
|
|
|
|
|
EXPECT_EQ(parameters.path(), u8"/path/to/exe"); |
|
|
|
EXPECT_EQ(parameters.name(), u8"/path/to/exe"); |
|
|
|
EXPECT_TRUE(parameters.arguments().empty()); |
|
|
|
EXPECT_TRUE(parameters.switches().empty()); |
|
|
|
EXPECT_TRUE(parameters.switches_set().empty()); |
|
|
@ -85,14 +85,14 @@ TEST(AppParametersTest, path_only) { |
|
|
|
|
|
|
|
auto obj = parameters.as_object(); |
|
|
|
EXPECT_FALSE(obj.null()); |
|
|
|
EXPECT_EQ(obj[u8"Path"], u8"/path/to/exe"); |
|
|
|
EXPECT_EQ(obj[u8"Name"], u8"/path/to/exe"); |
|
|
|
} |
|
|
|
|
|
|
|
TEST(AppParametersTest, path_only_w) { |
|
|
|
ArgWrapper<wchar_t> args{ L"/path/to/exe" }; |
|
|
|
app_parameters parameters{ args.argc(), args.argv() }; |
|
|
|
|
|
|
|
EXPECT_EQ(parameters.path(), u8"/path/to/exe"); |
|
|
|
EXPECT_EQ(parameters.name(), u8"/path/to/exe"); |
|
|
|
EXPECT_TRUE(parameters.arguments().empty()); |
|
|
|
EXPECT_TRUE(parameters.switches().empty()); |
|
|
|
EXPECT_TRUE(parameters.switches_set().empty()); |
|
|
@ -100,14 +100,14 @@ TEST(AppParametersTest, path_only_w) { |
|
|
|
|
|
|
|
auto obj = parameters.as_object(); |
|
|
|
EXPECT_FALSE(obj.null()); |
|
|
|
EXPECT_EQ(obj[u8"Path"], u8"/path/to/exe"); |
|
|
|
EXPECT_EQ(obj[u8"Name"], u8"/path/to/exe"); |
|
|
|
} |
|
|
|
|
|
|
|
TEST(AppParametersTest, single_switch) { |
|
|
|
ArgWrapper args{ "/path/to/exe", "-switch" }; |
|
|
|
app_parameters parameters{ args.argc(), args.argv() }; |
|
|
|
|
|
|
|
EXPECT_FALSE(parameters.path().empty()); |
|
|
|
EXPECT_FALSE(parameters.name().empty()); |
|
|
|
EXPECT_EQ(parameters.arguments().size(), 1U); |
|
|
|
EXPECT_EQ(parameters.switches().size(), 1U); |
|
|
|
EXPECT_EQ(parameters.switches_set().size(), 1U); |
|
|
@ -115,7 +115,7 @@ TEST(AppParametersTest, single_switch) { |
|
|
|
|
|
|
|
auto obj = parameters.as_object(); |
|
|
|
EXPECT_FALSE(obj.null()); |
|
|
|
EXPECT_EQ(obj[u8"Path"], u8"/path/to/exe"); |
|
|
|
EXPECT_EQ(obj[u8"Name"], u8"/path/to/exe"); |
|
|
|
EXPECT_EQ(obj[u8"Args"], object{ std::vector<std::u8string>{ u8"-switch" } }); |
|
|
|
EXPECT_EQ(obj[u8"Switches"], object{ std::vector<std::u8string>{ u8"switch" } }); |
|
|
|
} |
|
|
@ -124,7 +124,7 @@ TEST(AppParametersTest, double_switch) { |
|
|
|
ArgWrapper args{ "/path/to/exe", "-switch1", "--switch2" }; |
|
|
|
app_parameters parameters{ args.argc(), args.argv() }; |
|
|
|
|
|
|
|
EXPECT_FALSE(parameters.path().empty()); |
|
|
|
EXPECT_FALSE(parameters.name().empty()); |
|
|
|
EXPECT_EQ(parameters.arguments().size(), 2U); |
|
|
|
EXPECT_EQ(parameters.switches().size(), 2U); |
|
|
|
EXPECT_EQ(parameters.switches_set().size(), 2U); |
|
|
@ -134,7 +134,7 @@ TEST(AppParametersTest, double_switch) { |
|
|
|
std::vector<std::u8string> expected_args{ u8"-switch1", u8"--switch2" }; |
|
|
|
std::vector<std::u8string> expected_switches{ u8"switch1", u8"switch2" }; |
|
|
|
EXPECT_FALSE(obj.null()); |
|
|
|
EXPECT_EQ(obj[u8"Path"], u8"/path/to/exe"); |
|
|
|
EXPECT_EQ(obj[u8"Name"], u8"/path/to/exe"); |
|
|
|
EXPECT_EQ(obj[u8"Args"], expected_args); |
|
|
|
EXPECT_EQ(obj[u8"Switches"], expected_switches); |
|
|
|
} |
|
|
@ -143,7 +143,7 @@ TEST(AppParametersTest, duplicate_switch) { |
|
|
|
ArgWrapper args{ "/path/to/exe", "-switch", "--switch" }; |
|
|
|
app_parameters parameters{ args.argc(), args.argv() }; |
|
|
|
|
|
|
|
EXPECT_FALSE(parameters.path().empty()); |
|
|
|
EXPECT_FALSE(parameters.name().empty()); |
|
|
|
EXPECT_EQ(parameters.arguments().size(), 2U); |
|
|
|
EXPECT_EQ(parameters.switches().size(), 2U); |
|
|
|
EXPECT_EQ(parameters.switches_set().size(), 1U); |
|
|
@ -153,7 +153,7 @@ TEST(AppParametersTest, duplicate_switch) { |
|
|
|
std::vector<std::u8string> expected_args{ u8"-switch", u8"--switch" }; |
|
|
|
std::vector<std::u8string> expected_switches{ u8"switch", u8"switch" }; |
|
|
|
EXPECT_FALSE(obj.null()); |
|
|
|
EXPECT_EQ(obj[u8"Path"], u8"/path/to/exe"); |
|
|
|
EXPECT_EQ(obj[u8"Name"], u8"/path/to/exe"); |
|
|
|
EXPECT_EQ(obj[u8"Args"], expected_args); |
|
|
|
EXPECT_EQ(obj[u8"Switches"], expected_switches); |
|
|
|
} |
|
|
@ -162,7 +162,7 @@ TEST(AppParametersTest, single_value) { |
|
|
|
ArgWrapper args{ "/path/to/exe", "-key", "value" }; |
|
|
|
app_parameters parameters{ args.argc(), args.argv() }; |
|
|
|
|
|
|
|
EXPECT_FALSE(parameters.path().empty()); |
|
|
|
EXPECT_FALSE(parameters.name().empty()); |
|
|
|
EXPECT_EQ(parameters.arguments().size(), 2U); |
|
|
|
EXPECT_EQ(parameters.switches().size(), 0U); |
|
|
|
EXPECT_EQ(parameters.switches_set().size(), 0U); |
|
|
@ -172,7 +172,7 @@ TEST(AppParametersTest, single_value) { |
|
|
|
std::vector<std::u8string> expected_args{ u8"-key", u8"value" }; |
|
|
|
std::map<std::u8string, object> expected_values{ { u8"key", u8"value" } }; |
|
|
|
EXPECT_FALSE(obj.null()); |
|
|
|
EXPECT_EQ(obj[u8"Path"], u8"/path/to/exe"); |
|
|
|
EXPECT_EQ(obj[u8"Name"], u8"/path/to/exe"); |
|
|
|
EXPECT_EQ(obj[u8"Args"], expected_args); |
|
|
|
EXPECT_EQ(obj[u8"Values"], expected_values); |
|
|
|
} |
|
|
@ -181,7 +181,7 @@ TEST(AppParametersTest, single_value_eq) { |
|
|
|
ArgWrapper args{ "/path/to/exe", "-key=value" }; |
|
|
|
app_parameters parameters{ args.argc(), args.argv() }; |
|
|
|
|
|
|
|
EXPECT_FALSE(parameters.path().empty()); |
|
|
|
EXPECT_FALSE(parameters.name().empty()); |
|
|
|
EXPECT_EQ(parameters.arguments().size(), 1U); |
|
|
|
EXPECT_EQ(parameters.switches().size(), 0U); |
|
|
|
EXPECT_EQ(parameters.switches_set().size(), 0U); |
|
|
@ -191,7 +191,7 @@ TEST(AppParametersTest, single_value_eq) { |
|
|
|
std::vector<std::u8string> expected_args{ u8"-key=value" }; |
|
|
|
std::map<std::u8string, object> expected_values{ { u8"key", u8"value" } }; |
|
|
|
EXPECT_FALSE(obj.null()); |
|
|
|
EXPECT_EQ(obj[u8"Path"], u8"/path/to/exe"); |
|
|
|
EXPECT_EQ(obj[u8"Name"], u8"/path/to/exe"); |
|
|
|
EXPECT_EQ(obj[u8"Args"], expected_args); |
|
|
|
EXPECT_EQ(obj[u8"Values"], expected_values); |
|
|
|
} |
|
|
@ -200,7 +200,7 @@ TEST(AppParametersTest, multiword_value) { |
|
|
|
ArgWrapper args{ "/path/to/exe", "-key", "valuePart1", "valuePart2" }; |
|
|
|
app_parameters parameters{ args.argc(), args.argv() }; |
|
|
|
|
|
|
|
EXPECT_FALSE(parameters.path().empty()); |
|
|
|
EXPECT_FALSE(parameters.name().empty()); |
|
|
|
EXPECT_EQ(parameters.arguments().size(), 3U); |
|
|
|
EXPECT_EQ(parameters.switches().size(), 0U); |
|
|
|
EXPECT_EQ(parameters.switches_set().size(), 0U); |
|
|
@ -210,7 +210,7 @@ TEST(AppParametersTest, multiword_value) { |
|
|
|
std::vector<std::u8string> expected_args{ u8"-key", u8"valuePart1", u8"valuePart2" }; |
|
|
|
std::map<std::u8string, object> expected_values{ { u8"key", u8"valuePart1 valuePart2" } }; |
|
|
|
EXPECT_FALSE(obj.null()); |
|
|
|
EXPECT_EQ(obj[u8"Path"], u8"/path/to/exe"); |
|
|
|
EXPECT_EQ(obj[u8"Name"], u8"/path/to/exe"); |
|
|
|
EXPECT_EQ(obj[u8"Args"], expected_args); |
|
|
|
EXPECT_EQ(obj[u8"Values"], expected_values); |
|
|
|
} |
|
|
@ -219,7 +219,7 @@ TEST(AppParametersTest, multiword_value_eq) { |
|
|
|
ArgWrapper args{ "/path/to/exe", "-key=valuePart1", "valuePart2" }; |
|
|
|
app_parameters parameters{ args.argc(), args.argv() }; |
|
|
|
|
|
|
|
EXPECT_FALSE(parameters.path().empty()); |
|
|
|
EXPECT_FALSE(parameters.name().empty()); |
|
|
|
EXPECT_EQ(parameters.arguments().size(), 2U); |
|
|
|
EXPECT_EQ(parameters.switches().size(), 0U); |
|
|
|
EXPECT_EQ(parameters.switches_set().size(), 0U); |
|
|
@ -229,7 +229,7 @@ TEST(AppParametersTest, multiword_value_eq) { |
|
|
|
std::vector<std::u8string> expected_args{ u8"-key=valuePart1", u8"valuePart2" }; |
|
|
|
std::map<std::u8string, object> expected_values{ { u8"key", u8"valuePart1 valuePart2" } }; |
|
|
|
EXPECT_FALSE(obj.null()); |
|
|
|
EXPECT_EQ(obj[u8"Path"], u8"/path/to/exe"); |
|
|
|
EXPECT_EQ(obj[u8"Name"], u8"/path/to/exe"); |
|
|
|
EXPECT_EQ(obj[u8"Args"], expected_args); |
|
|
|
EXPECT_EQ(obj[u8"Values"], expected_values); |
|
|
|
} |
|
|
@ -238,7 +238,7 @@ TEST(AppParametersTest, double_value) { |
|
|
|
ArgWrapper args{ "/path/to/exe", "-key", "value", "--key2", "value2" }; |
|
|
|
app_parameters parameters{ args.argc(), args.argv() }; |
|
|
|
|
|
|
|
EXPECT_FALSE(parameters.path().empty()); |
|
|
|
EXPECT_FALSE(parameters.name().empty()); |
|
|
|
EXPECT_EQ(parameters.arguments().size(), 4U); |
|
|
|
EXPECT_EQ(parameters.switches().size(), 0U); |
|
|
|
EXPECT_EQ(parameters.switches_set().size(), 0U); |
|
|
@ -248,7 +248,7 @@ TEST(AppParametersTest, double_value) { |
|
|
|
std::vector<std::u8string> expected_args{ u8"-key", u8"value", u8"--key2", u8"value2" }; |
|
|
|
std::map<std::u8string, object> expected_values{ { u8"key", u8"value" }, { u8"key2", u8"value2" } }; |
|
|
|
EXPECT_FALSE(obj.null()); |
|
|
|
EXPECT_EQ(obj[u8"Path"], u8"/path/to/exe"); |
|
|
|
EXPECT_EQ(obj[u8"Name"], u8"/path/to/exe"); |
|
|
|
EXPECT_EQ(obj[u8"Args"], expected_args); |
|
|
|
EXPECT_EQ(obj[u8"Values"], expected_values); |
|
|
|
} |
|
|
@ -257,7 +257,7 @@ TEST(AppParametersTest, double_value_eq) { |
|
|
|
ArgWrapper args{ "/path/to/exe", "-key=value", "--key2=value2" }; |
|
|
|
app_parameters parameters{ args.argc(), args.argv() }; |
|
|
|
|
|
|
|
EXPECT_FALSE(parameters.path().empty()); |
|
|
|
EXPECT_FALSE(parameters.name().empty()); |
|
|
|
EXPECT_EQ(parameters.arguments().size(), 2U); |
|
|
|
EXPECT_EQ(parameters.switches().size(), 0U); |
|
|
|
EXPECT_EQ(parameters.switches_set().size(), 0U); |
|
|
@ -267,7 +267,7 @@ TEST(AppParametersTest, double_value_eq) { |
|
|
|
std::vector<std::u8string> expected_args{ u8"-key=value", u8"--key2=value2" }; |
|
|
|
std::map<std::u8string, object> expected_values{ { u8"key", u8"value" }, { u8"key2", u8"value2" } }; |
|
|
|
EXPECT_FALSE(obj.null()); |
|
|
|
EXPECT_EQ(obj[u8"Path"], u8"/path/to/exe"); |
|
|
|
EXPECT_EQ(obj[u8"Name"], u8"/path/to/exe"); |
|
|
|
EXPECT_EQ(obj[u8"Args"], expected_args); |
|
|
|
EXPECT_EQ(obj[u8"Values"], expected_values); |
|
|
|
} |
|
|
@ -276,7 +276,7 @@ TEST(AppParametersTest, switch_and_value) { |
|
|
|
ArgWrapper args{ "/path/to/exe", "--switch", "-key", "value" }; |
|
|
|
app_parameters parameters{ args.argc(), args.argv() }; |
|
|
|
|
|
|
|
EXPECT_FALSE(parameters.path().empty()); |
|
|
|
EXPECT_FALSE(parameters.name().empty()); |
|
|
|
EXPECT_EQ(parameters.arguments().size(), 3U); |
|
|
|
EXPECT_EQ(parameters.switches().size(), 1U); |
|
|
|
EXPECT_EQ(parameters.switches_set().size(), 1U); |
|
|
@ -287,7 +287,7 @@ TEST(AppParametersTest, switch_and_value) { |
|
|
|
std::vector<std::u8string> expected_switches{ u8"switch" }; |
|
|
|
std::map<std::u8string, object> expected_values{ { u8"key", u8"value" } }; |
|
|
|
EXPECT_FALSE(obj.null()); |
|
|
|
EXPECT_EQ(obj[u8"Path"], u8"/path/to/exe"); |
|
|
|
EXPECT_EQ(obj[u8"Name"], u8"/path/to/exe"); |
|
|
|
EXPECT_EQ(obj[u8"Args"], expected_args); |
|
|
|
EXPECT_EQ(obj[u8"Switches"], expected_switches); |
|
|
|
EXPECT_EQ(obj[u8"Values"], expected_values); |
|
|
@ -301,7 +301,7 @@ TEST(AppParametersTest, switch_and_value_w) { |
|
|
|
ArgWrapper<wchar_t> args{ L"/path/to/exe", L"--switch", L"-key", L"value" }; |
|
|
|
app_parameters parameters{ args.argc(), args.argv() }; |
|
|
|
|
|
|
|
EXPECT_FALSE(parameters.path().empty()); |
|
|
|
EXPECT_FALSE(parameters.name().empty()); |
|
|
|
EXPECT_EQ(parameters.arguments().size(), 3U); |
|
|
|
EXPECT_EQ(parameters.switches().size(), 1U); |
|
|
|
EXPECT_EQ(parameters.switches_set().size(), 1U); |
|
|
@ -312,7 +312,7 @@ TEST(AppParametersTest, switch_and_value_w) { |
|
|
|
std::vector<std::u8string> expected_switches{ u8"switch" }; |
|
|
|
std::map<std::u8string, object> expected_values{ { u8"key", u8"value" } }; |
|
|
|
EXPECT_FALSE(obj.null()); |
|
|
|
EXPECT_EQ(obj[u8"Path"], u8"/path/to/exe"); |
|
|
|
EXPECT_EQ(obj[u8"Name"], u8"/path/to/exe"); |
|
|
|
EXPECT_EQ(obj[u8"Args"], expected_args); |
|
|
|
EXPECT_EQ(obj[u8"Switches"], expected_switches); |
|
|
|
EXPECT_EQ(obj[u8"Values"], expected_values); |
|
|
@ -321,3 +321,38 @@ TEST(AppParametersTest, switch_and_value_w) { |
|
|
|
EXPECT_FALSE(parameters.has_switch(u8"switch2")); |
|
|
|
EXPECT_EQ(parameters.get_value(u8"key"), u8"value"); |
|
|
|
} |
|
|
|
|
|
|
|
TEST(AppParametersTest, arg_before_env) { |
|
|
|
ArgWrapper<wchar_t> args{ L"/path/to/exe", L"--switch", L"-key", L"value" }; |
|
|
|
ArgWrapper<wchar_t> envs{ L"key=other_value", L"other_key=some_value" }; |
|
|
|
app_parameters parameters{ args.argc(), args.argv(), envs.argv() }; |
|
|
|
|
|
|
|
EXPECT_EQ(parameters.get_arg_value(u8"key"), u8"value"); |
|
|
|
EXPECT_EQ(parameters.get_env_value(u8"key"), u8"other_value"); |
|
|
|
EXPECT_EQ(parameters.get_value(u8"key"), u8"value"); |
|
|
|
EXPECT_EQ(parameters.get_value(u8"other_key"), u8"some_value"); |
|
|
|
} |
|
|
|
|
|
|
|
TEST(AppParametersTest, arg_stop) { |
|
|
|
ArgWrapper<wchar_t> args{ L"/path/to/exe", L"--switch", L"-key", L"value", L"--", L"-other_key", L"value" }; |
|
|
|
ArgWrapper<wchar_t> envs{ L"key=other_value", L"other_key=some_value" }; |
|
|
|
app_parameters parameters{ args.argc(), args.argv(), envs.argv() }; |
|
|
|
|
|
|
|
EXPECT_EQ(parameters.get_arg_value(u8"key"), u8"value"); |
|
|
|
EXPECT_EQ(parameters.get_env_value(u8"key"), u8"other_value"); |
|
|
|
EXPECT_EQ(parameters.get_value(u8"key"), u8"value"); |
|
|
|
EXPECT_EQ(parameters.get_value(u8"other_key"), u8"some_value"); |
|
|
|
} |
|
|
|
|
|
|
|
TEST(AppParametersTest, precedent) { |
|
|
|
ArgWrapper<wchar_t> args{ L"/path/to/exe", L"some", L"words", L"--switch", L"-key", L"value", L"--", L"-other_key", L"value" }; |
|
|
|
ArgWrapper<wchar_t> envs{ L"key=other_value", L"other_key=some_value" }; |
|
|
|
app_parameters parameters{ args.argc(), args.argv(), envs.argv() }; |
|
|
|
|
|
|
|
EXPECT_EQ(parameters.precedent(), u8"some words"); |
|
|
|
EXPECT_TRUE(parameters.has_switch(u8"switch")); |
|
|
|
EXPECT_EQ(parameters.get_arg_value(u8"key"), u8"value"); |
|
|
|
EXPECT_EQ(parameters.get_env_value(u8"key"), u8"other_value"); |
|
|
|
EXPECT_EQ(parameters.get_value(u8"key"), u8"value"); |
|
|
|
EXPECT_EQ(parameters.get_value(u8"other_key"), u8"some_value"); |
|
|
|
} |
|
|
|