From 188acb10569acaf076449c0043df23ca45eb6ea0 Mon Sep 17 00:00:00 2001 From: Wojciech Kozlowski Date: Fri, 15 Mar 2024 16:29:32 +0100 Subject: [PATCH] Add integration tests for pcap_loop (#337) --- tests/capture/activated/mod.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/capture/activated/mod.rs b/tests/capture/activated/mod.rs index 277795d6..740f5c07 100644 --- a/tests/capture/activated/mod.rs +++ b/tests/capture/activated/mod.rs @@ -136,3 +136,22 @@ fn test_filter() { let result = capture.next_packet(); assert!(result.is_ok()); } + +#[test] +fn read_packet_via_pcap_loop() { + let mut packets = 0; + let mut capture = capture_from_test_file("packet_snaplen_65535.pcap"); + capture + .for_each(None, |_| { + packets += 1; + }) + .unwrap(); + assert_eq!(packets, 1); +} + +#[test] +#[should_panic] +fn panic_in_pcap_loop() { + let mut capture = capture_from_test_file("packet_snaplen_65535.pcap"); + capture.for_each(None, |_| panic!()).unwrap(); +}