Skip to content

Commit

Permalink
Utility: test corrade_add_resource() with Unicode filenames.
Browse files Browse the repository at this point in the history
Causes CMake with Ninja+MSVC to go into an infinite loop, MinGW fails
during build. Wow.
  • Loading branch information
mosra committed Aug 27, 2018
1 parent b47ea83 commit 7028980
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Corrade/Utility/Test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,18 @@ corrade_add_test(UtilityUnicodeTest UnicodeTest.cpp LIBRARIES CorradeUtilityTest
corrade_add_resource(ResourceTestData ResourceTestFiles/resources.conf)
corrade_add_resource(ResourceTestEmptyFileData ResourceTestFiles/resources-empty-file.conf)
corrade_add_resource(ResourceTestNothingData ResourceTestFiles/resources-nothing.conf)

# CMake < 3.1 can't handle UTF-8 in file(STRINGS)
if(NOT CMAKE_VERSION VERSION_LESS 3.1)
corrade_add_resource(ResourceTestUtf8Data ResourceTestFiles/hýždě.conf)
endif()

corrade_add_test(UtilityResourceTest
ResourceTest.cpp
${ResourceTestData}
${ResourceTestEmptyFileData}
${ResourceTestNothingData}
${ResourceTestUtf8Data}
LIBRARIES CorradeUtilityTestLib
FILES
ResourceTestFiles/compiled.cpp
Expand Down Expand Up @@ -195,6 +202,11 @@ corrade_add_test(UtilityResourceTest
ResourceTestFiles/resources-overriden-nonexistent-file.conf)
target_include_directories(UtilityResourceTest PRIVATE ${CMAKE_CURRENT_BINARY_DIR})

# CMake < 3.1 can't handle UTF-8 in file(STRINGS), disable relevant test case
if(CMAKE_VERSION VERSION_LESS 3.1)
target_compile_definitions(UtilityResourceTest PRIVATE "RESOURCETETST_NO_UNICODE")
endif()

# Static lib resource test
add_library(ResourceTestDataLib STATIC ${ResourceTestData})
target_link_libraries(ResourceTestDataLib CorradeUtility)
Expand Down
13 changes: 13 additions & 0 deletions src/Corrade/Utility/Test/ResourceTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ struct ResourceTest: TestSuite::Tester {
void getEmptyFile();
void getNonexistent();
void getNothing();
void getUtf8Filename();

void overrideGroup();
void overrideGroupFallback();
Expand Down Expand Up @@ -83,6 +84,7 @@ ResourceTest::ResourceTest() {
&ResourceTest::getEmptyFile,
&ResourceTest::getNonexistent,
&ResourceTest::getNothing,
&ResourceTest::getUtf8Filename,

&ResourceTest::overrideGroup,
&ResourceTest::overrideGroupFallback,
Expand Down Expand Up @@ -239,6 +241,17 @@ void ResourceTest::getNothing() {
CORRADE_VERIFY(r.get("nonexistentFile").empty());
}

void ResourceTest::getUtf8Filename() {
#ifdef RESOURCETETST_NO_UNICODE
CORRADE_SKIP("CMake < 3.1 used, can't test compilation of resources with UTF-8 filenames.");
#else
Resource r("unicode");
CORRADE_COMPARE_AS(r.get("hýždě.bin"),
Directory::join(RESOURCE_TEST_DIR, "hýždě.bin"),
TestSuite::Compare::StringToFile);
#endif
}

void ResourceTest::overrideGroup() {
std::ostringstream out;
Debug redirectDebug{&out};
Expand Down

0 comments on commit 7028980

Please sign in to comment.