diff --git a/coresdk/src/test/unit_tests/unit_test_bitmap.cpp b/coresdk/src/test/unit_tests/unit_test_bitmap.cpp index 28c240bf..7193f887 100644 --- a/coresdk/src/test/unit_tests/unit_test_bitmap.cpp +++ b/coresdk/src/test/unit_tests/unit_test_bitmap.cpp @@ -4,6 +4,8 @@ #include "catch.hpp" +#include + #include "types.h" #include "graphics.h" #include "resources.h" @@ -134,3 +136,40 @@ TEST_CASE("bitmap bounding details can be retrieved", "[bitmap]") } free_bitmap(bmp); } + +TEST_CASE("bitmap filename can be retrieved", "[bitmap_filename]") +{ + SECTION("returns correct filename for bitmap") + { + std::string expected_filename = "rocket_sprt.png"; + + // Load a bitmap + bitmap bmp = load_bitmap("rocket", expected_filename); + REQUIRE(bmp != nullptr); + REQUIRE(bitmap_valid(bmp)); + + // Extract filename + std::string filepath = bitmap_filename(bmp); + REQUIRE(filepath.size() >= expected_filename.size()); + size_t idx = filepath.size() - expected_filename.size(); + std::string filename = filepath.substr(idx); + + REQUIRE(filename == expected_filename); + free_bitmap(bmp); + } + + SECTION("returns empty string for null bitmap") + { + bitmap null_bmp = nullptr; + std::string filepath = bitmap_filename(null_bmp); + REQUIRE(filepath == ""); + } + + SECTION("returns empty string for newly created bitmap") + { + bitmap created_bmp = create_bitmap("new bitmap", 100, 100); + std::string filepath = bitmap_filename(created_bmp); + REQUIRE(filepath == ""); + free_bitmap(created_bmp); + } +} \ No newline at end of file