From 49fc75926e55b5da009f6fe45e08be41c868552d Mon Sep 17 00:00:00 2001 From: Thomas Geymayer Date: Wed, 11 Jun 2014 00:29:17 +0200 Subject: [PATCH] Use Boost.Test to test utf8tolatin1 - others to be converted too... --- simgear/misc/CMakeLists.txt | 9 +++--- simgear/misc/utf8tolatin1_test.cxx | 46 ++++++++++++++---------------- 2 files changed, 26 insertions(+), 29 deletions(-) diff --git a/simgear/misc/CMakeLists.txt b/simgear/misc/CMakeLists.txt index 6b4790af..deb72963 100644 --- a/simgear/misc/CMakeLists.txt +++ b/simgear/misc/CMakeLists.txt @@ -63,13 +63,14 @@ add_executable(test_path path_test.cxx ) add_test(path ${EXECUTABLE_OUTPUT_PATH}/test_path) target_link_libraries(test_path ${TEST_LIBS}) -add_executable(test_utf8tolatin1 utf8tolatin1_test.cxx ) -add_test(utf8tolatin1 ${EXECUTABLE_OUTPUT_PATH}/test_utf8tolatin1) -target_link_libraries(test_utf8tolatin1 ${TEST_LIBS}) - endif(ENABLE_TESTS) add_boost_test(SVGpreserveAspectRatio SOURCES SVGpreserveAspectRatio_test.cxx LIBRARIES ${TEST_LIBS} ) + +add_boost_test(utf8tolatin1 + SOURCES utf8tolatin1_test.cxx + LIBRARIES ${TEST_LIBS} +) diff --git a/simgear/misc/utf8tolatin1_test.cxx b/simgear/misc/utf8tolatin1_test.cxx index 9b6049ef..67bf113f 100644 --- a/simgear/misc/utf8tolatin1_test.cxx +++ b/simgear/misc/utf8tolatin1_test.cxx @@ -1,30 +1,26 @@ +/// Unit tests for utf8ToLatin1 conversion function +#define BOOST_TEST_MODULE misc +#include + #include "strutils.hxx" -#include #include -int main() +BOOST_AUTO_TEST_CASE( utf8_latin1_conversion ) { - std::string utf8_string1 = "Zweibr\u00FCcken"; - //valid UTF-8, convertible to Latin-1 - std::string latin1_string1 = "Zweibr\374cken"; - //Latin-1, not valid UTF-8 - std::string utf8_string2 = "\u600f\U00010143"; - //valid UTF-8, out of range for Latin-1 - - std::string output_string1u = simgear::strutils::utf8ToLatin1(utf8_string1); - if (output_string1u.compare(latin1_string1)){ - std::cerr << "Conversion fail: " - << output_string1u << "!=" << latin1_string1; - return 1; - } - std::string output_string1l = simgear::strutils::utf8ToLatin1(latin1_string1); - if (output_string1l.compare(latin1_string1)){ - std::cerr << "Non-conversion fail: " - << output_string1l << "!=" << latin1_string1; - return 1; - } - std::string output_string3 = simgear::strutils::utf8ToLatin1(utf8_string2); - //we don't check the result of this one as there is no right answer, - //just make sure it doesn't crash/hang - return 0; + std::string utf8_string1 = "Zweibr\u00FCcken"; + //valid UTF-8, convertible to Latin-1 + std::string latin1_string1 = "Zweibr\374cken"; + //Latin-1, not valid UTF-8 + std::string utf8_string2 = "\u600f\U00010143"; + //valid UTF-8, out of range for Latin-1 + + std::string output_string1u = simgear::strutils::utf8ToLatin1(utf8_string1); + BOOST_CHECK_EQUAL(output_string1u, latin1_string1); + + std::string output_string1l = simgear::strutils::utf8ToLatin1(latin1_string1); + BOOST_CHECK_EQUAL(output_string1l, latin1_string1); + + std::string output_string3 = simgear::strutils::utf8ToLatin1(utf8_string2); + //we don't check the result of this one as there is no right answer, + //just make sure it doesn't crash/hang } -- 2.39.5