edith
Clone
https://git.tahinli.com/Tahinli/edith.git
0 watching·0 forks·Rust·18.3 MiB·ff99ad6·Tahinli·6 days ago·1055 commits
| 1 | //! The export sheet's behaviour, as values: presets, the range radio, the |
| 2 | //! estimate, the geometry against the timeline, the overwrite answers and the |
| 3 | //! "More settings" disclosure (DESIGN §9). |
| 4 | |
| 5 | use super::*; |
| 6 | use crate::export_ui::*; |
| 7 | use crate::ui::widgets::{load_folds_from, save_folds_to}; |
| 8 | use engine::export::{HdrTransfer, ProResProfile}; |
| 9 | use engine::export_presets::{self as presets, Category}; |
| 10 | |
| 11 | fn base() -> Picked { |
| 12 | Picked { |
| 13 | format: Format::Av1, |
| 14 | bps: 3_000_000, |
| 15 | audio_kbps: 128, |
| 16 | size: None, |
| 17 | depth: None, |
| 18 | loudness: None, |
| 19 | prores: Default::default(), |
| 20 | hdr: Default::default(), |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | #[test] |
| 25 | fn a_preset_tile_lays_the_engine_preset_over_the_settings_and_custom_follows_a_change() { |
| 26 | let youtube = presets::by_id("youtube_1080p").expect("the table has it"); |
| 27 | let picked = picked_with(base(), youtube); |
| 28 | assert_eq!(picked.format, youtube.format); |
| 29 | assert_eq!(Some(picked.bps), youtube.bitrate); |
| 30 | assert_eq!(picked.size, youtube.target.size); |
| 31 | // AAC 384 is above the rates the engine writes; it takes the top one. |
| 32 | assert_eq!(picked.audio_kbps, *AUDIO_KBPS.last().unwrap()); |
| 33 | assert!(preset_applies(picked, youtube)); |
| 34 | assert_eq!(matching_preset(picked, Some("youtube_1080p")).map(|p| p.id), Some("youtube_1080p")); |
| 35 | // Any setting moved off the preset is Custom. |
| 36 | let changed = Picked { bps: 9_000_000, ..picked }; |
| 37 | assert!(matching_preset(changed, Some("youtube_1080p")).is_none()); |
| 38 | let changed = Picked { size: Some((1280, 720)), ..picked }; |
| 39 | assert!(matching_preset(changed, Some("youtube_1080p")).is_none()); |
| 40 | // A sound preset carries its loudness target and drops the canvas. |
| 41 | let podcast = presets::by_id("podcast").expect("the table has it"); |
| 42 | let picked = picked_with(Picked { size: Some((1920, 1080)), ..base() }, podcast); |
| 43 | assert_eq!(picked.format, Format::M4a); |
| 44 | assert_eq!(picked.loudness, podcast.loudness); |
| 45 | assert_eq!(matching_preset(picked, None).map(|p| p.id), Some("podcast")); |
| 46 | // Every row of the engine's table applies to itself: no tile can be |
| 47 | // pressed and immediately read as Custom. |
| 48 | for p in presets::presets() { |
| 49 | assert!(preset_applies(picked_with(base(), p), p), "{} is never lit", p.id); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | #[test] |
| 54 | fn every_preset_tile_says_what_it_makes_under_a_named_group() { |
| 55 | for p in presets::presets() { |
| 56 | let said = preset_result(p, Some((1920, 1080))); |
| 57 | assert!(!said.is_empty()); |
| 58 | match p.target.output { |
| 59 | presets::Output::Video => assert!(said.contains('\u{d7}'), "{said}"), |
| 60 | presets::Output::AudioOnly => assert!(!said.contains('\u{d7}'), "{said}"), |
| 61 | } |
| 62 | } |
| 63 | assert_eq!(preset_result(presets::by_id("youtube_1080p").unwrap(), None), "1920\u{d7}1080 \u{b7} H.264"); |
| 64 | for c in [Category::Web, Category::Social, Category::Audio, Category::Archive] { |
| 65 | assert!(presets::presets().iter().any(|p| p.target.category == c)); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | #[test] |
| 70 | fn the_range_radio_names_both_lengths_and_says_why_the_marks_are_off() { |
| 71 | let opts = range_options(Some((30, 150)), true, 900, 30.); |
| 72 | assert_eq!(opts.whole, "30.0 s long"); |
| 73 | let marks = opts.marks.expect("valid marks are a choice"); |
| 74 | assert_eq!(marks, format!("1 s \u{2013} 5 s \u{b7} {} long", span_word(120, 30.))); |
| 75 | assert_eq!(opts.marks_off, None); |
| 76 | // No marks at all: off, with how to set them. |
| 77 | let opts = range_options(None, false, 900, 30.); |
| 78 | assert!(opts.marks.is_none()); |
| 79 | assert!(opts.marks_off.unwrap().contains("In and Out")); |
| 80 | // Marks that lie past the end: off, and said differently. |
| 81 | let opts = range_options(None, true, 900, 30.); |
| 82 | assert!(opts.marks_off.unwrap().contains("past the end")); |
| 83 | } |
| 84 | |
| 85 | #[test] |
| 86 | fn the_estimate_never_says_zero_for_a_range_with_something_in_it() { |
| 87 | let one_frame = 1. / 30.; |
| 88 | for &(format, ..) in SHEET_FORMATS.iter() { |
| 89 | for fixed in [true, false] { |
| 90 | let est = size_estimate(format, BPS_MIN, 128, true, one_frame, 48_000, fixed); |
| 91 | assert!(est.low > 0 && est.high >= est.low, "{format:?}"); |
| 92 | let said = size_words(est); |
| 93 | assert!(said.starts_with("about "), "{said}"); |
| 94 | assert!(!said.contains(" 0 ") && !said.ends_with(" 0 KB"), "{said}"); |
| 95 | } |
| 96 | } |
| 97 | // An hour at 8 Mb/s with 256 kbps of sound. |
| 98 | let hour = size_estimate(Format::Mp4, 8_000_000, 256, true, 3600., 48_000, true); |
| 99 | assert_eq!(size_words(hour), "about 3.73 GB"); |
| 100 | // A quality-driven encode is a span, not a single number. |
| 101 | let span = size_estimate(Format::Av1, 8_000_000, 256, true, 60., 48_000, false); |
| 102 | assert!(size_words(span).contains(" to "), "{}", size_words(span)); |
| 103 | // The time: measured or nothing at all, never a guess and never a fake zero. |
| 104 | assert_eq!(export_time_words(0.01, Some(30.), false), "about 1 s to export"); |
| 105 | assert_eq!(export_time_words(100., Some(1.), false), "about 1 min 40 s to export"); |
| 106 | assert_eq!(export_time_words(100., None, true), ""); |
| 107 | assert_eq!(export_time_words(100., None, false), ""); |
| 108 | } |
| 109 | |
| 110 | #[test] |
| 111 | fn tall_and_square_sizes_are_offered_and_named_by_their_shape() { |
| 112 | assert!(RESOLUTIONS.contains(&(1080, 1920)), "vertical is on the project list"); |
| 113 | assert!(RESOLUTIONS.contains(&(1080, 1080)), "square is on the project list"); |
| 114 | assert_eq!(size_name(1920, 1080), "1080p"); |
| 115 | assert_eq!(size_name(1080, 1920), "1080\u{d7}1920"); |
| 116 | assert_eq!(size_row_label(1080, 1920), "1080\u{d7}1920 (vertical 9:16)"); |
| 117 | assert_eq!(size_row_label(1080, 1080), "1080\u{d7}1080 (square)"); |
| 118 | assert_eq!(size_row_label(1280, 720), "720p"); |
| 119 | // The settings list shows them, the media's own shape cycled in beside them. |
| 120 | let rows = pending_resolution_choices(None); |
| 121 | assert!(rows.iter().any(|r| r.1.as_ref() == "1080\u{d7}1920 (vertical 9:16)")); |
| 122 | let rows = resolution_choices((1080, 1920), (1080, 1920)); |
| 123 | assert_eq!(rows.iter().filter(|r| r.0 == Choice::Size(1080, 1920)).count(), 1); |
| 124 | assert_eq!(rows.iter().find(|r| r.0 == Choice::Size(1080, 1920)).map(|r| r.2.to_string()), Some("matches your media".to_string())); |
| 125 | } |
| 126 | |
| 127 | #[test] |
| 128 | fn a_tall_preset_names_its_size_in_pixels_not_as_a_height() { |
| 129 | let shorts = presets::by_id("shorts_reels").expect("the Shorts preset exists"); |
| 130 | assert!(preset_spec(shorts, Some((1920, 1080))).starts_with("1080\u{d7}1920 "), "{}", preset_spec(shorts, None)); |
| 131 | let landscape = presets::by_id("youtube_1080p").expect("the YouTube preset exists"); |
| 132 | assert!(preset_spec(landscape, None).starts_with("1920\u{d7}1080 "), "{}", preset_spec(landscape, None)); |
| 133 | } |
| 134 | |
| 135 | #[test] |
| 136 | fn an_export_never_writes_over_a_source() { |
| 137 | let src = std::path::Path::new("/nonexistent-edith-test/speech.mp4"); |
| 138 | assert!(is_a_source(src, &[src])); |
| 139 | assert!(!is_a_source(std::path::Path::new("/nonexistent-edith-test/speech-edit.mp4"), &[src])); |
| 140 | } |
| 141 | |
| 142 | #[test] |
| 143 | fn a_new_project_starts_on_the_footage_rate() { |
| 144 | use crate::player::project_dialogs::{default_rate_index, NEW_RATES}; |
| 145 | let rate = |footage: Option<f64>| NEW_RATES[default_rate_index(footage)]; |
| 146 | assert_eq!(rate(Some(25.)), 25.); |
| 147 | assert_eq!(rate(Some(23.976)), 24.); |
| 148 | assert_eq!(rate(Some(29.97)), 30.); |
| 149 | assert_eq!(rate(None), 30.); |
| 150 | assert_eq!(rate(Some(12.)), 30.); |
| 151 | } |
| 152 | |
| 153 | #[test] |
| 154 | fn the_window_title_follows_the_project_name() { |
| 155 | use std::path::Path; |
| 156 | let none = Path::new(""); |
| 157 | assert_eq!(crate::library_meta::shown_title("speech", none, None, false), "speech — edith"); |
| 158 | let saved = Path::new("/nonexistent-edith-test/speech.edith"); |
| 159 | assert_eq!(crate::library_meta::shown_title("Untitled", saved, None, true), "speech — edith"); |
| 160 | assert_eq!(crate::library_meta::shown_title("Untitled", saved, None, false), "Untitled — edith"); |
| 161 | assert_eq!(crate::library_meta::shown_title("Untitled", none, Some(saved), false), "speech — edith"); |
| 162 | } |
| 163 | |
| 164 | /// The three summary rows for the settings a preset describes. |
| 165 | fn rows_for(p: &presets::Preset, size: &str) -> [(&'static str, String); 3] { |
| 166 | let next = picked_with(base(), p); |
| 167 | summary_rows( |
| 168 | &SummaryIn { |
| 169 | gif: Default::default(), |
| 170 | format: next.format, |
| 171 | target: next.size.unwrap_or((1280, 720)), |
| 172 | fps: 25., |
| 173 | bps: next.bps, |
| 174 | audio_kbps: next.audio_kbps, |
| 175 | sound: true, |
| 176 | seat: EncoderSeat::Software, |
| 177 | depth: next.depth, |
| 178 | prores: next.prores, |
| 179 | hdr: next.hdr, |
| 180 | sound_bits: None, |
| 181 | hevc_speed: Default::default(), |
| 182 | size, |
| 183 | }, |
| 184 | "~1 s", |
| 185 | ) |
| 186 | } |
| 187 | |
| 188 | #[test] |
| 189 | fn the_summary_says_the_file_in_plain_words() { |
| 190 | let p = presets::by_id("youtube_1080p").unwrap(); |
| 191 | let rows = rows_for(p, "about 150 MB"); |
| 192 | assert_eq!(rows[0], ("Video", "H.264 \u{b7} 1920\u{d7}1080 \u{b7} 25\u{a0}fps \u{b7} 8\u{a0}Mb/s".to_string())); |
| 193 | assert_eq!(rows[1], ("Audio", "AAC stereo \u{b7} 320\u{a0}kb/s".to_string())); |
| 194 | assert_eq!(rows[2], ("File", "MP4 \u{b7} Software \u{b7} ~150 MB \u{b7} ~1 s".to_string())); |
| 195 | } |
| 196 | |
| 197 | #[test] |
| 198 | fn the_summary_matches_the_settings_of_every_preset() { |
| 199 | for p in presets::presets() { |
| 200 | let next = picked_with(base(), p); |
| 201 | let [(_, video), (_, audio), (_, file)] = rows_for(p, "about 1 MB"); |
| 202 | assert!(file.starts_with(container_word(p.format)), "{}: {file}", p.id); |
| 203 | assert!(file.contains("~1 MB"), "{}: {file}", p.id); |
| 204 | match p.target.output { |
| 205 | presets::Output::Video => { |
| 206 | // An HDR file names its transfer in the codec's place, to fit the line. |
| 207 | let head = if p.hdr == HdrTransfer::Sdr { codec_word(p.format) } else { hdr_word(p.hdr) }; |
| 208 | assert!(video.starts_with(head), "{}: {video}", p.id); |
| 209 | let (w, h) = p.target.size.unwrap_or((1280, 720)); |
| 210 | assert!(video.contains(&format!("{w}\u{d7}{h}")), "{}: {video}", p.id); |
| 211 | assert!(file.contains("Software"), "{}: {file}", p.id); |
| 212 | // A ProRes profile is its own rate and its sound is PCM, not AAC. |
| 213 | if p.format == Format::ProRes { |
| 214 | assert!(video.starts_with("ProRes 422") && audio.starts_with("PCM stereo"), "{}: {video} / {audio}", p.id); |
| 215 | continue; |
| 216 | } |
| 217 | let mbps = rate_label(next.bps).trim_end_matches(".0").to_string(); |
| 218 | assert!(video.contains(&format!("{mbps}\u{a0}Mb/s")), "{}: {video}", p.id); |
| 219 | let sound = if p.format == Format::Webm { "Opus" } else { "AAC" }; |
| 220 | assert!(audio.starts_with(&format!("{sound} stereo")) && audio.contains(&next.audio_kbps.to_string()), "{}: {audio}", p.id); |
| 221 | } |
| 222 | presets::Output::AudioOnly => { |
| 223 | assert!(!video.contains('\u{d7}') && !file.contains("Software"), "{}: {video} / {file}", p.id); |
| 224 | assert!(audio.contains("stereo"), "{}: {audio}", p.id); |
| 225 | } |
| 226 | } |
| 227 | // No row is long enough to wrap in the dock (about 40 characters). |
| 228 | for line in [&video, &audio, &file] { |
| 229 | assert!(line.chars().count() <= 44, "{}: {line}", p.id); |
| 230 | } |
| 231 | } |
| 232 | let [_, (_, none), _] = summary_rows(&SummaryIn { sound: false, ..summary_in(Format::Flac) }, ""); |
| 233 | assert_eq!(none, "None"); |
| 234 | let [(_, ten), ..] = summary_rows(&SummaryIn { depth: Some(10), ..summary_in(Format::Av1) }, ""); |
| 235 | assert!(ten.starts_with("AV1 10-bit"), "{ten}"); |
| 236 | } |
| 237 | |
| 238 | #[test] |
| 239 | fn the_summary_names_the_prores_quality_the_hdr_and_the_sound_depth() { |
| 240 | let pro = SummaryIn { prores: ProResProfile::Hq, sound_bits: Some(16), ..summary_in(Format::ProRes) }; |
| 241 | let [(_, video), (_, audio), (_, file)] = summary_rows(&pro, ""); |
| 242 | assert_eq!(video, "ProRes 422 HQ \u{b7} 1920\u{d7}1080 \u{b7} 30\u{a0}fps", "no Mb/s for a profile"); |
| 243 | assert_eq!(audio, "PCM stereo \u{b7} 16-bit"); |
| 244 | assert!(file.starts_with("MOV"), "{file}"); |
| 245 | let [_, (_, audio), _] = summary_rows(&SummaryIn { sound_bits: None, ..pro }, ""); |
| 246 | assert!(audio.ends_with("24-bit"), "{audio}"); |
| 247 | let hdr = SummaryIn { hdr: HdrTransfer::Pq, depth: Some(10), ..summary_in(Format::HevcMp4) }; |
| 248 | let [(_, video), ..] = summary_rows(&hdr, ""); |
| 249 | assert!(video.starts_with("HDR10 \u{b7}"), "{video}"); |
| 250 | let [(_, plain), ..] = summary_rows(&summary_in(Format::HevcMp4), ""); |
| 251 | assert!(plain.starts_with("HEVC \u{b7}"), "{plain}"); |
| 252 | } |
| 253 | |
| 254 | #[test] |
| 255 | fn the_prores_and_hdr_presets_lay_their_settings_over_the_sheet_and_back() { |
| 256 | let master = presets::by_id("archive_prores").expect("the table has it"); |
| 257 | let picked = picked_with(base(), master); |
| 258 | assert_eq!((picked.format, picked.prores, picked.hdr), (Format::ProRes, ProResProfile::Hq, HdrTransfer::Sdr)); |
| 259 | assert!(preset_applies(picked, master)); |
| 260 | let hdr = presets::by_id("hdr10_hevc").expect("the table has it"); |
| 261 | let picked = picked_with(picked, hdr); |
| 262 | assert_eq!((picked.format, picked.hdr, picked.depth), (Format::HevcMp4, HdrTransfer::Pq, Some(10))); |
| 263 | // A preset of another file kind clears the HDR tag the engine would refuse on it. |
| 264 | let plain = picked_with(picked, presets::by_id("youtube_1080p").unwrap()); |
| 265 | assert_eq!(plain.hdr, HdrTransfer::Sdr); |
| 266 | // Every format has a container and codec row to pick it by, ProRes included. |
| 267 | assert!(COMBOS.iter().any(|&(c, k, f)| (c, k, f) == ("MOV", "ProRes", Format::ProRes))); |
| 268 | assert_eq!(format_in_container("MOV", Format::Mp4), Some(Format::ProRes)); |
| 269 | } |
| 270 | |
| 271 | fn summary_in(format: Format) -> SummaryIn<'static> { |
| 272 | SummaryIn { |
| 273 | gif: Default::default(), |
| 274 | format, |
| 275 | target: (1920, 1080), |
| 276 | fps: 30., |
| 277 | bps: 6_000_000, |
| 278 | audio_kbps: 128, |
| 279 | sound: true, |
| 280 | seat: EncoderSeat::Software, |
| 281 | depth: None, |
| 282 | prores: Default::default(), |
| 283 | hdr: Default::default(), |
| 284 | hevc_speed: Default::default(), |
| 285 | sound_bits: None, |
| 286 | size: "about 30 MB", |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | #[test] |
| 291 | fn a_detail_flips_the_preset_box_to_custom_from_the_one_before() { |
| 292 | assert_eq!(preset_box_text(Some("youtube_1080p"), Some("youtube_1080p")), "YouTube 1920\u{d7}1080"); |
| 293 | assert_eq!(preset_box_text(None, Some("youtube_1080p")), "Custom"); |
| 294 | assert_eq!(preset_box_text(None, None), "Custom"); |
| 295 | // The flip is a flag, not a comparison: a detail that happens to land on |
| 296 | // another preset's numbers is still Custom (from the one picked). |
| 297 | let player = fn_body_of("player/export.rs", "fn current_preset"); |
| 298 | assert!(player.contains("export_sheet.custom"), "{player}"); |
| 299 | let pick = fn_body_of("player/export.rs", "fn apply_export_pick"); |
| 300 | assert!(pick.contains("export_sheet.custom = true"), "{pick}"); |
| 301 | let choose = fn_body_of("player/export.rs", "fn choose_preset"); |
| 302 | assert!(choose.contains("export_sheet.custom = false"), "{choose}"); |
| 303 | } |
| 304 | |
| 305 | #[test] |
| 306 | fn every_container_and_codec_pair_is_one_engine_format_and_reachable() { |
| 307 | for f in [ |
| 308 | Format::Mp4, Format::Av1, Format::Av1Mp4, Format::Hevc, Format::HevcMp4, Format::Webm, Format::Wav, |
| 309 | Format::Flac, Format::Mp3, Format::Ogg, Format::M4a, Format::Opus, |
| 310 | ] { |
| 311 | assert!(COMBOS.iter().any(|(.., g)| *g == f), "{f:?} has no row"); |
| 312 | let (c, k, _) = *COMBOS.iter().find(|(.., g)| *g == f).unwrap(); |
| 313 | assert_eq!((c, k), (container_word(f), if f == Format::Wav { "PCM" } else { codec_word(f) }), "{f:?}"); |
| 314 | assert_eq!(format_in_container(c, f), Some(f), "{f:?}"); |
| 315 | } |
| 316 | // AV1 in MP4 moved to MKV stays AV1; H.264 moved to MKV lands on its first. |
| 317 | assert_eq!(format_in_container("MKV", Format::Av1Mp4), Some(Format::Av1)); |
| 318 | assert_eq!(format_in_container("MKV", Format::Mp4), Some(Format::Hevc)); |
| 319 | assert_eq!(format_in_container("WAV", Format::Mp4), Some(Format::Wav)); |
| 320 | } |
| 321 | |
| 322 | #[test] |
| 323 | fn the_details_rows_are_direct_choices_and_the_button_stays_pinned() { |
| 324 | let card = src_text("ui/cards/export.rs"); |
| 325 | let more = fn_body_of("ui/cards/export.rs", "fn sheet_more"); |
| 326 | for row in [ |
| 327 | "Container", "Codec", "Encoder", "Bitrate", "Resolution", "Frame rate", "Bit depth", "Sample rate", |
| 328 | "Channels", "Loudness", "Chapters", "Captions", "Quality", "HDR", "Sound depth", |
| 329 | ] { |
| 330 | assert!(more.contains(&format!("\"{row}\"")), "Details lost {row}"); |
| 331 | } |
| 332 | // Every list row opens a list of every value; none steps one on per click. |
| 333 | for row in [ |
| 334 | "Container", "Codec", "Seat", "Bitrate", "Size", "Depth", "Profile", "Hdr", "SoundDepth", "Kbps", "Loudness", |
| 335 | "Captions", |
| 336 | ] { |
| 337 | assert!(more.contains(&format!("ExportRow::{row}")), "{row} has no list"); |
| 338 | } |
| 339 | assert!(!more.contains("cycle") && !more.contains("step"), "a Details row steps on click"); |
| 340 | // The footer is outside the scrolling body, so Export is reachable at 720. |
| 341 | let face = fn_body_of("ui/cards/export.rs", "fn sheet_settings"); |
| 342 | assert!(face.contains(".overflow_y_scroll()") && face.contains("sheet_footer("), "{face}"); |
| 343 | assert!(face.find(".overflow_y_scroll()").unwrap() < face.find("sheet_footer(").unwrap()); |
| 344 | assert!(card.contains("fn sheet_footer") && card.contains(".flex_none()")); |
| 345 | // Details start closed, and the size estimate is on the simple layer. |
| 346 | assert!(face.contains("more.then(|| self.sheet_more(cx))")); |
| 347 | assert!(fn_body_of("ui/cards/export.rs", "fn sheet_summary").contains("size_words(size)")); |
| 348 | } |
| 349 | |
| 350 | /// A function's source, from its signature to the next top-level or method item. |
| 351 | fn fn_body_of(file: &str, sig: &str) -> String { |
| 352 | let text = src_text(file); |
| 353 | let at = text.find(sig).unwrap_or_else(|| panic!("{sig} not in {file}")); |
| 354 | let rest = &text[at..]; |
| 355 | let end = ["\n pub(crate) fn ", "\n fn ", "\nfn ", "\npub(crate) fn "] |
| 356 | .iter() |
| 357 | .filter_map(|m| rest[10..].find(m)) |
| 358 | .min() |
| 359 | .map_or(rest.len(), |e| e + 10); |
| 360 | rest[..end].to_string() |
| 361 | } |
| 362 | |
| 363 | #[test] |
| 364 | fn the_warnings_say_upscaling_starved_bitrate_and_a_dropped_picture() { |
| 365 | let ctx = WarnCtx { |
| 366 | format: Format::Mp4, |
| 367 | target: (3840, 2160), |
| 368 | project: (1920, 1080), |
| 369 | fps: 30., |
| 370 | video_bps: 1_000_000, |
| 371 | timeline_has_picture: true, |
| 372 | timeline_has_sound: true, |
| 373 | seconds: 10., |
| 374 | }; |
| 375 | let said = warnings(&ctx).join("\n"); |
| 376 | assert!(said.contains("Stretched up"), "{said}"); |
| 377 | assert!(said.contains("Low bitrate"), "{said}"); |
| 378 | let fine = WarnCtx { target: (1920, 1080), video_bps: 8_000_000, ..ctx }; |
| 379 | assert!(warnings(&fine).is_empty(), "{:?}", warnings(&fine)); |
| 380 | let song = WarnCtx { format: Format::Mp3, ..fine }; |
| 381 | assert!(warnings(&song).join("").contains("picture is left out")); |
| 382 | let empty = WarnCtx { seconds: 0., ..fine }; |
| 383 | assert!(warnings(&empty).join("").contains("nothing to export")); |
| 384 | } |
| 385 | |
| 386 | /// The hard rule: nothing covers the timeline. Export is a dock tab now, in |
| 387 | /// flow beside Media and Clip: the panel has no absolute box of its own and |
| 388 | /// the old centred sheet's rectangle is gone. |
| 389 | #[test] |
| 390 | fn the_export_panel_is_a_dock_tab_in_flow() { |
| 391 | let card = src_text("ui/cards/export.rs"); |
| 392 | let panel = fn_body("export_panel"); |
| 393 | assert!(!panel.contains("absolute()") && !card.contains("SCRIM"), "the panel floats"); |
| 394 | assert!(!src_text("export_ui.rs").contains("fn sheet_rect(")); |
| 395 | let dock = src_text("ui/dock_stance.rs"); |
| 396 | for tab in ["dock-tab-src", "dock-tab-clip", "dock-tab-export"] { |
| 397 | assert!(dock.contains(&format!("\"{tab}\"")), "{tab} is not a tab"); |
| 398 | } |
| 399 | let (src, clip, export) = ( |
| 400 | dock.find("dock_tab(\"dock-tab-src\"").unwrap(), |
| 401 | dock.find("dock_tab(\"dock-tab-clip\"").unwrap(), |
| 402 | dock.find("dock_tab(\"dock-tab-export\"").unwrap(), |
| 403 | ); |
| 404 | assert!(src < clip && clip < export, "tabs are Media | Clip | Export"); |
| 405 | // The full-width primary button is the footer's only control, and the |
| 406 | // settings face has no "More below" fade. |
| 407 | assert!(!card.contains("More below")); |
| 408 | let footer = &card[card.find("fn sheet_footer(").unwrap()..]; |
| 409 | let footer = &footer[..footer.find("\n}\n").unwrap()]; |
| 410 | assert!(footer.contains("\"export-confirm\"") && !footer.contains("export-dismiss")); |
| 411 | } |
| 412 | |
| 413 | #[test] |
| 414 | fn a_preset_row_reads_size_codec_and_rate_on_one_line() { |
| 415 | let p = engine::export_presets::presets() |
| 416 | .iter() |
| 417 | .find(|p| p.target.output == engine::export_presets::Output::Video && p.bitrate.is_some()) |
| 418 | .expect("a video preset with a rate"); |
| 419 | let spec = preset_spec(p, Some((1920, 1080))); |
| 420 | assert!(spec.contains("\u{d7}") && spec.contains(" \u{b7} ") && spec.contains("Mb/s"), "{spec}"); |
| 421 | assert!(!spec.contains('\n')); |
| 422 | } |
| 423 | |
| 424 | /// The sheet's body says when more of it is below: on while the body can |
| 425 | /// still scroll down, off at the end and when it does not scroll at all. |
| 426 | #[test] |
| 427 | fn the_sheet_body_says_more_is_below_until_its_end() { |
| 428 | assert!(more_below_shows(0., 300.)); |
| 429 | assert!(more_below_shows(-150., 300.)); |
| 430 | assert!(!more_below_shows(-300., 300.)); |
| 431 | assert!(!more_below_shows(0., 0.)); |
| 432 | // One fade for both scrolled bodies: the sheet's and the Settings rows'. |
| 433 | for (file, source, track) in [ |
| 434 | ( |
| 435 | "ui/cards/export.rs", |
| 436 | include_str!("../ui/cards/export.rs"), |
| 437 | ".track_scroll(&self.export_body_scroll)", |
| 438 | ), |
| 439 | ( |
| 440 | "ui/settings_stance.rs", |
| 441 | include_str!("../ui/settings_stance.rs"), |
| 442 | ".track_scroll(&player.settings_rows_scroll)", |
| 443 | ), |
| 444 | ] { |
| 445 | assert!(source.contains(track), "{file} lost its tracked scroll"); |
| 446 | assert!( |
| 447 | source.contains("crate::ui::widgets::more_below(") || source.contains("plate_more_below("), |
| 448 | "{file} no longer draws the shared more-below fade" |
| 449 | ); |
| 450 | assert!(!source.contains("fn more_below("), "{file} grew its own copy of the fade"); |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | #[test] |
| 455 | fn keep_both_writes_beside_the_file_and_the_fields_refuse_in_plain_words() { |
| 456 | let taken = |p: &Path| { |
| 457 | [PathBuf::from("/v/film.mp4"), PathBuf::from("/v/film (2).mp4")].contains(&p.to_path_buf()) |
| 458 | }; |
| 459 | assert_eq!(unique_path(Path::new("/v/film.mp4"), taken), PathBuf::from("/v/film (3).mp4")); |
| 460 | assert_eq!(unique_path(Path::new("/v/new.mp4"), taken), PathBuf::from("/v/new.mp4")); |
| 461 | assert_ne!(Overwrite::Replace, Overwrite::KeepBoth); |
| 462 | assert_eq!(parse_stem(" holiday "), Ok("holiday".to_string())); |
| 463 | assert!(parse_stem("").is_err() && parse_stem("a/b").is_err()); |
| 464 | let home = std::env::temp_dir(); |
| 465 | assert_eq!(parse_folder("~", home.to_str()), Ok(home.clone())); |
| 466 | assert_eq!(parse_folder("/no/such/folder/edith", None), Err("That folder does not exist.")); |
| 467 | // The overwrite question's three answers are on the sheet's keys and buttons. |
| 468 | let handler = fn_body("export_moment_key"); |
| 469 | for (key, answer) in [ |
| 470 | ("\"enter\"", "Overwrite::Replace"), |
| 471 | ("\"k\"", "Overwrite::KeepBoth"), |
| 472 | ("ESCAPE", "Overwrite::Cancel"), |
| 473 | ] { |
| 474 | assert!(handler.contains(&format!("{key} => self.answer_overwrite({answer}, cx)"))); |
| 475 | } |
| 476 | } |
| 477 | |
| 478 | #[test] |
| 479 | fn more_settings_starts_closed_and_remembers_being_opened() { |
| 480 | let mut folds = std::collections::BTreeSet::new(); |
| 481 | assert!(!folds.contains(EXPORT_MORE_FOLD), "the disclosure opens closed"); |
| 482 | assert!(toggle_fold(&mut folds, EXPORT_MORE_FOLD)); |
| 483 | let path = std::env::temp_dir().join(format!("edith-folds-{}", std::process::id())); |
| 484 | save_folds_to(&folds, &path); |
| 485 | assert!(load_folds_from(&path).contains(EXPORT_MORE_FOLD)); |
| 486 | assert!(!toggle_fold(&mut folds, EXPORT_MORE_FOLD)); |
| 487 | save_folds_to(&folds, &path); |
| 488 | assert!(!load_folds_from(&path).contains(EXPORT_MORE_FOLD)); |
| 489 | std::fs::remove_file(path).ok(); |
| 490 | } |
| 491 | |
| 492 | /// The trial write that prices the time: software seat only (never Auto or |
| 493 | /// Hardware, whatever the sheet's encoder is set to), a bounded range, a file |
| 494 | /// in the temporary folder, deleted when it lands and when a real export |
| 495 | /// takes over, and started on the engine's worker rather than run here. |
| 496 | #[test] |
| 497 | fn the_timing_trial_is_software_only_temporary_and_cleaned_up() { |
| 498 | for &(format, ..) in SHEET_FORMATS.iter() { |
| 499 | let s = pace_bench_settings(8_000_000, format, 256, Some((1280, 720)), Some(10), 30); |
| 500 | assert_eq!(s.seat, EncoderSeat::Software, "{format:?}"); |
| 501 | assert_eq!(s.range, Some((0, 30))); |
| 502 | let out = pace_bench_path(format); |
| 503 | assert!(out.starts_with(std::env::temp_dir()), "{}", out.display()); |
| 504 | assert_eq!(out.extension().and_then(|e| e.to_str()), Some(format.ext())); |
| 505 | } |
| 506 | let body = fn_body("cache_export_pace"); |
| 507 | assert!(body.contains("pace_bench_settings(") && body.contains("pace_bench_path(")); |
| 508 | assert!(!body.contains("self.encoder_seat()") && !body.contains("EncoderSeat::Auto")); |
| 509 | assert!(body.contains("std::fs::remove_file(out)"), "a landed trial is not deleted"); |
| 510 | assert!(body.contains("session.export_to_with(&out, &settings)")); |
| 511 | let start = fn_body("start_export"); |
| 512 | assert!( |
| 513 | start.contains("bench.handle.cancel()") && start.contains("std::fs::remove_file(&bench.out)"), |
| 514 | "a real export does not stop and delete the trial" |
| 515 | ); |
| 516 | } |
| 517 | |
| 518 | /// The panel's body scrolls with the wheel and the keys (up/down/page/home/ |
| 519 | /// end), and only the dock's Clip-tab frame decides where a card opens. |
| 520 | #[test] |
| 521 | fn the_export_panel_scrolls_by_wheel_and_keys_and_cards_share_one_frame() { |
| 522 | assert!(src_text("ui/cards/export.rs").contains(".track_scroll(&self.export_scroll)")); |
| 523 | let keys = fn_body("export_moment_key"); |
| 524 | for key in ["\"up\"", "\"down\"", "\"pageup\"", "\"pagedown\"", "\"home\"", "\"end\""] { |
| 525 | assert!(keys.contains(&format!("{key} =>")), "{key} does not scroll the panel"); |
| 526 | } |
| 527 | // A card closes back to the Clip list, never to Media; only a docked |
| 528 | // card is in flow; the head has no jargon glyph; label-only tooltips go. |
| 529 | assert!(fn_body("close_card").contains("self.dock_src_active = false")); |
| 530 | let common = src_text("ui/cards/common.rs"); |
| 531 | assert!(!common.contains("fills the room") && !common.contains("card-head-maximize")); |
| 532 | assert!(common.contains(".when(!chord.is_empty(), |d| {")); |
| 533 | assert!(src_text("ui/dock_stance.rs").contains("\"dock-verb-tools\"")); |
| 534 | assert!(!fn_body("toggle_maximize").contains("!self.card_maximized")); |
| 535 | } |
| 536 | |
| 537 | /// A slider's knob sits where its readout says: every colour and transform |
| 538 | /// band maps value to fraction through its own range, neutral values land |
| 539 | /// inside the track (brightness 0 mid-way), and the card rows all use |
| 540 | /// `slider_fraction`, the one mapping. |
| 541 | #[test] |
| 542 | fn a_slider_knob_maps_its_value_through_the_same_range_as_the_readout() { |
| 543 | use crate::transform_ui::*; |
| 544 | use crate::ui::widgets::slider_fraction; |
| 545 | let neutral = engine::color::ColorParams::default(); |
| 546 | for (band, &(_, lo, hi)) in COLOR_BANDS.iter().enumerate() { |
| 547 | let mut p = neutral; |
| 548 | let v = *crate::export_ui::band_mut(&mut p, band); |
| 549 | let at = slider_fraction(v, lo, hi); |
| 550 | assert!((at * (hi - lo) + lo - v).abs() < 1e-5, "band {band}"); |
| 551 | assert!(at > 0. && at < 1., "neutral band {band} sits on a track end"); |
| 552 | assert_eq!(slider_fraction(lo, lo, hi), 0.); |
| 553 | assert_eq!(slider_fraction(hi, lo, hi), 1.); |
| 554 | } |
| 555 | // Every transform slider, rotation included: the neutral placement sits |
| 556 | // inside the track, a signed turn puts 0 degrees mid-track and -90 at a |
| 557 | // quarter, and a drag reads back through the same range the row draws. |
| 558 | let identity = engine::transform::TransformParams::default(); |
| 559 | for band in 0..TRANSFORM_BANDS.len() { |
| 560 | let (lo, hi) = slider_range(band); |
| 561 | let v = *transform_band_mut(&mut identity.clone(), band); |
| 562 | let at = knob_fraction(band, v); |
| 563 | assert!((0.0..=1.0).contains(&at), "band {band}"); |
| 564 | if band == ROTATE_BAND { |
| 565 | assert_eq!(knob_fraction(band, 0.), 0.5); |
| 566 | assert_eq!(knob_fraction(band, 270.), 0.25); |
| 567 | assert_eq!(knob_fraction(band, 90.), 0.75); |
| 568 | } else { |
| 569 | assert_eq!(knob_fraction(band, lo), 0.); |
| 570 | assert_eq!(knob_fraction(band, hi), 1.); |
| 571 | assert!((at * (hi - lo) + lo - v).abs() < 1e-4 || at == 0. || at == 1., "band {band}"); |
| 572 | } |
| 573 | } |
| 574 | assert_eq!(slider_fraction(0., -1., 1.), 0.5); |
| 575 | assert_eq!(slider_fraction(1., 0., 2.), 0.5); |
| 576 | for card in ["color.rs", "transform.rs"] { |
| 577 | let text = src_text(&format!("ui/cards/{card}")); |
| 578 | assert!(text.contains("fraction: slider_fraction(") || text.contains("let fraction = slider_fraction(") || text.contains("fraction: knob_fraction("), "{card}"); |
| 579 | } |
| 580 | // Colour lists all four controls, rotation is one row, and hint text is sans. |
| 581 | assert!(src_text("ui/cards/color.rs").contains("(0..COLOR_BANDS.len())")); |
| 582 | let help = &src_text("ui/cards/common.rs"); |
| 583 | let help = &help[help.find("pub(super) fn dark_help").unwrap()..]; |
| 584 | assert!(!help[..help.find("\n}\n").unwrap()].contains("mono(")); |
| 585 | } |
| 586 | |
| 587 | #[test] |
| 588 | fn an_opus_export_is_called_opus_everywhere_and_never_aac() { |
| 589 | assert_eq!(Format::Opus.ext(), "opus"); |
| 590 | assert_eq!(codec_word(Format::Opus), "Opus"); |
| 591 | assert_eq!(sheet_format_name(Format::Opus), "Opus"); |
| 592 | assert_eq!(format_label(Format::Opus), "Opus"); |
| 593 | assert!(SHEET_FORMATS.iter().any(|(f, ..)| *f == Format::Opus)); |
| 594 | let line = summary_rows(&summary_in(Format::Opus), "")[1].1.clone(); |
| 595 | assert!(line.contains("Opus") && !line.contains("AAC"), "{line}"); |
| 596 | let tile = presets::by_id("podcast_opus").expect("the table has it"); |
| 597 | assert_eq!(tile.format, Format::Opus); |
| 598 | let result = preset_result(tile, None); |
| 599 | assert!(result.contains("Opus") && !result.contains("AAC"), "{result}"); |
| 600 | } |
| 601 | |
| 602 | #[test] |
| 603 | fn match_project_is_the_first_preset_and_custom_waits_for_a_change() { |
| 604 | assert_eq!(preset_box_text(Some(MATCH_PROJECT), None), "Match project"); |
| 605 | assert_eq!(preset_box_text(None, Some(MATCH_PROJECT)), "Custom"); |
| 606 | let now = fn_body_of("player/export.rs", "fn preset_now"); |
| 607 | assert!(now.contains("export_sheet.custom") && now.contains("MATCH_PROJECT") && now.contains("DEFAULT_AUDIO_KBPS")); |
| 608 | let rows = fn_body_of("player/export.rs", "fn export_choices"); |
| 609 | assert!(rows.find("MATCH_PROJECT").unwrap() < rows.find("presets::presets()").unwrap(), "it is not listed first"); |
| 610 | let choose = fn_body_of("player/export.rs", "fn choose_preset"); |
| 611 | assert!(choose.contains("self.custom_bps = 0") && choose.contains("Format::Mp4")); |
| 612 | } |
| 613 | |
| 614 | #[test] |
| 615 | fn the_warning_has_one_reserved_line_and_read_only_rows_are_plain_text() { |
| 616 | let summary = fn_body_of("ui/cards/export.rs", "fn sheet_summary"); |
| 617 | assert!(summary.contains("\"export-warning\"") && summary.contains(".h(px(18.))"), "the warning line is not reserved"); |
| 618 | let said = warnings(&WarnCtx { |
| 619 | format: Format::Mp4, |
| 620 | target: (1920, 1080), |
| 621 | project: (1280, 720), |
| 622 | fps: 25., |
| 623 | video_bps: 8_000_000, |
| 624 | timeline_has_picture: true, |
| 625 | timeline_has_sound: true, |
| 626 | seconds: 2., |
| 627 | }); |
| 628 | assert_eq!(said, vec!["Stretched up from 1280\u{d7}720 \u{2014} won't look sharper".to_string()]); |
| 629 | let more = fn_body_of("ui/cards/export.rs", "fn sheet_more"); |
| 630 | assert!(more.contains("info_note(") && !more.contains("info_box")); |
| 631 | let field = fn_body_of("ui/cards/export.rs", "fn field_row"); |
| 632 | assert!(!field.contains("mono("), "the Name and Folder fields are mono again"); |
| 633 | } |
| 634 | |
| 635 | #[test] |
| 636 | fn a_point_on_the_timeline_is_said_in_plain_seconds() { |
| 637 | use crate::export_ui::point_word; |
| 638 | assert_eq!(point_word(0, 30.), "0 s"); |
| 639 | assert_eq!(point_word(30, 30.), "1 s"); |
| 640 | assert_eq!(point_word(45, 30.), "1.5 s"); |
| 641 | assert_eq!(point_word(30 * 65, 30.), "1 min 5 s"); |
| 642 | } |
| 643 | |
| 644 | #[test] |
| 645 | fn a_clicked_field_keeps_its_text_and_a_tabbed_one_selects_it_all() { |
| 646 | use crate::player::text_field::TextField; |
| 647 | assert!(!TextField::clicked("name").all); |
| 648 | assert!(TextField::tabbed("name").all); |
| 649 | } |
| 650 | |
| 651 | #[test] |
| 652 | fn a_refused_export_name_or_folder_is_never_dropped_by_a_click_elsewhere() { |
| 653 | // The click on Export blurs the fields first: a refused edit must stay open with its note, |
| 654 | // and the export start must take the same edit and refuse to run on the old folder. |
| 655 | let blur = include_str!("../player/blur.rs"); |
| 656 | let body = blur |
| 657 | .split_once("fn blur_text_fields") |
| 658 | .and_then(|(_, rest)| rest.split_once("if self.cue_edit")) |
| 659 | .map(|(body, _)| body) |
| 660 | .expect("blur_text_fields takes the export field first"); |
| 661 | assert!(body.contains("self.commit_field();"), "the typed text is taken"); |
| 662 | assert!(!body.contains("export_sheet.field = None"), "a refused edit is not dropped: {body}"); |
| 663 | assert!(!body.contains("export_sheet.note = None"), "the refusal note stays: {body}"); |
| 664 | let export = include_str!("../player/export.rs"); |
| 665 | let start = export |
| 666 | .split_once("pub(crate) fn start_export") |
| 667 | .map(|(_, rest)| rest) |
| 668 | .expect("start_export exists"); |
| 669 | assert!( |
| 670 | start.split_once("let settings").is_some_and(|(head, _)| head.contains("commit_pending_field()")), |
| 671 | "the export takes the pending edit before anything is written" |
| 672 | ); |
| 673 | } |
| 674 | |
| 675 | /// A typed name is a file under the format's extension, except a numbered run, which is a folder |
| 676 | /// named as typed: `gui_seq`, never `gui_seq.png`. |
| 677 | #[test] |
| 678 | fn a_typed_name_for_a_numbered_run_is_a_folder_without_an_extension() { |
| 679 | assert_eq!(typed_name("gui_seq", Format::PngSequence), "gui_seq"); |
| 680 | assert_eq!(typed_name("take.v2", Format::PngSequence), "take.v2"); |
| 681 | assert_eq!(typed_name("take", Format::Still), "take.png"); |
| 682 | assert_eq!(typed_name("take", Format::Gif), "take.gif"); |
| 683 | } |