-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: add test cases for wide character path conversions (#754)
- Loading branch information
Showing
5 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <boost/core/lightweight_test.hpp> | ||
#include <boost/gil/io/path_spec.hpp> | ||
#include <cstring> | ||
#include <locale> | ||
#include <string> | ||
|
||
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(); | ||
} |