OpenRCT2/test/tests/ImageImporterTests.cpp

60 lines
1.9 KiB
C++
Raw Normal View History

/*****************************************************************************
* Copyright (c) 2014-2024 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
2018-06-22 22:29:03 +02:00
#include "TestData.h"
#include <gtest/gtest.h>
2018-05-12 01:04:16 +02:00
#include <openrct2/core/Path.hpp>
#include <openrct2/drawing/ImageImporter.h>
2018-06-22 22:29:03 +02:00
#include <string_view>
2018-05-12 01:04:16 +02:00
using namespace OpenRCT2::Drawing;
class ImageImporterTests : public testing::Test
{
public:
static std::string GetImagePath(const std::string& name)
2018-05-12 01:04:16 +02:00
{
return Path::Combine(TestData::GetBasePath(), u8"images", name.c_str());
2018-05-12 01:04:16 +02:00
}
2018-06-22 22:29:03 +02:00
static uint32_t GetHash(void* buffer, size_t bufferLength)
2018-05-12 01:04:16 +02:00
{
uint32_t hash = 27;
2018-05-12 01:04:16 +02:00
for (size_t i = 0; i < bufferLength; i++)
{
hash = (13 * hash) + (reinterpret_cast<uint8_t*>(buffer))[i];
2018-05-12 01:04:16 +02:00
}
return hash;
}
};
TEST_F(ImageImporterTests, Import_Logo)
{
auto logoPath = GetImagePath("logo.png");
ImageImporter importer;
auto image = Imaging::ReadFromFile(logoPath, IMAGE_FORMAT::PNG_32);
auto meta = ImageImportMeta{ .offset = { 3, 5 } };
auto result = importer.Import(image, meta);
2018-05-12 01:04:16 +02:00
ASSERT_EQ(result.Buffer.data(), result.Element.offset);
2018-05-12 01:04:16 +02:00
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.data());
auto hash = GetHash(result.Buffer.data(), result.Buffer.size());
ASSERT_EQ(uint32_t(0x212A99BC), hash);
2018-05-12 01:04:16 +02:00
}