Skip to content

Commit

Permalink
Test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Procyonae committed Apr 2, 2024
1 parent 6c55530 commit 5a283b6
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 0 deletions.
10 changes: 10 additions & 0 deletions data/mods/TEST_DATA/furniture.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@
"required_str": 8,
"hacksaw": { "duration": "80 minutes" }
},
{
"type": "furniture",
"id": "test_f_migration_new_id",
"name": "Furniture Test Migration",
"description": "Id to test migration from it's invalid counterparts test_t_migration_old_id and test_f_migration_old_id to.",
"symbol": "f",
"color": "blue",
"move_cost_mod": 1,
"required_str": 8
},
{
"type": "furniture",
"id": "test_f_oxytorch1",
Expand Down
13 changes: 13 additions & 0 deletions data/mods/TEST_DATA/ter_furn_migration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
{
"type": "ter_furn_transform",
"from_ter": "test_t_migration_old_id",
"to_ter": "test_t_migration_new_id",
"to_furn": "test_f_migration_new_id"
},
{
"type": "ter_furn_transform",
"from_ter": "test_f_migration_old_id",
"to_furn": "test_f_migration_new_id"
}
]
10 changes: 10 additions & 0 deletions data/mods/TEST_DATA/terrain.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,16 @@
},
"prying": { "result": "t_grass", "duration": "30 seconds", "prying_data": { "difficulty": 100, "breakable": true } }
},
{
"type": "terrain",
"id": "test_t_migration_new_id",
"name": "Terrain Test Migration",
"description": "Id to test migration from it's invalid counterpart test_t_migration_old_id to.",
"symbol": "t",
"color": "blue",
"move_cost": 1,
"bash": { "sound": "thump", "ter_set": "t_null", "str_min": 50, "str_max": 100, "str_min_supported": 100, "bash_below": true }
},
{
"type": "terrain",
"id": "test_t_bash_persist",
Expand Down
73 changes: 73 additions & 0 deletions tests/submap_load_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
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 furn_str_id furn_test_f_migration_new_id( "test_f_migration_new_id" );

static const ter_str_id ter_t_dirt( "t_dirt" );
static const ter_str_id ter_test_t_migration_new_id( "test_t_migration_new_id" );

// NOLINTNEXTLINE(cata-static-declarations)
extern const int savegame_version;

Expand Down Expand Up @@ -767,6 +772,29 @@ static std::string submap_cosmetic_ss(
" \"computers\": [ ]\n"
"}\n"
);
static std::string submap_pre_migration_ss(
"{\n"
" \"version\": 32,\n"
" \"coordinates\": [ 0, 0, 0 ],\n"
" \"turn_last_touched\": 0,\n"
" \"temperature\": 0,\n"
" \"terrain\": [ [ \"test_t_migration_old_id\", 1, \"t_dirt\", 10, \"test_t_migration_old_id\", 1, \"t_dirt\", 132 ] ],\n"
" \"radiation\": [ 0, 144 ],\n"
" \"furniture\": [\n"
" [ 0, 0, \"f_bookcase\" ],\n"
" [ 0, 11, \"test_f_migration_old_id\" ],\n"
" [ 11, 11, \"test_f_migration_old_id\" ],\n"
" ],\n"
" \"items\": [ ],\n"
" \"traps\": [ ],\n"
" \"fields\": [ ],\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." );
Expand All @@ -786,6 +814,8 @@ 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_post_migration = json_loader::from_string( submap_post_migration_ss );

Check failure on line 818 in tests/submap_load_test.cpp

View workflow job for this annotation

GitHub Actions / build (other)

Variable 'submap_post_migration' declared but not used. [cata-unused-statics,-warnings-as-errors]

Check failure on line 818 in tests/submap_load_test.cpp

View workflow job for this annotation

GitHub Actions / build (other)

use of undeclared identifier 'submap_post_migration_ss' [clang-diagnostic-error]

static void load_from_jsin( submap &sm, const JsonValue &jsin )
{
Expand Down Expand Up @@ -1407,3 +1437,46 @@ TEST_CASE( "submap_computer_load", "[submap][load]" )
REQUIRE( sm.has_computer( point_south ) );
REQUIRE( sm.has_computer( {3, 5} ) );
}

TEST_CASE( "submap_ter_furn_migration", "[submap][load]" )
{
submap sm;
load_from_jsin( sm, submap_pre_migration );
submap_checks checks;
checks.terrain = false;
checks.furniture = false;

REQUIRE( is_normal_submap( sm, checks ) );

const ter_id ter_nw = sm.get_ter( corner_nw );
const ter_id ter_ne = sm.get_ter( corner_ne );
const ter_id ter_sw = sm.get_ter( corner_sw );
const ter_id ter_se = sm.get_ter( corner_se );

const furn_id furn_nw = sm.get_furn( corner_nw );
const furn_id furn_ne = sm.get_furn( corner_ne );
const furn_id furn_sw = sm.get_furn( corner_sw );
const furn_id furn_se = sm.get_furn( corner_se );

// North corners should have migrated from test_t_migration_old_id to test_t_migration_new_id
INFO( string_format( "ter nw: %s", ter_nw.id().str() ) );
INFO( string_format( "ter ne: %s", ter_ne.id().str() ) );
REQUIRE( ter_nw == ter_test_t_migration_new_id );
REQUIRE( ter_ne == ter_test_t_migration_new_id );
// West one should still have a f_bookcase as it overrides the test_f_migration_new_id placed by migration
INFO( string_format( "furn nw: %s", furn_nw.id().str() ) );
REQUIRE( furn_nw == furn_test_f_migration_new_id );
// East one should now have test_f_migration_new_id as per the migration
INFO( string_format( "furn ne: %s", furn_ne.id().str() ) );
REQUIRE( furn_ne == furn_test_f_migration_new_id );
// South corners should still have t_dirt
INFO( string_format( "ter sw: %s", ter_sw.id().str() ) );
INFO( string_format( "ter se: %s", ter_se.id().str() ) );
REQUIRE( ter_sw == ter_t_dirt );
REQUIRE( ter_se == ter_t_dirt );
// But should have migrated test_f_migration_old_id to test_f_migration_new_id
INFO( string_format( "furn sw: %s", furn_sw.id().str() ) );
INFO( string_format( "furn se: %s", furn_se.id().str() ) );
REQUIRE( furn_sw == furn_test_f_migration_new_id );
REQUIRE( furn_se == furn_test_f_migration_new_id );
}

0 comments on commit 5a283b6

Please sign in to comment.