test(graphics): implement end-to-end graphics surface and activity window integration test
This commit is contained in:
parent
a5f60dd899
commit
64d96c7df2
1 changed files with 37 additions and 0 deletions
37
crates/molotov-core/tests/graphics_surface_test.rs
Normal file
37
crates/molotov-core/tests/graphics_surface_test.rs
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
use molotov_core::graphics::c_api::*;
|
||||||
|
use molotov_core::graphics::surface::GraphicsSurface;
|
||||||
|
use molotov_core::graphics::types::{ANativeWindow_Buffer, WindowFormat};
|
||||||
|
use molotov_core::jni::activity::ActivityRunner;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_end_to_end_graphics_surface_and_activity_binding() {
|
||||||
|
let mut runner = ActivityRunner::new();
|
||||||
|
let surface = Box::new(GraphicsSurface::new(1280, 720, WindowFormat::Rgba8888));
|
||||||
|
let window_handle = Box::into_raw(surface) as *mut ();
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
// 1. Notify activity that native window was created
|
||||||
|
runner.trigger_window_created(window_handle as *mut _);
|
||||||
|
|
||||||
|
// 2. Engine queries window geometry
|
||||||
|
assert_eq!(ANativeWindow_getWidth(window_handle), 1280);
|
||||||
|
assert_eq!(ANativeWindow_getHeight(window_handle), 720);
|
||||||
|
|
||||||
|
// 3. Engine renders frame
|
||||||
|
let mut buf = std::mem::MaybeUninit::<ANativeWindow_Buffer>::uninit();
|
||||||
|
assert_eq!(ANativeWindow_lock(window_handle, buf.as_mut_ptr(), std::ptr::null_mut()), 0);
|
||||||
|
|
||||||
|
let buffer = buf.assume_init();
|
||||||
|
// Write solid color into buffer (RGBA = 255, 0, 0, 255)
|
||||||
|
let pixel_count = (buffer.width * buffer.height) as usize;
|
||||||
|
let pixels = std::slice::from_raw_parts_mut(buffer.bits as *mut u32, pixel_count);
|
||||||
|
pixels.fill(0xff00_00ff);
|
||||||
|
|
||||||
|
assert_eq!(ANativeWindow_unlockAndPost(window_handle), 0);
|
||||||
|
|
||||||
|
// 4. Notify activity on window destroy
|
||||||
|
runner.trigger_window_destroyed(window_handle as *mut _);
|
||||||
|
ANativeWindow_release(window_handle);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in a new issue