test(assets): implement end-to-end asset manager and mod overlay streaming test
This commit is contained in:
parent
4850bade6b
commit
bf3b3d84c8
1 changed files with 28 additions and 0 deletions
28
crates/molotov-core/tests/asset_manager_test.rs
Normal file
28
crates/molotov-core/tests/asset_manager_test.rs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
use molotov_core::assets::c_api::*;
|
||||
use std::ffi::CString;
|
||||
|
||||
#[test]
|
||||
fn test_end_to_end_asset_and_mod_overlay_streaming() {
|
||||
// Register base asset and mod override
|
||||
let mgr_handle = register_test_asset("content/fonts/arial.ttf", b"DEFAULT_FONT_DATA".to_vec());
|
||||
if let Ok(mut mgr) = GLOBAL_ASSET_MANAGER.write() {
|
||||
mgr.add_mod_override("content/fonts/arial.ttf", b"CUSTOM_COMIC_SANS_MOD".to_vec());
|
||||
}
|
||||
|
||||
unsafe {
|
||||
let path = CString::new("content/fonts/arial.ttf").unwrap();
|
||||
let asset = AAssetManager_open(mgr_handle, path.as_ptr(), 1);
|
||||
assert!(!asset.is_null());
|
||||
|
||||
let len = AAsset_getLength(asset);
|
||||
assert_eq!(len, 21);
|
||||
|
||||
let mut out = vec![0u8; len as usize];
|
||||
let read = AAsset_read(asset, out.as_mut_ptr() as *mut _, len as usize);
|
||||
assert_eq!(read, 21);
|
||||
assert_eq!(&out, b"CUSTOM_COMIC_SANS_MOD", "Must load custom user mod");
|
||||
|
||||
AAsset_close(asset);
|
||||
}
|
||||
}
|
||||
Reference in a new issue