|
1 | 1 | mod support; |
2 | 2 |
|
3 | 3 | use assert_cmd::Command; |
| 4 | +use audiowaveform::Waveform; |
4 | 5 | use predicates::prelude::*; |
5 | 6 |
|
6 | 7 | use self::support::{ |
@@ -55,6 +56,68 @@ fn rejects_invalid_enum_values_via_clap() { |
55 | 56 | .stderr(predicate::str::contains("possible values")); |
56 | 57 | } |
57 | 58 |
|
| 59 | +#[test] |
| 60 | +fn rejects_non_finite_numeric_values() { |
| 61 | + let input = fixture_path("test_file_stereo_8bit_64spp_wav.dat"); |
| 62 | + let input = input.to_str().expect("utf8"); |
| 63 | + |
| 64 | + Command::cargo_bin("audiowaveform") |
| 65 | + .expect("binary") |
| 66 | + .args([ |
| 67 | + "-q", |
| 68 | + "-i", |
| 69 | + input, |
| 70 | + "--output-format", |
| 71 | + "png", |
| 72 | + "-z", |
| 73 | + "64", |
| 74 | + "--start", |
| 75 | + "inf", |
| 76 | + ]) |
| 77 | + .assert() |
| 78 | + .failure() |
| 79 | + .stderr("Invalid start time: minimum 0\n"); |
| 80 | + |
| 81 | + Command::cargo_bin("audiowaveform") |
| 82 | + .expect("binary") |
| 83 | + .args([ |
| 84 | + "-q", |
| 85 | + "-i", |
| 86 | + input, |
| 87 | + "--output-format", |
| 88 | + "png", |
| 89 | + "-z", |
| 90 | + "64", |
| 91 | + "--amplitude-scale", |
| 92 | + "NaN", |
| 93 | + ]) |
| 94 | + .assert() |
| 95 | + .failure() |
| 96 | + .stderr("Error: Invalid amplitude scale: must be a positive number\n"); |
| 97 | +} |
| 98 | + |
| 99 | +#[test] |
| 100 | +fn rejects_raw_channel_counts_that_do_not_fit_the_library_type() { |
| 101 | + Command::cargo_bin("audiowaveform") |
| 102 | + .expect("binary") |
| 103 | + .args([ |
| 104 | + "-q", |
| 105 | + "--input-format", |
| 106 | + "raw", |
| 107 | + "--output-format", |
| 108 | + "wav", |
| 109 | + "--raw-samplerate", |
| 110 | + "48000", |
| 111 | + "--raw-channels", |
| 112 | + "65537", |
| 113 | + "--raw-format", |
| 114 | + "s16le", |
| 115 | + ]) |
| 116 | + .assert() |
| 117 | + .failure() |
| 118 | + .stderr("Invalid number of input channels: maximum 65535\n"); |
| 119 | +} |
| 120 | + |
58 | 121 | #[test] |
59 | 122 | fn generates_dat_output_to_file_and_stdout() { |
60 | 123 | let output = named_temp_file(".dat"); |
@@ -133,6 +196,40 @@ fn generates_json_and_text_outputs_to_stdout() { |
133 | 196 | .stderr("Done\n"); |
134 | 197 | } |
135 | 198 |
|
| 199 | +#[test] |
| 200 | +fn applies_fixed_amplitude_scaling_to_waveform_data_output() { |
| 201 | + let unscaled_output = named_temp_file(".json"); |
| 202 | + let scaled_output = named_temp_file(".json"); |
| 203 | + |
| 204 | + for (output, amplitude_scale) in [(&unscaled_output, "1.0"), (&scaled_output, "2.0")] { |
| 205 | + Command::cargo_bin("audiowaveform") |
| 206 | + .expect("binary") |
| 207 | + .args([ |
| 208 | + "-q", |
| 209 | + "-i", |
| 210 | + fixture_path("test_file_stereo.wav").to_str().expect("utf8"), |
| 211 | + "-o", |
| 212 | + output.path().to_str().expect("utf8"), |
| 213 | + "-z", |
| 214 | + "64", |
| 215 | + "--amplitude-scale", |
| 216 | + amplitude_scale, |
| 217 | + ]) |
| 218 | + .assert() |
| 219 | + .success(); |
| 220 | + } |
| 221 | + |
| 222 | + let unscaled = Waveform::load_from_path(unscaled_output.path(), None).expect("unscaled"); |
| 223 | + let scaled = Waveform::load_from_path(scaled_output.path(), None).expect("scaled"); |
| 224 | + let expected = unscaled |
| 225 | + .interleaved_samples() |
| 226 | + .iter() |
| 227 | + .map(|value| (i32::from(*value) * 2).clamp(i32::from(i16::MIN), i32::from(i16::MAX)) as i16) |
| 228 | + .collect::<Vec<_>>(); |
| 229 | + |
| 230 | + assert_eq!(scaled.interleaved_samples(), expected); |
| 231 | +} |
| 232 | + |
136 | 233 | #[test] |
137 | 234 | fn generates_png_output_to_file_and_stdout() { |
138 | 235 | let output = named_temp_file(".png"); |
|
0 commit comments