diff options
author | David Robillard <d@drobilla.net> | 2019-11-18 16:20:33 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2019-11-18 19:33:16 +0100 |
commit | 47beee70b04438f291ba00b6dc9d14ec4a54c662 (patch) | |
tree | f26cd7364a69907becdc6e52db13cc8fe583207c /test | |
parent | dd90f0dc8918e3ebfc4f526e332bfdb71129531f (diff) | |
download | pugl-47beee70b04438f291ba00b6dc9d14ec4a54c662.tar.gz pugl-47beee70b04438f291ba00b6dc9d14ec4a54c662.tar.bz2 pugl-47beee70b04438f291ba00b6dc9d14ec4a54c662.zip |
Add test utility function for logging errors
Diffstat (limited to 'test')
-rw-r--r-- | test/pugl_cairo_test.c | 4 | ||||
-rw-r--r-- | test/pugl_gl3_test.c | 6 | ||||
-rw-r--r-- | test/pugl_print_events.c | 3 | ||||
-rw-r--r-- | test/pugl_test.c | 10 | ||||
-rw-r--r-- | test/test_utils.h | 16 |
5 files changed, 23 insertions, 16 deletions
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 <math.h> +#include <stdarg.h> #include <stdint.h> #include <stdio.h> #include <string.h> @@ -156,6 +157,19 @@ perspective(float* m, float fov, float aspect, float zNear, float zFar) } 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) { return fprintf(stderr, "Modifiers:%s%s%s%s\n", @@ -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]); } } |