Skip to content

Commit

Permalink
test: 💍 dotlottie_player_core integration tests (#112)
Browse files Browse the repository at this point in the history
* test: 💍 dotlottie_player_core integration tests

* chore: 🤖 include "make test" in Makefile help

* chore: 🤖 improve assertion style
  • Loading branch information
theashraf authored Apr 4, 2024
1 parent 8aa3605 commit bd2f45b
Show file tree
Hide file tree
Showing 21 changed files with 3,265 additions and 181 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/check-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ jobs:
env:
APPLE_MACOSX_SDK: MacOSX13
run: make demo-player
- name: Run Tests
run: make test
10 changes: 10 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[workspace]

resolver = "2"

members = [
"demo-player",
"dotlottie-rs",
"dotlottie-fms",
"dotlottie-ffi"
]
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,14 @@ mac-setup: export UNIFFI_BINDGEN_CPP_VERSION:= $(UNIFFI_BINDGEN_CPP_VERSION)
mac-setup:
@./.$@.sh

.PHONY: test
test: test-all

.PHONY: test-all
test-all:
$(info $(YELLOW)Running tests for workspace$(NC))
cargo test -- --test-threads=1

.PHONY: help
help:
@echo "Welcome to the $(GREEN)dotlottie-player$(NC) build system!"
Expand Down Expand Up @@ -962,5 +970,6 @@ help:
@echo " - $(YELLOW)clean-deps$(NC) - clean up all native dependency builds & artifacts"
@echo " - $(YELLOW)clean-build$(NC) - clean up any extraneous build files (useful for ensuring a clean working directory)"
@echo " - $(YELLOW)distclean$(NC) - clean up everything"
@echo " - $(YELLOW)test$(NC) - run all tests"
@echo
@echo
6 changes: 3 additions & 3 deletions dotlottie-fms/src/dolottie_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ impl DotLottieManager {
}
}

pub fn init(&mut self, dotlottie: Vec<u8>) -> Result<bool, DotLottieError> {
pub fn init(&mut self, dotlottie: &[u8]) -> Result<bool, DotLottieError> {
// Initialize the manager with the dotLottie file
let manifest = get_manifest(&dotlottie);
let manifest = get_manifest(dotlottie);

match manifest {
Ok(manifest) => {
Expand All @@ -70,7 +70,7 @@ impl DotLottieManager {

self.active_animation_id = id;
self.manifest = manifest;
self.zip_data = dotlottie;
self.zip_data = dotlottie.to_vec();

return Ok(true);
}
Expand Down
2 changes: 1 addition & 1 deletion dotlottie-fms/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ pub fn get_animations(bytes: &Vec<u8>) -> Result<Vec<AnimationContainer>, DotLot
///
/// bytes: The bytes of the dotLottie file
/// Result<Manifest, DotLottieError>: The extracted manifest, or an error
pub fn get_manifest(bytes: &Vec<u8>) -> Result<Manifest, DotLottieError> {
pub fn get_manifest(bytes: &[u8]) -> Result<Manifest, DotLottieError> {
let mut archive =
ZipArchive::new(io::Cursor::new(bytes)).map_err(|_| DotLottieError::ArchiveOpenError)?;

Expand Down
44 changes: 36 additions & 8 deletions dotlottie-rs/src/dotlottie_player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub enum PlaybackState {
Stopped,
}

#[derive(Clone, Copy, PartialEq)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Mode {
Forward,
Reverse,
Expand Down Expand Up @@ -67,6 +67,22 @@ pub struct Config {
pub marker: String,
}

impl Default for Config {
fn default() -> Self {
Config {
mode: Mode::Forward,
loop_animation: false,
speed: 1.0,
use_frame_interpolation: true,
autoplay: false,
segment: vec![],
background_color: 0x00000000,
layout: Layout::default(),
marker: String::new(),
}
}
}

struct DotLottieRuntime {
renderer: LottieRenderer,
playback_state: PlaybackState,
Expand Down Expand Up @@ -587,10 +603,6 @@ impl DotLottieRuntime {
}
}

if self.config.autoplay && loaded {
self.play();
}

loaded
}

Expand All @@ -613,8 +625,8 @@ impl DotLottieRuntime {
}
}

pub fn load_dotlottie_data(&mut self, file_data: &Vec<u8>, width: u32, height: u32) -> bool {
if self.dotlottie_manager.init(file_data.clone()).is_err() {
pub fn load_dotlottie_data(&mut self, file_data: &[u8], width: u32, height: u32) -> bool {
if self.dotlottie_manager.init(file_data).is_err() {
return false;
}

Expand Down Expand Up @@ -768,6 +780,10 @@ impl DotLottiePlayer {
self.observers.read().unwrap().iter().for_each(|observer| {
observer.on_load();
});

if self.config().autoplay {
self.play();
}
} else {
self.observers.read().unwrap().iter().for_each(|observer| {
observer.on_load_error();
Expand All @@ -789,6 +805,10 @@ impl DotLottiePlayer {
self.observers.read().unwrap().iter().for_each(|observer| {
observer.on_load();
});

if self.config().autoplay {
self.play();
}
} else {
self.observers.read().unwrap().iter().for_each(|observer| {
observer.on_load_error();
Expand All @@ -800,7 +820,7 @@ impl DotLottiePlayer {
is_ok
}

pub fn load_dotlottie_data(&self, file_data: &Vec<u8>, width: u32, height: u32) -> bool {
pub fn load_dotlottie_data(&self, file_data: &[u8], width: u32, height: u32) -> bool {
let is_ok = self
.runtime
.write()
Expand All @@ -810,6 +830,10 @@ impl DotLottiePlayer {
self.observers.read().unwrap().iter().for_each(|observer| {
observer.on_load();
});

if self.config().autoplay {
self.play();
}
} else {
self.observers.read().unwrap().iter().for_each(|observer| {
observer.on_load_error();
Expand All @@ -831,6 +855,10 @@ impl DotLottiePlayer {
self.observers.read().unwrap().iter().for_each(|observer| {
observer.on_load();
});

if self.config().autoplay {
self.play();
}
} else {
self.observers.read().unwrap().iter().for_each(|observer| {
observer.on_load_error();
Expand Down
2 changes: 0 additions & 2 deletions dotlottie-rs/src/lottie_renderer/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use thiserror::Error;

mod tests;

use crate::{Animation, Canvas, Layout, Shape, TvgColorspace, TvgEngine, TvgError};

#[derive(Error, Debug)]
Expand Down
167 changes: 0 additions & 167 deletions dotlottie-rs/src/lottie_renderer/tests.rs

This file was deleted.

Binary file added dotlottie-rs/tests/assets/emoji.lottie
Binary file not shown.
Loading

0 comments on commit bd2f45b

Please sign in to comment.