From 008b96204e5988a8a0faca3d535ef8c07601e42e Mon Sep 17 00:00:00 2001 From: Lorenzo Carletti Date: Sat, 18 Dec 2021 02:08:25 +0100 Subject: [PATCH] Add target_name boundary tests --- README.md | 25 ++++++++++++++++ build.ps1 | 3 +- src/c/tests/battle_test.c | 36 ++++++++++++++++++++++-- src/c/tests/battle_test.h | 7 ++++- src/c/tests/{utils.c => test_m2_utils.c} | 23 ++++++--------- src/c/tests/{utils.h => test_m2_utils.h} | 14 +++------ src/c/tests/test_utils.c | 14 +++++++++ src/c/tests/test_utils.h | 14 +++++++++ 8 files changed, 107 insertions(+), 29 deletions(-) rename src/c/tests/{utils.c => test_m2_utils.c} (65%) rename src/c/tests/{utils.h => test_m2_utils.h} (56%) create mode 100644 src/c/tests/test_utils.c create mode 100644 src/c/tests/test_utils.h diff --git a/README.md b/README.md index f77f35d..f4690ff 100644 --- a/README.md +++ b/README.md @@ -60,3 +60,28 @@ This project aims to both complete the VWF codebase and to provide a tool for tr 2. `dotnet build tools/ScriptToolGui -o bin/ScriptToolGui` 3. Run with `dotnet bin/ScriptToolGui/ScriptToolGui.dll` (or just run the EXE file directly). +# Testing + +## Dependencies +- [mGBA 0.9.3 or later, or nightly built after Nov 29, 2021](https://mgba.io/downloads.html) +- [Building dependencies](#Building) + +1. One-time setup + 1. Install .NET Core 2.1, PowerShell Core, and GNU Arm Embedded Toolchain. Make sure the Arm toolchain's `bin` folder is in your `PATH`. + 2. Create a `bin` folder in the root of the repo. + 3. Copy MOTHER 1+2 ROM to `bin/m12fresh.gba`. + 4. Copy EarthBound ROM to `bin/eb.smc`. + 5. Run `build-tools.ps1`. + - Windows: `.\build-tools.ps1` in a PowerShell prompt + - Linux and MacOS: `pwsh build-tools.ps1` + 6. Copy/build `armips` to `bin`. + - Windows: grab the latest release [here](https://github.com/Kingcom/armips/releases) and copy the executable to `bin/armips.exe`. + - Linux: follow the [README](https://github.com/Kingcom/armips/blob/master/Readme.md) to build `armips` and copy the executable to `bin/armips`. + - MacOS: grab the latest release [here](https://github.com/Emory-M/armips/releases) and copy the executable to `bin/armips`. + 7. Copy/build `mgba-sdl` to `bin`. + - You can also use mgba-QT (which is normally named mgba), but you will need to change the name of the executed program in `test.ps1`. +2. Running the tests + 1. Run `test.ps1`. + 2. The default compiled ROM is copied to `bin/m12test.gba`. + 3. The tests' log will be in `bin/test.log`. + 4. The output will also be visible in the console. diff --git a/build.ps1 b/build.ps1 index da3ef51..c9a3155 100644 --- a/build.ps1 +++ b/build.ps1 @@ -36,7 +36,8 @@ $input_c_files = $input_c_test_files = "src/c/tests/main_test.c", - "src/c/tests/utils.c", + "src/c/tests/test_utils.c", + "src/c/tests/test_m2_utils.c", "src/c/tests/battle_test.c", "src/c/tests/debug_printf/test_print.c", "src/c/tests/debug_printf/mgba.c", diff --git a/src/c/tests/battle_test.c b/src/c/tests/battle_test.c index 2c9d865..22a1494 100644 --- a/src/c/tests/battle_test.c +++ b/src/c/tests/battle_test.c @@ -1,6 +1,4 @@ #include "battle_test.h" -#include "utils.h" -#include "debug_printf/test_print.h" void test_encounter_text() { @@ -56,9 +54,40 @@ void test_death_text() } +void test_target_text() +{ + m2_btl_user_ptr->is_enemy = true; + m2_btl_enemies_size = 1; + m2_btl_user_ptr->letter = 1; + m2_btl_user_ptr->unknown_3[0] = 1; + + for(int j = 0; j <= 230; j++) + { + m2_btl_user_ptr->id = j; + m2_btl_user_ptr->enemy_id = j; + printTargetOfAttack(0,0); + store_pixels_overworld_buffer(0x10); // This is just for visualization purposes + assert_message(text_stayed_inside(window_pointers[3]), "Target text for Enemy %d", j); + } + + m2_btl_user_ptr->letter = W_LETTER - INITIAL_SYMBOL_ENEMY; + m2_btl_user_ptr->unknown_3[0] = 0; + + for(int j = 0; j <= 230; j++) + { + m2_btl_user_ptr->id = j; + m2_btl_user_ptr->enemy_id = j; + printTargetOfAttack(0,0); + store_pixels_overworld_buffer(0x10); // This is just for visualization purposes + assert_message(text_stayed_inside(window_pointers[3]), "Target text for Enemy %d - W", j); + } + +} + static void _setup() { (window_pointers[2]) = (struct WINDOW*)0x2029F88; + (window_pointers[3]) = (struct WINDOW*)0x2029FD8; m2_setupwindow((window_pointers[2]), 4, 1, 0x16, 4); m2_btl_user_ptr = (BATTLE_DATA*)0x2021110; m2_btl_target_ptr = (BATTLE_DATA*)0x2021110; @@ -69,12 +98,15 @@ static void _setup() (*(short*)(0x30023DC)) = 0; // Default delay between prints (*(int*)(0x3005220)) = 0x2028820; *tilemap_pointer= (unsigned short*)0x2028018; + (*(byte*)(0x202514C)) = 8; // Point to the btl_user_ptr (*(unsigned short*)(0x500001E)) = 0x7FFF; // Make it so it's easy to check what's being written m2_script_readability = false; + setup_overworld_buffer(); } void start_battle_tests() { run_test(test_encounter_text); run_test(test_death_text); + run_test(test_target_text); } \ No newline at end of file diff --git a/src/c/tests/battle_test.h b/src/c/tests/battle_test.h index 5a8023f..7f8d551 100644 --- a/src/c/tests/battle_test.h +++ b/src/c/tests/battle_test.h @@ -1,6 +1,11 @@ -#include "../battle_data.h" +#include "test_utils.h" +#include "test_m2_utils.h" #include "debug_printf/test_print.h" +#include "../battle_data.h" +#include "../battle.h" +#include "../vwf.h" + #define INITIAL_SYMBOL_ENEMY 0x70 void start_battle_tests(); diff --git a/src/c/tests/utils.c b/src/c/tests/test_m2_utils.c similarity index 65% rename from src/c/tests/utils.c rename to src/c/tests/test_m2_utils.c index 76b0719..79034b2 100644 --- a/src/c/tests/utils.c +++ b/src/c/tests/test_m2_utils.c @@ -1,19 +1,7 @@ -#include "utils.h" +#include "test_m2_utils.h" -#define CPUFASTSET_FILL (0x1000000) -#define IWRAM (0x3000000) -#define IWRAM_SIZE (0x8000-0x2000) - -#define NON_IWRAM_RESET 0xFD - -#define RIGHT_BORDER_TILE 0x0095 - -void blank_memory() -{ - int blank_value = 0; - cpufastset(&blank_value, (void*)IWRAM, CPUFASTSET_FILL | (IWRAM_SIZE >> 2)); - reg_ram_reset(NON_IWRAM_RESET); -} +#define RIGHT_BORDER_TILE 0x0095 +#define OVERWORLD_BUFFER_LIMIT 0x2028000 void setup_ness_name() { @@ -41,4 +29,9 @@ bool text_stayed_inside(WINDOW* window) return false; return true; +} + +void setup_overworld_buffer() +{ + *((int*)(OVERWORLD_BUFFER_POINTER)) = OVERWORLD_BUFFER_LIMIT - OVERWORLD_BUFFER_SIZE; } \ No newline at end of file diff --git a/src/c/tests/utils.h b/src/c/tests/test_m2_utils.h similarity index 56% rename from src/c/tests/utils.h rename to src/c/tests/test_m2_utils.h index eb6cd61..a260fd5 100644 --- a/src/c/tests/utils.h +++ b/src/c/tests/test_m2_utils.h @@ -1,24 +1,18 @@ -#ifndef TEST_UTILS -#define TEST_UTILS +#ifndef TEST_M2_UTILS +#define TEST_M2_UTILS #include "../window.h" +#include "../vwf.h" #include "../locs.h" #define W_LETTER 0x87 #define KING_OFFSET 0x1C -#define run_test(func) \ - blank_memory();\ - _setup();\ - func(); - void setup_ness_name(); void setup_king_name(); -void blank_memory(); bool text_stayed_inside(WINDOW* window); +void setup_overworld_buffer(); -extern void cpufastset(void *source, void *dest, int mode); -extern void reg_ram_reset(int flag); extern int m2_setupwindow(WINDOW* window, short window_x, short window_y, short window_width, short window_height); #endif \ No newline at end of file diff --git a/src/c/tests/test_utils.c b/src/c/tests/test_utils.c new file mode 100644 index 0000000..6e4e5fb --- /dev/null +++ b/src/c/tests/test_utils.c @@ -0,0 +1,14 @@ +#include "test_utils.h" + +#define CPUFASTSET_FILL (0x1000000) +#define IWRAM (0x3000000) +#define IWRAM_SIZE (0x8000-0x2000) + +#define NON_IWRAM_RESET 0xFD + +void blank_memory() +{ + int blank_value = 0; + cpufastset(&blank_value, (void*)IWRAM, CPUFASTSET_FILL | (IWRAM_SIZE >> 2)); + reg_ram_reset(NON_IWRAM_RESET); +} \ No newline at end of file diff --git a/src/c/tests/test_utils.h b/src/c/tests/test_utils.h new file mode 100644 index 0000000..d2b1e8c --- /dev/null +++ b/src/c/tests/test_utils.h @@ -0,0 +1,14 @@ +#ifndef TEST_UTILS +#define TEST_UTILS + +#define run_test(func) \ + blank_memory();\ + _setup();\ + func(); + +void blank_memory(); + +extern void cpufastset(void *source, void *dest, int mode); +extern void reg_ram_reset(int flag); + +#endif \ No newline at end of file