From dcda45d8ae46197d304d737c102b13643808203f Mon Sep 17 00:00:00 2001 From: skal Date: Thu, 5 Feb 2026 18:13:39 +0100 Subject: test(assets): Add tests for Texture Asset support - Added test_image.tga (generated via tools/gen_test_tga.cc). - Updated test_assets_list.txt to include the TGA. - Updated test_assets.cc to verify image decompression and pixel values. --- assets/final/test_assets_list.txt | 1 + assets/final/test_image.tga | Bin 0 -> 34 bytes src/tests/test_assets.cc | 19 +++++++++++++++++++ tools/gen_test_tga.cc | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+) create mode 100644 assets/final/test_image.tga create mode 100644 tools/gen_test_tga.cc diff --git a/assets/final/test_assets_list.txt b/assets/final/test_assets_list.txt index 602d15d..c9dd83b 100644 --- a/assets/final/test_assets_list.txt +++ b/assets/final/test_assets_list.txt @@ -4,5 +4,6 @@ NULL_ASSET, NONE, null.bin, "A zero-byte file." SHADER_SNIPPET_A, NONE, shaders/test_snippet_a.wgsl, "Test snippet A" SHADER_SNIPPET_B, NONE, shaders/test_snippet_b.wgsl, "Test snippet B" PROC_NOISE_256, PROC(gen_noise, 4321, 8), _, "Procedural noise for testing" +TEST_IMAGE, NONE, test_image.tga, "A test TGA image" PROC_UNKNOWN, PROC(gen_unknown_func, 0), _, "Unknown proc function" PROC_FAIL, PROC(gen_noise, -1337, 8), _, "Failing proc function" diff --git a/assets/final/test_image.tga b/assets/final/test_image.tga new file mode 100644 index 0000000..7b05b08 Binary files /dev/null and b/assets/final/test_image.tga differ diff --git a/src/tests/test_assets.cc b/src/tests/test_assets.cc index a1ae795..5ae266e 100644 --- a/src/tests/test_assets.cc +++ b/src/tests/test_assets.cc @@ -91,6 +91,25 @@ int main() { assert(non_zero_data); printf("Procedural asset DropAsset and re-generation test: SUCCESS\n"); + // Test Texture Asset (TGA loading) + printf("\nRunning Texture Asset test...\n"); + TextureAsset tex = GetTextureAsset(AssetId::ASSET_TEST_IMAGE); + assert(tex.pixels != nullptr); + assert(tex.width == 2); + assert(tex.height == 2); + + // Verify pixels (Expected RGBA) + // Pixel 0: Red (255, 0, 0, 255) + assert(tex.pixels[0] == 255 && tex.pixels[1] == 0 && tex.pixels[2] == 0 && tex.pixels[3] == 255); + // Pixel 1: Green (0, 255, 0, 255) + assert(tex.pixels[4] == 0 && tex.pixels[5] == 255 && tex.pixels[6] == 0 && tex.pixels[7] == 255); + // Pixel 2: Blue (0, 0, 255, 255) + assert(tex.pixels[8] == 0 && tex.pixels[9] == 0 && tex.pixels[10] == 255 && tex.pixels[11] == 255); + // Pixel 3: White (255, 255, 255, 255) + assert(tex.pixels[12] == 255 && tex.pixels[13] == 255 && tex.pixels[14] == 255 && tex.pixels[15] == 255); + + printf("Texture Asset content verification: SUCCESS\n"); + // Test Unknown Procedural Function printf("\nRunning Unknown Procedural Function test...\n"); size_t unknown_size = 0; diff --git a/tools/gen_test_tga.cc b/tools/gen_test_tga.cc new file mode 100644 index 0000000..7414eea --- /dev/null +++ b/tools/gen_test_tga.cc @@ -0,0 +1,35 @@ +#include +#include + +int main() { + FILE* f = fopen("assets/final/test_image.tga", "wb"); + if (!f) return 1; + + // TGA Header (Uncompressed True-Color, 2x2, 32-bit) + uint8_t header[18] = { + 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 2, 0, // Width: 2 (LE) + 2, 0, // Height: 2 (LE) + 32, // Depth: 32 bit + 0x28 // Descriptor: Top-Left origin, 8-bit alpha + }; + fwrite(header, 1, 18, f); + + // Pixel Data (BGRA order for TGA usually, but let's see what stbi expects/returns) + // stbi converts to requested format (RGBA). + // Let's write BGRA: + // Pixel 0 (0,0): Red -> 00 00 FF FF + // Pixel 1 (1,0): Green -> 00 FF 00 FF + // Pixel 2 (0,1): Blue -> FF 00 00 FF + // Pixel 3 (1,1): White -> FF FF FF FF + + uint8_t pixels[] = { + 0x00, 0x00, 0xFF, 0xFF, // Red + 0x00, 0xFF, 0x00, 0xFF, // Green + 0xFF, 0x00, 0x00, 0xFF, // Blue + 0xFF, 0xFF, 0xFF, 0xFF // White + }; + fwrite(pixels, 1, sizeof(pixels), f); + fclose(f); + return 0; +} -- cgit v1.2.3