mirror of
https://github.com/OpenRCT2/OpenRCT2.git
synced 2025-01-23 02:41:58 -05:00
Add test for ImageImporter
This commit is contained in:
parent
f212894eb0
commit
44764874a3
4 changed files with 55 additions and 0 deletions
|
@ -147,6 +147,12 @@ add_executable(test_localisation ${STRING_TEST_SOURCES})
|
||||||
target_link_libraries(test_localisation ${GTEST_LIBRARIES} test-common ${LDL} z)
|
target_link_libraries(test_localisation ${GTEST_LIBRARIES} test-common ${LDL} z)
|
||||||
add_test(NAME localisation COMMAND test_localisation)
|
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
|
# Ride ratings test
|
||||||
set(RIDE_RATINGS_TEST_SOURCES "${CMAKE_CURRENT_LIST_DIR}/RideRatings.cpp"
|
set(RIDE_RATINGS_TEST_SOURCES "${CMAKE_CURRENT_LIST_DIR}/RideRatings.cpp"
|
||||||
"${CMAKE_CURRENT_LIST_DIR}/TestData.cpp")
|
"${CMAKE_CURRENT_LIST_DIR}/TestData.cpp")
|
||||||
|
|
48
test/tests/ImageImporterTests.cpp
Normal file
48
test/tests/ImageImporterTests.cpp
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
#include <string_view>
|
||||||
|
#include <openrct2/core/Path.hpp>
|
||||||
|
#include <openrct2/drawing/ImageImporter.h>
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
#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);
|
||||||
|
}
|
BIN
test/tests/testdata/images/logo.png
vendored
Normal file
BIN
test/tests/testdata/images/logo.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.5 KiB |
|
@ -57,6 +57,7 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="LanguagePackTest.cpp" />
|
<ClCompile Include="LanguagePackTest.cpp" />
|
||||||
|
<ClCompile Include="ImageImporterTests.cpp" />
|
||||||
<ClCompile Include="IniReaderTest.cpp" />
|
<ClCompile Include="IniReaderTest.cpp" />
|
||||||
<ClCompile Include="IniWriterTest.cpp" />
|
<ClCompile Include="IniWriterTest.cpp" />
|
||||||
<ClCompile Include="Localisation.cpp" />
|
<ClCompile Include="Localisation.cpp" />
|
||||||
|
|
Loading…
Reference in a new issue