use super::super::{BuildError, file, mono_script};
use super::{AtlasScene, Built, CutOptions, by_name, one, plain, rgba, scene};
use crate::env::bundle;
fn broken_bundle() -> Vec<u8> {
let mut b = bundle(&[("CAB-n", vec![0; 64])]);
b.truncate(48);
b
}
fn cab(id: &str) -> Result<Vec<u8>, BuildError> {
file(
&[],
&[
mono_script(1, "NGUIAtlas"),
rgba(2, id, 0xF0, 1, 1),
by_name(3, id, vec![plain("s", (0, 0, 1, 1))]),
],
true,
)
}
pub fn member_fails() -> Built {
Ok(scene(
vec![
one("x.bundle", &[("CAB-x", cab("x")?)], &["d.bundle"]),
super::SceneBundle {
id: "d.bundle".to_owned(),
data: broken_bundle(),
deps: Vec::new(),
},
],
&["x.bundle"],
CutOptions::default(),
))
}
pub fn member_not_a_bundle() -> Built {
Ok(scene(
vec![
one("x.bundle", &[("CAB-x", cab("x")?)], &["d.bundle"]),
super::SceneBundle {
id: "d.bundle".to_owned(),
data: cab("d")?,
deps: Vec::new(),
},
],
&["x.bundle"],
CutOptions::default(),
))
}
pub fn input_not_a_bundle() -> Built {
Ok(scene(
vec![super::SceneBundle {
id: "x.bundle".to_owned(),
data: cab("x")?,
deps: Vec::new(),
}],
&["x.bundle"],
CutOptions::default(),
))
}
pub fn reach_fails() -> Built {
Ok(scene(
vec![one(
"x.bundle",
&[("CAB-x", cab("x")?), ("CAB-n", broken_bundle())],
&[],
)],
&["x.bundle"],
CutOptions::default(),
))
}
pub fn selection_fails() -> Built {
Ok(scene(
vec![one(
"x.bundle",
&[
("CAB-x", cab("x")?),
("CAB-n", broken_bundle()),
("CAB-n", b"raw bytes".to_vec()),
],
&[],
)],
&["x.bundle"],
CutOptions::default(),
))
}
pub fn failure_scenes() -> Result<Vec<(&'static str, AtlasScene)>, BuildError> {
let all: [(&'static str, super::Make); 5] = [
("member_fails", member_fails),
("member_not_a_bundle", member_not_a_bundle),
("input_not_a_bundle", input_not_a_bundle),
("reach_fails", reach_fails),
("selection_fails", selection_fails),
];
all.into_iter().map(|(name, f)| Ok((name, f()?))).collect()
}