fix: failures in big endian machines tests
This commit is contained in:
@ -43,3 +43,6 @@ add_library(base STATIC
|
||||
)
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
byteSwapped = !byteSwapped;
|
||||
#endif
|
||||
// convert each character
|
||||
while (n > 0) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
byteSwapped = !byteSwapped;
|
||||
#endif
|
||||
// convert each character
|
||||
for (; n > 0; --n) {
|
||||
auto c = decode32(data, byteSwapped);
|
||||
|
||||
@ -35,6 +35,9 @@ function(create_test)
|
||||
|
||||
add_executable(${m_NAME} ${m_SOURCE})
|
||||
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})
|
||||
set_tests_properties(${m_NAME} PROPERTIES DEPENDS ${m_DEPENDS})
|
||||
set_property(GLOBAL APPEND PROPERTY ${CMAKE_PROJECT_NAME}_tests ${m_NAME})
|
||||
|
||||
@ -42,8 +42,12 @@ void UnicodeTests::UCS2ToUTF8_kUCS2()
|
||||
QVERIFY(!errors);
|
||||
#ifdef _WIN32
|
||||
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
|
||||
QCOMPARE(result, std::string("h\0e\0l", 5)); // mixed-platform expected result
|
||||
#endif // WORDS_BIGENDIAN
|
||||
#endif // _WIN32
|
||||
}
|
||||
|
||||
|
||||
@ -32,11 +32,13 @@ void ClipboardChunksTests::formatDataChunk()
|
||||
{
|
||||
ClipboardID id = 0;
|
||||
uint32_t sequence = 1;
|
||||
uint32_t temp_m_chunk;
|
||||
std::string mockData("mock data");
|
||||
ClipboardChunk *chunk = ClipboardChunk::data(id, sequence, mockData);
|
||||
memcpy(&temp_m_chunk, &chunk->m_chunk[1], 4);
|
||||
|
||||
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[6], 'm');
|
||||
QCOMPARE(chunk->m_chunk[7], 'o');
|
||||
@ -56,10 +58,12 @@ void ClipboardChunksTests::endFormatData()
|
||||
{
|
||||
ClipboardID id = 1;
|
||||
uint32_t sequence = 1;
|
||||
uint32_t temp_m_chunk;
|
||||
ClipboardChunk *chunk = ClipboardChunk::end(id, sequence);
|
||||
memcpy(&temp_m_chunk, &chunk->m_chunk[1], 4);
|
||||
|
||||
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[6], '\0');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user