diff --git a/test/tests/CMakeLists.txt b/test/tests/CMakeLists.txt index 50ef66c92b..2c23d182bf 100644 --- a/test/tests/CMakeLists.txt +++ b/test/tests/CMakeLists.txt @@ -147,6 +147,12 @@ add_executable(test_localisation ${STRING_TEST_SOURCES}) target_link_libraries(test_localisation ${GTEST_LIBRARIES} test-common ${LDL} z) add_test(NAME localisation COMMAND test_localisation) +# ImageImporter tests +add_executable(test_imageimporter "${CMAKE_CURRENT_LIST_DIR}/ImageImporterTests.cpp" + "${CMAKE_CURRENT_LIST_DIR}/TestData.cpp") +target_link_libraries(test_imageimporter ${GTEST_LIBRARIES} libopenrct2) +add_test(NAME ImageImporter COMMAND test_imageimporter) + # Ride ratings test set(RIDE_RATINGS_TEST_SOURCES "${CMAKE_CURRENT_LIST_DIR}/RideRatings.cpp" "${CMAKE_CURRENT_LIST_DIR}/TestData.cpp") diff --git a/test/tests/ImageImporterTests.cpp b/test/tests/ImageImporterTests.cpp new file mode 100644 index 0000000000..9e5f2bd71a --- /dev/null +++ b/test/tests/ImageImporterTests.cpp @@ -0,0 +1,48 @@ +#include +#include +#include +#include +#include "TestData.h" + +using namespace OpenRCT2::Drawing; + +class ImageImporterTests : public testing::Test +{ +public: + static std::string GetImagePath(const std::string_view& name) + { + return Path::Combine(TestData::GetBasePath(), "images", name.data()); + } + + static uint32 GetHash(void * buffer, size_t bufferLength) + { + uint32 hash = 27; + for (size_t i = 0; i < bufferLength; i++) + { + hash = (13 * hash) + ((uint8 *)buffer)[i]; + } + return hash; + } +}; + +TEST_F(ImageImporterTests, Import_Logo) +{ + auto logoPath = GetImagePath("logo.png"); + + ImageImporter importer; + auto image = Imaging::ReadFromFile(logoPath, IMAGE_FORMAT::PNG_32); + auto result = importer.Import(image, 3, 5, ImageImporter::IMPORT_FLAGS::RLE); + + ASSERT_EQ(result.Buffer, result.Element.offset); + ASSERT_EQ(128, result.Element.width); + ASSERT_EQ(128, result.Element.height); + ASSERT_EQ(3, result.Element.x_offset); + ASSERT_EQ(5, result.Element.y_offset); + ASSERT_EQ(0, result.Element.zoomed_offset); + + // Check to ensure RLE data doesn't change unexpectedly. + // Update expected hash if change is expected. + ASSERT_NE(nullptr, result.Buffer); + auto hash = GetHash(result.Buffer, result.BufferLength); + ASSERT_EQ(0xCEF27C7D, hash); +} diff --git a/test/tests/testdata/images/logo.png b/test/tests/testdata/images/logo.png new file mode 100644 index 0000000000..f99b17660d Binary files /dev/null and b/test/tests/testdata/images/logo.png differ diff --git a/test/tests/tests.vcxproj b/test/tests/tests.vcxproj index 8c23f3c620..8b582769ac 100644 --- a/test/tests/tests.vcxproj +++ b/test/tests/tests.vcxproj @@ -57,6 +57,7 @@ +