Improve testing framework

Replaced Criterrion with CMock. Added few tests, currently not working
properly. Random test upgrades.
This commit is contained in:
Piotr Krygier committed 2025-06-20 13:44:33 +02:00
1 parent 56c0b7922f
commit f5ab5f3f27
29 files changed
+140082 -310

No files matched your search

+45 -6
View File
@@ -1,12 +1,51 @@
find_package(Criterion)
find_package(Vulkan REQUIRED)
find_package(vma REQUIRED)
find_package(glfw3 REQUIRED)
find_package(Cmock REQUIRED)
find_package(stb REQUIRED)
add_definitions( -DRSE_TEST=1 )
add_executable(tests
src/rse_math_tests.c)
src/main.c
src/mocks/vulkan/Mockvulkan_core.c
src/mocks/GLFW/Mockglfw3.c
src/mocks/vk_mem_alloc.c
src/rse_math_tests.c
src/rse_graphics_window_tests.c
src/rse_graphics_vulkan_tests.c
${PROJECT_SOURCE_DIR}/graphics/src/window.c
${PROJECT_SOURCE_DIR}/graphics/src/vulkan_base.c
${PROJECT_SOURCE_DIR}/graphics/src/vulkan_pipeline.c
${PROJECT_SOURCE_DIR}/graphics/src/rse_vulkan_commands.c
${PROJECT_SOURCE_DIR}/graphics/src/vulkan_buffers.c
${PROJECT_SOURCE_DIR}/graphics/src/vulkan_descriptors.c
${PROJECT_SOURCE_DIR}/graphics/src/rse_graphics.c
${PROJECT_SOURCE_DIR}/graphics/src/rse_math.c
${PROJECT_SOURCE_DIR}/graphics/src/mesh_controller.c
${PROJECT_SOURCE_DIR}/graphics/src/vulkan_commons.c
${PROJECT_SOURCE_DIR}/graphics/src/rse_vulkan_image.c
${PROJECT_SOURCE_DIR}/graphics/src/rse_text_renderer.c
${PROJECT_SOURCE_DIR}/utilities/src/logger.c
${PROJECT_SOURCE_DIR}/utilities/src/file_utils.c
${PROJECT_SOURCE_DIR}/utilities/src/rse_task_linux.c
)
target_include_directories(tests PRIVATE
${criterion_INCLUDE_DIR}
${CMAKE_SOURCE_DIR})
${CMAKE_SOURCE_DIR}
${glfw3_INCLUDE_DIR}
${Vulkan_INCLUDE_DIR}
${unity_INCLUDE_DIR}
${cmock_INCLUDE_DIR}
src/mocks/
${PROJECT_SOURCE_DIR}/graphics/
${PROJECT_SOURCE_DIR}/graphics/src/
${PROJECT_SOURCE_DIR}/utilities/
)
target_link_libraries(tests PRIVATE
${criterion}
rse_graphics)
${cmock}
${unity}
m
)
+27
View File
@@ -0,0 +1,27 @@
/**
* @file main.c
* @author Piotr Krygier (everyonecancode@gmail.com)
* @brief Main file for tests
* @version 0.1
* @date 2024-02-16
*
* @copyright Copyright (c) 2024
*
*/
#define RSE_TEST 1
#include "rse_commons.h"
#define VMA_IMPLEMENTATION
#include "unity_internals.h"
#include "rse_graphics_window_tests.h"
#include "rse_math_tests.h"
#include "rse_graphics_vulkan_tests.h"
int main(int argc, char *argv[])
{
UNITY_BEGIN();
rse_graphics_window_tests();
rse_math_tests();
rse_graphics_vulkan_tests();
return UNITY_END();
}
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+44
View File
@@ -0,0 +1,44 @@
#ifndef FTTYPES_H
#define FTTYPES_H
#define FT_FREETYPE_H <stdio.h>
#define FT_LOAD_RENDER 1
typedef void* FT_Library;
typedef int FT_Error;
typedef long FT_Long;
typedef unsigned long FT_ULong;
typedef unsigned int FT_UInt;
typedef FT_Long FT_Int32;
typedef struct {
int x;
int y;
} FT_Vector;
typedef struct {
int width;
int rows;
void *buffer;
} FT_Bitmap;
typedef struct {
int bitmap_left;
int bitmap_top;
FT_Vector advance;
FT_Bitmap bitmap;
} FT_GlyphSlotRec_;
typedef struct {
int num_glyphs;
FT_GlyphSlotRec_ *glyph;
} FT_FaceRec_;
typedef FT_FaceRec_* FT_Face;
FT_Error FT_Init_FreeType( FT_Library *alibrary ) { return 0; }
FT_Error FT_New_Face( FT_Library library, const char* filepathname, FT_Long face_index, FT_Face *aface ) { return 0; }
FT_Error FT_Set_Pixel_Sizes( FT_Face face, FT_UInt pixel_width, FT_UInt pixel_height ) { return 0; }
FT_Error FT_Load_Char( FT_Face face, FT_ULong char_code, FT_Int32 load_flags ) { return 0; }
#endif // FTTYPES_H
+15
View File
@@ -0,0 +1,15 @@
#ifndef STBI_IMAGE_H
#define STBI_IMAGE_H
#define STBI_rgb_alpha 4
typedef unsigned char stbi_uc;
stbi_uc g_mocked_uc;
void stbi_image_free (void *retval_from_stbi_load) {}
stbi_uc *stbi_load(char const *filename, int *x, int *y, int *comp, int req_comp) { return &g_mocked_uc; }
#endif // STBI_IMAGE_H
+12
View File
@@ -0,0 +1,12 @@
#include "vk_mem_alloc.h"
VkResult vmaCreateAllocator(VmaAllocatorCreateInfo* pCreateInfo, VmaAllocator* pAllocator) { return VK_SUCCESS; }
VkResult vmaCreateBuffer(VmaAllocator allocator, const VkBufferCreateInfo* pBufferCreateInfo, const VmaAllocationCreateInfo* pAllocationCreateInfo, VkBuffer* pBuffer, VmaAllocation* pAllocation, VmaAllocationInfo* pAllocationInfo) { return VK_SUCCESS; }
VkResult vmaCreateImage(VmaAllocator allocator, const VkImageCreateInfo* pImageCreateInfo, const VmaAllocationCreateInfo* pAllocationCreateInfo, VkImage* pImage, VmaAllocation* pAllocation, VmaAllocationInfo* pAllocationInfo) { return VK_SUCCESS; }
void vmaDestroyAllocator(VmaAllocator allocator) {}
void vmaDestroyBuffer(VmaAllocator allocator, VkBuffer buffer, VmaAllocation allocation) {}
void vmaDestroyImage(VmaAllocator allocator, VkImage image, VmaAllocation allocation) {}
VkResult vmaMapMemory(VmaAllocator allocator, VmaAllocation allocation, void** ppData) { return VK_SUCCESS; }
+71
View File
@@ -0,0 +1,71 @@
#ifndef AMD_VULKAN_MEMORY_ALLOCATOR_H
#define AMD_VULKAN_MEMORY_ALLOCATOR_H
#include <stdint.h>
#include <vulkan/vulkan.h>
#define VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE 1
#define VMA_ALLOCATION_CREATE_MAPPED_BIT 2
#define VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT 3
#define VMA_MEMORY_USAGE_AUTO_PREFER_HOST 4
#define VMA_MEMORY_USAGE_AUTO 5;
#define VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT 6
typedef int VmaAllocation;
typedef int VmaAllocator;
typedef int VmaMemoryUsage;
typedef int VmaAllocationCreateFlags;
typedef struct {
VkBuffer buffer;
VmaAllocation allocation;
} VmaBuffer;
typedef struct {
VkImage image;
VmaAllocation allocation;
} VmaImage;
typedef struct {
float priority;
uint32_t flags;
uint32_t usage;
uint32_t requiredFlags;
uint32_t preferredFlags;
uint32_t memoryTypeBits;
void* pool;
void* pUserData;
} VmaAllocationCreateInfo;
typedef struct {
VkDeviceMemory memory;
VkDeviceSize offset;
VkDeviceSize size;
void* pMappedData;
} VmaAllocationInfo;
typedef struct {
void* vkGetInstanceProcAddr;
void* vkGetDeviceProcAddr;
} VmaVulkanFunctions;
typedef struct {
uint32_t vulkanApiVersion;
VkPhysicalDevice physicalDevice;
VkDevice device;
VkInstance instance;
VmaVulkanFunctions* pVulkanFunctions;
} VmaAllocatorCreateInfo;
VkResult vmaCreateAllocator(VmaAllocatorCreateInfo* pCreateInfo, VmaAllocator* pAllocator);
VkResult vmaCreateBuffer(VmaAllocator allocator, const VkBufferCreateInfo* pBufferCreateInfo, const VmaAllocationCreateInfo* pAllocationCreateInfo, VkBuffer* pBuffer, VmaAllocation* pAllocation, VmaAllocationInfo* pAllocationInfo);
VkResult vmaCreateImage(VmaAllocator allocator, const VkImageCreateInfo* pImageCreateInfo, const VmaAllocationCreateInfo* pAllocationCreateInfo, VkImage* pImage, VmaAllocation* pAllocation, VmaAllocationInfo* pAllocationInfo);
void vmaDestroyAllocator(VmaAllocator allocator);
void vmaDestroyBuffer(VmaAllocator allocator, VkBuffer buffer, VmaAllocation allocation);
void vmaDestroyImage(VmaAllocator allocator, VkImage image, VmaAllocation allocation);
VkResult vmaMapMemory(VmaAllocator allocator, VmaAllocation allocation, void** ppData);
#endif // AMD_VULKAN_MEMORY_ALLOCATOR_H
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
-183
View File
@@ -1,183 +0,0 @@
#include "criterion/criterion.h"
#include "graphics/src/rse_math.h"
/*-----------------RSE MATH TEST------------------------*/
TestSuite(rse_math);
Test(rse_math, normalize)
{
float res_x = 0.8017f;
float res_y = 0.2672f;
float res_z = 0.5345f;
struct vec3_t test_vec = {3.0f, 1.0f, 2.0f};
struct vec3_t result = rse_math_normalize_vec3(&test_vec);
cr_expect_float_eq(result.x, res_x, 0.0001, "Expected %f, got %f", res_x, result.x);
cr_expect_float_eq(result.y, res_y, 0.0001, "Expected %f, got %f", res_y, result.y);
cr_expect_float_eq(result.z, res_z, 0.0001, "Expected %f, got %f", res_z, result.z);
}
Test(rse_math, cross)
{
float res_x = -3.0f;
float res_y = 6.0f;
float res_z = -3.0f;
struct vec3_t test_vec1 = {2.0f, 3.0f, 4.0f};
struct vec3_t test_vec2 = {5.0f, 6.0f, 7.0f};
struct vec3_t result = rse_math_cross_vec3(&test_vec1, &test_vec2);
cr_expect_float_eq(result.x, res_x, 0.0001, "Expected %f, got %f", res_x, result.x);
cr_expect_float_eq(result.y, res_y, 0.0001, "Expected %f, got %f", res_y, result.y);
cr_expect_float_eq(result.z, res_z, 0.0001, "Expected %f, got %f", res_z, result.z);
}
Test(rse_math, look_at)
{
struct vec3_t eye;
struct vec3_t center;
struct vec3_t up;
struct mat4_t result;
struct mat4_t expected;
eye.x = 0.0f;
eye.y = 0.0f;
eye.z = 5.0f;
center.x = 0.0f;
center.y = 0.0f;
center.z = 0.0f;
up.x = 0.0f;
up.y = 0.1f;
up.z = 0.0f;
expected.x_1 = 1.0f;
expected.y_1 = 0.0f;
expected.z_1 = 0.0f;
expected.w_1 = 0.0f;
expected.x_2 = 0.0f;
expected.y_2 = 1.0f;
expected.z_2 = 0.0f;
expected.w_2 = 0.0f;
expected.x_3 = 0.0f;
expected.y_3 = 0.0f;
expected.z_3 = 1.0f;
expected.w_3 = 0.0f;
expected.x_4 = 0.0f;
expected.y_4 = 0.0f;
expected.z_4 = -5.0f;
expected.w_4 = 1.0f;
result = rse_math_look_at(&eye, &center, &up);
cr_expect_float_eq(result.x_1, expected.x_1, 0.0001, "Expected x_1 %f, got %f", expected.x_1, result.x_1);
cr_expect_float_eq(result.y_1, expected.y_1, 0.0001, "Expected y_1 %f, got %f", expected.y_1, result.y_1);
cr_expect_float_eq(result.z_1, expected.z_1, 0.0001, "Expected z_1 %f, got %f", expected.z_1, result.z_1);
cr_expect_float_eq(result.w_1, expected.w_1, 0.0001, "Expected w_1 %f, got %f", expected.w_1, result.w_1);
cr_expect_float_eq(result.x_2, expected.x_2, 0.0001, "Expected x_2 %f, got %f", expected.x_2, result.x_2);
cr_expect_float_eq(result.y_2, expected.y_2, 0.0001, "Expected y_2 %f, got %f", expected.y_2, result.y_2);
cr_expect_float_eq(result.z_2, expected.z_2, 0.0001, "Expected z_2 %f, got %f", expected.z_2, result.z_2);
cr_expect_float_eq(result.w_2, expected.w_2, 0.0001, "Expected w_2 %f, got %f", expected.w_2, result.w_2);
cr_expect_float_eq(result.x_3, expected.x_3, 0.0001, "Expected x_3 %f, got %f", expected.x_3, result.x_3);
cr_expect_float_eq(result.y_3, expected.y_3, 0.0001, "Expected y_3 %f, got %f", expected.y_3, result.y_3);
cr_expect_float_eq(result.z_3, expected.z_3, 0.0001, "Expected z_3 %f, got %f", expected.z_3, result.z_3);
cr_expect_float_eq(result.w_3, expected.w_3, 0.0001, "Expected w_3 %f, got %f", expected.w_3, result.w_3);
cr_expect_float_eq(result.x_4, expected.x_4, 0.0001, "Expected x_4 %f, got %f", expected.x_4, result.x_4);
cr_expect_float_eq(result.y_4, expected.y_4, 0.0001, "Expected y_4 %f, got %f", expected.y_4, result.y_4);
cr_expect_float_eq(result.z_4, expected.z_4, 0.0001, "Expected z_4 %f, got %f", expected.z_4, result.z_4);
cr_expect_float_eq(result.w_4, expected.w_4, 0.0001, "Expected w_4 %f, got %f", expected.w_4, result.w_4);
}
Test(rse_math, radians)
{
float degrees;
float radians;
float expected_radians;
degrees = 45.0f;
expected_radians = 0.7853;
radians = rse_math_deg_to_radians(degrees);
cr_expect_float_eq(radians, expected_radians, 0.0001, "Expected %f, got %f", expected_radians, radians);
}
Test(rse_math, perspective)
{
float fovy;
float width;
float height;
float z_near;
float z_far;
struct mat4_t result;
struct mat4_t expected;
fovy = rse_math_deg_to_radians(45.0f);
width = 640.0f;
height = 480.0f;
z_near = 0.1f;
z_far = 20.0f;
expected.x_1 = -1.81066012;
expected.y_1 = 0;
expected.z_1 = 0;
expected.w_1 = 0;
expected.x_2 = 0;
expected.y_2 = 2.41421342;
expected.z_2 = 0;
expected.w_2 = 0;
expected.x_3 = 0;
expected.y_3 = 0;
expected.z_3 = -1.0100503;
expected.w_3 = -1;
expected.x_4 = 0;
expected.y_4 = 0;
expected.z_4 = -0.201005027;
expected.w_4 = 0;
result = rse_math_perspective(fovy, width / height, z_near, z_far);
cr_expect_float_eq(result.x_1, expected.x_1, 0.0001, "Expected x_1 %f, got %f", expected.x_1, result.x_1);
cr_expect_float_eq(result.y_1, expected.y_1, 0.0001, "Expected y_1 %f, got %f", expected.y_1, result.y_1);
cr_expect_float_eq(result.z_1, expected.z_1, 0.0001, "Expected z_1 %f, got %f", expected.z_1, result.z_1);
cr_expect_float_eq(result.w_1, expected.w_1, 0.0001, "Expected w_1 %f, got %f", expected.w_1, result.w_1);
cr_expect_float_eq(result.x_2, expected.x_2, 0.0001, "Expected x_2 %f, got %f", expected.x_2, result.x_2);
cr_expect_float_eq(result.y_2, expected.y_2, 0.0001, "Expected y_2 %f, got %f", expected.y_2, result.y_2);
cr_expect_float_eq(result.z_2, expected.z_2, 0.0001, "Expected z_2 %f, got %f", expected.z_2, result.z_2);
cr_expect_float_eq(result.w_2, expected.w_2, 0.0001, "Expected w_2 %f, got %f", expected.w_2, result.w_2);
cr_expect_float_eq(result.x_3, expected.x_3, 0.0001, "Expected x_3 %f, got %f", expected.x_3, result.x_3);
cr_expect_float_eq(result.y_3, expected.y_3, 0.0001, "Expected y_3 %f, got %f", expected.y_3, result.y_3);
cr_expect_float_eq(result.z_3, expected.z_3, 0.0001, "Expected z_3 %f, got %f", expected.z_3, result.z_3);
cr_expect_float_eq(result.w_3, expected.w_3, 0.0001, "Expected w_3 %f, got %f", expected.w_3, result.w_3);
cr_expect_float_eq(result.x_4, expected.x_4, 0.0001, "Expected x_4 %f, got %f", expected.x_4, result.x_4);
cr_expect_float_eq(result.y_4, expected.y_4, 0.0001, "Expected y_4 %f, got %f", expected.y_4, result.y_4);
cr_expect_float_eq(result.z_4, expected.z_4, 0.0001, "Expected z_4 %f, got %f", expected.z_4, result.z_4);
cr_expect_float_eq(result.w_4, expected.w_4, 0.0001, "Expected w_4 %f, got %f", expected.w_4, result.w_4);
}
/*-----------------RSE TEXTURES TEST------------------------*/
#include "graphics/src/rse_texture.h"
TestSuite(rse_textures);
Test(rse_textures, load_png_image)
{
rse_load_texture("../../test_image.jpg");
}
+61
View File
@@ -0,0 +1,61 @@
/**
* @file rse_graphics_vulkan_tests.c
* @author Piotr Krygier (everyonecancode@gmail.com)
* @brief
* @version 0.1
* @date 2024-02-16
*
* @copyright Copyright (c) 2024
*
*/
#include "mocks/vulkan/Mockvulkan_core.h"
#include "mocks/GLFW/Mockglfw3.h"
#include "rse_graphics_vulkan_tests.h"
#include <stdio.h>
#include "graphics/rse_graphics.h"
#include "utilities/rse_errors_common.h"
#include "unity.h"
#include "vulkan/vulkan_core.h"
static void test_rse_graphics_init(void)
{
VkExtensionProperties extenstion_properties[1];
VkLayerProperties layer_properties[1];
uint32_t count = 1;
sprintf(extenstion_properties[0].extensionName, "VK_KHR_surface");
sprintf(layer_properties[0].layerName, "VK_LAYER_KHRONOS_validation");
/* initialize GLFW */
glfwInit_ExpectAndReturn(GLFW_TRUE);
glfwVulkanSupported_ExpectAndReturn(GLFW_TRUE);
glfwSetErrorCallback_ExpectAndReturn(NULL, NULL);
glfwSetErrorCallback_IgnoreArg_callback();
glfwWindowHint_Expect(GLFW_CLIENT_API, GLFW_NO_API);
glfwCreateWindow_ExpectAndReturn(640, 480, "RedScarfEngine", NULL, NULL, (GLFWwindow*)1);
glfwSetKeyCallback_ExpectAndReturn((GLFWwindow*)1, NULL, NULL);
glfwSetKeyCallback_IgnoreArg_callback();
glfwSetFramebufferSizeCallback_ExpectAndReturn((GLFWwindow*)1, NULL, NULL);
glfwSetFramebufferSizeCallback_IgnoreArg_callback();
/* create instance */
vkEnumerateInstanceLayerProperties_ExpectAnyArgsAndReturn(VK_SUCCESS);
vkEnumerateInstanceLayerProperties_ExpectAnyArgsAndReturn(VK_SUCCESS);
vkEnumerateInstanceLayerProperties_ReturnThruPtr_pPropertyCount(&count);
/* TODO: Currently, due to the implementation, layer_properties that we get here is NULL.
* This is because mocked rse_malloc does nothing. Fix this somehow */
vkEnumerateInstanceLayerProperties_ReturnThruPtr_pProperties(layer_properties);
vkEnumerateInstanceExtensionProperties_ExpectAnyArgsAndReturn(VK_SUCCESS);
vkEnumerateInstanceExtensionProperties_ExpectAnyArgsAndReturn(VK_SUCCESS);
vkEnumerateInstanceExtensionProperties_ReturnThruPtr_pPropertyCount(&count);
vkEnumerateInstanceExtensionProperties_ReturnThruPtr_pProperties(extenstion_properties);
TEST_ASSERT_EQUAL(RSE_ERROR_NO_ERROR, rse_graphics_init());
}
void rse_graphics_vulkan_tests(void)
{
RUN_TEST(test_rse_graphics_init);
}
+17
View File
@@ -0,0 +1,17 @@
/**
* @file rse_graphics_vulkan_tests.h
* @author Piotr Krygier (everyonecancode@gmail.com)
* @brief Tests for rse_graphics_vulkan module
* @version 0.1
* @date 2024-02-16
*
* @copyright Copyright (c) 2024
*
*/
#ifndef RSE_GRAPHICS_VULKAN_TESTS_H
#define RSE_GRAPHICS_VULKAN_TESTS_H
void rse_graphics_vulkan_tests(void);
#endif // RSE_GRAPHICS_VULKAN_TESTS_H
+60
View File
@@ -0,0 +1,60 @@
#include "rse_graphics_window_tests.h"
/*-----------------RSE WINDOW TESTS------------------------*/
#include "mocks/GLFW/Mockglfw3.h"
#include "graphics/src/window.h"
#include "utilities/rse_errors_common.h"
#include "graphics/src/rse_window_errors.h"
void setUp (void) {}
void tearDown (void) {}
static void test_rse_window_init_window_init_success()
{
uint8_t window = 0;
glfwInit_ExpectAndReturn(GLFW_TRUE);
glfwVulkanSupported_ExpectAndReturn(GLFW_TRUE);
glfwSetErrorCallback_ExpectAndReturn(NULL, NULL);
glfwSetErrorCallback_IgnoreArg_callback();
glfwWindowHint_Expect(GLFW_CLIENT_API, GLFW_NO_API);
glfwCreateWindow_ExpectAndReturn(640, 480, "RedScarfEngine", NULL, NULL, (GLFWwindow*)&window);
glfwSetKeyCallback_ExpectAndReturn((GLFWwindow*)&window, NULL, NULL);
glfwSetKeyCallback_IgnoreArg_callback();
glfwSetFramebufferSizeCallback_ExpectAndReturn((GLFWwindow*)&window, NULL, NULL);
glfwSetFramebufferSizeCallback_IgnoreArg_callback();
TEST_ASSERT_EQUAL(RSE_ERROR_NO_ERROR, window_init());
}
static void test_rse_window_init_glfw_init_failed()
{
glfwInit_ExpectAndReturn(GLFW_FALSE);
TEST_ASSERT_EQUAL(WINDOW_ERROR_GLFW_INIT_FAILED, window_init());
}
static void test_rse_window_init_glfw_vulkan_not_supported()
{
glfwInit_ExpectAndReturn(GLFW_TRUE);
glfwVulkanSupported_ExpectAndReturn(GLFW_FALSE);
TEST_ASSERT_EQUAL(WINDOW_ERROR_VULKAN_NOT_LOADED, window_init());
}
static void test_rse_window_init_window_not_created()
{
glfwInit_ExpectAndReturn(GLFW_TRUE);
glfwVulkanSupported_ExpectAndReturn(GLFW_TRUE);
glfwSetErrorCallback_ExpectAndReturn(NULL, NULL);
glfwSetErrorCallback_IgnoreArg_callback();
glfwWindowHint_Expect(GLFW_CLIENT_API, GLFW_NO_API);
glfwCreateWindow_ExpectAndReturn(640, 480, "RedScarfEngine", NULL, NULL, NULL);
TEST_ASSERT_EQUAL(WINDOW_ERROR_WINDOW_NOT_CREATED, window_init());
}
void rse_graphics_window_tests(void)
{
RUN_TEST(test_rse_window_init_window_init_success);
RUN_TEST(test_rse_window_init_glfw_init_failed);
RUN_TEST(test_rse_window_init_glfw_vulkan_not_supported);
RUN_TEST(test_rse_window_init_window_not_created);
}
+17
View File
@@ -0,0 +1,17 @@
/**
* @file rse_graphics_window_tests.h
* @author Piotr Krygier (everyonecancode@gmail.com)
* @brief Tests for rse_graphics module
* @version 0.1
* @date 2024-02-16
*
* @copyright Copyright (c) 2024
*
*/
#ifndef RSE_GRAPHICS_TESTS_H
#define RSE_GRAPHICS_TESTS_H
void rse_graphics_window_tests(void);
#endif // RSE_GRAPHICS_TESTS_H
+91 -77
View File
@@ -1,31 +1,36 @@
#include "criterion/criterion.h"
#include "graphics/src/rse_math.h"
/**
* @file rse_math_tests.c
* @author Piotr Krygier (everyonecancode@gmail.com)
* @brief Tests for rse_math module
* @version 0.1
* @date 2024-02-16
*
* @copyright Copyright (c) 2024
*
*/
#include "rse_math_tests.h"
#include "graphics/src/rse_math.h"
#include "unity.h"
#include <stdio.h>
#include <math.h>
/*-----------------RSE MATH TEST------------------------*/
TestSuite(rse_math);
Test(rse_math, normalize)
static void test_rse_math_test_vector3_normalize(void)
{
float res_x = 0.8017f;
float res_y = 0.2672f;
float res_z = 0.5345f;
float res_x = 0.8017837f;
float res_y = 0.2672612f;
float res_z = 0.5345224f;
struct vec3_t test_vec = {3.0f, 1.0f, 2.0f};
struct vec3_t result = rse_math_normalize_vec3(&test_vec);
cr_expect_float_eq(result.x, res_x, 0.0001, "Expected %f, got %f", res_x, result.x);
cr_expect_float_eq(result.y, res_y, 0.0001, "Expected %f, got %f", res_y, result.y);
cr_expect_float_eq(result.z, res_z, 0.0001, "Expected %f, got %f", res_z, result.z);
TEST_ASSERT_EQUAL_FLOAT(res_x, result.x);
TEST_ASSERT_EQUAL_FLOAT(res_y, result.y);
TEST_ASSERT_EQUAL_FLOAT(res_z, result.z);
}
Test(rse_math, cross)
static void test_rse_math_test_vector3_cross(void)
{
float res_x = -3.0f;
float res_y = 6.0f;
@@ -35,12 +40,12 @@ Test(rse_math, cross)
struct vec3_t result = rse_math_cross_vec3(&test_vec1, &test_vec2);
cr_expect_float_eq(result.x, res_x, 0.0001, "Expected %f, got %f", res_x, result.x);
cr_expect_float_eq(result.y, res_y, 0.0001, "Expected %f, got %f", res_y, result.y);
cr_expect_float_eq(result.z, res_z, 0.0001, "Expected %f, got %f", res_z, result.z);
TEST_ASSERT_EQUAL_FLOAT(res_x, result.x);
TEST_ASSERT_EQUAL_FLOAT(res_y, result.y);
TEST_ASSERT_EQUAL_FLOAT(res_z, result.z);
}
Test(rse_math, look_at)
static void test_rse_math_test_look_at(void)
{
struct vec3_t eye;
struct vec3_t center;
@@ -82,45 +87,44 @@ Test(rse_math, look_at)
result = rse_math_look_at(&eye, &center, &up);
cr_expect_float_eq(result.x_1, expected.x_1, 0.0001, "Expected x_1 %f, got %f", expected.x_1, result.x_1);
cr_expect_float_eq(result.y_1, expected.y_1, 0.0001, "Expected y_1 %f, got %f", expected.y_1, result.y_1);
cr_expect_float_eq(result.z_1, expected.z_1, 0.0001, "Expected z_1 %f, got %f", expected.z_1, result.z_1);
cr_expect_float_eq(result.w_1, expected.w_1, 0.0001, "Expected w_1 %f, got %f", expected.w_1, result.w_1);
TEST_ASSERT_EQUAL_FLOAT(expected.x_1, result.x_1);
TEST_ASSERT_EQUAL_FLOAT(expected.y_1, result.y_1);
TEST_ASSERT_EQUAL_FLOAT(expected.z_1, result.z_1);
TEST_ASSERT_EQUAL_FLOAT(expected.w_1, result.w_1);
cr_expect_float_eq(result.x_2, expected.x_2, 0.0001, "Expected x_2 %f, got %f", expected.x_2, result.x_2);
cr_expect_float_eq(result.y_2, expected.y_2, 0.0001, "Expected y_2 %f, got %f", expected.y_2, result.y_2);
cr_expect_float_eq(result.z_2, expected.z_2, 0.0001, "Expected z_2 %f, got %f", expected.z_2, result.z_2);
cr_expect_float_eq(result.w_2, expected.w_2, 0.0001, "Expected w_2 %f, got %f", expected.w_2, result.w_2);
TEST_ASSERT_EQUAL_FLOAT(expected.x_2, result.x_2);
TEST_ASSERT_EQUAL_FLOAT(expected.y_2, result.y_2);
TEST_ASSERT_EQUAL_FLOAT(expected.z_2, result.z_2);
TEST_ASSERT_EQUAL_FLOAT(expected.w_2, result.w_2);
cr_expect_float_eq(result.x_3, expected.x_3, 0.0001, "Expected x_3 %f, got %f", expected.x_3, result.x_3);
cr_expect_float_eq(result.y_3, expected.y_3, 0.0001, "Expected y_3 %f, got %f", expected.y_3, result.y_3);
cr_expect_float_eq(result.z_3, expected.z_3, 0.0001, "Expected z_3 %f, got %f", expected.z_3, result.z_3);
cr_expect_float_eq(result.w_3, expected.w_3, 0.0001, "Expected w_3 %f, got %f", expected.w_3, result.w_3);
cr_expect_float_eq(result.x_4, expected.x_4, 0.0001, "Expected x_4 %f, got %f", expected.x_4, result.x_4);
cr_expect_float_eq(result.y_4, expected.y_4, 0.0001, "Expected y_4 %f, got %f", expected.y_4, result.y_4);
cr_expect_float_eq(result.z_4, expected.z_4, 0.0001, "Expected z_4 %f, got %f", expected.z_4, result.z_4);
cr_expect_float_eq(result.w_4, expected.w_4, 0.0001, "Expected w_4 %f, got %f", expected.w_4, result.w_4);
TEST_ASSERT_EQUAL_FLOAT(expected.x_3, result.x_3);
TEST_ASSERT_EQUAL_FLOAT(expected.y_3, result.y_3);
TEST_ASSERT_EQUAL_FLOAT(expected.z_3, result.z_3);
TEST_ASSERT_EQUAL_FLOAT(expected.w_3, result.w_3);
TEST_ASSERT_EQUAL_FLOAT(expected.x_4, result.x_4);
TEST_ASSERT_EQUAL_FLOAT(expected.y_4, result.y_4);
TEST_ASSERT_EQUAL_FLOAT(expected.z_4, result.z_4);
TEST_ASSERT_EQUAL_FLOAT(expected.w_4, result.w_4);
}
Test(rse_math, radians)
static void rse_math_test_radians(void)
{
float degrees;
float radians;
float expected_radians;
degrees = 45.0f;
expected_radians = 0.7853;
expected_radians = 0.7853982;
radians = rse_math_deg_to_radians(degrees);
cr_expect_float_eq(radians, expected_radians, 0.0001, "Expected %f, got %f", expected_radians, radians);
TEST_ASSERT_EQUAL_FLOAT(expected_radians, radians);
}
Test(rse_math, perspective)
static void rse_math_test_perspective(void)
{
float fovy;
float fovy;
float width;
float height;
float z_near;
@@ -156,29 +160,28 @@ Test(rse_math, perspective)
result = rse_math_perspective(fovy, width / height, z_near, z_far);
cr_expect_float_eq(result.x_1, expected.x_1, 0.0001, "Expected x_1 %f, got %f", expected.x_1, result.x_1);
cr_expect_float_eq(result.y_1, expected.y_1, 0.0001, "Expected y_1 %f, got %f", expected.y_1, result.y_1);
cr_expect_float_eq(result.z_1, expected.z_1, 0.0001, "Expected z_1 %f, got %f", expected.z_1, result.z_1);
cr_expect_float_eq(result.w_1, expected.w_1, 0.0001, "Expected w_1 %f, got %f", expected.w_1, result.w_1);
TEST_ASSERT_EQUAL_FLOAT(expected.x_1, result.x_1);
TEST_ASSERT_EQUAL_FLOAT(expected.y_1, result.y_1);
TEST_ASSERT_EQUAL_FLOAT(expected.z_1, result.z_1);
TEST_ASSERT_EQUAL_FLOAT(expected.w_1, result.w_1);
cr_expect_float_eq(result.x_2, expected.x_2, 0.0001, "Expected x_2 %f, got %f", expected.x_2, result.x_2);
cr_expect_float_eq(result.y_2, expected.y_2, 0.0001, "Expected y_2 %f, got %f", expected.y_2, result.y_2);
cr_expect_float_eq(result.z_2, expected.z_2, 0.0001, "Expected z_2 %f, got %f", expected.z_2, result.z_2);
cr_expect_float_eq(result.w_2, expected.w_2, 0.0001, "Expected w_2 %f, got %f", expected.w_2, result.w_2);
TEST_ASSERT_EQUAL_FLOAT(expected.x_2, result.x_2);
TEST_ASSERT_EQUAL_FLOAT(expected.y_2, result.y_2);
TEST_ASSERT_EQUAL_FLOAT(expected.z_2, result.z_2);
TEST_ASSERT_EQUAL_FLOAT(expected.w_2, result.w_2);
cr_expect_float_eq(result.x_3, expected.x_3, 0.0001, "Expected x_3 %f, got %f", expected.x_3, result.x_3);
cr_expect_float_eq(result.y_3, expected.y_3, 0.0001, "Expected y_3 %f, got %f", expected.y_3, result.y_3);
cr_expect_float_eq(result.z_3, expected.z_3, 0.0001, "Expected z_3 %f, got %f", expected.z_3, result.z_3);
cr_expect_float_eq(result.w_3, expected.w_3, 0.0001, "Expected w_3 %f, got %f", expected.w_3, result.w_3);
cr_expect_float_eq(result.x_4, expected.x_4, 0.0001, "Expected x_4 %f, got %f", expected.x_4, result.x_4);
cr_expect_float_eq(result.y_4, expected.y_4, 0.0001, "Expected y_4 %f, got %f", expected.y_4, result.y_4);
cr_expect_float_eq(result.z_4, expected.z_4, 0.0001, "Expected z_4 %f, got %f", expected.z_4, result.z_4);
cr_expect_float_eq(result.w_4, expected.w_4, 0.0001, "Expected w_4 %f, got %f", expected.w_4, result.w_4);
TEST_ASSERT_EQUAL_FLOAT(expected.x_3, result.x_3);
TEST_ASSERT_EQUAL_FLOAT(expected.y_3, result.y_3);
TEST_ASSERT_EQUAL_FLOAT(expected.z_3, result.z_3);
TEST_ASSERT_EQUAL_FLOAT(expected.w_3, result.w_3);
TEST_ASSERT_EQUAL_FLOAT(expected.x_4, result.x_4);
TEST_ASSERT_EQUAL_FLOAT(expected.y_4, result.y_4);
TEST_ASSERT_EQUAL_FLOAT(expected.z_4, result.z_4);
TEST_ASSERT_EQUAL_FLOAT(expected.w_4, result.w_4);
}
Test(rse_math, rotation)
static void rse_math_test_rotation(void)
{
struct mat4_t matrix_to_rotate = rse_math_uniform_mat4();
struct vec3_t rotation_vector = {1.0f, 0.0f, 0.0f};
@@ -195,23 +198,34 @@ Test(rse_math, rotation)
result = rse_math_rotate(matrix_to_rotate, rotation, rotation_vector);
cr_expect_float_eq(result.x_1, expected.x_1, 0.0001, "Expected x_1 %f, got %f", expected.x_1, result.x_1);
cr_expect_float_eq(result.y_1, expected.y_1, 0.0001, "Expected y_1 %f, got %f", expected.y_1, result.y_1);
cr_expect_float_eq(result.z_1, expected.z_1, 0.0001, "Expected z_1 %f, got %f", expected.z_1, result.z_1);
cr_expect_float_eq(result.w_1, expected.w_1, 0.0001, "Expected w_1 %f, got %f", expected.w_1, result.w_1);
cr_expect_float_eq(result.x_2, expected.x_2, 0.0001, "Expected x_2 %f, got %f", expected.x_2, result.x_2);
cr_expect_float_eq(result.y_2, expected.y_2, 0.0001, "Expected y_2 %f, got %f", expected.y_2, result.y_2);
cr_expect_float_eq(result.z_2, expected.z_2, 0.0001, "Expected z_2 %f, got %f", expected.z_2, result.z_2);
cr_expect_float_eq(result.w_2, expected.w_2, 0.0001, "Expected w_2 %f, got %f", expected.w_2, result.w_2);
TEST_ASSERT_EQUAL_FLOAT(expected.x_1, result.x_1);
TEST_ASSERT_EQUAL_FLOAT(expected.y_1, result.y_1);
TEST_ASSERT_EQUAL_FLOAT(expected.z_1, result.z_1);
TEST_ASSERT_EQUAL_FLOAT(expected.w_1, result.w_1);
cr_expect_float_eq(result.x_3, expected.x_3, 0.0001, "Expected x_3 %f, got %f", expected.x_3, result.x_3);
cr_expect_float_eq(result.y_3, expected.y_3, 0.0001, "Expected y_3 %f, got %f", expected.y_3, result.y_3);
cr_expect_float_eq(result.z_3, expected.z_3, 0.0001, "Expected z_3 %f, got %f", expected.z_3, result.z_3);
cr_expect_float_eq(result.w_3, expected.w_3, 0.0001, "Expected w_3 %f, got %f", expected.w_3, result.w_3);
TEST_ASSERT_EQUAL_FLOAT(expected.x_2, result.x_2);
TEST_ASSERT_EQUAL_FLOAT(expected.y_2, result.y_2);
TEST_ASSERT_EQUAL_FLOAT(expected.z_2, result.z_2);
TEST_ASSERT_EQUAL_FLOAT(expected.w_2, result.w_2);
cr_expect_float_eq(result.x_4, expected.x_4, 0.0001, "Expected x_4 %f, got %f", expected.x_4, result.x_4);
cr_expect_float_eq(result.y_4, expected.y_4, 0.0001, "Expected y_4 %f, got %f", expected.y_4, result.y_4);
cr_expect_float_eq(result.z_4, expected.z_4, 0.0001, "Expected z_4 %f, got %f", expected.z_4, result.z_4);
cr_expect_float_eq(result.w_4, expected.w_4, 0.0001, "Expected w_4 %f, got %f", expected.w_4, result.w_4);
}
TEST_ASSERT_EQUAL_FLOAT(expected.x_3, result.x_3);
TEST_ASSERT_EQUAL_FLOAT(expected.y_3, result.y_3);
TEST_ASSERT_EQUAL_FLOAT(expected.z_3, result.z_3);
TEST_ASSERT_EQUAL_FLOAT(expected.w_3, result.w_3);
TEST_ASSERT_EQUAL_FLOAT(expected.x_4, result.x_4);
TEST_ASSERT_EQUAL_FLOAT(expected.y_4, result.y_4);
TEST_ASSERT_EQUAL_FLOAT(expected.z_4, result.z_4);
TEST_ASSERT_EQUAL_FLOAT(expected.w_4, result.w_4);
}
void rse_math_tests(void)
{
RUN_TEST(test_rse_math_test_vector3_normalize);
RUN_TEST(test_rse_math_test_vector3_cross);
RUN_TEST(test_rse_math_test_look_at);
RUN_TEST(rse_math_test_radians);
RUN_TEST(rse_math_test_perspective);
RUN_TEST(rse_math_test_rotation);
}
+12
View File
@@ -0,0 +1,12 @@
/**
* @file rse_math_tests.h
* @author Piotr Krygier (everyonecancode@gmail.com)
* @brief Tests for rse_math module
* @version 0.1
* @date 2024-02-16
*
* @copyright Copyright (c) 2024
*
*/
void rse_math_tests(void);