diff --git a/test/core/CMakeLists.txt b/test/core/CMakeLists.txt index 2b70482aa..ee0933290 100644 --- a/test/core/CMakeLists.txt +++ b/test/core/CMakeLists.txt @@ -41,3 +41,4 @@ add_subdirectory(image_view) add_subdirectory(algorithm) add_subdirectory(image_processing) add_subdirectory(histogram) +add_subdirectory(io) diff --git a/test/core/Jamfile b/test/core/Jamfile index 9305b8762..25156392e 100644 --- a/test/core/Jamfile +++ b/test/core/Jamfile @@ -33,3 +33,4 @@ build-project image_view ; build-project algorithm ; build-project image_processing ; build-project histogram ; +build-project io ; diff --git a/test/core/io/CMakeLists.txt b/test/core/io/CMakeLists.txt new file mode 100644 index 000000000..171e35485 --- /dev/null +++ b/test/core/io/CMakeLists.txt @@ -0,0 +1,25 @@ +# +# Copyright (c) 2024 Dirk Stolle +# +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) +# +foreach(_name + path_spec) + set(_test t_core_io_${_name}) + set(_target test_core_io_${_name}) + + add_executable(${_target} "") + target_sources(${_target} PRIVATE ${_name}.cpp) + target_link_libraries(${_target} + PRIVATE + gil_compile_options + gil_include_directories + gil_dependencies) + add_test(NAME ${_test} COMMAND ${_target}) + + unset(_name) + unset(_target) + unset(_test) +endforeach() diff --git a/test/core/io/Jamfile b/test/core/io/Jamfile new file mode 100644 index 000000000..f696d7076 --- /dev/null +++ b/test/core/io/Jamfile @@ -0,0 +1,13 @@ +# Boost.GIL (Generic Image Library) - tests +# +# Copyright (c) 2024 Dirk Stolle +# +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or +# copy at http://www.boost.org/LICENSE_1_0.txt) + +import testing ; + +compile path_spec.cpp ; + +run path_spec.cpp ; diff --git a/test/core/io/path_spec.cpp b/test/core/io/path_spec.cpp new file mode 100644 index 000000000..8179512e6 --- /dev/null +++ b/test/core/io/path_spec.cpp @@ -0,0 +1,59 @@ +// +// Copyright 2024 Dirk Stolle +// +// Distributed under the Boost Software License, Version 1.0 +// See accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt + +#include +#include +#include +#include +#include + +namespace gil = boost::gil; + +void test_convert_to_string_from_wstring() +{ + std::wstring const path = L"/some_path/傳/привет/qwerty"; + std::string const expected = "/some_path/\xE5\x82\xB3/\xD0\xBF\xD1\x80\xD0\xB8\xD0\xB2\xD0\xB5\xD1\x82/qwerty"; + + std::string string = gil::detail::convert_to_string(path); + BOOST_TEST_EQ( 34, string.size() ); + BOOST_TEST_EQ( expected, string ); +} + +void test_convert_to_native_string_from_wchar_t_ptr() +{ + wchar_t const* path = L"/some_path/傳/привет/qwerty"; + char const* expected = "/some_path/\xE5\x82\xB3/\xD0\xBF\xD1\x80\xD0\xB8\xD0\xB2\xD0\xB5\xD1\x82/qwerty"; + + char const* string = gil::detail::convert_to_native_string(path); + BOOST_TEST_EQ( 34, strlen(string) ); + BOOST_TEST_EQ( 0, std::strcmp(expected, string) ); + delete[] string; +} + +void test_convert_to_native_string_from_wstring() +{ + std::wstring const path = L"/some_path/傳/привет/qwerty"; + char const* expected = "/some_path/\xE5\x82\xB3/\xD0\xBF\xD1\x80\xD0\xB8\xD0\xB2\xD0\xB5\xD1\x82/qwerty"; + + char const* string = gil::detail::convert_to_native_string(path); + BOOST_TEST_EQ( 34, strlen(string) ); + BOOST_TEST_EQ( 0, std::strcmp(expected, string) ); + delete[] string; +} + +int main() +{ + // Set global locale to one that uses UTF-8. Could be "en_US.UTF-8" or + // "C.UTF-8" or something similar, as long as it exists on the system. + std::locale::global(std::locale("C.UTF-8")); + + test_convert_to_string_from_wstring(); + test_convert_to_native_string_from_wchar_t_ptr(); + test_convert_to_native_string_from_wstring(); + + return boost::report_errors(); +}