aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/test/unit_tests
diff options
context:
space:
mode:
Diffstat (limited to 'test/unit_tests')
-rw-r--r--test/unit_tests/CMakeLists.txt12
-rw-r--r--test/unit_tests/cmd_line.cpp34
-rw-r--r--test/unit_tests/error.cpp23
-rw-r--r--test/unit_tests/handle.cpp21
-rw-r--r--test/unit_tests/main.cpp7
5 files changed, 97 insertions, 0 deletions
diff --git a/test/unit_tests/CMakeLists.txt b/test/unit_tests/CMakeLists.txt
new file mode 100644
index 0000000..33a6101
--- /dev/null
+++ b/test/unit_tests/CMakeLists.txt
@@ -0,0 +1,12 @@
+file(GLOB unit_tests_src "*.cpp")
+add_executable(unit_tests ${unit_tests_src})
+target_link_libraries(unit_tests PRIVATE winapi_common)
+set_target_properties(unit_tests PROPERTIES OUTPUT_NAME winapi-common-unit-tests)
+
+find_package(Boost REQUIRED COMPONENTS unit_test_framework)
+target_link_libraries(unit_tests PRIVATE Boost::disable_autolinking Boost::unit_test_framework)
+
+install(TARGETS unit_tests RUNTIME DESTINATION bin)
+if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
+ install(FILES "$<TARGET_PDB_FILE:unit_tests>" DESTINATION bin OPTIONAL)
+endif()
diff --git a/test/unit_tests/cmd_line.cpp b/test/unit_tests/cmd_line.cpp
new file mode 100644
index 0000000..4506304
--- /dev/null
+++ b/test/unit_tests/cmd_line.cpp
@@ -0,0 +1,34 @@
+// Copyright (c) 2020 Egor Tensin <Egor.Tensin@gmail.com>
+// 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 <winapi/cmd_line.hpp>
+
+#include <boost/test/unit_test.hpp>
+
+#include <string>
+
+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()
diff --git a/test/unit_tests/error.cpp b/test/unit_tests/error.cpp
new file mode 100644
index 0000000..f70d95d
--- /dev/null
+++ b/test/unit_tests/error.cpp
@@ -0,0 +1,23 @@
+// Copyright (c) 2020 Egor Tensin <Egor.Tensin@gmail.com>
+// 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 <winapi/error.hpp>
+
+#include <boost/test/unit_test.hpp>
+
+#include <windows.h>
+
+#include <string>
+
+BOOST_AUTO_TEST_SUITE(error_tests)
+
+BOOST_AUTO_TEST_CASE(file_not_found) {
+ const std::string actual{winapi::error::windows(ERROR_FILE_NOT_FOUND, "CreateFileW").what()};
+ BOOST_TEST(actual ==
+ "Function CreateFileW failed with error code 2: The system cannot find the file "
+ "specified.");
+}
+
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/test/unit_tests/handle.cpp b/test/unit_tests/handle.cpp
new file mode 100644
index 0000000..13551f4
--- /dev/null
+++ b/test/unit_tests/handle.cpp
@@ -0,0 +1,21 @@
+// Copyright (c) 2020 Egor Tensin <Egor.Tensin@gmail.com>
+// 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 <winapi/handle.hpp>
+
+#include <boost/test/unit_test.hpp>
+
+#include <windows.h>
+
+BOOST_AUTO_TEST_SUITE(handle_tests)
+
+BOOST_AUTO_TEST_CASE(null) {
+ { winapi::Handle h{NULL}; }
+ BOOST_TEST(true, "NULL handle closed successfully");
+ { winapi::Handle h{INVALID_HANDLE_VALUE}; }
+ BOOST_TEST(true, "INVALID_HANDLE_VALUE handle closed successfully");
+}
+
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/test/unit_tests/main.cpp b/test/unit_tests/main.cpp
new file mode 100644
index 0000000..d7e8d4f
--- /dev/null
+++ b/test/unit_tests/main.cpp
@@ -0,0 +1,7 @@
+// Copyright (c) 2020 Egor Tensin <Egor.Tensin@gmail.com>
+// This file is part of the "winapi-common" project.
+// For details, see https://github.com/egor-tensin/winapi-common.
+// Distributed under the MIT License.
+
+#define BOOST_TEST_MODULE winapi_common tests
+#include <boost/test/unit_test.hpp>