Skip to main content

astrelis_test_utils/
lib.rs

1//! Test utilities for Astrelis engine.
2//!
3//! This crate provides testing infrastructure for the Astrelis game engine,
4//! including mock GPU contexts and render trait abstractions.
5//!
6//! # Overview
7//!
8//! The main components are:
9//!
10//! - [`RenderContext`] - Trait abstracting GPU operations
11//! - `MockRenderContext` - Mock implementation for testing (requires `mock` feature)
12//! - GPU wrapper types (`GpuBuffer`, `GpuTexture`, etc.) - Can be real or mock
13//!
14//! # Example
15//!
16//! ```rust
17//! # #[cfg(feature = "mock")]
18//! # {
19//! use astrelis_test_utils::{MockRenderContext, RenderContext};
20//! use wgpu::*;
21//!
22//! // Create a mock context for testing
23//! let mock = MockRenderContext::new();
24//!
25//! // Use it like a real GPU context
26//! let buffer = mock.create_buffer(&BufferDescriptor {
27//!     label: Some("test_buffer"),
28//!     size: 1024,
29//!     usage: BufferUsages::VERTEX,
30//!     mapped_at_creation: false,
31//! });
32//!
33//! // Verify operations in tests
34//! assert_eq!(mock.count_buffer_creates(), 1);
35//! assert!(buffer.is_mock());
36//! # }
37//! ```
38//!
39//! # Design Philosophy
40//!
41//! This crate follows several key design principles:
42//!
43//! ## 1. No Lifetimes
44//!
45//! All GPU wrapper types are owned and use reference counting internally.
46//! This eliminates lifetime parameters from propagating through the codebase.
47//!
48//! ## 2. Interior Mutability
49//!
50//! Mock implementations use `Mutex` for interior mutability, allowing `&self`
51//! methods to record calls.
52//!
53//! ## 3. Object Safety
54//!
55//! The `RenderContext` trait is object-safe (`dyn RenderContext`), allowing
56//! for polymorphic usage with both real and mock contexts.
57
58pub mod gpu_types;
59#[cfg(feature = "mock")]
60pub mod mock_render;
61pub mod render_context;
62
63// Re-export main types at crate root
64pub use gpu_types::*;
65#[cfg(feature = "mock")]
66pub use mock_render::*;
67pub use render_context::*;