| 1 | use super::*; |
| 2 | use crate::expr::ExprEngine; |
| 3 | use std::path::Path; |
| 4 | |
| 5 | pub(super) fn sample_comp() -> Comp { |
| 6 | let src = r#"Composition { |
| 7 | 	CurrentTime = 10, |
| 8 | 	RenderRange = { 0, 100 }, |
| 9 | 	GlobalRange = { 0, 100 }, |
| 10 | 	Prefs = { |
| 11 | 		Comp = { |
| 12 | 			FrameFormat = { |
| 13 | 				Width = 1920, |
| 14 | 				Height = 1080, |
| 15 | 				Rate = 24, |
| 16 | 				DepthFull = 3, |
| 17 | 			}, |
| 18 | 		}, |
| 19 | 	}, |
| 20 | 	Tools = ordered() { |
| 21 | 		BG1 = Background { |
| 22 | 			Inputs = { |
| 23 | 				Width = Input { Value = 1920, }, |
| 24 | 				Height = Input { Value = 1080, }, |
| 25 | 				TopLeftRed = Input { Value = 0.25, }, |
| 26 | 			}, |
| 27 | 			ViewInfo = OperatorInfo { Pos = { 100, 50 } }, |
| 28 | 		}, |
| 29 | 		BC1 = BrightnessContrast { |
| 30 | 			Inputs = { |
| 31 | 				Input = Input { |
| 32 | 					SourceOp = "BG1", |
| 33 | 					Source = "Output", |
| 34 | 				}, |
| 35 | 				Gain = Input { |
| 36 | 					SourceOp = "BC1Gain", |
| 37 | 					Source = "Value", |
| 38 | 				}, |
| 39 | 			}, |
| 40 | 			ViewInfo = OperatorInfo { Pos = { 300, 50 } }, |
| 41 | 		}, |
| 42 | 		BC1Gain = BezierSpline { |
| 43 | 			SplineColor = { Red = 255, Green = 128, Blue = 0 }, |
| 44 | 			KeyFrames = { |
| 45 | 				[0] = { 1, Flags = { Linear = true } }, |
| 46 | 				[30] = { 2, Flags = { Linear = true } }, |
| 47 | 			}, |
| 48 | 		}, |
| 49 | 		SurfaceTracker1 = SurfaceTracker { |
| 50 | 			Inputs = { |
| 51 | 				Source = Input { |
| 52 | 					SourceOp = "BC1", |
| 53 | 					Source = "Output", |
| 54 | 				}, |
| 55 | 				MeshBlob = Input { |
| 56 | 					Value = TrackingMesh { |
| 57 | 						Vertices = { 1, 2, 3 }, |
| 58 | 					}, |
| 59 | 				}, |
| 60 | 			}, |
| 61 | 			ViewInfo = OperatorInfo { Pos = { 500, 50 } }, |
| 62 | 		}, |
| 63 | 	}, |
| 64 | }"#; |
| 65 | Comp::from_fusion_str(src).expect("parse sample comp") |
| 66 | } |
| 67 | |
| 68 | #[test] |
| 69 | fn add_node_naming_and_tool_defaults() { |
| 70 | let mut comp = sample_comp(); |
| 71 | let rev0 = comp.revision; |
| 72 | |
| 73 | let t1 = comp.add_node("Transform", None, [120.0, 200.0]); |
| 74 | let t2 = comp.add_node("Transform", None, [240.0, 200.0]); |
| 75 | assert_eq!(comp.node(t1).name, "Transform1"); |
| 76 | assert_eq!(comp.node(t2).name, "Transform2"); |
| 77 | assert_eq!(comp.node(t1).pos, [120.0, 200.0]); |
| 78 | assert!(comp.revision >= rev0 + 2); |
| 79 | |
| 80 | let h0 = comp.add_node("Background", Some("HeroBG"), [0.0, 0.0]); |
| 81 | let h1 = comp.add_node("Background", Some("HeroBG"), [50.0, 0.0]); |
| 82 | let h2 = comp.add_node("Background", Some("HeroBG"), [100.0, 0.0]); |
| 83 | assert_eq!(comp.node(h0).name, "HeroBG"); |
| 84 | assert_eq!(comp.node(h1).name, "HeroBG_1"); |
| 85 | assert_eq!(comp.node(h2).name, "HeroBG_2"); |
| 86 | |
| 87 | // Cover all common Fusion 21.1 tool categories + generic fallback |
| 88 | let kinds = [ |
| 89 | "Background", |
| 90 | "Merge", |
| 91 | "Transform", |
| 92 | "Blur", |
| 93 | "Glow", |
| 94 | "SoftGlow", |
| 95 | "BrightnessContrast", |
| 96 | "ColorCorrector", |
| 97 | "ColorGain", |
| 98 | "RectangleMask", |
| 99 | "EllipseMask", |
| 100 | "PolylineMask", |
| 101 | "BitmapMask", |
| 102 | "TextPlus", |
| 103 | "Loader", |
| 104 | "Saver", |
| 105 | "Displace", |
| 106 | "FastNoise", |
| 107 | "PipeRouter", |
| 108 | "Switch", |
| 109 | "TimeStretcher", |
| 110 | "TimeSpeed", |
| 111 | "Renderer3D", |
| 112 | "Camera3D", |
| 113 | "Merge3D", |
| 114 | "Transform3D", |
| 115 | "ImagePlane3D", |
| 116 | "Shape3D", |
| 117 | "Note", |
| 118 | "Underlay", |
| 119 | "MyCustomThirdPartyTool", |
| 120 | ]; |
| 121 | for (i, kind) in kinds.iter().enumerate() { |
| 122 | let id = comp.add_node(kind, None, [i as f32 * 50.0, 400.0]); |
| 123 | assert_eq!(comp.node(id).kind, *kind); |
| 124 | assert!(comp.node(id).raw.get_table("ViewInfo").is_some()); |
| 125 | } |
| 126 | |
| 127 | // Roundtrip all newly created nodes cleanly |
| 128 | let s = comp.to_fusion_string(); |
| 129 | let reloaded = Comp::from_fusion_str(&s).expect("roundtrip added nodes"); |
| 130 | assert_eq!(reloaded.nodes.len(), comp.nodes.len()); |
| 131 | assert_eq!( |
| 132 | reloaded.node(reloaded.find_node("HeroBG").unwrap()).static_number("Width"), |
| 133 | Some(1920.0) |
| 134 | ); |
| 135 | } |
| 136 | |
| 137 | #[test] |
| 138 | fn connect_cycle_detection_disconnect_and_splice() { |
| 139 | let mut comp = sample_comp(); |
| 140 | let bg = comp.find_node("BG1").unwrap(); |
| 141 | let bc = comp.find_node("BC1").unwrap(); |
| 142 | let st = comp.find_node("SurfaceTracker1").unwrap(); |
| 143 | |
| 144 | // Self-loop rejected |
| 145 | assert!(comp.connect_output(bg, "Output", bg, "EffectMask").is_err()); |
| 146 | // Direct cycle BG1 -> BC1 -> BG1 rejected |
| 147 | assert!(comp.connect_output(bc, "Output", bg, "EffectMask").is_err()); |
| 148 | // Transitive cycle BG1 -> BC1 -> SurfaceTracker1 -> BG1 rejected |
| 149 | assert!(comp.connect_output(st, "Output", bg, "EffectMask").is_err()); |
| 150 | |
| 151 | // Splice a Blur into BG1 -> BC1.Input |
| 152 | let blur = comp.add_node("Blur", None, [200.0, 50.0]); |
| 153 | comp.splice_node_into_pipe(blur, bg, bc, "Input") |
| 154 | .expect("splice blur"); |
| 155 | assert_eq!(comp.node(blur).connected_node("Input"), Some("BG1")); |
| 156 | assert_eq!(comp.node(bc).connected_node("Input"), Some("Blur1")); |
| 157 | |
| 158 | // Disconnect returns true once, then false |
| 159 | assert!(comp.disconnect(bc, "Input")); |
| 160 | assert!(!comp.disconnect(bc, "Input")); |
| 161 | assert_eq!(comp.node(bc).connected_node("Input"), None); |
| 162 | |
| 163 | // Reconnect and verify roundtrip |
| 164 | comp.connect_output(blur, "Output", bc, "Input") |
| 165 | .expect("reconnect"); |
| 166 | let reloaded = Comp::from_fusion_str(&comp.to_fusion_string()).expect("roundtrip"); |
| 167 | assert_eq!( |
| 168 | reloaded.node(reloaded.find_node("BC1").unwrap()).connected_node("Input"), |
| 169 | Some("Blur1") |
| 170 | ); |
| 171 | } |
| 172 | |
| 173 | #[test] |
| 174 | fn params_expressions_passthrough_pos_and_keyframes() { |
| 175 | let mut comp = sample_comp(); |
| 176 | let bc = comp.find_node("BC1").unwrap(); |
| 177 | |
| 178 | assert!(comp.set_input_value(bc, "Gamma", ParamValue::Number(1.45))); |
| 179 | assert!(comp.set_input_expression(bc, "Brightness", Some("time * 0.01".to_owned()))); |
| 180 | assert!(comp.toggle_passthrough(bc)); |
| 181 | comp.set_node_pos(bc, [333.0, 77.0]); |
| 182 | |
| 183 | // Set keyframe on static input -> creates new BezierSpline and wires it |
| 184 | let sp_name = comp.set_keyframe(bc, "Contrast", 0.0, 0.2).expect("kf 0"); |
| 185 | assert_eq!(sp_name, "BC1Contrast"); |
| 186 | let sp_name2 = comp.set_keyframe(bc, "Contrast", 20.0, 0.8).expect("kf 20"); |
| 187 | assert_eq!(sp_name2, sp_name); |
| 188 | // Update existing keyframe at frame 20 |
| 189 | comp.set_keyframe(bc, "Contrast", 20.0, 0.9).expect("update kf 20"); |
| 190 | assert_eq!(comp.splines[&sp_name].keyframes.len(), 2); |
| 191 | |
| 192 | // Evaluate via Comp::eval_number |
| 193 | let expr = ExprEngine::new(); |
| 194 | let val_mid = comp.eval_number(comp.node(bc), "Contrast", 10.0, 0.0, &expr); |
| 195 | assert!((val_mid - 0.55).abs() < 1e-5, "got {val_mid}"); |
| 196 | |
| 197 | // Delete keyframe |
| 198 | assert!(comp.delete_keyframe(&sp_name, 20.0)); |
| 199 | assert!(!comp.delete_keyframe(&sp_name, 20.0)); |
| 200 | assert_eq!(comp.splines[&sp_name].keyframes.len(), 1); |
| 201 | |
| 202 | // Roundtrip |
| 203 | let reloaded = Comp::from_fusion_str(&comp.to_fusion_string()).expect("roundtrip"); |
| 204 | let r_bc = reloaded.node(reloaded.find_node("BC1").unwrap()); |
| 205 | assert!(r_bc.bypassed); |
| 206 | assert_eq!(r_bc.pos, [333.0, 77.0]); |
| 207 | assert_eq!(r_bc.static_number("Gamma"), Some(1.45)); |
| 208 | assert_eq!( |
| 209 | r_bc.inputs.get("Brightness").and_then(|b| b.expression.as_deref()), |
| 210 | Some("time * 0.01") |
| 211 | ); |
| 212 | assert_eq!(r_bc.connected_node("Contrast"), Some("BC1Contrast")); |
| 213 | assert_eq!(reloaded.splines["BC1Contrast"].keyframes.len(), 1); |
| 214 | |
| 215 | // Clear expression and un-bypass |
| 216 | assert!(comp.set_input_expression(bc, "Brightness", None)); |
| 217 | assert!(!comp.toggle_passthrough(bc)); |
| 218 | let reloaded2 = Comp::from_fusion_str(&comp.to_fusion_string()).expect("roundtrip 2"); |
| 219 | let r_bc2 = reloaded2.node(reloaded2.find_node("BC1").unwrap()); |
| 220 | assert!(!r_bc2.bypassed); |
| 221 | assert_eq!( |
| 222 | r_bc2.inputs.get("Brightness").and_then(|b| b.expression.as_deref()), |
| 223 | None |
| 224 | ); |
| 225 | } |
| 226 | |
| 227 | #[test] |
| 228 | fn rename_duplicate_and_delete_nodes_roundtrip() { |
| 229 | let mut comp = sample_comp(); |
| 230 | let bg = comp.find_node("BG1").unwrap(); |
| 231 | let bc = comp.find_node("BC1").unwrap(); |
| 232 | |
| 233 | // Rename validation |
| 234 | assert!(comp.rename_node(bg, "").is_err()); |
| 235 | assert!(comp.rename_node(bg, "123Bad").is_err()); |
| 236 | assert!(comp.rename_node(bg, "function").is_err()); |
| 237 | assert!(comp.rename_node(bg, "BC1").is_err()); |
| 238 | |
| 239 | // Rename BG1 -> PlateBG and verify BC1.Input SourceOp is rewritten |
| 240 | let new_name = comp.rename_node(bg, "PlateBG").expect("rename BG1"); |
| 241 | assert_eq!(new_name, "PlateBG"); |
| 242 | assert!(comp.find_node("BG1").is_none()); |
| 243 | assert_eq!(comp.find_node("PlateBG"), Some(bg)); |
| 244 | assert_eq!(comp.node(bc).connected_node("Input"), Some("PlateBG")); |
| 245 | |
| 246 | // Duplicate [PlateBG, BC1] together -> internal wire preserved, BC1Gain spline cloned |
| 247 | let dups = comp.duplicate_nodes(&[bg, bc], [0.0, 150.0]); |
| 248 | assert_eq!(dups.len(), 2); |
| 249 | let dup_bg = dups[0]; |
| 250 | let dup_bc = dups[1]; |
| 251 | assert_eq!(comp.node(dup_bg).name, "PlateBG_1"); |
| 252 | assert_eq!(comp.node(dup_bc).name, "BC1_1"); |
| 253 | assert_eq!(comp.node(dup_bg).pos, [100.0, 200.0]); |
| 254 | assert_eq!(comp.node(dup_bc).connected_node("Input"), Some("PlateBG_1")); |
| 255 | let dup_gain_spline = comp.node(dup_bc).connected_node("Gain").unwrap().to_owned(); |
| 256 | assert_ne!(dup_gain_spline, "BC1Gain"); |
| 257 | assert!(comp.splines.contains_key(&dup_gain_spline)); |
| 258 | |
| 259 | // Share BC1Gain with dup_bg (artificial) vs exclusive spline on dup_bc: |
| 260 | // Deleting dup_bc should prune `dup_gain_spline` while leaving `BC1Gain` intact. |
| 261 | let deleted = comp.delete_nodes(&[dup_bc]); |
| 262 | assert_eq!(deleted, vec!["BC1_1".to_owned()]); |
| 263 | assert!(!comp.splines.contains_key(&dup_gain_spline)); |
| 264 | assert!(comp.splines.contains_key("BC1Gain")); |
| 265 | |
| 266 | // Delete BC1 -> SurfaceTracker1.Source unwired, BC1Gain pruned, NodeId indices compact |
| 267 | let bc_now = comp.find_node("BC1").unwrap(); |
| 268 | let del2 = comp.delete_nodes(&[bc_now]); |
| 269 | assert_eq!(del2, vec!["BC1".to_owned()]); |
| 270 | assert!(!comp.splines.contains_key("BC1Gain")); |
| 271 | for (idx, n) in comp.nodes.iter().enumerate() { |
| 272 | assert_eq!(n.id, NodeId(idx)); |
| 273 | assert_eq!(comp.find_node(&n.name), Some(NodeId(idx))); |
| 274 | } |
| 275 | let st_now = comp.find_node("SurfaceTracker1").unwrap(); |
| 276 | assert_eq!(comp.node(st_now).connected_node("Source"), None); |
| 277 | |
| 278 | // Full roundtrip preserves unknown SurfaceTracker1 verbatim + all structural mutations |
| 279 | let reloaded = Comp::from_fusion_str(&comp.to_fusion_string()).expect("roundtrip"); |
| 280 | assert!(reloaded.find_node("PlateBG").is_some()); |
| 281 | assert!(reloaded.find_node("PlateBG_1").is_some()); |
| 282 | assert!(reloaded.find_node("BC1").is_none()); |
| 283 | assert!(reloaded.find_node("SurfaceTracker1").is_some()); |
| 284 | assert!(!reloaded.splines.contains_key("BC1Gain")); |
| 285 | let r_st = reloaded.node(reloaded.find_node("SurfaceTracker1").unwrap()); |
| 286 | assert_eq!(r_st.connected_node("Source"), None); |
| 287 | assert!( |
| 288 | r_st.raw |
| 289 | .get_table("Inputs") |
| 290 | .and_then(|i| i.get_table("MeshBlob")) |
| 291 | .is_some() |
| 292 | ); |
| 293 | } |
| 294 | |
| 295 | #[test] |
| 296 | fn roundtrip_mutations_on_real_20_falling_comp() { |
| 297 | let path = Path::new("/Volumes/Project/trees/fusion/20_falling.comp"); |
| 298 | if !path.exists() { |
| 299 | return; |
| 300 | } |
| 301 | let mut comp = Comp::from_fusion_file(path).expect("load 20_falling.comp"); |
| 302 | let orig_count = comp.nodes.len(); |
| 303 | |
| 304 | let blur = comp.add_node("Blur", Some("TestGlowBlur"), [1000.0, -500.0]); |
| 305 | let merge19 = comp.find_node("Merge19").expect("Merge19"); |
| 306 | comp.set_input_value(blur, "XBlurSize", ParamValue::Number(4.5)); |
| 307 | comp.set_input_expression(blur, "YBlurSize", Some("XBlurSize * 2".to_owned())); |
| 308 | comp.toggle_passthrough(blur); |
| 309 | let sp = comp |
| 310 | .set_keyframe(blur, "Blend", 2200.0, 0.5) |
| 311 | .expect("keyframe blend"); |
| 312 | comp.set_keyframe(blur, "Blend", 2250.0, 1.0) |
| 313 | .expect("keyframe blend 2"); |
| 314 | comp.connect_output(merge19, "Output", blur, "Input") |
| 315 | .expect("connect Merge19 -> blur"); |
| 316 | comp.rename_node(blur, "TestGlowBlurRenamed") |
| 317 | .expect("rename blur"); |
| 318 | |
| 319 | let serialized = comp.to_fusion_string(); |
| 320 | let reloaded = Comp::from_fusion_str(&serialized).expect("re-parse mutated 20_falling"); |
| 321 | assert_eq!(reloaded.nodes.len(), orig_count + 1); |
| 322 | let r_blur_id = reloaded |
| 323 | .find_node("TestGlowBlurRenamed") |
| 324 | .expect("TestGlowBlurRenamed"); |
| 325 | let r_blur = reloaded.node(r_blur_id); |
| 326 | assert!(r_blur.bypassed); |
| 327 | assert_eq!(r_blur.connected_node("Input"), Some("Merge19")); |
| 328 | assert_eq!(r_blur.static_number("XBlurSize"), Some(4.5)); |
| 329 | assert_eq!( |
| 330 | r_blur.inputs.get("YBlurSize").and_then(|b| b.expression.as_deref()), |
| 331 | Some("XBlurSize * 2") |
| 332 | ); |
| 333 | assert_eq!(reloaded.splines[&sp].keyframes.len(), 2); |
| 334 | } |
| 335 | |
| 336 | pub(super) const GROUP_SNIPPET: &str = r#"{ |
| 337 | 	Tools = ordered() { |
| 338 | 		Group1 = GroupOperator { |
| 339 | 			Inputs = { |
| 340 | 				Input1 = InstanceInput { SourceOp = "Inner1", Source = "Input", }, |
| 341 | 			}, |
| 342 | 			Outputs = { |
| 343 | 				Output1 = InstanceOutput { SourceOp = "Inner1", Source = "Output", }, |
| 344 | 			}, |
| 345 | 			ViewInfo = GroupInfo { Pos = { 10, 20 } }, |
| 346 | 			Tools = ordered() { |
| 347 | 				Inner1 = Blur { |
| 348 | 					Inputs = { |
| 349 | 						XBlurSize = Input { SourceOp = "Inner1Size", Source = "Value", }, |
| 350 | 					}, |
| 351 | 					ViewInfo = OperatorInfo { Pos = { 0, 0 } }, |
| 352 | 				}, |
| 353 | 				Inner1Size = BezierSpline { |
| 354 | 					KeyFrames = { [0] = { 1, Flags = { Linear = true } } }, |
| 355 | 				}, |
| 356 | 			}, |
| 357 | 		}, |
| 358 | 	}, |
| 359 | }"#; |
| 360 | |
| 361 | #[test] |
| 362 | fn rename_rewrites_inline_input_expressions() { |
| 363 | let src = r#"Composition { Tools = ordered() { |
| 364 | Blur1 = Blur { Inputs = { XBlurSize = Input { Value = 4, }, }, }, |
| 365 | T1 = Transform { Inputs = { Size = Input { Expression = "Blur1.XBlurSize * 2", }, }, }, |
| 366 | } }"#; |
| 367 | let mut comp = Comp::from_fusion_str(src).unwrap(); |
| 368 | let engine = ExprEngine::new(); |
| 369 | let size = |c: &Comp| c.eval_number(c.node(c.find_node("T1").unwrap()), "Size", 0.0, -1.0, &engine); |
| 370 | assert_eq!(size(&comp), 8.0); |
| 371 | |
| 372 | let blur = comp.find_node("Blur1").unwrap(); |
| 373 | comp.rename_node(blur, "Soft").unwrap(); |
| 374 | let expression = |c: &Comp| { |
| 375 | c.node(c.find_node("T1").unwrap()).inputs["Size"].expression.clone() |
| 376 | }; |
| 377 | assert_eq!(expression(&comp).as_deref(), Some("Soft.XBlurSize * 2")); |
| 378 | assert_eq!(size(&comp), 8.0); |
| 379 | |
| 380 | let text = comp.to_fusion_string(); |
| 381 | assert!(!text.contains("Blur1"), "{text}"); |
| 382 | let saved = Comp::from_fusion_str(&text).unwrap(); |
| 383 | assert_eq!(expression(&saved).as_deref(), Some("Soft.XBlurSize * 2")); |
| 384 | assert_eq!(size(&saved), 8.0); |
| 385 | } |
| 386 | |
| 387 | const SHADOWED_GROUP: &str = r#"Composition { Tools = ordered() { |
| 388 | Blur1 = Blur { }, |
| 389 | C = Transform { Inputs = { Input = Input { SourceOp = "Blur1", Source = "Output", }, }, }, |
| 390 | Group1 = GroupOperator { |
| 391 | Outputs = { MainOutput1 = InstanceOutput { SourceOp = "T", Source = "Output", }, }, |
| 392 | Tools = ordered() { |
| 393 | Blur1 = Blur { }, |
| 394 | T = Transform { Inputs = { Input = Input { SourceOp = "Blur1", Source = "Output", }, }, }, |
| 395 | }, |
| 396 | }, |
| 397 | } }"#; |
| 398 | |
| 399 | #[test] |
| 400 | fn deleting_a_group_keeps_same_named_top_level_tools_and_wires() { |
| 401 | let mut comp = Comp::from_fusion_str(SHADOWED_GROUP).unwrap(); |
| 402 | comp.delete_nodes(&[comp.find_node("Group1").unwrap()]); |
| 403 | assert!(comp.find_node("T").is_none()); |
| 404 | let c = comp.node(comp.find_node("C").unwrap()); |
| 405 | assert_eq!(c.connected_node("Input"), Some("Blur1")); |
| 406 | |
| 407 | let saved = Comp::from_fusion_str(&comp.to_fusion_string()).unwrap(); |
| 408 | assert!(saved.find_node("Blur1").is_some()); |
| 409 | assert_eq!(saved.node(saved.find_node("C").unwrap()).connected_node("Input"), Some("Blur1")); |
| 410 | } |
| 411 | |
| 412 | #[test] |
| 413 | fn deleting_a_private_tool_only_unwires_its_own_group() { |
| 414 | let mut comp = Comp::from_fusion_str(SHADOWED_GROUP).unwrap(); |
| 415 | let private = comp.nodes.iter().find(|n| n.internal && n.name == "Blur1").unwrap().id; |
| 416 | comp.delete_nodes(&[private]); |
| 417 | let (c, t) = (comp.find_node("C").unwrap(), comp.find_node("T").unwrap()); |
| 418 | assert_eq!(comp.node(c).connected_node("Input"), Some("Blur1")); |
| 419 | assert_eq!(comp.node(t).connected_node("Input"), None); |
| 420 | |
| 421 | let saved = Comp::from_fusion_str(&comp.to_fusion_string()).unwrap(); |
| 422 | assert_eq!(saved.nodes.iter().filter(|n| n.name == "Blur1").count(), 1); |
| 423 | assert_eq!(saved.node(saved.find_node("C").unwrap()).connected_node("Input"), Some("Blur1")); |
| 424 | } |
| 425 | |
| 426 | #[test] |
| 427 | fn default_ports_and_tool_defaults_match_the_engine() { |
| 428 | for (kind, port) in [ |
| 429 | ("Merge", "Background"), |
| 430 | ("Dissolve", "Background"), |
| 431 | ("ChannelBoolean", "Background"), |
| 432 | ("BitmapMask", "Image"), |
| 433 | ("Switch", "Input0"), |
| 434 | ("Fuse.Switch", "Input1"), |
| 435 | ("Merge3D", "SceneInput1"), |
| 436 | ("Renderer3D", "SceneInput"), |
| 437 | ("Duplicate3D", "SceneInput"), |
| 438 | ("ImagePlane3D", "MaterialInput"), |
| 439 | ("TextureTransformOperator", "MaterialInput"), |
| 440 | ("Fuse.Outline", "Image"), |
| 441 | ("Custom", "Image1"), |
| 442 | ("GroupOperator", "MainInput1"), |
| 443 | ("Blur", "Input"), |
| 444 | ] { |
| 445 | assert_eq!(default_main_input_port(kind), port, "{kind}"); |
| 446 | } |
| 447 | let defaults = |kind| defaults::default_inputs_for_kind(kind, 1920, 1080); |
| 448 | let has = |kind, key: &str, v: ParamValue| defaults(kind).contains(&(key.to_owned(), v)); |
| 449 | assert!(has("Fuse.Switch", "Which", ParamValue::Number(1.0))); |
| 450 | assert!(has("Switch", "Source", ParamValue::Number(0.0))); |
| 451 | assert!(has("Camera3D", "FLength", ParamValue::Number(35.0))); |
| 452 | assert!(has("TimeStretcher", "InterpolateBetweenFrames", ParamValue::Number(1.0))); |
| 453 | assert!(has("Displace", "RefractionStrength", ParamValue::Number(0.05))); |
| 454 | assert!(has("TextPlus", "Font", ParamValue::Text("Helvetica Neue".into()))); |
| 455 | assert!(has("TextPlus", "Style", ParamValue::Text("Regular".into()))); |
| 456 | assert!(has("SoftGlow", "Filter", ParamValue::FuId("Gaussian".into()))); |
| 457 | } |