Skip to content

Commit

Permalink
Testing on unicode converters can be disabled on CMake (can be a temp…
Browse files Browse the repository at this point in the history
…orary fix for CI on WIndows)
  • Loading branch information
pbosetti committed Sep 2, 2024
1 parent 36aada5 commit 07155d7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 8 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ add_executable(tests tests.cpp)
target_link_libraries(tests cppy3)
include_directories(${PROJECT_SOURCE_DIR})

option(CPPY3_TEST_UNICODE_CONVERTERS "Test for proper working of Unicode conversion utilities" ON)

if(CPPY3_TEST_UNICODE_CONVERTERS)
add_definitions(-DTEST_UNICODE_CONVERTERS)
else()
add_definitions(-DTEST_UNICODE_CONVERTERS=0)
endif()

if(Python3_NumPy_FOUND)
include_directories(${Python3_NumPy_INCLUDE_DIRS})
if(WIN32)
Expand Down
8 changes: 5 additions & 3 deletions tests/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@
#define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp>

#define DEBUG_UNICODE_CONVERTERS 1
#ifndef TEST_UNICODE_CONVERTERS
#define TEST_UNICODE_CONVERTERS 1
#endif


TEST_CASE( "Utils", "" ) {
#if TEST_UNICODE_CONVERTERS
SECTION( "unicode converters" ) {
const std::string utf8Str("зачем вы посетили нас в глуши забытого селенья");
const std::wstring unicodeStr(L"зачем вы посетили нас в глуши забытого селенья");

#if DEBUG_UNICODE_CONVERTERS
#if 1
constexpr char locale_name[] = "en_US.UTF-8";
setlocale( LC_ALL, locale_name );
Expand All @@ -37,11 +39,11 @@ TEST_CASE( "Utils", "" ) {

std::wcout << unicodeStr << std::endl;
std::wcout << "UTF8->Unicode:" << cppy3::UTF8ToWide(utf8Str) << std::endl;
#endif

REQUIRE(cppy3::WideToUTF8(unicodeStr) == utf8Str);
REQUIRE(cppy3::UTF8ToWide(utf8Str) == unicodeStr);
}
#endif
}

TEST_CASE( "cppy3: Embedding Python into C++ code", "main funcs" ) {
Expand Down

0 comments on commit 07155d7

Please sign in to comment.