From 3c3437b50e024f66c0779d2ef3defc0143e0878e Mon Sep 17 00:00:00 2001 From: Dan Kotov Date: Sun, 1 Sep 2024 08:21:14 -0400 Subject: [PATCH] test: add rust parse event output filtering test --- src/parser/src/e2e_test.rs | 107 ++++++++++++++++++++++++++++++++++++- 1 file changed, 106 insertions(+), 1 deletion(-) diff --git a/src/parser/src/e2e_test.rs b/src/parser/src/e2e_test.rs index 4166465..618086d 100644 --- a/src/parser/src/e2e_test.rs +++ b/src/parser/src/e2e_test.rs @@ -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(); @@ -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 = 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> = 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();