Improve testing framework
Replaced Criterrion with CMock. Added few tests, currently not working properly. Random test upgrades.
This commit is contained in:
1 parent
56c0b7922f
commit
f5ab5f3f27
29 files changed
+140082
-310
No files matched your search
@@ -7,7 +7,6 @@ project("RedScarfEngine"
|
||||
set(CMAKE_C_STANDARD 23)
|
||||
|
||||
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror")
|
||||
|
||||
add_subdirectory(red_scarf_engine)
|
||||
add_subdirectory(utilities)
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
set(CMOCK_DIR "${PROJECT_SOURCE_DIR}/third_party/cmock/")
|
||||
|
||||
|
||||
find_library(
|
||||
cmock
|
||||
NAMES cmock
|
||||
HINTS ${CMOCK_DIR}/build/src/
|
||||
)
|
||||
|
||||
find_library(
|
||||
unity
|
||||
NAMES unity
|
||||
HINTS ${CMOCK_DIR}/build/vendor/unity/src/
|
||||
)
|
||||
|
||||
set(cmock_INCLUDE_DIR "${CMOCK_DIR}/src/")
|
||||
set(unity_INCLUDE_DIR "${CMOCK_DIR}/vendor/unity/src/")
|
||||
@@ -23,3 +23,7 @@ tag = master
|
||||
[FreeType]
|
||||
dl_url = https://download.savannah.gnu.org/releases/freetype/freetype-2.10.0.tar.gz
|
||||
custom_commands = tar -xf FreeType && mv freetype-2.10.0 freetype && rm FreeType && cd freetype && cmake -E make_directory build && cmake -E chdir build cmake -D BUILD_SHARED_LIBS:BOOL=true .. && cmake --build build
|
||||
|
||||
[CMock]
|
||||
git_url = https://github.com/throwtheswitch/cmock.git
|
||||
custom_commands = cd cmock && bundle install
|
||||
@@ -7,6 +7,8 @@ find_package(FreeType REQUIRED)
|
||||
find_package(Vulkan COMPONENTS glslc)
|
||||
find_program(glslc_executable NAMES glslc HINTS ${Vulkan_GLSLC_EXECUTABLE}/..)
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror")
|
||||
|
||||
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/shaders)
|
||||
|
||||
cmake_policy(SET CMP0116 NEW)
|
||||
@@ -35,7 +37,11 @@ shaders/solid_objects.frag
|
||||
shaders/on_screen_text.frag
|
||||
)
|
||||
|
||||
add_library(rse_graphics SHARED shaders/shader.vert.num shaders/shader.frag.num)
|
||||
add_library(rse_graphics SHARED
|
||||
shaders/shader.vert.num
|
||||
shaders/solid_objects.frag.num
|
||||
shaders/on_screen_text.frag.num
|
||||
)
|
||||
target_include_directories(rse_graphics PRIVATE
|
||||
${PROJECT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
|
||||
@@ -14,5 +14,5 @@ layout(location = 0) out vec4 outColor;
|
||||
|
||||
void main() {
|
||||
vec4 texturePixels = texture(texSampler[instanceTextureId], fragTexCoord);
|
||||
outColor = vec4(fragColor * texturePixels, texturePixels.a);
|
||||
outColor = vec4(fragColor * texturePixels.rgb, texturePixels.a);
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "vulkan_buffers.h"
|
||||
|
||||
#include "src/vulkan_commons.h"
|
||||
#include "utilities/rse_commons.h"
|
||||
#include "vulkan_errors.h"
|
||||
#include "locale_vulkan.h"
|
||||
#include "utilities/logger.h"
|
||||
@@ -212,7 +213,7 @@ void update_uniform_buffers()
|
||||
g_vulkan_state.swapchain_extent.width / (float)g_vulkan_state.swapchain_extent.height,
|
||||
z_near,
|
||||
z_far);
|
||||
memcpy(g_vulkan_state.uniform_buffers[g_vulkan_state.current_frame].allocation_info.pMappedData, &ubo, sizeof(ubo));
|
||||
rse_memcpy(g_vulkan_state.uniform_buffers[g_vulkan_state.current_frame].allocation_info.pMappedData, &ubo, sizeof(ubo));
|
||||
}
|
||||
|
||||
rse_err_t rse_add_vertices(uint16_t mesh_id,
|
||||
@@ -239,7 +240,7 @@ rse_err_t rse_add_vertices(uint16_t mesh_id,
|
||||
|
||||
/* Fill staging buffer with vertex data */
|
||||
memset(staging_buffer.allocation_info.pMappedData, 0, MAX_VERTEX_BUFFER_SIZE);
|
||||
memcpy(staging_buffer.allocation_info.pMappedData, vertices, vertices_size);
|
||||
rse_memcpy(staging_buffer.allocation_info.pMappedData, vertices, vertices_size);
|
||||
copy_buffer(staging_buffer.buffer,
|
||||
g_vertex_buffer.buffer,
|
||||
vertices_size,
|
||||
@@ -251,7 +252,7 @@ rse_err_t rse_add_vertices(uint16_t mesh_id,
|
||||
|
||||
/* Fill staging buffer with index data */
|
||||
memset(staging_buffer.allocation_info.pMappedData, 0, indices_size);
|
||||
memcpy(staging_buffer.allocation_info.pMappedData, indices, indices_size);
|
||||
rse_memcpy(staging_buffer.allocation_info.pMappedData, indices, indices_size);
|
||||
copy_buffer(staging_buffer.buffer,
|
||||
index_buffer->buffer,
|
||||
indices_size,
|
||||
@@ -267,7 +268,7 @@ rse_err_t rse_add_vertices(uint16_t mesh_id,
|
||||
draw_indirect_command.vertexOffset = vertex_data->buffer_offset;
|
||||
draw_indirect_command.firstInstance = 0;
|
||||
|
||||
memcpy(g_draw_indirect_command_buffer.allocation_info.pMappedData + (mesh_id * sizeof(VkDrawIndexedIndirectCommand)), &draw_indirect_command, sizeof(VkDrawIndexedIndirectCommand));
|
||||
rse_memcpy(g_draw_indirect_command_buffer.allocation_info.pMappedData + (mesh_id * sizeof(VkDrawIndexedIndirectCommand)), &draw_indirect_command, sizeof(VkDrawIndexedIndirectCommand));
|
||||
|
||||
return RSE_ERROR_NO_ERROR;
|
||||
}
|
||||
@@ -289,7 +290,7 @@ rse_err_t update_mesh_instances(uint16_t mesh_id, struct rse_instance_data_t* in
|
||||
&staging_buffer));
|
||||
|
||||
/* Copy transformation information about instance */
|
||||
memcpy(staging_buffer.allocation_info.pMappedData, instance_data, instance_size);
|
||||
rse_memcpy(staging_buffer.allocation_info.pMappedData, instance_data, instance_size);
|
||||
copy_buffer(staging_buffer.buffer,
|
||||
instance_buffer->buffer,
|
||||
instance_size,
|
||||
@@ -299,9 +300,9 @@ rse_err_t update_mesh_instances(uint16_t mesh_id, struct rse_instance_data_t* in
|
||||
|
||||
instance_buffer->allocated_size += instance_size;
|
||||
|
||||
memcpy(&draw_indirect_command, g_draw_indirect_command_buffer.allocation_info.pMappedData + (mesh_id * sizeof(VkDrawIndexedIndirectCommand)), sizeof(VkDrawIndexedIndirectCommand));
|
||||
rse_memcpy(&draw_indirect_command, g_draw_indirect_command_buffer.allocation_info.pMappedData + (mesh_id * sizeof(VkDrawIndexedIndirectCommand)), sizeof(VkDrawIndexedIndirectCommand));
|
||||
draw_indirect_command.instanceCount++;
|
||||
memcpy(g_draw_indirect_command_buffer.allocation_info.pMappedData + (mesh_id * sizeof(VkDrawIndexedIndirectCommand)), &draw_indirect_command, sizeof(VkDrawIndexedIndirectCommand));
|
||||
rse_memcpy(g_draw_indirect_command_buffer.allocation_info.pMappedData + (mesh_id * sizeof(VkDrawIndexedIndirectCommand)), &draw_indirect_command, sizeof(VkDrawIndexedIndirectCommand));
|
||||
|
||||
return RSE_ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "src/window.h"
|
||||
#include "utilities/file_utils.h"
|
||||
#include "utilities/logger.h"
|
||||
#include "utilities/rse_commons.h"
|
||||
#include "utilities/rse_errors_common.h"
|
||||
#include "vulkan/vulkan_core.h"
|
||||
#include "vulkan_errors.h"
|
||||
@@ -16,7 +17,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define SHADER_MODULES_COUNT 3U
|
||||
#define SHADER_MODULES_COUNT 2U
|
||||
|
||||
enum shader_stage_t
|
||||
{
|
||||
@@ -146,7 +147,7 @@ static rse_err_t create_swapchain()
|
||||
|
||||
/* Obtain swapchain images */
|
||||
vkGetSwapchainImagesKHR(g_vulkan_state.device, g_vulkan_state.swapchain, &g_swapchain_images_count, NULL);
|
||||
g_swapchain_images = (VkImage*)malloc(sizeof(VkImage) * g_swapchain_images_count);
|
||||
rse_malloc(g_swapchain_images, sizeof(VkImage) * g_swapchain_images_count);
|
||||
vkGetSwapchainImagesKHR(g_vulkan_state.device, g_vulkan_state.swapchain, &g_swapchain_images_count, g_swapchain_images);
|
||||
|
||||
return RSE_ERROR_NO_ERROR;
|
||||
@@ -159,7 +160,7 @@ static rse_err_t create_swapchain()
|
||||
*/
|
||||
static rse_err_t create_swapchain_image_views()
|
||||
{
|
||||
g_vulkan_state.swapchain_image_views = malloc(sizeof(VkImageView) * g_swapchain_images_count);
|
||||
rse_malloc(g_vulkan_state.swapchain_image_views, sizeof(VkImageView) * g_swapchain_images_count);
|
||||
for (size_t i = 0; i < g_swapchain_images_count; i++) {
|
||||
VkImageViewCreateInfo create_info;
|
||||
|
||||
@@ -381,18 +382,18 @@ static rse_err_t fill_shader_stages(VkPipelineShaderStageCreateInfo* shader_stag
|
||||
VkPipelineShaderStageCreateInfo frag_shader_stage_info = {};
|
||||
|
||||
rse_read_file(g_shader_paths[VERTEX], &buffer_size, NULL);
|
||||
buffer = malloc(buffer_size);
|
||||
rse_malloc(buffer, buffer_size);
|
||||
rse_read_file(g_shader_paths[VERTEX], &buffer_size, buffer);
|
||||
|
||||
STATUS_CHECK(create_shader_module(buffer, buffer_size, &vertex_shader_module));
|
||||
free(buffer);
|
||||
rse_free(buffer);
|
||||
|
||||
rse_read_file(g_shader_paths[FRAGMENTS], &buffer_size, NULL);
|
||||
buffer = malloc(buffer_size);
|
||||
rse_malloc(buffer, buffer_size);
|
||||
rse_read_file(g_shader_paths[FRAGMENTS], &buffer_size, buffer);
|
||||
|
||||
STATUS_CHECK(create_shader_module(buffer, buffer_size, &fragments_shader_module));
|
||||
free(buffer);
|
||||
rse_free(buffer);
|
||||
|
||||
/* Vertex Shader Pipeline Stage */
|
||||
vert_shader_stage_info.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
|
||||
@@ -415,8 +416,8 @@ static rse_err_t fill_shader_stages(VkPipelineShaderStageCreateInfo* shader_stag
|
||||
shader_stages[VERTEX] = vert_shader_stage_info;
|
||||
shader_stages[FRAGMENTS] = frag_shader_stage_info;
|
||||
|
||||
memcpy(&g_shader_modules[0], &vertex_shader_module, sizeof(VkShaderModule));
|
||||
memcpy(&g_shader_modules[1], &fragments_shader_module, sizeof(VkShaderModule));
|
||||
rse_memcpy(&g_shader_modules[0], &vertex_shader_module, sizeof(VkShaderModule));
|
||||
rse_memcpy(&g_shader_modules[1], &fragments_shader_module, sizeof(VkShaderModule));
|
||||
|
||||
return RSE_ERROR_NO_ERROR;
|
||||
}
|
||||
@@ -434,7 +435,7 @@ static void fill_dynamic_pipeline_state_info(VkPipelineDynamicStateCreateInfo* d
|
||||
* pipeline create structures. I'll list ignored members of structs, that will be ignored due to the
|
||||
* settings and also functions, that will need to be called to set specific state.
|
||||
*/
|
||||
dynamic_states = malloc(sizeof(VkDynamicState) * 2);
|
||||
rse_malloc(dynamic_states, sizeof(VkDynamicState) * 2);
|
||||
dynamic_states[0] = VK_DYNAMIC_STATE_VIEWPORT; /* VkPipelineViewportStateCreateInfo:pViewport; vkCmdSetViewport() */
|
||||
dynamic_states[1] = VK_DYNAMIC_STATE_SCISSOR; /* VkPipelineViewportStateCreateInfo:pScissors; vkCmdSetScissors() */
|
||||
|
||||
@@ -456,7 +457,7 @@ static void fill_dynamic_pipeline_state_info(VkPipelineDynamicStateCreateInfo* d
|
||||
*/
|
||||
static void free_dynamic_pipeline_state_info(VkPipelineDynamicStateCreateInfo* dynamic_state)
|
||||
{
|
||||
free((VkDynamicState*)dynamic_state->pDynamicStates);
|
||||
rse_free((VkDynamicState*)dynamic_state->pDynamicStates);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -468,14 +469,15 @@ static void fill_vertex_input_info(VkPipelineVertexInputStateCreateInfo* vertex_
|
||||
{
|
||||
const size_t binding_descriptions_count = 2;
|
||||
const size_t attribute_descriptions_count = 7;
|
||||
/* This is clusterfuck with some magic numbers here and there and unneeded malloc and memcpy stuff. Change,
|
||||
/* TODO: This is clusterfuck with some magic numbers here and there and unneeded malloc and memcpy stuff. Change,
|
||||
* so you won't feel ashamed. */
|
||||
VkVertexInputBindingDescription vertex_binding_description = get_binding_description();
|
||||
VkVertexInputAttributeDescription* vertex_attribute_descriptions = get_attribute_descriptions();
|
||||
VkVertexInputBindingDescription* binding_descriptions = malloc(sizeof(VkVertexInputBindingDescription)
|
||||
* binding_descriptions_count);
|
||||
VkVertexInputAttributeDescription* attribute_descriptions = malloc(sizeof(VkVertexInputAttributeDescription)
|
||||
* attribute_descriptions_count);
|
||||
VkVertexInputBindingDescription* binding_descriptions = NULL;
|
||||
VkVertexInputAttributeDescription* attribute_descriptions = NULL;
|
||||
|
||||
rse_malloc(binding_descriptions, sizeof(VkVertexInputBindingDescription) * binding_descriptions_count);
|
||||
rse_malloc(attribute_descriptions, sizeof(VkVertexInputAttributeDescription) * attribute_descriptions_count);
|
||||
|
||||
binding_descriptions[0] = vertex_binding_description;
|
||||
|
||||
@@ -483,7 +485,7 @@ static void fill_vertex_input_info(VkPipelineVertexInputStateCreateInfo* vertex_
|
||||
binding_descriptions[1].stride = sizeof(struct rse_instance_data_t);
|
||||
binding_descriptions[1].inputRate = VK_VERTEX_INPUT_RATE_INSTANCE;
|
||||
|
||||
memcpy(attribute_descriptions, vertex_attribute_descriptions, sizeof(VkVertexInputAttributeDescription) * 3);
|
||||
rse_memcpy(attribute_descriptions, vertex_attribute_descriptions, sizeof(VkVertexInputAttributeDescription) * 3);
|
||||
|
||||
attribute_descriptions[3].binding = 1;
|
||||
attribute_descriptions[3].location = 3;
|
||||
@@ -523,8 +525,8 @@ static void fill_vertex_input_info(VkPipelineVertexInputStateCreateInfo* vertex_
|
||||
*/
|
||||
static void free_vertex_input_info(VkPipelineVertexInputStateCreateInfo* vertex_input_info)
|
||||
{
|
||||
free((VkVertexInputBindingDescription*)vertex_input_info->pVertexBindingDescriptions);
|
||||
free((VkVertexInputAttributeDescription*)vertex_input_info->pVertexAttributeDescriptions);
|
||||
rse_free((VkVertexInputBindingDescription*)vertex_input_info->pVertexBindingDescriptions);
|
||||
rse_free((VkVertexInputAttributeDescription*)vertex_input_info->pVertexAttributeDescriptions);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -548,9 +550,11 @@ static void fill_input_assembly_info(VkPipelineInputAssemblyStateCreateInfo* inp
|
||||
*/
|
||||
static void fill_viewport_state_info(VkPipelineViewportStateCreateInfo* viewport_state)
|
||||
{
|
||||
VkViewport* viewport = malloc(sizeof(VkViewport));
|
||||
VkRect2D* scissor = malloc(sizeof(VkRect2D));
|
||||
VkViewport* viewport = NULL;
|
||||
VkRect2D* scissor = NULL;
|
||||
|
||||
rse_malloc(viewport, sizeof(VkViewport));
|
||||
rse_malloc(scissor, sizeof(VkRect2D));
|
||||
viewport->x = 0.0f;
|
||||
viewport->y = 0.0f;
|
||||
viewport->width = (float)(g_vulkan_state.swapchain_extent.width);
|
||||
@@ -577,8 +581,8 @@ static void fill_viewport_state_info(VkPipelineViewportStateCreateInfo* viewport
|
||||
*/
|
||||
static void free_viewport_state_info(VkPipelineViewportStateCreateInfo* viewport_state)
|
||||
{
|
||||
free((VkViewport*)viewport_state->pViewports);
|
||||
free((VkRect2D*)viewport_state->pScissors);
|
||||
rse_free((VkViewport*)viewport_state->pViewports);
|
||||
rse_free((VkRect2D*)viewport_state->pScissors);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -628,7 +632,9 @@ static void fill_multisampling_state_info(VkPipelineMultisampleStateCreateInfo*
|
||||
*/
|
||||
static void fill_color_blend_state_info(VkPipelineColorBlendStateCreateInfo* color_blending)
|
||||
{
|
||||
VkPipelineColorBlendAttachmentState* color_blend_attachment = malloc(sizeof(VkPipelineColorBlendAttachmentState));
|
||||
VkPipelineColorBlendAttachmentState* color_blend_attachment = NULL;
|
||||
|
||||
rse_malloc(color_blend_attachment, sizeof(VkPipelineColorBlendAttachmentState));
|
||||
|
||||
color_blend_attachment->blendEnable = VK_TRUE;
|
||||
color_blend_attachment->srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
|
||||
@@ -660,7 +666,7 @@ static void fill_color_blend_state_info(VkPipelineColorBlendStateCreateInfo* col
|
||||
*/
|
||||
static void free_color_blend_info(VkPipelineColorBlendStateCreateInfo* color_blending)
|
||||
{
|
||||
free((VkPipelineColorBlendAttachmentState*)color_blending->pAttachments);
|
||||
rse_free((VkPipelineColorBlendAttachmentState*)color_blending->pAttachments);
|
||||
}
|
||||
|
||||
static void fill_depth_stencil_info(VkPipelineDepthStencilStateCreateInfo* depth_stencil)
|
||||
@@ -749,7 +755,9 @@ static rse_err_t create_graphics_pipeline()
|
||||
*/
|
||||
static rse_err_t create_framebuffers()
|
||||
{
|
||||
g_vulkan_state.swapchain_framebuffers = malloc(sizeof(VkFramebuffer) * g_swapchain_images_count);
|
||||
g_vulkan_state.swapchain_framebuffers = NULL;
|
||||
|
||||
rse_malloc(g_vulkan_state.swapchain_framebuffers, sizeof(VkFramebuffer) * g_swapchain_images_count);
|
||||
|
||||
for (size_t i = 0; i < g_swapchain_images_count; i++) {
|
||||
VkImageView attachments[] = {rse_get_color_image_view(), rse_get_depth_image_view(), g_vulkan_state.swapchain_image_views[i]};
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror")
|
||||
|
||||
add_executable(${PROJECT_NAME} src/main.c)
|
||||
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE
|
||||
|
||||
+45
-6
@@ -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
|
||||
)
|
||||
@@ -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
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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; }
|
||||
@@ -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
@@ -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, ¢er, &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");
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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
@@ -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, ¢er, &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);
|
||||
}
|
||||
@@ -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);
|
||||
@@ -1,3 +1,5 @@
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror")
|
||||
|
||||
add_library(rse_utilities SHARED)
|
||||
|
||||
target_include_directories(rse_utilities PRIVATE
|
||||
|
||||
+2
-6
@@ -12,16 +12,11 @@
|
||||
#ifndef RSE_LOGGER_H
|
||||
#define RSE_LOGGER_H
|
||||
|
||||
#ifndef LOG_LEVEL
|
||||
#define LOG_LEVEL LOGLEVEL_DEBUG
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
|
||||
#define LOGGER(log_level, ...) _log_log(log_level, __FILENAME__, __LINE__, __VA_ARGS__)
|
||||
// #define LOGGER(log_level, ...) printf("[##log_level] %s:%d", __FILE__, __LINE__); printf(__VA_ARGS__)
|
||||
|
||||
#define LOGT(...) LOGGER(LOGLEVEL_TRACE, __VA_ARGS__)
|
||||
#define LOGD(...) LOGGER(LOGLEVEL_DEBUG, __VA_ARGS__)
|
||||
@@ -41,7 +36,8 @@ enum log_level_t
|
||||
LOGLEVEL_INFO,
|
||||
LOGLEVEL_WARNING,
|
||||
LOGLEVEL_ERROR,
|
||||
LOGLEVEL_FATAL
|
||||
LOGLEVEL_FATAL,
|
||||
LOGLEVEL_NONE
|
||||
};
|
||||
|
||||
void _log_log(unsigned int level, const char* file, int line, const char* fmt, ...);
|
||||
|
||||
+12
-2
@@ -19,13 +19,23 @@
|
||||
* @brief Macro for allocating memory and checking it on the same line
|
||||
*
|
||||
*/
|
||||
#ifndef RSE_TEST
|
||||
#define rse_malloc(ptr, size) \
|
||||
ptr = malloc(size); \
|
||||
if (ptr == NULL) { \
|
||||
LOGF(common_messages[COMMON_ERROR_MEMORY_ALLOCATION_FAILED]); \
|
||||
return RSE_COMMON_ERROR_MALLLOC_FAILED; \
|
||||
LOGF(common_messages[COMMON_ERROR_MEMORY_ALLOCATION_FAILED]); \
|
||||
exit(1); \
|
||||
}
|
||||
|
||||
#define rse_free(ptr) free(ptr);
|
||||
|
||||
#define rse_memcpy(dst, src, size) memcpy(dst, src, size);
|
||||
#else
|
||||
#define rse_malloc(ptr, size) ptr = NULL;
|
||||
#define rse_free(ptr)
|
||||
#define rse_memcpy(dst, src, size)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Error type for RSE
|
||||
*
|
||||
|
||||
@@ -5,10 +5,19 @@ const char* log_levels[] = {
|
||||
"[TRACE]", "[DEBUG]", "[INFO]", "WARNING", "[ERROR]", "[FATAL]"
|
||||
};
|
||||
|
||||
#ifndef LOGLEVEL
|
||||
#define LOGLEVEL LOGLEVEL_DEBUG
|
||||
#endif
|
||||
|
||||
void _log_log(unsigned int level, const char* file, int line, const char* fmt, ...)
|
||||
{
|
||||
va_list list;
|
||||
|
||||
if (level < LOGLEVEL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
va_start(list, fmt);
|
||||
fprintf(stdout, "%s %s:%d: ", log_levels[level], file, line);
|
||||
vfprintf(stdout, fmt, list);
|
||||
|
||||
Reference in new issue
Block a user