From 3c115e12beb8c1a2b22f225eb1bc91ff7383a007 Mon Sep 17 00:00:00 2001 From: scawful Date: Wed, 7 Aug 2024 16:11:03 -0400 Subject: [PATCH] add sprite_builder_test --- src/test/CMakeLists.txt | 1 + src/test/zelda3/sprite_builder_test.cc | 77 ++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 src/test/zelda3/sprite_builder_test.cc diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index 4dc51572..a689002c 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -21,6 +21,7 @@ add_executable( test/gfx/compression_test.cc test/gfx/snes_palette_test.cc test/zelda3/room_object_test.cc + test/zelda3/sprite_builder_test.cc cli/command_handler.cc app/rom.cc app/rom_test.cc diff --git a/src/test/zelda3/sprite_builder_test.cc b/src/test/zelda3/sprite_builder_test.cc new file mode 100644 index 00000000..45696bbc --- /dev/null +++ b/src/test/zelda3/sprite_builder_test.cc @@ -0,0 +1,77 @@ +#include "app/zelda3/sprite/sprite_builder.h" + +#include +#include + +namespace yaze_test { +namespace zelda3_test { + +using namespace yaze::app::zelda3; + +class SpriteBuilderTest : public ::testing::Test { + protected: + void SetUp() override { + // Create a new sprite + SpriteBuilder sprite = SpriteBuilder::Create("Puffstool") + .SetProperty("NbrTiles", 2) + .SetProperty("Health", 10) + .SetProperty("Harmless", false); + // Create an anonymous global action for the sprite to run before each + // action + SpriteAction globalAction = SpriteAction::Create().AddInstruction( + SpriteInstruction::BehaveAsBarrier()); + // Create an action for the SprAction::LocalJumpTable + SpriteAction walkAction = + SpriteAction::Create("Walk") + .AddInstruction(SpriteInstruction::PlayAnimation(0, 6, 10)) + .AddInstruction(SpriteInstruction::ApplySpeedTowardsPlayer(2)) + .AddInstruction(SpriteInstruction::MoveXyz()) + .AddInstruction(SpriteInstruction::BounceFromTileCollision()) + .AddCustomInstruction("JSL $0DBB7C"); // Custom ASM + // Link to the idle action. If the action does not exist, build will fail + walkAction.SetNextAction("IdleAction"); + + // Idle action which jumps to a fn. If the fn does not exist, build will + // fail + SpriteAction idleAction = + SpriteAction::Create("IdleAction") + .AddInstruction(SpriteInstruction::JumpToFunction("IdleFn")); + idleAction.SetNextAction("Walk"); + + // Build the function that the idle action jumps to + SpriteAction idleFunction = SpriteAction::Create("IdleFn").AddInstruction( + SpriteInstruction::MoveXyz()); + + // Add actions and functions to sprite + sprite.SetGlobalAction(globalAction); + sprite.AddAction(idleAction); // 0x00 + sprite.AddAction(walkAction); // 0x01 + sprite.AddFunction(idleFunction); // Local + } + void TearDown() override {} + + SpriteBuilder sprite; +}; + +TEST_F(SpriteBuilderTest, BuildSpritePropertiesOk) { + EXPECT_THAT(sprite.BuildProperties(), + testing::HasSubstr(R"(!SPRID = $00 +!NbrTiles = $00 +!Harmless = $00 +)")); +} + +TEST_F(SpriteBuilderTest, BuildSpriteOk) { + EXPECT_THAT(sprite.Build(), testing::HasSubstr(R"( + Sprite_Puffstool_Main: + JSL Sprite_BehaveAsBarrier + LDA.w SprAction, X + JSL JumpTableLocal + + dw Sprite_Puffstool_IdleAction + dw Sprite_Puffstool_Walk + )")); +} + +} // namespace zelda3_test +} // namespace yaze_test \ No newline at end of file