mirror of
https://github.com/enduro2d/enduro2d.git
synced 2025-12-15 00:11:55 +07:00
added tests for align_ceil/align_floor, fixed unit tests for loader, replaced C-style cast to reinterpret_cast
This commit is contained in:
@@ -88,7 +88,7 @@ namespace
|
||||
|
||||
bool is_dds(const void* data, std::size_t byte_size) {
|
||||
if ( byte_size > sizeof(dds_header_with_magic) ) {
|
||||
const auto* hdr = (const dds_header_with_magic*) data;
|
||||
const auto* hdr = reinterpret_cast<const dds_header_with_magic*>(data);
|
||||
return hdr->dwMagicFourCC == 0x20534444; // DDS
|
||||
}
|
||||
return false;
|
||||
@@ -145,7 +145,7 @@ namespace e2d::images::impl
|
||||
if ( !is_dds(src.data(), src.size()) ) {
|
||||
return false;
|
||||
}
|
||||
const dds_header& hdr = ((const dds_header_with_magic*)src.data())->header;
|
||||
const dds_header& hdr = reinterpret_cast<const dds_header_with_magic*>(src.data())->header;
|
||||
const u8* content = src.data() + sizeof(dds_header_with_magic);
|
||||
if ( math::check_all_flags(hdr.dwCaps2, ddsf_cubemap) ||
|
||||
math::check_all_flags(hdr.dwCaps2, ddsf_volume) ||
|
||||
|
||||
@@ -109,8 +109,8 @@ namespace
|
||||
static_assert(sizeof(pvr_header) == 52, "invalid PVR header size");
|
||||
|
||||
bool is_pvr(const void* data, std::size_t byte_size) {
|
||||
if (byte_size > sizeof(pvr_header)) {
|
||||
const pvr_header* hdr = (const pvr_header*) data;
|
||||
if ( byte_size > sizeof(pvr_header) ) {
|
||||
const pvr_header* hdr = reinterpret_cast<const pvr_header*>(data);
|
||||
return hdr->version == 0x03525650;
|
||||
}
|
||||
return false;
|
||||
@@ -201,7 +201,7 @@ namespace e2d::images::impl
|
||||
if ( !is_pvr(src.data(), src.size()) ) {
|
||||
return false;
|
||||
}
|
||||
const pvr_header& hdr = *(const pvr_header*)src.data();
|
||||
const pvr_header& hdr = *reinterpret_cast<const pvr_header*>(src.data());
|
||||
const u8* content = src.data() + sizeof(pvr_header) + hdr.metaDataSize;
|
||||
if ( hdr.numSurfaces != 1 || hdr.numFaces != 1 || hdr.depth > 1 ) {
|
||||
return false; // cubemap and volume textures are not supported
|
||||
|
||||
@@ -661,4 +661,8 @@ TEST_CASE("math") {
|
||||
REQUIRE_FALSE(math::approximately<u32>(umin,umax,1));
|
||||
REQUIRE_FALSE(math::approximately<u32>(umax,umin,1));
|
||||
}
|
||||
{
|
||||
REQUIRE(math::align_ceil(11, 4) == 16);
|
||||
REQUIRE(math::align_floor(11, 4) == 8);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,13 +151,16 @@ TEST_CASE("images") {
|
||||
{"bin/images/ship_rg8.pvr", true, image_data_format::ga8},
|
||||
{"bin/images/ship_rgb8.pvr", true, image_data_format::rgb8}
|
||||
};
|
||||
str resources;
|
||||
REQUIRE(filesystem::extract_predef_path(
|
||||
resources,
|
||||
filesystem::predef_path::resources));
|
||||
|
||||
for (auto& info : test_images) {
|
||||
image img;
|
||||
input_stream_uptr stream = make_read_file(info.name);
|
||||
input_stream_uptr stream = make_read_file(path::combine(resources, info.name));
|
||||
REQUIRE(stream);
|
||||
|
||||
REQUIRE(images::try_load_image(img, make_read_file(info.name)) == info.can_load);
|
||||
image img;
|
||||
REQUIRE(images::try_load_image(img, stream) == info.can_load);
|
||||
if ( info.can_load ) {
|
||||
REQUIRE(img.format() == info.format);
|
||||
REQUIRE(img.size().x == 64);
|
||||
|
||||
Reference in New Issue
Block a user