diff options
Diffstat (limited to '')
-rw-r--r-- | test/unit_tests/CMakeLists.txt | 5 | ||||
-rw-r--r-- | test/unit_tests/resource.cpp | 57 | ||||
-rw-r--r-- | test/unit_tests/resource.rc | 15 | ||||
-rw-r--r-- | test/unit_tests/resource_ids.h | 3 |
4 files changed, 77 insertions, 3 deletions
diff --git a/test/unit_tests/CMakeLists.txt b/test/unit_tests/CMakeLists.txt index 19ce0c0..8aaa6d3 100644 --- a/test/unit_tests/CMakeLists.txt +++ b/test/unit_tests/CMakeLists.txt @@ -1,6 +1,5 @@ -file(GLOB unit_tests_cpp "*.cpp") -file(GLOB unit_tests_hpp "*.hpp") -add_executable(unit_tests ${unit_tests_cpp} ${unit_tests_hpp}) +file(GLOB unit_tests_files "*.cpp" "*.h" "*.hpp" "*.rc") +add_executable(unit_tests ${unit_tests_files}) set_target_properties(unit_tests PROPERTIES OUTPUT_NAME winapi-common-unit-tests) target_link_libraries(unit_tests PRIVATE winapi_common winapi_utf8) diff --git a/test/unit_tests/resource.cpp b/test/unit_tests/resource.cpp new file mode 100644 index 0000000..894edca --- /dev/null +++ b/test/unit_tests/resource.cpp @@ -0,0 +1,57 @@ +// 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 "resource_ids.h" + +#include <winapi/process.hpp> +#include <winapi/utf8.hpp> + +#include <boost/config.hpp> +#include <boost/format.hpp> +#include <boost/test/unit_test.hpp> + +using namespace winapi; + +#include <ostream> +#include <vector> + +namespace std { + +ostream& operator<<(ostream& os, unsigned char c) { + return os << boost::format("%|1$02x|") % static_cast<unsigned int>(c); +} + +ostream& operator<<(ostream& os, const vector<unsigned char>& cs) { + for (auto c : cs) { + os << c; + } + return os; +} + +} // namespace std + +BOOST_TEST_SPECIALIZED_COLLECTION_COMPARE(Buffer); + +BOOST_AUTO_TEST_SUITE(resource_tests) + +BOOST_AUTO_TEST_CASE(get_string) { + BOOST_STATIC_CONSTEXPR auto expected = "This is a test resource string!"; + const auto actual = Process::get_resource_string(IDS_TEST_STRING); + BOOST_TEST(actual == expected); +} + +BOOST_AUTO_TEST_CASE(get_string_wide) { + BOOST_STATIC_CONSTEXPR auto expected = "This is another test string, wide this time."; + const auto actual = Process::get_resource_string(IDS_TEST_STRING_WIDE); + BOOST_TEST(actual == expected); +} + +BOOST_AUTO_TEST_CASE(get_data) { + static const Buffer expected{0xde, 0xad, 0xbe, 0xef}; + const auto actual = Process::get_resource(ID_TEST_DATA).copy(); + BOOST_TEST(actual == expected); +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/unit_tests/resource.rc b/test/unit_tests/resource.rc new file mode 100644 index 0000000..4ff6e5c --- /dev/null +++ b/test/unit_tests/resource.rc @@ -0,0 +1,15 @@ +#include "resource_ids.h" + +#include <windows.h> + +STRINGTABLE +{ + IDS_TEST_STRING, "This is a test resource string!" + IDS_TEST_STRING_WIDE, L"This is another test string, wide this time." +} + +// 0xdeadbeef, byte by byte +ID_TEST_DATA RCDATA +{ + 0xadde, 0xefbe +} diff --git a/test/unit_tests/resource_ids.h b/test/unit_tests/resource_ids.h new file mode 100644 index 0000000..46046bf --- /dev/null +++ b/test/unit_tests/resource_ids.h @@ -0,0 +1,3 @@ +#define IDS_TEST_STRING 69 +#define IDS_TEST_STRING_WIDE 70 +#define ID_TEST_DATA 420 |