From e36ac14ae9a3991b95915c4434e2ab5f47b3b512 Mon Sep 17 00:00:00 2001 From: Procyonae <45432782+Procyonae@users.noreply.github.com> Date: Wed, 12 Jun 2024 21:10:05 +0100 Subject: [PATCH] Add field type migration test --- .../mods/TEST_DATA/field_type_migrations.json | 7 +++ data/mods/TEST_DATA/fields.json | 5 ++ tests/submap_load_test.cpp | 56 ++++++++++++++++++- 3 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 data/mods/TEST_DATA/field_type_migrations.json diff --git a/data/mods/TEST_DATA/field_type_migrations.json b/data/mods/TEST_DATA/field_type_migrations.json new file mode 100644 index 0000000000000..aece20cf45fce --- /dev/null +++ b/data/mods/TEST_DATA/field_type_migrations.json @@ -0,0 +1,7 @@ +[ + { + "type": "field_type_migration", + "from_field": "test_fd_migration_old_id", + "to_field": "test_fd_migration_new_id" + } +] diff --git a/data/mods/TEST_DATA/fields.json b/data/mods/TEST_DATA/fields.json index 7a2b6e816691e..b0b069f2824d3 100644 --- a/data/mods/TEST_DATA/fields.json +++ b/data/mods/TEST_DATA/fields.json @@ -64,5 +64,10 @@ "display_items": false, "display_field": true, "looks_like": "fd_fog" + }, + { + "id": "test_fd_migration_new_id", + "type": "field_type", + "intensity_levels": [ { "name": "migrated" } ] } ] diff --git a/tests/submap_load_test.cpp b/tests/submap_load_test.cpp index 6d9ece9f5bb7f..8465bdc458a1e 100644 --- a/tests/submap_load_test.cpp +++ b/tests/submap_load_test.cpp @@ -27,6 +27,8 @@ static const construction_str_id construction_constr_ground_cable( "constr_ground_cable" ); static const construction_str_id construction_constr_rack_coat( "constr_rack_coat" ); +static const field_type_str_id field_test_fd_migration_new_id( "test_fd_migration_new_id" ); + static const furn_str_id furn_f_bookcase( "f_bookcase" ); static const furn_str_id furn_f_coffin_c( "f_coffin_c" ); static const furn_str_id furn_f_crate_o( "f_crate_o" ); @@ -781,7 +783,7 @@ static std::string submap_cosmetic_ss( " \"computers\": [ ]\n" "}\n" ); -static std::string submap_pre_migration_ss( +static std::string submap_ter_furn_pre_migration_ss( "{\n" " \"version\": 32,\n" " \"coordinates\": [ 0, 0, 0 ],\n" @@ -804,6 +806,25 @@ static std::string submap_pre_migration_ss( " \"computers\": [ ]\n" "}\n" ); +static std::string submap_fd_pre_migration_ss( + "{\n" + " \"version\": 32,\n" + " \"coordinates\": [ 0, 0, 0 ],\n" + " \"turn_last_touched\": 0,\n" + " \"temperature\": 0,\n" + " \"terrain\": [ [ \"t_dirt\", 144 ] ],\n" + " \"radiation\": [ 0, 144 ],\n" + " \"furniture\": [ ],\n" + " \"items\": [ ],\n" + " \"traps\": [ ],\n" + " \"fields\": [ 0, 0, [ \"test_fd_migration_old_id\", 1, 1997 ] ],\n" + " \"cosmetics\": [ ],\n" + " \"spawns\": [ ],\n" + " \"vehicles\": [ ],\n" + " \"partial_constructions\": [ ],\n" + " \"computers\": [ ]\n" + "}\n" +); static_assert( SEEX == 12, "Reminder to update submap tests when SEEX changes." ); static_assert( SEEY == 12, "Reminder to update submap tests when SEEY changes." ); @@ -823,7 +844,9 @@ static JsonValue submap_vehicle = json_loader::from_string( submap_vehicle_ss ); static JsonValue submap_construction = json_loader::from_string( submap_construction_ss ); static JsonValue submap_computer = json_loader::from_string( submap_computer_ss ); static JsonValue submap_cosmetic = json_loader::from_string( submap_cosmetic_ss ); -static JsonValue submap_pre_migration = json_loader::from_string( submap_pre_migration_ss ); +static JsonValue submap_ter_furn_pre_migration = json_loader::from_string( + submap_ter_furn_pre_migration_ss ); +static JsonValue submap_fd_pre_migration = json_loader::from_string( submap_fd_pre_migration_ss ); static void load_from_jsin( submap &sm, const JsonValue &jsin ) { @@ -1448,7 +1471,7 @@ TEST_CASE( "submap_computer_load", "[submap][load]" ) TEST_CASE( "submap_ter_furn_migration", "[submap][load]" ) { submap sm; - load_from_jsin( sm, submap_pre_migration ); + load_from_jsin( sm, submap_ter_furn_pre_migration ); submap_checks checks; checks.terrain = false; checks.furniture = false; @@ -1487,3 +1510,30 @@ TEST_CASE( "submap_ter_furn_migration", "[submap][load]" ) REQUIRE( furn_sw == furn_test_f_migration_new_id ); REQUIRE( furn_se == furn_test_f_migration_new_id ); } + +TEST_CASE( "submap_fd_migration", "[submap][load]" ) +{ + submap sm; + load_from_jsin( sm, submap_fd_pre_migration ); + submap_checks checks; + checks.fields = false; + + REQUIRE( is_normal_submap( sm, checks ) ); + + const field field_ne = sm.get_field( corner_ne ); + + // North east corner should have migrated from test_fd_migration_old_id to test_fd_migration_new_id + std::string fields_list; + bool found_field_new_id = false; + int total_fields = 0; + auto it = field_ne.begin(); + while( it != field_ne.end() ) { + const field_type_id &type = it->first; + fields_list += type.id().str() + " "; + found_field_new_id |= type == field_test_fd_migration_new_id; + total_fields++; + it++; + } + INFO( string_format( "%d fields found: %s", total_fields, fields_list ) ); + REQUIRE( ( found_field_new_id && total_fields == 1 ) ); +}