mirror of
https://git.shylie.info/shylie/glerminal.git
synced 2025-11-27 11:41:03 +00:00
Setup basic testing framework
This commit is contained in:
57
tests/CMakeLists.txt
Normal file
57
tests/CMakeLists.txt
Normal file
@@ -0,0 +1,57 @@
|
||||
cmake_minimum_required(VERSION 3.28)
|
||||
|
||||
set(CMAKE_FOLDER tests)
|
||||
|
||||
add_library(test-common STATIC
|
||||
${CMAKE_SOURCE_DIR}/source/glad/glad.h
|
||||
|
||||
test-common/test-common.h
|
||||
test-common/stb_image_write.h
|
||||
test-common/test-common.cpp
|
||||
)
|
||||
|
||||
target_include_directories(test-common
|
||||
PUBLIC
|
||||
test-common
|
||||
PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/source
|
||||
)
|
||||
|
||||
target_link_libraries(test-common PRIVATE glerminal)
|
||||
|
||||
file(GLOB_RECURSE
|
||||
TEST_RESOURCES
|
||||
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
CONFIGURE_DEPENDS
|
||||
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/resources/**.png
|
||||
)
|
||||
|
||||
foreach(RESOURCE_FILE ${TEST_RESOURCES})
|
||||
add_custom_command(
|
||||
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${RESOURCE_FILE}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/${RESOURCE_FILE}
|
||||
${CMAKE_CURRENT_BINARY_DIR}/${RESOURCE_FILE}
|
||||
DEPENDS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/${RESOURCE_FILE}
|
||||
)
|
||||
endforeach()
|
||||
|
||||
file(GLOB_RECURSE
|
||||
TEST_SOURCES
|
||||
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
CONFIGURE_DEPENDS
|
||||
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
|
||||
)
|
||||
|
||||
list(REMOVE_ITEM TEST_SOURCES test-common/test-common.cpp)
|
||||
list(TRANSFORM TEST_RESOURCES PREPEND ${CMAKE_CURRENT_BINARY_DIR}/)
|
||||
|
||||
foreach(SOURCE_FILE ${TEST_SOURCES})
|
||||
get_filename_component(SOURCE_FILENAME ${SOURCE_FILE} NAME_WLE)
|
||||
add_executable(test-${SOURCE_FILENAME} WIN32 ${SOURCE_FILE} ${TEST_RESOURCES})
|
||||
target_link_libraries(test-${SOURCE_FILENAME} PRIVATE glerminal test-common)
|
||||
add_test(NAME test-${SOURCE_FILENAME} COMMAND test-${SOURCE_FILENAME})
|
||||
endforeach()
|
||||
31
tests/basic.cpp
Normal file
31
tests/basic.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include <glerminal.h>
|
||||
|
||||
#include <test-common.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
void init()
|
||||
{
|
||||
glerminal_load_sprites_file("resources/image.png");
|
||||
|
||||
for (int i = 0; i < GRID_HEIGHT; i++)
|
||||
{
|
||||
glerminal_set(i, i, 0, 1);
|
||||
}
|
||||
|
||||
glerminal_flush();
|
||||
|
||||
glerminal_test_save_image();
|
||||
|
||||
glerminal_quit();
|
||||
}
|
||||
|
||||
void mainloop(float) {}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
glerminal_run(init, mainloop);
|
||||
|
||||
return 0;
|
||||
}
|
||||
3
tests/resources/image.png
Normal file
3
tests/resources/image.png
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:05ec57e986f3fbd9efcc6c9f8e571393af4db90d8eb92f041990ed690bddaf89
|
||||
size 196
|
||||
1724
tests/test-common/stb_image_write.h
Normal file
1724
tests/test-common/stb_image_write.h
Normal file
File diff suppressed because it is too large
Load Diff
21
tests/test-common/test-common.cpp
Normal file
21
tests/test-common/test-common.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#include <test-common.h>
|
||||
|
||||
#include <glerminal.h>
|
||||
#include <glad/glad.h>
|
||||
|
||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
#include <stb_image_write.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
unsigned char pixels[1280 * 800 * 3];
|
||||
}
|
||||
|
||||
void glerminal_test_save_image()
|
||||
{
|
||||
glReadBuffer(GL_LEFT);
|
||||
glReadPixels(0, 0, GRID_WIDTH * CELL_SCALE * 8, GRID_HEIGHT * CELL_SCALE * 8, GL_RGB, GL_UNSIGNED_BYTE, pixels);
|
||||
|
||||
stbi_flip_vertically_on_write(true);
|
||||
stbi_write_png("image.png", GRID_WIDTH * CELL_SCALE * 8, GRID_HEIGHT * CELL_SCALE * 8, 3, pixels, 1280 * 3);
|
||||
}
|
||||
6
tests/test-common/test-common.h
Normal file
6
tests/test-common/test-common.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef GLERMINAL_TEST_COMMON_H
|
||||
#define GLERMINAL_TEST_COMMON_H
|
||||
|
||||
void glerminal_test_save_image();
|
||||
|
||||
#endif//GLERMINAL_TEST_COMMON_H
|
||||
Reference in New Issue
Block a user