diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-04-10 08:21:56 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-04-10 10:37:58 +0200 |
commit | 64ba60362e057923ffc247770d364578241ddd45 (patch) | |
tree | 34d45975efc664a578a741f2049d55b4b898e483 | |
parent | 6a0b3e502f2a5889a01992edca2b458ed4c0e18c (diff) |
tests
-rw-r--r-- | test/bitmask.cpp | 31 | ||||
-rw-r--r-- | test/bitmask.embed.inc | 18 | ||||
-rw-r--r-- | test/save.cpp | 5 |
3 files changed, 28 insertions, 26 deletions
diff --git a/test/bitmask.cpp b/test/bitmask.cpp index ef8f3b1c..caaaad13 100644 --- a/test/bitmask.cpp +++ b/test/bitmask.cpp @@ -5,43 +5,42 @@ #include <Corrade/Containers/ArrayView.h> #include <Corrade/Containers/StridedArrayView.h> #include <Magnum/Trade/ImageData.h> -#include <Magnum/ImageView.h> -#include <Magnum/PixelFormat.h> - -//#define DO_GENERATE namespace floormat { namespace { -const unsigned char data_door_close[] = { +const unsigned char img_bitmask[] = { #include "bitmask.embed.inc" }; -constexpr auto data_nbytes = arraySize(data_door_close); -static_assert(data_nbytes == 128); +constexpr auto data_nbytes = arraySize(img_bitmask); +constexpr auto size = Vector2i{21, 52}; +static_assert(size_t{size.product()+7}/8 == data_nbytes); void bitmask_test() { - auto img = loader.texture(loader.SCENERY_PATH, "door-close"_s); + auto img = loader.texture(loader.SCENERY_PATH, "control-panel"_s); auto bitmask = anim_atlas::make_bitmask(img); - fm_assert(img.pixelSize() == 4 && (size_t)img.size().product() >= data_nbytes); + fm_assert(bitmask.size() == size_t{size.product()}); + fm_assert(img.pixelSize() == 4 && img.size() == size); +//#define DO_GENERATE #ifdef DO_GENERATE - for (auto i = 0uz; i < data_nbytes; i++) + fputc('\n', stdout); + for (auto i = 0u; i < (bitmask.size()+7)/8; i++) { - if (i && i % 16 == 0) - printf("\n"); printf("0x%02hhx,", bitmask.data()[i]); - if ((i+1) % 16 != 0) - printf(" "); + if (i % 15 == 14) + printf("\n"); } printf("\n"); fflush(stdout); #endif + fm_assert(img.size().product() == Int{data_nbytes}); const auto len = std::min(data_nbytes, (size_t)bitmask.size()+7 >> 3); for (auto i = 0uz; i < len; i++) - if ((unsigned char)bitmask.data()[i] != data_door_close[i]) - fm_abort("wrong value at bit %zu, should be' 0x%02hhx'", i, data_door_close[i]); + if ((unsigned char)bitmask.data()[i] != img_bitmask[i]) + fm_abort("wrong value at bit %zu, should be' 0x%02hhx'", i, img_bitmask[i]); } } // namespace diff --git a/test/bitmask.embed.inc b/test/bitmask.embed.inc index fa8268dd..459dfe79 100644 --- a/test/bitmask.embed.inc +++ b/test/bitmask.embed.inc @@ -1,8 +1,10 @@ -0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x03,0x00,0x00,0x00,0x00,0x1c,0x00,0x00,0x00,0x00,0xf0,0x01,0x00,0xfe,0x07, +0x00,0x0f,0x00,0xf8,0x3f,0x00,0xff,0xff,0x00,0xff,0x20,0xfc,0xff,0x1c,0xff, +0x80,0xff,0xff,0xf0,0xff,0xff,0x3e,0xff,0xc0,0xff,0xff,0xf8,0xff,0xff,0x1f, +0xff,0xe0,0xff,0xff,0x7c,0xff,0x80,0xff,0xff,0xf0,0xff,0xff,0x3e,0xff,0xc0, +0xff,0xff,0xf8,0xff,0xff,0x1f,0xff,0xe0,0xff,0xff,0x7c,0xff,0x80,0xff,0xff, +0xf0,0xff,0xff,0x3e,0xff,0xc0,0xff,0xff,0xf8,0xff,0xff,0x1f,0xff,0xe0,0xff, +0xff,0x7c,0xff,0x80,0xff,0xff,0xf0,0xff,0xff,0x3e,0xff,0xc0,0xff,0xff,0xf8, +0xfe,0xff,0x1f,0xff,0xe0,0xe3,0xff,0x7c,0xff,0x80,0x0f,0xff,0xf0,0x01,0xfc, +0x3e,0xf8,0xc0,0x07,0xe0,0xf8,0x00,0x80,0x1f,0x00,0xc0,0x03,0x00,0x70,0x00, +0x00,0xd8, diff --git a/test/save.cpp b/test/save.cpp index b2f10794..e5dcf9a6 100644 --- a/test/save.cpp +++ b/test/save.cpp @@ -181,11 +181,11 @@ void test_save_objs() { const auto tmp = Path::join(loader.TEMP_PATH, "test/test-save-objs.dat"_s); - // todo! test non-zero offset_frac // todo! test all object and scenery types! - auto w = world(); { // --- counter --- + auto w = world(); + const auto ctr = w.object_counter(); const auto ctrʹ = ctr + 364; fm_assert(ctrʹ > ctr); @@ -201,6 +201,7 @@ void test_save_objs() } { // --- critter --- + auto w = world(); critter_proto p; p.atlas = loader.anim_atlas("npc-walk", loader.ANIM_PATH); p.offset = Vector2b{-1, 2}; |