Files
breeze/tests/apps_test_fixture.zi
T

54 lines
1.9 KiB
Ziran

#import "byte_text_linux"
#import, file "storage_test_support.zi";
#import, file "../src/app/app_types.zi";
#import, file "../src/apps/shared_state.zi";
#import, file "../src/apps/module_host.zi";
bundle_data: *void;
libc :: #system_library "c";
TestBundleFileOpen :: (path: *u8, mode: *u8) -> *void #foreign libc "fopen";
TestBundleFileClose :: (file: *void) -> s32 #foreign libc "fclose";
TestBundleFileSeek :: (file: *void, offset: s64, origin: s32) -> s32 #foreign libc "fseek";
TestBundleFileTell :: (file: *void) -> s64 #foreign libc "ftell";
TestBundleFileRead :: (data: *void, size: usize, count: usize, file: *void) -> usize #foreign libc "fread";
TestBundleAllocate :: (size: usize) -> *void #foreign libc "malloc";
TestBundleRelease :: (memory: *void) #foreign libc "free";
// Route decisions and habit commits run through the same bundles as the app.
LoadTestApps :: (app: *InnerBreeze) -> bool {
file := TestBundleFileOpen(pointer_of("build/inbe.zx\0"), cstr("rb"))
if file == null {
return false
}
if TestBundleFileSeek(file, 0, 2) != 0 {
TestBundleFileClose(file)
return false
}
size := TestBundleFileTell(file)
if size <= 0 || TestBundleFileSeek(file, 0, 0) != 0 {
TestBundleFileClose(file)
return false
}
bundle_data = TestBundleAllocate(cast(usize)size)
if bundle_data == null {
TestBundleFileClose(file)
return false
}
read := TestBundleFileRead(bundle_data, 1, cast(usize)size, file)
TestBundleFileClose(file)
if read != cast(usize)size {
return false
}
// This fixture exposes only the locale asset; bind the real persistence
// effects, then load the compiled root bundle explicitly.
unused AppsStart(app)
return AppsOpenPackage(TextFromBytes(BytesFromPointer(
cast(*u8)bundle_data, cast(u64)size)))
}
CloseTestApps :: () {
AppsClose()
TestBundleRelease(bundle_data)
bundle_data = null
}