Skip to content

Commit

Permalink
test: add rust parse event output filtering test
Browse files Browse the repository at this point in the history
  • Loading branch information
dankotov committed Sep 1, 2024
1 parent bdb2a1a commit 3c3437b
Showing 1 changed file with 106 additions and 1 deletion.
107 changes: 106 additions & 1 deletion src/parser/src/e2e_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,7 @@ mod tests {
}

#[test]
fn test_prop_state_filter() {
fn test_parse_ticks_prop_state_filter() {
let huf = create_huffman_lookup_table();
let huf2 = create_huffman_lookup_table();

Expand Down Expand Up @@ -1293,6 +1293,111 @@ mod tests {
assert_eq!(manually_filtered_positions, automatically_filtered_positions);
}

#[test]
fn test_parse_event_prop_state_filter() {
let huf = create_huffman_lookup_table();
let huf2 = create_huffman_lookup_table();

let settings = ParserInputs {
wanted_players: vec![76561198244754626],
real_name_to_og_name: AHashMap::default(),
wanted_player_props: vec!["X".to_string(), "CCSGameRulesProxy.CCSGameRules.m_bBombPlanted".to_string()],
wanted_events: vec!["player_death".to_string()],
wanted_other_props: vec![],
parse_ents: true,
wanted_ticks: vec![],
wanted_player_prop_states: AHashMap::default(),
wanted_other_prop_states: AHashMap::default(),
parse_projectiles: true,
only_header: false,
count_props: false,
only_convars: false,
huffman_lookup_table: &huf,
order_by_steamid: false,
};

let mut wanted_player_prop_states: AHashMap<std::string::String, Variant> = AHashMap::default();
wanted_player_prop_states.insert(
"CCSGameRulesProxy.CCSGameRules.m_bBombPlanted".to_string(),
Variant::Bool(true),
);
let settings_with_filter = ParserInputs {
wanted_players: vec![76561198244754626],
real_name_to_og_name: AHashMap::default(),
wanted_player_props: vec!["X".to_string()],
wanted_events: vec!["player_death".to_string()],
wanted_other_props: vec![],
parse_ents: true,
wanted_ticks: vec![],
wanted_player_prop_states: AHashMap::default(),
wanted_other_prop_states: wanted_player_prop_states,
parse_projectiles: true,
only_header: false,
count_props: false,
only_convars: false,
huffman_lookup_table: &huf2,
order_by_steamid: false,
};

let mut ds = Parser::new(settings, crate::parse_demo::ParsingMode::ForceMultiThreaded);
let mut ds_with_filter = Parser::new(settings_with_filter, crate::parse_demo::ParsingMode::ForceMultiThreaded);
let file = File::open("test_demo.dem").unwrap();
let mmap = unsafe { MmapOptions::new().map(&file).unwrap() };
let output = ds.parse_demo(&mmap).unwrap();
let output_with_filter = ds_with_filter.parse_demo(&mmap).unwrap();

let positions = match output
.df
.get(&PLAYER_X_ID)
.unwrap()
.data
.clone()
.unwrap_or(VarVec::F32(vec![]))
{
VarVec::F32(positions_vec) => positions_vec,
_ => vec![],
};
let bomb_prop_id = output
.prop_controller
.prop_infos
.iter()
.find(|prop| prop.prop_name == "CCSGameRulesProxy.CCSGameRules.m_bBombPlanted")
.map(|prop| prop.id)
.unwrap();
let bomb = match output
.df
.get(&bomb_prop_id)
.unwrap()
.data
.clone()
.unwrap_or(VarVec::Bool(vec![]))
{
VarVec::Bool(bomb_vec) => bomb_vec,
_ => vec![],
};
let manually_filtered_positions: Vec<Option<f32>> = positions
.iter()
.zip(bomb.iter())
.filter_map(|(xPos, bombPlanted)| match bombPlanted {
Some(true) => Some(*xPos),
_ => None,
})
.collect();
let automatically_filtered_positions = match output_with_filter
.df
.get(&PLAYER_X_ID)
.unwrap()
.data
.clone()
.unwrap_or(VarVec::F32(vec![]))
{
VarVec::F32(positions_vec) => positions_vec,
_ => vec![],
};

assert_eq!(manually_filtered_positions, automatically_filtered_positions);
}

#[test]
fn test_player_filter() {
let huf = create_huffman_lookup_table();
Expand Down

0 comments on commit 3c3437b

Please sign in to comment.