Skip to content

Commit

Permalink
add pocket_mods test
Browse files Browse the repository at this point in the history
  • Loading branch information
mqrause committed Nov 28, 2023
1 parent cc33f0e commit d6b3ecb
Show file tree
Hide file tree
Showing 4 changed files with 245 additions and 0 deletions.
179 changes: 179 additions & 0 deletions data/mods/TEST_DATA/pocket_mods_test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
[
{
"type": "test_data",
"pocket_mod_data": {
"change existing magazine well": {
"base_item": "debug_gun_with_mag_well",
"mod_item": "debug_retool_mag_well",
"expected_pockets": { "MAGAZINE_WELL": 1 }
},
"add magazine well to item without one": {
"base_item": "debug_gun_no_mag_well",
"mod_item": "debug_retool_mag_well",
"expected_pockets": { "MAGAZINE_WELL": 1 }
},
"add pocket to pocketless tool": {
"base_item": "debug_tool_no_pockets",
"mod_item": "debug_retool_container_no_mag_well",
"expected_pockets": { "CONTAINER": 1 }
},
"add pocket to tool with pocket": {
"base_item": "debug_tool_one_pocket",
"mod_item": "debug_retool_container_no_mag_well",
"expected_pockets": { "CONTAINER": 2 }
}
}
},
{
"id": "debug_gun_no_mag_well",
"type": "GUN",
"name": { "str": "debug gun without mag well" },
"copy-from": "rifle_auto",
"description": "Just a debug gun.",
"weight": "902 g",
"volume": "1550 ml",
"longest_side": "520 mm",
"price": 125000,
"price_postapoc": 4000,
"to_hit": -1,
"material": [ "aluminum", "steel", "plastic" ],
"symbol": "(",
"color": "black",
"ammo": [ "NULL" ],
"dispersion": 150,
"durability": 7,
"min_cycle_recoil": 1350,
"weapon_category": [ "AUTOMATIC_RIFLES" ],
"valid_mod_locations": [ [ "bore", 1 ], [ "grip", 1 ], [ "mechanism", 4 ], [ "sling", 1 ], [ "stock accessory", 2 ], [ "stock", 1 ] ],
"melee_damage": { "bash": 12 }
},
{
"id": "debug_gun_with_mag_well",
"type": "GUN",
"name": "debug gun with mag well",
"copy-from": "debug_gun_no_mag_well",
"pocket_data": [
{
"pocket_type": "MAGAZINE_WELL",
"ammo_restriction": { "223": 20 }
}
]
},
{
"id": "debug_tool_no_pockets",
"type": "TOOL",
"name": "debug tool with no pockets",
"description": "debug",
"symbol": "(",
"volume": "1L",
"weight": "1kg"
},
{
"id": "debug_tool_one_pocket",
"type": "TOOL",
"name": "debug tool with one pocket",
"copy-from": "debug_tool_no_pockets",
"pocket_data": [
{
"pocket_type": "CONTAINER",
"max_contains_volume": "2L"
}
]
},
{
"id": "debug_retool_container_no_mag_well",
"type": "TOOLMOD",
"name": "debug toolmod to add container",
"description": "debug",
"symbol": "(",
"volume": "1L",
"weight": "1kg",
"pocket_mods": [
{
"pocket_type": "CONTAINER",
"max_contains_volume": "1L"
}
]
},
{
"id": "debug_retool_mag_well",
"type": "GUNMOD",
"name": { "str": "debug gunmod to add/alter magazine well" },
"description": "This is a complete upper receiver assembly containing a barrel, handguard, and bolt carrier group that, given the right knowledge, is installable upon an AR-15-style rifle’s lower frame. Swappable uppers allow compatible firearms to be retooled for different cartridges and barrel lengths, with this kit furnishing a weapon with a standard 16-inch barrel chambered for .223 Remington ammunition.",
"weight": "2268 g",
"volume": "1550 ml",
"longest_side": "480 mm",
"integral_volume": "1550 ml",
"integral_weight": "2268 g",
"integral_longest_side": "41 cm",
"barrel_length": "406 mm",
"price": 25999,
"price_postapoc": 1000,
"material": [ "steel", "aluminum", "plastic" ],
"symbol": ":",
"color": "green",
"location": "bore",
"mod_targets": [ "debug_modular_ar15" ],
"install_time": "5 m",
"ammo_modifier": [ "223" ],
"magazine_adaptor": [
[
"223",
[
"stanag30",
"stanag5",
"stanag5ranger",
"stanag10",
"stanag10ranger",
"stanag20",
"stanag20ranger",
"stanag30ranger",
"stanag40",
"stanag40ranger",
"stanag50",
"stanag60",
"stanag60drum",
"stanag90",
"stanag100",
"stanag100drum",
"stanag150",
"stanag20_beowulf",
"stanag20ranger_beowulf",
"stanag30_beowulf",
"stanag30ranger_beowulf",
"survivor223mag"
]
]
],
"pocket_mods": [
{
"pocket_type": "MAGAZINE_WELL",
"item_restriction": [
"stanag30",
"stanag5",
"stanag5ranger",
"stanag10",
"stanag10ranger",
"stanag20",
"stanag20ranger",
"stanag30ranger",
"stanag40",
"stanag40ranger",
"stanag50",
"stanag60",
"stanag60drum",
"stanag90",
"stanag100",
"stanag100drum",
"stanag150",
"stanag20_beowulf",
"stanag20ranger_beowulf",
"stanag30_beowulf",
"stanag30ranger_beowulf",
"survivor223mag"
]
}
],
"add_mod": [ [ "brass catcher", 1 ], [ "bayonet lug", 1 ], [ "rail", 2 ], [ "sights", 1 ], [ "underbarrel", 1 ], [ "muzzle", 1 ] ]
}
]
14 changes: 14 additions & 0 deletions src/test_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ std::map<vproto_id, std::vector<double>> test_data::drag_data;
std::map<vproto_id, efficiency_data> test_data::eff_data;
std::map<itype_id, double> test_data::expected_dps;
std::map<spawn_type, std::vector<container_spawn_test_data>> test_data::container_spawn_data;
std::map<std::string, pocket_mod_test_data> test_data::pocket_mod_data;
std::map<std::string, npc_boarding_test_data> test_data::npc_boarding_data;

