-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(fms): 🐛 invalid embed of image assets (#132)
* fix(fms): 🐛 invalid embed of image assets * test: 💍 add a regression test
- Loading branch information
Showing
2 changed files
with
95 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,118 @@ | ||
#[cfg(test)] | ||
#[test] | ||
fn get_animation_test() { | ||
use std::{fs::File, io::Read}; | ||
mod tests { | ||
#[test] | ||
fn get_animation_test() { | ||
use std::{fs::File, io::Read}; | ||
|
||
use crate::get_animation; | ||
use crate::get_animation; | ||
|
||
let file_path = format!( | ||
"{}{}", | ||
env!("CARGO_MANIFEST_DIR"), | ||
"/src/tests/resources/emoji-collection.lottie" | ||
); | ||
let file_path = format!( | ||
"{}{}", | ||
env!("CARGO_MANIFEST_DIR"), | ||
"/src/tests/resources/emoji-collection.lottie" | ||
); | ||
|
||
let mut animation_file = File::open(file_path).unwrap(); | ||
let mut buffer = Vec::new(); | ||
let mut animation_file = File::open(file_path).unwrap(); | ||
let mut buffer = Vec::new(); | ||
|
||
animation_file.read_to_end(&mut buffer).unwrap(); | ||
animation_file.read_to_end(&mut buffer).unwrap(); | ||
|
||
let animation = get_animation(&buffer, "anger").unwrap(); | ||
let animation = get_animation(&buffer, "anger").unwrap(); | ||
|
||
assert_eq!(animation.contains("ADBE Vector Graphic - Stroke"), true); | ||
} | ||
assert_eq!(animation.contains("ADBE Vector Graphic - Stroke"), true); | ||
} | ||
|
||
#[test] | ||
fn get_animations_test() { | ||
use std::{fs::File, io::Read}; | ||
#[test] | ||
fn get_animations_test() { | ||
use std::{fs::File, io::Read}; | ||
|
||
let file_path = format!( | ||
"{}{}", | ||
env!("CARGO_MANIFEST_DIR"), | ||
"/src/tests/resources/emoji-collection.lottie" | ||
); | ||
let file_path = format!( | ||
"{}{}", | ||
env!("CARGO_MANIFEST_DIR"), | ||
"/src/tests/resources/emoji-collection.lottie" | ||
); | ||
|
||
let mut animation_file = File::open(file_path).unwrap(); | ||
let mut buffer = Vec::new(); | ||
let mut animation_file = File::open(file_path).unwrap(); | ||
let mut buffer = Vec::new(); | ||
|
||
animation_file.read_to_end(&mut buffer).unwrap(); | ||
animation_file.read_to_end(&mut buffer).unwrap(); | ||
|
||
let animation = crate::get_animations(&buffer).unwrap(); | ||
let animation = crate::get_animations(&buffer).unwrap(); | ||
|
||
assert_eq!(animation.len(), 62); | ||
assert_eq!(animation.len(), 62); | ||
|
||
assert_eq!(animation[0].id, "anger"); | ||
assert_eq!(animation[5].id, "confused"); | ||
} | ||
assert_eq!(animation[0].id, "anger"); | ||
assert_eq!(animation[5].id, "confused"); | ||
} | ||
|
||
#[test] | ||
fn get_manifest_test() { | ||
use std::{fs::File, io::Read}; | ||
|
||
let file_path = format!( | ||
"{}{}", | ||
env!("CARGO_MANIFEST_DIR"), | ||
"/src/tests/resources/emoji-collection.lottie" | ||
); | ||
|
||
let mut animation_file = File::open(file_path).unwrap(); | ||
let mut buffer = Vec::new(); | ||
|
||
animation_file.read_to_end(&mut buffer).unwrap(); | ||
|
||
let manifest = crate::get_manifest(&buffer).unwrap(); | ||
|
||
// First and last animations | ||
let first_animation_lock = manifest.animations; | ||
|
||
let first_animation = first_animation_lock.first().unwrap(); | ||
|
||
#[test] | ||
fn get_manifest_test() { | ||
use std::{fs::File, io::Read}; | ||
assert_eq!(first_animation.id == "anger", true); | ||
|
||
let file_path = format!( | ||
"{}{}", | ||
env!("CARGO_MANIFEST_DIR"), | ||
"/src/tests/resources/emoji-collection.lottie" | ||
); | ||
let last_animation = first_animation_lock.last().unwrap(); | ||
|
||
let mut animation_file = File::open(file_path).unwrap(); | ||
let mut buffer = Vec::new(); | ||
assert_eq!(last_animation.id == "yummy", true); | ||
} | ||
|
||
animation_file.read_to_end(&mut buffer).unwrap(); | ||
#[test] | ||
fn get_animation_with_image_assets_test() { | ||
let dotlottie_bytes = &include_bytes!("../resources/bull.lottie").to_vec(); | ||
let animation_name = "animation_1"; | ||
|
||
let manifest = crate::get_manifest(&buffer).unwrap(); | ||
let lottie_string = crate::get_animation(&dotlottie_bytes, animation_name) | ||
.expect("Failed to get animation from lottie bytes"); | ||
|
||
// First and last animations | ||
let first_animation_lock = manifest.animations; | ||
let lottie_json = | ||
jzon::parse(&lottie_string).expect("Failed to parse lottie string to JSON"); | ||
|
||
let first_animation = first_animation_lock.first().unwrap(); | ||
let assets = lottie_json["assets"] | ||
.as_array() | ||
.expect("Expected assets to be an array"); | ||
|
||
assert_eq!(first_animation.id == "anger", true); | ||
for asset in assets { | ||
assert_eq!( | ||
asset["e"] | ||
.as_i64() | ||
.expect("Expected embed property to be an integer"), | ||
1, | ||
"Expected asset to be embedded with 'e' set to 1" | ||
); | ||
|
||
let last_animation = first_animation_lock.last().unwrap(); | ||
assert!( | ||
asset["u"] | ||
.as_str() | ||
.expect("Expected asset URL ('u') to be a string") | ||
.is_empty(), | ||
"Expected asset URL ('u') to be empty" | ||
); | ||
|
||
assert_eq!(last_animation.id == "yummy", true); | ||
assert!( | ||
asset["p"] | ||
.as_str() | ||
.expect("Expected asset path ('p') to be a string") | ||
.starts_with("data:image/"), | ||
"Expected asset path ('p') to be a data URL starting with 'data:image/'" | ||
); | ||
} | ||
} | ||
} |