This repository has been archived on 2026-10-10. You can view files and clone it, but cannot push or open issues or pull requests.
molotov/crates/molotov-core/tests/graphics_fixes_test.rs

54 lines
1.7 KiB
Rust

// 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, ARect, WindowFormat};
use molotov_core::graphics::window::{WindowConfig, WindowManager};
use molotov_core::jni::activity::ActivityRunner;
use std::sync::{Arc, Mutex};
#[test]
fn test_dirty_rect_clamping_on_lock() {
let surface = Arc::new(GraphicsSurface::new(800, 600, WindowFormat::Rgba8888));
let handle = register_window_surface(surface);
let mut buf = std::mem::MaybeUninit::<ANativeWindow_Buffer>::uninit();
let mut dirty = ARect {
left: -50,
top: -20,
right: 1500,
bottom: 2000,
};
unsafe {
assert_eq!(ANativeWindow_lock(handle, buf.as_mut_ptr(), &mut dirty), 0);
// Clamping check
assert_eq!(dirty.left, 0);
assert_eq!(dirty.top, 0);
assert_eq!(dirty.right, 800);
assert_eq!(dirty.bottom, 600);
// While locked, setBuffersGeometry must return -EBUSY
assert_eq!(ANativeWindow_setBuffersGeometry(handle, 1024, 768, 1), -libc::EBUSY);
assert_eq!(ANativeWindow_unlockAndPost(handle), 0);
ANativeWindow_release(handle);
}
}
#[test]
fn test_window_manager_syncs_with_activity_runner() {
let runner = Arc::new(Mutex::new(ActivityRunner::new()));
let config = WindowConfig {
title: "Test".to_string(),
width: 1280,
height: 720,
fullscreen: false,
vulkan: true,
};
let mut manager = WindowManager::new_with_activity(config, Some(runner.clone()));
manager.handle_resize(1920, 1080);
assert_eq!(manager.width(), 1920);
assert_eq!(manager.height(), 1080);
}