From 47beee70b04438f291ba00b6dc9d14ec4a54c662 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 18 Nov 2019 16:20:33 +0100 Subject: Add test utility function for logging errors --- test/pugl_cairo_test.c | 4 +--- test/pugl_gl3_test.c | 6 ++---- test/pugl_print_events.c | 3 +-- test/pugl_test.c | 10 ++++------ test/test_utils.h | 16 +++++++++++++++- 5 files changed, 23 insertions(+), 16 deletions(-) (limited to 'test') diff --git a/test/pugl_cairo_test.c b/test/pugl_cairo_test.c index 1ce9edd..61f8ce1 100644 --- a/test/pugl_cairo_test.c +++ b/test/pugl_cairo_test.c @@ -230,9 +230,7 @@ main(int argc, char** argv) PuglStatus st = puglCreateWindow(view, "Pugl Test"); if (st) { - fprintf(stderr, "error: Failed to create window (%s)\n", - puglStrerror(st)); - return 1; + return logError("Failed to create window (%s)\n", puglStrerror(st)); } puglShowWindow(view); diff --git a/test/pugl_gl3_test.c b/test/pugl_gl3_test.c index 06e816c..4f9bbb5 100644 --- a/test/pugl_gl3_test.c +++ b/test/pugl_gl3_test.c @@ -315,9 +315,7 @@ main(int argc, char** argv) const PuglStatus st = puglCreateWindow(app.view, "Pugl OpenGL 3"); if (st) { - fprintf(stderr, "error: Failed to create window (%s)\n", - puglStrerror(st)); - return 1; + return logError("Failed to create window (%s)\n", puglStrerror(st)); } // Enter context to set up GL stuff @@ -325,7 +323,7 @@ main(int argc, char** argv) // Load GL functions via GLAD if (!gladLoadGLLoader((GLADloadproc)&puglGetProcAddress)) { - fprintf(stderr, "error: Failed to load GL\n"); + logError("Failed to load GL\n"); puglFreeView(app.view); puglFreeWorld(app.world); return 1; diff --git a/test/pugl_print_events.c b/test/pugl_print_events.c index c61b7f9..5e6fba1 100644 --- a/test/pugl_print_events.c +++ b/test/pugl_print_events.c @@ -65,8 +65,7 @@ main(void) puglSetEventFunc(app.view, onEvent); if (puglCreateWindow(app.view, "Pugl Event Printer")) { - fprintf(stderr, "error: Failed to create window\n"); - return 1; + return logError("Failed to create window\n"); } puglShowWindow(app.view); diff --git a/test/pugl_test.c b/test/pugl_test.c index c680866..99720d2 100644 --- a/test/pugl_test.c +++ b/test/pugl_test.c @@ -330,9 +330,8 @@ main(int argc, char** argv) const uint8_t title[] = { 'P', 'u', 'g', 'l', ' ', 'P', 'r', 0xC3, 0xBC, 'f', 'u', 'n', 'g', 0 }; if ((st = puglCreateWindow(app.parent, (const char*)title))) { - fprintf(stderr, "error: Failed to create parent window (%s)\n", - puglStrerror(st)); - return 1; + return logError("Failed to create parent window (%s)\n", + puglStrerror(st)); } puglSetFrame(app.child, getChildFrame(parentFrame)); @@ -348,9 +347,8 @@ main(int argc, char** argv) puglSetEventFunc(app.child, onEvent); if ((st = puglCreateWindow(app.child, NULL))) { - fprintf(stderr, "error: Failed to create child window (%s)\n", - puglStrerror(st)); - return 1; + return logError("Failed to create child window (%s)\n", + puglStrerror(st)); } puglShowWindow(app.parent); diff --git a/test/test_utils.h b/test/test_utils.h index f0f0c75..1f36772 100644 --- a/test/test_utils.h +++ b/test/test_utils.h @@ -17,6 +17,7 @@ #include "pugl/pugl.h" #include +#include #include #include #include @@ -155,6 +156,19 @@ perspective(float* m, float fov, float aspect, float zNear, float zFar) m[12] = 0; m[13] = 0; m[14] = qn; m[15] = 0; } +static inline int +logError(const char* fmt, ...) +{ + fprintf(stderr, "error: "); + + va_list args; + va_start(args, fmt); + vfprintf(stderr, fmt, args); + va_end(args); + + return 1; +} + static inline int printModifiers(const uint32_t mods) { @@ -286,7 +300,7 @@ puglParseTestOptions(int* pargc, char*** pargv) break; } else { opts.help = true; - fprintf(stderr, "error: Unknown option: %s\n", argv[i]); + logError("Unknown option: %s\n", argv[i]); } } -- cgit v1.2.1