Skip to content

Commit 73ea36b

Browse files
committed
[add] automock to some traits and make lambda-platform a default member.
1 parent b97dec9 commit 73ea36b

5 files changed

Lines changed: 45 additions & 17 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ members = [
99

1010
default-members = [
1111
"lambda",
12+
"crates/lambda-platform",
1213
"tools/lambda_rs_demo"
1314
]

crates/lambda-platform/src/gfx/gpu.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,14 @@ use gfx_hal::{
77
PhysicalDevice,
88
QueueFamily,
99
},
10-
pso::ShaderStageFlags,
1110
queue::{
1211
Queue,
1312
QueueGroup,
1413
},
15-
window::{
16-
Extent2D,
17-
PresentError,
18-
PresentationSurface,
19-
Suboptimal,
20-
},
14+
window::Extent2D,
2115
};
16+
#[cfg(test)]
17+
use mockall::automock;
2218

2319
use super::{
2420
command::CommandBuffer,
@@ -35,14 +31,12 @@ pub struct GpuBuilder {
3531
}
3632

3733
impl GpuBuilder {
38-
#[inline]
3934
pub fn new() -> Self {
4035
return Self {
4136
render_queue_type: RenderQueueType::Graphical,
4237
};
4338
}
4439

45-
#[inline]
4640
pub fn with_render_queue_type(mut self, queue_type: RenderQueueType) -> Self {
4741
self.render_queue_type = queue_type;
4842
return self;
@@ -94,7 +88,7 @@ pub struct Gpu<B: gfx_hal::Backend> {
9488
queue_group: QueueGroup<B>,
9589
}
9690

97-
#[derive(Clone, Copy)]
91+
#[derive(Clone, Copy, Debug)]
9892
pub enum RenderQueueType {
9993
Compute,
10094
Graphical,
@@ -204,6 +198,14 @@ impl<RenderBackend: gfx_hal::Backend> Gpu<RenderBackend> {
204198
}
205199
}
206200

201+
#[cfg(test)]
202+
mod tests {
203+
#[test]
204+
fn test_gpu_builder() {
205+
assert_eq!(2 + 2, 4);
206+
}
207+
}
208+
207209
// --------------------------------- GPU INTERNALS -----------------------------
208210

209211
pub mod internal {

crates/lambda-platform/src/gfx/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ use gfx_hal::Instance as _;
1919

2020
pub struct InstanceBuilder {}
2121

22+
#[cfg(test)]
23+
use mockall::automock;
24+
25+
#[cfg_attr(test, automock)]
2226
impl InstanceBuilder {
2327
pub fn new() -> Self {
2428
return Self {};

crates/lambda-platform/src/gfx/shader.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ use gfx_hal::{
22
device::Device,
33
pso::Specialization as ShaderSpecializations,
44
};
5+
#[cfg(test)]
6+
use mockall::automock;
57

68
use super::gpu;
79

@@ -19,6 +21,7 @@ pub struct ShaderModuleBuilder {
1921
specializations: ShaderSpecializations<'static>,
2022
}
2123

24+
#[cfg_attr(test, automock)]
2225
impl ShaderModuleBuilder {
2326
pub fn new() -> Self {
2427
return Self {
@@ -74,11 +77,10 @@ pub struct ShaderModule<RenderBackend: gfx_hal::Backend> {
7477
shader_type: ShaderModuleType,
7578
}
7679

80+
#[cfg_attr(test, automock)]
7781
impl<RenderBackend: gfx_hal::Backend> ShaderModule<RenderBackend> {
7882
/// Destroy the shader module and free the memory on the GPU.
7983
pub fn destroy(self, gpu: &mut gpu::Gpu<RenderBackend>) {
80-
// TODO(vmarcella): Add documentation for the shader module.
81-
println!("Destroying shader module.");
8284
unsafe {
8385
gpu::internal::logical_device_for(gpu)
8486
.destroy_shader_module(self.shader_module)
@@ -91,7 +93,7 @@ impl<RenderBackend: gfx_hal::Backend> ShaderModule<RenderBackend> {
9193
}
9294

9395
/// Get the specializations being applied to the current shader module.
94-
pub fn specializations(&self) -> &ShaderSpecializations {
96+
pub fn specializations(&self) -> &ShaderSpecializations<'static> {
9597
return &self.specializations;
9698
}
9799
}
@@ -121,6 +123,13 @@ mod tests {
121123
super::ShaderSpecializations::default().data
122124
);
123125
}
126+
127+
#[test]
128+
fn shader_builder_builds_correctly() {
129+
let shader_builder = super::ShaderModuleBuilder::new()
130+
.with_entry_name("test")
131+
.with_specializations(super::ShaderSpecializations::default());
132+
}
124133
}
125134

126135
/// Internal functions for the shader module. User applications most likely

crates/lambda-platform/src/gfx/surface.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,16 @@ pub struct Swapchain {
7474
format: gfx_hal::format::Format,
7575
}
7676

77+
#[cfg_attr(test, automock)]
7778
impl<RenderBackend: gfx_hal::Backend> Surface<RenderBackend> {
7879
/// Apply a swapchain to the current surface. This is required whenever a
7980
/// swapchain has been invalidated (I.E. by window resizing)
80-
pub fn apply_swapchain(
81+
pub fn apply_swapchain<'surface>(
8182
&mut self,
8283
gpu: &Gpu<RenderBackend>,
8384
swapchain: Swapchain,
8485
timeout_in_nanoseconds: u64,
85-
) -> Result<(), &str> {
86+
) -> Result<(), &'surface str> {
8687
let device = super::gpu::internal::logical_device_for(gpu);
8788
self.extent = Some(swapchain.config.extent);
8889

@@ -128,13 +129,11 @@ impl<RenderBackend: gfx_hal::Backend> Surface<RenderBackend> {
128129
}
129130

130131
/// private function to invalidate the surface swapchain.
131-
#[inline]
132132
fn invalidate_swapchain(&mut self) {
133133
self.swapchain_is_valid = false;
134134
}
135135

136136
/// Destroy the current surface and it's underlying resources.
137-
#[inline]
138137
pub fn destroy(self, instance: &Instance<RenderBackend>) {
139138
println!("Destroying the surface: {}", self.name);
140139

@@ -199,6 +198,7 @@ impl SwapchainBuilder {
199198
#[cfg(test)]
200199
mod tests {
201200
use super::*;
201+
use crate::gfx::MockInstanceBuilder;
202202

203203
#[test]
204204
fn test_surface_builder() {
@@ -217,6 +217,18 @@ mod tests {
217217
let swapchain_builder = SwapchainBuilder::new().with_size(1920, 1080);
218218
assert_eq!(swapchain_builder.size, (1920, 1080));
219219
}
220+
221+
#[test]
222+
fn test_surface_builder_e2e() {
223+
//let instance = MockInstanceBuilder::new().build("TestInstance");
224+
let surface_builder = SurfaceBuilder::new().with_name("TestSurface");
225+
//let surface = surface_builder.build(&instance);
226+
227+
//assert_eq!(surface.name, "TestSurface".to_string());
228+
//assert_eq!(surface.swapchain_is_valid, false);
229+
//assert_eq!(surface.image, None);
230+
//assert_eq!(surface.frame_buffer_attachment, None);
231+
}
220232
}
221233

222234
/// Internal functions to work with the gfx-hal surface components

0 commit comments

Comments
 (0)