From: German Service Network Date: Sat, 13 Dec 2025 10:20:57 +0000 (+0100) Subject: Add binary test and example data X-Git-Url: https://git.gsnw.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b0caaff8c8c265aa60c5d391fbc6e20be98bd5ad;p=EnergyLogger4000-Reader.git Add binary test and example data --- diff --git a/tests/binary_integration_test.rs b/tests/binary_integration_test.rs new file mode 100644 index 0000000..3c21805 --- /dev/null +++ b/tests/binary_integration_test.rs @@ -0,0 +1,39 @@ +use std::process::Command; +use std::path::Path; + +fn binary_name() -> String { + if cfg!(windows) { + "EnergyLogger4000-Reader.exe".into() + } else { + "EnergyLogger4000-Reader".into() + } +} + +#[test] +fn test_info_file() { + let manifest_dir = env!("CARGO_MANIFEST_DIR"); + + let binary_path = Path::new(manifest_dir) + .join("target") + .join("debug") + .join(binary_name()); + + let info_test_file = Path::new(env!("CARGO_MANIFEST_DIR")) + .join("tests") + .join("data") + .join("B032361A.BIN"); + + let output = Command::new(binary_path) + .current_dir(manifest_dir) + .arg("-f") + .arg(info_test_file) + .output() + .expect("failed to run binary"); + + assert!(output.status.success(), "Binary exited with {:?}\nstderr:\n{}", output.status.code(), String::from_utf8_lossy(&output.stderr)); + + // Checkoutput info file + let expected_output = "----- FINAL RESULT -----\n--- INFO ---\nUnit ID: 1\nTimestamp: 2025-12-11 17:34:00\nTarif 1: 0.35000000000000003\nTarif 2: 0.25\nTotal power comsumption: 0.045 kWh\nTotal recorded time 2269.98 h\nTotal on time 297.16 h\n- Day: 1\n-- Total kWh today min: 0.009 kWh\n-- Total recorded time today min: 7.4 h\n-- Total on time today min: 0.85 h\n- Day: 2\n-- Total kWh today min: 0.013 kWh\n-- Total recorded time today min: 2.15 h\n-- Total on time today min: 1.71 h\n- Day: 3\n-- Total kWh today min: 0.022 kWh\n-- Total recorded time today min: 6.45 h\n-- Total on time today min: 2.46 h\n- Day: 4\n-- Total kWh today min: 0 kWh\n-- Total recorded time today min: 0 h\n-- Total on time today min: 0 h\n- Day: 5\n-- Total kWh today min: 0 kWh\n-- Total recorded time today min: 0 h\n-- Total on time today min: 0 h\n- Day: 6\n-- Total kWh today min: 0 kWh\n-- Total recorded time today min: 0 h\n-- Total on time today min: 0 h\n- Day: 7\n-- Total kWh today min: 0 kWh\n-- Total recorded time today min: 0 h\n-- Total on time today min: 0 h\n- Day: 8\n-- Total kWh today min: 0 kWh\n-- Total recorded time today min: 0 h\n-- Total on time today min: 0 h\n- Day: 9\n-- Total kWh today min: 0 kWh\n-- Total recorded time today min: 0 h\n-- Total on time today min: 0 h\n- Day: 10\n-- Total kWh today min: 0 kWh\n-- Total recorded time today min: 0 h\n-- Total on time today min: 0 h\n"; + let actual_output = String::from_utf8_lossy(&output.stdout); + assert_eq!(actual_output, expected_output, "Unexpected output:\n{}", actual_output); +} diff --git a/tests/data/B032361A.BIN b/tests/data/B032361A.BIN new file mode 100644 index 0000000..aa39a56 Binary files /dev/null and b/tests/data/B032361A.BIN differ diff --git a/tests/data/B032361B.BIN b/tests/data/B032361B.BIN new file mode 100644 index 0000000..cd3c866 Binary files /dev/null and b/tests/data/B032361B.BIN differ diff --git a/tests/data/B032361C.BIN b/tests/data/B032361C.BIN new file mode 100644 index 0000000..a6738ba Binary files /dev/null and b/tests/data/B032361C.BIN differ