void efficiency_data::deserialize( const JsonObject &jo )
Expand Down Expand Up @@ -40,6 +41,13 @@ void container_spawn_test_data::deserialize( const JsonObject &jo )
}
}

void pocket_mod_test_data::deserialize( const JsonObject &jo )
{
jo.read( "base_item", base_item );
jo.read( "mod_item", mod_item );
jo.read( "expected_pockets", expected_pockets );
}

void npc_boarding_test_data::deserialize( const JsonObject &jo )
{
jo.read( "vehicle", veh_prototype );
Expand Down Expand Up @@ -111,6 +119,12 @@ void test_data::load( const JsonObject &jo )
}
}

if( jo.has_object( "pocket_mod_data" ) ) {
std::map<std::string, pocket_mod_test_data> new_pocket_mod_data;
jo.read( "pocket_mod_data", new_pocket_mod_data );
pocket_mod_data.insert( new_pocket_mod_data.begin(), new_pocket_mod_data.end() );
}

if( jo.has_object( "npc_boarding_data" ) ) {
std::map<std::string, npc_boarding_test_data> new_boarding_data;
jo.read( "npc_boarding_data", new_boarding_data );
Expand Down
10 changes: 10 additions & 0 deletions src/test_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "point.h"
#include "type_id.h"
#include "pocket_type.h"

class JsonObject;

Expand Down Expand Up @@ -40,6 +41,14 @@ struct container_spawn_test_data {
void deserialize( const JsonObject &jo );
};

struct pocket_mod_test_data {
itype_id base_item;
itype_id mod_item;
std::map<pocket_type, size_t> expected_pockets;

void deserialize( const JsonObject &jo );
};

struct npc_boarding_test_data {
vproto_id veh_prototype;
tripoint player_pos;
Expand All @@ -58,6 +67,7 @@ class test_data
static std::map<vproto_id, efficiency_data> eff_data;
static std::map<itype_id, double> expected_dps;
static std::map<spawn_type, std::vector<container_spawn_test_data>> container_spawn_data;
static std::map<std::string, pocket_mod_test_data> pocket_mod_data;
static std::map<std::string, npc_boarding_test_data> npc_boarding_data;

static void load( const JsonObject &jo );
Expand Down
42 changes: 42 additions & 0 deletions tests/item_pocket_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "mapgen_helpers.h"
#include "player_helpers.h"
#include "ret_val.h"
#include "test_data.h"
#include "type_id.h"
#include "units.h"
#include "value_ptr.h"
Expand Down Expand Up @@ -2811,3 +2812,44 @@ TEST_CASE( "auto_whitelist", "[item][pocket][item_spawn]" )
check_whitelist( *spawned_w_modifier, edited, id );
}
}

TEST_CASE( "pocket_mods", "[pocket][toolmod][gunmod]" )
{
for( std::pair<const std::string, pocket_mod_test_data> &pocket_mod_data :
test_data::pocket_mod_data ) {
SECTION( pocket_mod_data.first ) {
item base_it( pocket_mod_data.second.base_item );
item mod_it( pocket_mod_data.second.mod_item );

base_it.put_in( mod_it, pocket_type::MOD );

std::vector<item_pocket *> new_pockets( base_it.get_contents().get_pockets( [](
item_pocket const & ) {
return true;
} ) );

for( std::pair<const pocket_type, size_t> &expected :
pocket_mod_data.second.expected_pockets ) {
std::vector<item_pocket *> pockets( base_it.get_contents().get_pockets( [expected](
item_pocket const & pock ) {
return pock.is_type( expected.first );
} ) );
CAPTURE( expected.first );
CHECK( expected.second == pockets.size() );
}

bool same_pocket_data = new_pockets.size() == base_it.type->pockets.size();
if( same_pocket_data ) {
for( const item_pocket *pocket : new_pockets ) {
if( std::find( base_it.type->pockets.begin(), base_it.type->pockets.end(),
*pocket->get_pocket_data() ) == base_it.type->pockets.end() ) {
same_pocket_data = false;
break;
}
}
}

CHECK_FALSE( same_pocket_data );
}
}
}

0 comments on commit d6b3ecb

Please sign in to comment.