fix: failures in big endian machines tests
This commit is contained in:
parent
64dc2299da
commit
d6b53ea718
5 changed files with 22 additions and 4 deletions
|
|
@ -43,3 +43,6 @@ add_library(base STATIC
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(base PRIVATE arch)
|
target_link_libraries(base PRIVATE arch)
|
||||||
|
if (CMAKE_CXX_BYTE_ORDER STREQUAL "BIG_ENDIAN")
|
||||||
|
target_compile_definitions(base PUBLIC WORDS_BIGENDIAN=1)
|
||||||
|
endif()
|
||||||
|
|
|
||||||
|
|
@ -439,7 +439,9 @@ std::string Unicode::doUTF16ToUTF8(const uint8_t *data, uint32_t n, bool *errors
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#ifdef WORDS_BIGENDIAN
|
||||||
|
byteSwapped = !byteSwapped;
|
||||||
|
#endif
|
||||||
// convert each character
|
// convert each character
|
||||||
while (n > 0) {
|
while (n > 0) {
|
||||||
if (uint32_t c = decode16(data, byteSwapped); c < 0x0000d800 || c > 0x0000dfff) {
|
if (uint32_t c = decode16(data, byteSwapped); c < 0x0000d800 || c > 0x0000dfff) {
|
||||||
|
|
@ -496,7 +498,9 @@ std::string Unicode::doUTF32ToUTF8(const uint8_t *data, uint32_t n, bool *errors
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#ifdef WORDS_BIGENDIAN
|
||||||
|
byteSwapped = !byteSwapped;
|
||||||
|
#endif
|
||||||
// convert each character
|
// convert each character
|
||||||
for (; n > 0; --n) {
|
for (; n > 0; --n) {
|
||||||
auto c = decode32(data, byteSwapped);
|
auto c = decode32(data, byteSwapped);
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,9 @@ function(create_test)
|
||||||
|
|
||||||
add_executable(${m_NAME} ${m_SOURCE})
|
add_executable(${m_NAME} ${m_SOURCE})
|
||||||
target_link_libraries(${m_NAME} ${m_DEPENDS} ${m_LIBS} Qt::Test)
|
target_link_libraries(${m_NAME} ${m_DEPENDS} ${m_LIBS} Qt::Test)
|
||||||
|
if (CMAKE_CXX_BYTE_ORDER STREQUAL "BIG_ENDIAN")
|
||||||
|
target_compile_definitions(${m_NAME} PUBLIC WORDS_BIGENDIAN=1)
|
||||||
|
endif()
|
||||||
add_test(NAME ${m_NAME} COMMAND $<TARGET_FILE:${m_NAME}> WORKING_DIRECTORY ${m_WORKING_DIRECTORY})
|
add_test(NAME ${m_NAME} COMMAND $<TARGET_FILE:${m_NAME}> WORKING_DIRECTORY ${m_WORKING_DIRECTORY})
|
||||||
set_tests_properties(${m_NAME} PROPERTIES DEPENDS ${m_DEPENDS})
|
set_tests_properties(${m_NAME} PROPERTIES DEPENDS ${m_DEPENDS})
|
||||||
set_property(GLOBAL APPEND PROPERTY ${CMAKE_PROJECT_NAME}_tests ${m_NAME})
|
set_property(GLOBAL APPEND PROPERTY ${CMAKE_PROJECT_NAME}_tests ${m_NAME})
|
||||||
|
|
|
||||||
|
|
@ -42,8 +42,12 @@ void UnicodeTests::UCS2ToUTF8_kUCS2()
|
||||||
QVERIFY(!errors);
|
QVERIFY(!errors);
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
QCOMPARE(result, std::string("hello", 5)); // mixed-platform expected result
|
QCOMPARE(result, std::string("hello", 5)); // mixed-platform expected result
|
||||||
|
#else
|
||||||
|
#ifdef WORDS_BIGENDIAN
|
||||||
|
QCOMPARE(result, std::string("\0h\0e\0", 5)); // mixed-platform expected result
|
||||||
#else
|
#else
|
||||||
QCOMPARE(result, std::string("h\0e\0l", 5)); // mixed-platform expected result
|
QCOMPARE(result, std::string("h\0e\0l", 5)); // mixed-platform expected result
|
||||||
|
#endif // WORDS_BIGENDIAN
|
||||||
#endif // _WIN32
|
#endif // _WIN32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,11 +32,13 @@ void ClipboardChunksTests::formatDataChunk()
|
||||||
{
|
{
|
||||||
ClipboardID id = 0;
|
ClipboardID id = 0;
|
||||||
uint32_t sequence = 1;
|
uint32_t sequence = 1;
|
||||||
|
uint32_t temp_m_chunk;
|
||||||
std::string mockData("mock data");
|
std::string mockData("mock data");
|
||||||
ClipboardChunk *chunk = ClipboardChunk::data(id, sequence, mockData);
|
ClipboardChunk *chunk = ClipboardChunk::data(id, sequence, mockData);
|
||||||
|
memcpy(&temp_m_chunk, &chunk->m_chunk[1], 4);
|
||||||
|
|
||||||
QCOMPARE(chunk->m_chunk[0], id);
|
QCOMPARE(chunk->m_chunk[0], id);
|
||||||
QCOMPARE((uint32_t)chunk->m_chunk[1], sequence);
|
QCOMPARE(temp_m_chunk, sequence);
|
||||||
QCOMPARE(chunk->m_chunk[5], ChunkType::DataChunk);
|
QCOMPARE(chunk->m_chunk[5], ChunkType::DataChunk);
|
||||||
QCOMPARE(chunk->m_chunk[6], 'm');
|
QCOMPARE(chunk->m_chunk[6], 'm');
|
||||||
QCOMPARE(chunk->m_chunk[7], 'o');
|
QCOMPARE(chunk->m_chunk[7], 'o');
|
||||||
|
|
@ -56,10 +58,12 @@ void ClipboardChunksTests::endFormatData()
|
||||||
{
|
{
|
||||||
ClipboardID id = 1;
|
ClipboardID id = 1;
|
||||||
uint32_t sequence = 1;
|
uint32_t sequence = 1;
|
||||||
|
uint32_t temp_m_chunk;
|
||||||
ClipboardChunk *chunk = ClipboardChunk::end(id, sequence);
|
ClipboardChunk *chunk = ClipboardChunk::end(id, sequence);
|
||||||
|
memcpy(&temp_m_chunk, &chunk->m_chunk[1], 4);
|
||||||
|
|
||||||
QCOMPARE(chunk->m_chunk[0], id);
|
QCOMPARE(chunk->m_chunk[0], id);
|
||||||
QCOMPARE((uint32_t)chunk->m_chunk[1], sequence);
|
QCOMPARE(temp_m_chunk, sequence);
|
||||||
QCOMPARE(chunk->m_chunk[5], ChunkType::DataEnd);
|
QCOMPARE(chunk->m_chunk[5], ChunkType::DataEnd);
|
||||||
QCOMPARE(chunk->m_chunk[6], '\0');
|
QCOMPARE(chunk->m_chunk[6], '\0');
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue