From 53c959a6795d098d800d85750f21afa721750c56 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Wed, 14 Oct 2020 19:51:42 +0300 Subject: cmd_line.hpp: rework for this project --- test/CMakeLists.txt | 2 +- test/cmd_line.cpp | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 test/cmd_line.cpp (limited to 'test') diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 4c09bcd..55cdf34 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,6 +1,6 @@ find_package(Boost REQUIRED COMPONENTS unit_test_framework) -add_executable(unit_tests main.cpp error.cpp handle.cpp) +add_executable(unit_tests main.cpp cmd_line.cpp error.cpp handle.cpp) target_link_libraries(unit_tests PRIVATE winapi_common) target_link_libraries(unit_tests PRIVATE Boost::disable_autolinking Boost::unit_test_framework) set_target_properties(unit_tests PROPERTIES OUTPUT_NAME winapi-common-unit-tests) diff --git a/test/cmd_line.cpp b/test/cmd_line.cpp new file mode 100644 index 0000000..4506304 --- /dev/null +++ b/test/cmd_line.cpp @@ -0,0 +1,34 @@ +// Copyright (c) 2020 Egor Tensin +// This file is part of the "winapi-common" project. +// For details, see https://github.com/egor-tensin/winapi-common. +// Distributed under the MIT License. + +#include + +#include + +#include + +BOOST_AUTO_TEST_SUITE(cmd_line_tests) + +BOOST_AUTO_TEST_CASE(query) { + const auto cmd_line = winapi::CommandLine::query(); + BOOST_TEST(cmd_line.has_argv0()); + BOOST_TEST_MESSAGE(cmd_line.get_argv0()); +} + +BOOST_AUTO_TEST_CASE(escape) { + wchar_t* argv[] = { + L"test.exe", + L"arg1 arg2", + LR"(path\to\file)", + LR"(path\to\dir\)", + LR"(weird\\argument)", + }; + const auto cmd_line = winapi::CommandLine::build_from_main(5, argv); + const auto expected = + R"("test.exe" "arg1 arg2" "path\to\file" "path\to\dir\\" "weird\\argument")"; + BOOST_TEST(cmd_line.join() == expected); +} + +BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3