add basic surface tests

This commit is contained in:
Gered 2015-01-18 22:22:58 -05:00
parent 7eeff3230e
commit 2982915da3
2 changed files with 84 additions and 0 deletions

View file

@ -21,3 +21,6 @@ target_link_libraries("test_wm" ${SDL2_LIBRARY})
add_executable("test_primitives" "${TESTS_DIR}/test_primitives.c" ${LIB_SRC_FILES})
target_link_libraries("test_primitives" ${SDL2_LIBRARY})
add_executable("test_surfaces" "${TESTS_DIR}/test_surfaces.c" ${LIB_SRC_FILES})
target_link_libraries("test_surfaces" ${SDL2_LIBRARY})

81
test/test_surfaces.c Normal file
View file

@ -0,0 +1,81 @@
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <fbgfx/surface.h>
void test_rgba(SURFACE_FLAGS flags) {
SURFACE *surface = surface_create(100, 100, SURFACE_FORMAT_RGBA, flags);
assert(surface != NULL);
// set + get
{
COLOR color = color_create_rgba(255, 0, 0, 255);
surface_set_pixel(surface, 20, 10, color);
COLOR read_color = surface_get_pixel(surface, 20, 10);
assert(read_color != 0);
assert(color == read_color);
}
// get (out of bounds, clipped)
{
COLOR read_color = surface_get_pixel(surface, -1, -1);
assert(read_color == 0);
}
surface_destroy(surface);
}
void test_rgb(SURFACE_FLAGS flags) {
SURFACE *surface = surface_create(100, 100, SURFACE_FORMAT_RGB, flags);
assert(surface != NULL);
// set + get
{
COLOR color = color_create_rgb(255, 0, 0);
surface_set_pixel(surface, 20, 10, color);
COLOR read_color = surface_get_pixel(surface, 20, 10);
assert(read_color != 0);
assert(color == read_color);
}
// get (out of bounds, clipped)
{
COLOR read_color = surface_get_pixel(surface, -1, -1);
assert(read_color == 0);
}
surface_destroy(surface);
}
void test_alpha(SURFACE_FLAGS flags) {
SURFACE *surface = surface_create(100, 100, SURFACE_FORMAT_ALPHA, flags);
assert(surface != NULL);
// set + get
// destination surface is alpha-only. setting RGB/RGBA colors drops the RGB portion
// and keeps only the alpha component, setting it in the destination
{
COLOR color = color_create_rgba(255, 0, 0, 255);
surface_set_pixel(surface, 20, 10, color);
COLOR read_color = surface_get_pixel(surface, 20, 10);
assert(read_color != 0);
assert(color != read_color);
assert(read_color = color_create_rgba(0, 0, 0, 255));
}
// get (out of bounds, clipped)
{
COLOR read_color = surface_get_pixel(surface, -1, -1);
assert(read_color == 0);
}
surface_destroy(surface);
}
int main(int argc, char **argv) {
test_rgba(SURFACE_FLAGS_NONE);
test_rgb(SURFACE_FLAGS_NONE);
test_alpha(SURFACE_FLAGS_NONE);
return 0;
}