From ecde0c8110da1c1f94cce7f6a1fa9406d04eca69 Mon Sep 17 00:00:00 2001 From: sanine Date: Fri, 19 Aug 2022 00:39:04 -0500 Subject: add several buffer-related functions --- src/gl/gl.test.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 2 deletions(-) (limited to 'src/gl/gl.test.c') diff --git a/src/gl/gl.test.c b/src/gl/gl.test.c index 9bacbf9..aa24fd2 100644 --- a/src/gl/gl.test.c +++ b/src/gl/gl.test.c @@ -6,13 +6,17 @@ int mock_glfwInit_(void); -int mock_hs_throw_error_(lua_State *L, const char *str); +int mock_hs_throw_error_(lua_State *L, const char *str, ...); void mock_glfwTerminate_(); +void mock_glBufferData_(int, size_t, const void *, int); #define glfwInit mock_glfwInit_ #define hs_throw_error mock_hs_throw_error_ #define glfwTerminate mock_glfwTerminate_ +#undef glBufferData +#define glBufferData mock_glBufferData_ #include "gl/gl.c" +#undef glBufferData #undef glfwTerminate #undef hs_throw_error #undef glfwInit @@ -31,7 +35,7 @@ int mock_glfwInit_() lily_mock_t *mock_hs_throw_error = NULL; -int mock_hs_throw_error_(lua_State *L, const char *str) +int mock_hs_throw_error_(lua_State *L, const char *str, ...) { struct lily_mock_arg_t args[] = { { sizeof(const char *), &str } @@ -53,6 +57,24 @@ void mock_glfwTerminate_() } +lily_mock_t *mock_glBufferData = NULL; +void mock_glBufferData_(int target, size_t size, const void *data, int usage) +{ + struct lily_mock_arg_t args[] = { + { sizeof(int), &target }, + { sizeof(size_t), &size }, + { sizeof(int), &usage } + }; + lily_mock_store_call(mock_glBufferData, args); + + size_t count = size/sizeof(lua_Number); + lua_Number *numbers = data; + for (int i=0; in_calls, 1); + int target; size_t size; int usage; + struct lily_mock_arg_t args[] = { + { sizeof(int), &target }, + { sizeof(size_t), &size }, + { sizeof(int), &usage } + }; + lily_mock_get_call(mock_glBufferData, args, 0); + lily_assert_int_equal(target, GL_ARRAY_BUFFER); + lily_assert_int_equal(size, 3*sizeof(lua_Number)); + lily_assert_int_equal(usage, GL_STATIC_DRAW); + + lua_Number n; + lily_get_value(mock_glBufferData, lua_Number, &n); + lily_assert_float_equal(n, 22, 0.1); + lily_get_value(mock_glBufferData, lua_Number, &n); + lily_assert_float_equal(n, 33, 0.1); + lily_get_value(mock_glBufferData, lua_Number, &n); + lily_assert_float_equal(n, 44, 0.1); +} + + void suite_gl() { lily_run_test(gl_init_succeeds); lily_run_test(gl_init_fails); lily_run_test(gl_terminate_works); + lily_run_test(gl_buffer_data_works); lily_mock_destroy(mock_glfwInit); lily_mock_destroy(mock_hs_throw_error); lily_mock_destroy(mock_glfwTerminate); + lily_mock_destroy(mock_glBufferData); } -- cgit v1.2.1