aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/test_build.c2
-rw-r--r--test/test_build.cpp2
-rw-r--r--test/test_clipboard.c116
-rw-r--r--test/test_gl_hints.c100
-rw-r--r--test/test_realize.c100
-rw-r--r--test/test_redisplay.c170
-rw-r--r--test/test_show_hide.c186
-rw-r--r--test/test_stub_hints.c82
-rw-r--r--test/test_timer.c168
-rw-r--r--test/test_update.c144
-rw-r--r--test/test_utils.h512
11 files changed, 790 insertions, 792 deletions
diff --git a/test/test_build.c b/test/test_build.c
index 5259c7c..957e0bd 100644
--- a/test/test_build.c
+++ b/test/test_build.c
@@ -28,5 +28,5 @@
int
main(void)
{
- return 0;
+ return 0;
}
diff --git a/test/test_build.cpp b/test/test_build.cpp
index 5beb4c3..20235e8 100644
--- a/test/test_build.cpp
+++ b/test/test_build.cpp
@@ -29,5 +29,5 @@
int
main()
{
- return 0;
+ return 0;
}
diff --git a/test/test_clipboard.c b/test/test_clipboard.c
index c1180b0..5749b65 100644
--- a/test/test_clipboard.c
+++ b/test/test_clipboard.c
@@ -30,75 +30,75 @@
#include <stddef.h>
typedef struct {
- PuglWorld* world;
- PuglView* views[2];
- PuglTestOptions opts;
- bool exposed;
+ PuglWorld* world;
+ PuglView* views[2];
+ PuglTestOptions opts;
+ bool exposed;
} PuglTest;
static PuglStatus
onEvent(PuglView* view, const PuglEvent* event)
{
- PuglTest* test = (PuglTest*)puglGetHandle(view);
+ PuglTest* test = (PuglTest*)puglGetHandle(view);
- if (event->type == PUGL_EXPOSE) {
- test->exposed = true;
- }
+ if (event->type == PUGL_EXPOSE) {
+ test->exposed = true;
+ }
- if (test->opts.verbose) {
- printEvent(event, "Event: ", true);
- }
+ if (test->opts.verbose) {
+ printEvent(event, "Event: ", true);
+ }
- return PUGL_SUCCESS;
+ return PUGL_SUCCESS;
}
int
main(int argc, char** argv)
{
- PuglTest test = {puglNewWorld(PUGL_PROGRAM, 0),
- {NULL, NULL},
- puglParseTestOptions(&argc, &argv),
- false};
-
- puglSetClassName(test.world, "Pugl Test");
-
- // Set up views
- for (unsigned i = 0u; i < 2; ++i) {
- test.views[i] = puglNewView(test.world);
- puglSetBackend(test.views[i], puglStubBackend());
- puglSetHandle(test.views[i], &test);
- puglSetEventFunc(test.views[i], onEvent);
- puglSetDefaultSize(test.views[i], 512, 512);
-
- assert(!puglShow(test.views[i]));
- }
-
- // Update until view is exposed
- while (!test.exposed) {
- assert(!puglUpdate(test.world, 0.0));
- }
-
- // Set clipboard text via the first view
- puglSetClipboard(test.views[0], NULL, "Text", 5);
-
- // Get clipboard contents via the second view
- const char* type = NULL;
- size_t len = 0;
- const void* const contents = puglGetClipboard(test.views[1], &type, &len);
-
- // Check that the data made it over
- assert(!strcmp(type, "text/plain"));
- assert(len == 5);
- assert(contents);
- assert(!strcmp((const char*)contents, "Text"));
-
- // Try setting the clipboard to an unsupported type
- assert(puglSetClipboard(test.views[0], "text/csv", "a,b,c", 6));
-
- // Tear down
- puglFreeView(test.views[0]);
- puglFreeView(test.views[1]);
- puglFreeWorld(test.world);
-
- return 0;
+ PuglTest test = {puglNewWorld(PUGL_PROGRAM, 0),
+ {NULL, NULL},
+ puglParseTestOptions(&argc, &argv),
+ false};
+
+ puglSetClassName(test.world, "Pugl Test");
+
+ // Set up views
+ for (unsigned i = 0u; i < 2; ++i) {
+ test.views[i] = puglNewView(test.world);
+ puglSetBackend(test.views[i], puglStubBackend());
+ puglSetHandle(test.views[i], &test);
+ puglSetEventFunc(test.views[i], onEvent);
+ puglSetDefaultSize(test.views[i], 512, 512);
+
+ assert(!puglShow(test.views[i]));
+ }
+
+ // Update until view is exposed
+ while (!test.exposed) {
+ assert(!puglUpdate(test.world, 0.0));
+ }
+
+ // Set clipboard text via the first view
+ puglSetClipboard(test.views[0], NULL, "Text", 5);
+
+ // Get clipboard contents via the second view
+ const char* type = NULL;
+ size_t len = 0;
+ const void* const contents = puglGetClipboard(test.views[1], &type, &len);
+
+ // Check that the data made it over
+ assert(!strcmp(type, "text/plain"));
+ assert(len == 5);
+ assert(contents);
+ assert(!strcmp((const char*)contents, "Text"));
+
+ // Try setting the clipboard to an unsupported type
+ assert(puglSetClipboard(test.views[0], "text/csv", "a,b,c", 6));
+
+ // Tear down
+ puglFreeView(test.views[0]);
+ puglFreeView(test.views[1]);
+ puglFreeWorld(test.world);
+
+ return 0;
}
diff --git a/test/test_gl_hints.c b/test/test_gl_hints.c
index c30d0ed..3be3651 100644
--- a/test/test_gl_hints.c
+++ b/test/test_gl_hints.c
@@ -30,60 +30,60 @@
static PuglStatus
onEvent(PuglView* view, const PuglEvent* event)
{
- (void)view;
- (void)event;
+ (void)view;
+ (void)event;
- return PUGL_SUCCESS;
+ return PUGL_SUCCESS;
}
int
main(void)
{
- PuglWorld* const world = puglNewWorld(PUGL_PROGRAM, 0);
- PuglView* const view = puglNewView(world);
-
- // Set up view
- puglSetClassName(world, "Pugl Test");
- puglSetBackend(view, puglGlBackend());
- puglSetEventFunc(view, onEvent);
- puglSetDefaultSize(view, 512, 512);
-
- // Set all hints that support it to PUGL_DONT_CARE
- assert(!puglSetViewHint(view, PUGL_RED_BITS, PUGL_DONT_CARE));
- assert(!puglSetViewHint(view, PUGL_GREEN_BITS, PUGL_DONT_CARE));
- assert(!puglSetViewHint(view, PUGL_BLUE_BITS, PUGL_DONT_CARE));
- assert(!puglSetViewHint(view, PUGL_ALPHA_BITS, PUGL_DONT_CARE));
- assert(!puglSetViewHint(view, PUGL_DEPTH_BITS, PUGL_DONT_CARE));
- assert(!puglSetViewHint(view, PUGL_STENCIL_BITS, PUGL_DONT_CARE));
- assert(!puglSetViewHint(view, PUGL_SAMPLES, PUGL_DONT_CARE));
- assert(!puglSetViewHint(view, PUGL_DOUBLE_BUFFER, PUGL_DONT_CARE));
- assert(!puglSetViewHint(view, PUGL_REFRESH_RATE, PUGL_DONT_CARE));
-
- // Realize view and print all hints for debugging convenience
- assert(!puglRealize(view));
- printViewHints(view);
-
- // Check that no hints are set to PUGL_DONT_CARE
- assert(puglGetViewHint(view, PUGL_USE_COMPAT_PROFILE) != PUGL_DONT_CARE);
- assert(puglGetViewHint(view, PUGL_USE_DEBUG_CONTEXT) != PUGL_DONT_CARE);
- assert(puglGetViewHint(view, PUGL_CONTEXT_VERSION_MAJOR) != PUGL_DONT_CARE);
- assert(puglGetViewHint(view, PUGL_CONTEXT_VERSION_MINOR) != PUGL_DONT_CARE);
- assert(puglGetViewHint(view, PUGL_RED_BITS) != PUGL_DONT_CARE);
- assert(puglGetViewHint(view, PUGL_GREEN_BITS) != PUGL_DONT_CARE);
- assert(puglGetViewHint(view, PUGL_BLUE_BITS) != PUGL_DONT_CARE);
- assert(puglGetViewHint(view, PUGL_ALPHA_BITS) != PUGL_DONT_CARE);
- assert(puglGetViewHint(view, PUGL_DEPTH_BITS) != PUGL_DONT_CARE);
- assert(puglGetViewHint(view, PUGL_STENCIL_BITS) != PUGL_DONT_CARE);
- assert(puglGetViewHint(view, PUGL_SAMPLES) != PUGL_DONT_CARE);
- assert(puglGetViewHint(view, PUGL_DOUBLE_BUFFER) != PUGL_DONT_CARE);
- assert(puglGetViewHint(view, PUGL_SWAP_INTERVAL) != PUGL_DONT_CARE);
- assert(puglGetViewHint(view, PUGL_RESIZABLE) != PUGL_DONT_CARE);
- assert(puglGetViewHint(view, PUGL_IGNORE_KEY_REPEAT) != PUGL_DONT_CARE);
- assert(puglGetViewHint(view, PUGL_REFRESH_RATE) != PUGL_DONT_CARE);
-
- // Tear down
- puglFreeView(view);
- puglFreeWorld(world);
-
- return 0;
+ PuglWorld* const world = puglNewWorld(PUGL_PROGRAM, 0);
+ PuglView* const view = puglNewView(world);
+
+ // Set up view
+ puglSetClassName(world, "Pugl Test");
+ puglSetBackend(view, puglGlBackend());
+ puglSetEventFunc(view, onEvent);
+ puglSetDefaultSize(view, 512, 512);
+
+ // Set all hints that support it to PUGL_DONT_CARE
+ assert(!puglSetViewHint(view, PUGL_RED_BITS, PUGL_DONT_CARE));
+ assert(!puglSetViewHint(view, PUGL_GREEN_BITS, PUGL_DONT_CARE));
+ assert(!puglSetViewHint(view, PUGL_BLUE_BITS, PUGL_DONT_CARE));
+ assert(!puglSetViewHint(view, PUGL_ALPHA_BITS, PUGL_DONT_CARE));
+ assert(!puglSetViewHint(view, PUGL_DEPTH_BITS, PUGL_DONT_CARE));
+ assert(!puglSetViewHint(view, PUGL_STENCIL_BITS, PUGL_DONT_CARE));
+ assert(!puglSetViewHint(view, PUGL_SAMPLES, PUGL_DONT_CARE));
+ assert(!puglSetViewHint(view, PUGL_DOUBLE_BUFFER, PUGL_DONT_CARE));
+ assert(!puglSetViewHint(view, PUGL_REFRESH_RATE, PUGL_DONT_CARE));
+
+ // Realize view and print all hints for debugging convenience
+ assert(!puglRealize(view));
+ printViewHints(view);
+
+ // Check that no hints are set to PUGL_DONT_CARE
+ assert(puglGetViewHint(view, PUGL_USE_COMPAT_PROFILE) != PUGL_DONT_CARE);
+ assert(puglGetViewHint(view, PUGL_USE_DEBUG_CONTEXT) != PUGL_DONT_CARE);
+ assert(puglGetViewHint(view, PUGL_CONTEXT_VERSION_MAJOR) != PUGL_DONT_CARE);
+ assert(puglGetViewHint(view, PUGL_CONTEXT_VERSION_MINOR) != PUGL_DONT_CARE);
+ assert(puglGetViewHint(view, PUGL_RED_BITS) != PUGL_DONT_CARE);
+ assert(puglGetViewHint(view, PUGL_GREEN_BITS) != PUGL_DONT_CARE);
+ assert(puglGetViewHint(view, PUGL_BLUE_BITS) != PUGL_DONT_CARE);
+ assert(puglGetViewHint(view, PUGL_ALPHA_BITS) != PUGL_DONT_CARE);
+ assert(puglGetViewHint(view, PUGL_DEPTH_BITS) != PUGL_DONT_CARE);
+ assert(puglGetViewHint(view, PUGL_STENCIL_BITS) != PUGL_DONT_CARE);
+ assert(puglGetViewHint(view, PUGL_SAMPLES) != PUGL_DONT_CARE);
+ assert(puglGetViewHint(view, PUGL_DOUBLE_BUFFER) != PUGL_DONT_CARE);
+ assert(puglGetViewHint(view, PUGL_SWAP_INTERVAL) != PUGL_DONT_CARE);
+ assert(puglGetViewHint(view, PUGL_RESIZABLE) != PUGL_DONT_CARE);
+ assert(puglGetViewHint(view, PUGL_IGNORE_KEY_REPEAT) != PUGL_DONT_CARE);
+ assert(puglGetViewHint(view, PUGL_REFRESH_RATE) != PUGL_DONT_CARE);
+
+ // Tear down
+ puglFreeView(view);
+ puglFreeWorld(world);
+
+ return 0;
}
diff --git a/test/test_realize.c b/test/test_realize.c
index bb0b327..3c4e09a 100644
--- a/test/test_realize.c
+++ b/test/test_realize.c
@@ -34,67 +34,67 @@
#include <stddef.h>
typedef enum {
- START,
- CREATED,
+ START,
+ CREATED,
} State;
typedef struct {
- PuglWorld* world;
- PuglView* view;
- PuglTestOptions opts;
- State state;
+ PuglWorld* world;
+ PuglView* view;
+ PuglTestOptions opts;
+ State state;
} PuglTest;
static PuglStatus
onEvent(PuglView* view, const PuglEvent* event)
{
- PuglTest* test = (PuglTest*)puglGetHandle(view);
-
- if (test->opts.verbose) {
- printEvent(event, "Event: ", true);
- }
-
- switch (event->type) {
- case PUGL_CREATE:
- assert(test->state == START);
- test->state = CREATED;
- break;
- default:
- break;
- }
-
- return PUGL_SUCCESS;
+ PuglTest* test = (PuglTest*)puglGetHandle(view);
+
+ if (test->opts.verbose) {
+ printEvent(event, "Event: ", true);
+ }
+
+ switch (event->type) {
+ case PUGL_CREATE:
+ assert(test->state == START);
+ test->state = CREATED;
+ break;
+ default:
+ break;
+ }
+
+ return PUGL_SUCCESS;
}
int
main(int argc, char** argv)
{
- PuglTest test = {puglNewWorld(PUGL_PROGRAM, 0),
- NULL,
- puglParseTestOptions(&argc, &argv),
- START};
-
- // Set up view
- test.view = puglNewView(test.world);
- puglSetClassName(test.world, "Pugl Test");
- puglSetBackend(test.view, puglStubBackend());
- puglSetHandle(test.view, &test);
- puglSetEventFunc(test.view, onEvent);
- puglSetDefaultSize(test.view, 512, 512);
-
- // Create initially invisible window
- assert(!puglRealize(test.view));
- assert(!puglGetVisible(test.view));
- while (test.state < CREATED) {
- assert(!puglUpdate(test.world, -1.0));
- }
-
- // Check that calling realize() again is okay
- assert(puglRealize(test.view) == PUGL_FAILURE);
-
- // Tear down
- puglFreeView(test.view);
- puglFreeWorld(test.world);
-
- return 0;
+ PuglTest test = {puglNewWorld(PUGL_PROGRAM, 0),
+ NULL,
+ puglParseTestOptions(&argc, &argv),
+ START};
+
+ // Set up view
+ test.view = puglNewView(test.world);
+ puglSetClassName(test.world, "Pugl Test");
+ puglSetBackend(test.view, puglStubBackend());
+ puglSetHandle(test.view, &test);
+ puglSetEventFunc(test.view, onEvent);
+ puglSetDefaultSize(test.view, 512, 512);
+
+ // Create initially invisible window
+ assert(!puglRealize(test.view));
+ assert(!puglGetVisible(test.view));
+ while (test.state < CREATED) {
+ assert(!puglUpdate(test.world, -1.0));
+ }
+
+ // Check that calling realize() again is okay
+ assert(puglRealize(test.view) == PUGL_FAILURE);
+
+ // Tear down
+ puglFreeView(test.view);
+ puglFreeWorld(test.world);
+
+ return 0;
}
diff --git a/test/test_redisplay.c b/test/test_redisplay.c
index 1d5b084..c5b9887 100644
--- a/test/test_redisplay.c
+++ b/test/test_redisplay.c
@@ -38,19 +38,18 @@ static const double timeout = -1.0;
#endif
typedef enum {
- START,
- EXPOSED,
- SHOULD_REDISPLAY,
- POSTED_REDISPLAY,
- REDISPLAYED,
+ START,
+ EXPOSED,
+ SHOULD_REDISPLAY,
+ POSTED_REDISPLAY,
+ REDISPLAYED,
} State;
-typedef struct
-{
- PuglWorld* world;
- PuglView* view;
- PuglTestOptions opts;
- State state;
+typedef struct {
+ PuglWorld* world;
+ PuglView* view;
+ PuglTestOptions opts;
+ State state;
} PuglTest;
static const PuglRect redisplayRect = {2, 4, 8, 16};
@@ -59,83 +58,84 @@ static const uintptr_t postRedisplayId = 42;
static PuglStatus
onEvent(PuglView* view, const PuglEvent* event)
{
- PuglTest* test = (PuglTest*)puglGetHandle(view);
-
- if (test->opts.verbose) {
- printEvent(event, "Event: ", true);
- }
-
- switch (event->type) {
- case PUGL_UPDATE:
- if (test->state == SHOULD_REDISPLAY) {
- puglPostRedisplayRect(view, redisplayRect);
- test->state = POSTED_REDISPLAY;
- }
- break;
-
- case PUGL_EXPOSE:
- if (test->state == START) {
- test->state = EXPOSED;
- } else if (test->state == POSTED_REDISPLAY &&
- event->expose.x == redisplayRect.x &&
- event->expose.y == redisplayRect.y &&
- event->expose.width == redisplayRect.width &&
- event->expose.height == redisplayRect.height) {
- test->state = REDISPLAYED;
- }
- break;
-
- case PUGL_CLIENT:
- if (event->client.data1 == postRedisplayId) {
- test->state = SHOULD_REDISPLAY;
- }
- break;
-
- default: break;
- }
-
- return PUGL_SUCCESS;
+ PuglTest* test = (PuglTest*)puglGetHandle(view);
+
+ if (test->opts.verbose) {
+ printEvent(event, "Event: ", true);
+ }
+
+ switch (event->type) {
+ case PUGL_UPDATE:
+ if (test->state == SHOULD_REDISPLAY) {
+ puglPostRedisplayRect(view, redisplayRect);
+ test->state = POSTED_REDISPLAY;
+ }
+ break;
+
+ case PUGL_EXPOSE:
+ if (test->state == START) {
+ test->state = EXPOSED;
+ } else if (test->state == POSTED_REDISPLAY &&
+ event->expose.x == redisplayRect.x &&
+ event->expose.y == redisplayRect.y &&
+ event->expose.width == redisplayRect.width &&
+ event->expose.height == redisplayRect.height) {
+ test->state = REDISPLAYED;
+ }
+ break;
+
+ case PUGL_CLIENT:
+ if (event->client.data1 == postRedisplayId) {
+ test->state = SHOULD_REDISPLAY;
+ }
+ break;
+
+ default:
+ break;
+ }
+
+ return PUGL_SUCCESS;
}
int
main(int argc, char** argv)
{
- PuglTest app = {puglNewWorld(PUGL_PROGRAM, 0),
- NULL,
- puglParseTestOptions(&argc, &argv),
- START};
-
- // Set up view
- app.view = puglNewView(app.world);
- puglSetClassName(app.world, "Pugl Test");
- puglSetBackend(app.view, puglStubBackend());
- puglSetHandle(app.view, &app);
- puglSetEventFunc(app.view, onEvent);
- puglSetDefaultSize(app.view, 512, 512);
-
- // Create and show window
- assert(!puglRealize(app.view));
- assert(!puglShow(app.view));
- while (app.state != EXPOSED) {
- assert(!puglUpdate(app.world, timeout));
- }
-
- // Send a custom event to trigger a redisplay in the event loop
- PuglEvent client_event = {{PUGL_CLIENT, 0}};
- client_event.client.data1 = postRedisplayId;
- client_event.client.data2 = 0;
- assert(!puglSendEvent(app.view, &client_event));
-
- // Loop until an expose happens in the same iteration as the redisplay
- app.state = SHOULD_REDISPLAY;
- while (app.state != REDISPLAYED) {
- assert(!puglUpdate(app.world, timeout));
- assert(app.state != POSTED_REDISPLAY);
- }
-
- // Tear down
- puglFreeView(app.view);
- puglFreeWorld(app.world);
-
- return 0;
+ PuglTest app = {puglNewWorld(PUGL_PROGRAM, 0),
+ NULL,
+ puglParseTestOptions(&argc, &argv),
+ START};
+
+ // Set up view
+ app.view = puglNewView(app.world);
+ puglSetClassName(app.world, "Pugl Test");
+ puglSetBackend(app.view, puglStubBackend());
+ puglSetHandle(app.view, &app);
+ puglSetEventFunc(app.view, onEvent);
+ puglSetDefaultSize(app.view, 512, 512);
+
+ // Create and show window
+ assert(!puglRealize(app.view));
+ assert(!puglShow(app.view));
+ while (app.state != EXPOSED) {
+ assert(!puglUpdate(app.world, timeout));
+ }
+
+ // Send a custom event to trigger a redisplay in the event loop
+ PuglEvent client_event = {{PUGL_CLIENT, 0}};
+ client_event.client.data1 = postRedisplayId;
+ client_event.client.data2 = 0;
+ assert(!puglSendEvent(app.view, &client_event));
+
+ // Loop until an expose happens in the same iteration as the redisplay
+ app.state = SHOULD_REDISPLAY;
+ while (app.state != REDISPLAYED) {
+ assert(!puglUpdate(app.world, timeout));
+ assert(app.state != POSTED_REDISPLAY);
+ }
+
+ // Tear down
+ puglFreeView(app.view);
+ puglFreeWorld(app.world);
+
+ return 0;
}
diff --git a/test/test_show_hide.c b/test/test_show_hide.c
index 4280408..584448c 100644
--- a/test/test_show_hide.c
+++ b/test/test_show_hide.c
@@ -31,118 +31,118 @@
#include <stddef.h>
typedef enum {
- START,
- CREATED,
- CONFIGURED,
- MAPPED,
- EXPOSED,
- UNMAPPED,
- DESTROYED,
+ START,
+ CREATED,
+ CONFIGURED,
+ MAPPED,
+ EXPOSED,
+ UNMAPPED,
+ DESTROYED,
} State;
typedef struct {
- PuglWorld* world;
- PuglView* view;
- PuglTestOptions opts;
- State state;
+ PuglWorld* world;
+ PuglView* view;
+ PuglTestOptions opts;
+ State state;
} PuglTest;
static PuglStatus
onEvent(PuglView* view, const PuglEvent* event)
{
- PuglTest* test = (PuglTest*)puglGetHandle(view);
-
- if (test->opts.verbose) {
- printEvent(event, "Event: ", true);
- }
-
- switch (event->type) {
- case PUGL_CREATE:
- assert(test->state == START);
- test->state = CREATED;
- break;
- case PUGL_CONFIGURE:
- if (test->state == CREATED) {
- test->state = CONFIGURED;
- }
- break;
- case PUGL_MAP:
- assert(test->state == CONFIGURED || test->state == UNMAPPED);
- test->state = MAPPED;
- break;
- case PUGL_EXPOSE:
- assert(test->state == MAPPED || test->state == EXPOSED);
- test->state = EXPOSED;
- break;
- case PUGL_UNMAP:
- assert(test->state == EXPOSED);
- test->state = UNMAPPED;
- break;
- case PUGL_DESTROY:
- assert(test->state == UNMAPPED);
- test->state = DESTROYED;
- break;
- default:
- break;
- }
-
- return PUGL_SUCCESS;
+ PuglTest* test = (PuglTest*)puglGetHandle(view);
+
+ if (test->opts.verbose) {
+ printEvent(event, "Event: ", true);
+ }
+
+ switch (event->type) {
+ case PUGL_CREATE:
+ assert(test->state == START);
+ test->state = CREATED;
+ break;
+ case PUGL_CONFIGURE:
+ if (test->state == CREATED) {
+ test->state = CONFIGURED;
+ }
+ break;
+ case PUGL_MAP:
+ assert(test->state == CONFIGURED || test->state == UNMAPPED);
+ test->state = MAPPED;
+ break;
+ case PUGL_EXPOSE:
+ assert(test->state == MAPPED || test->state == EXPOSED);
+ test->state = EXPOSED;
+ break;
+ case PUGL_UNMAP:
+ assert(test->state == EXPOSED);
+ test->state = UNMAPPED;
+ break;
+ case PUGL_DESTROY:
+ assert(test->state == UNMAPPED);
+ test->state = DESTROYED;
+ break;
+ default:
+ break;
+ }
+
+ return PUGL_SUCCESS;
}
static void
tick(PuglWorld* world)
{
#ifdef __APPLE__
- // FIXME: Expose events are not events on MacOS, so we can't block
- // indefinitely here since it will block forever
- assert(!puglUpdate(world, 1 / 30.0));
+ // FIXME: Expose events are not events on MacOS, so we can't block
+ // indefinitely here since it will block forever
+ assert(!puglUpdate(world, 1 / 30.0));
#else
- assert(!puglUpdate(world, -1));
+ assert(!puglUpdate(world, -1));
#endif
}
int
main(int argc, char** argv)
{
- PuglTest test = {puglNewWorld(PUGL_PROGRAM, 0),
- NULL,
- puglParseTestOptions(&argc, &argv),
- START};
-
- // Set up view
- test.view = puglNewView(test.world);
- puglSetClassName(test.world, "Pugl Test");
- puglSetBackend(test.view, puglStubBackend());
- puglSetHandle(test.view, &test);
- puglSetEventFunc(test.view, onEvent);
- puglSetDefaultSize(test.view, 512, 512);
-
- // Create initially invisible window
- assert(!puglRealize(test.view));
- assert(!puglGetVisible(test.view));
- while (test.state < CREATED) {
- tick(test.world);
- }
-
- // Show and hide window a couple of times
- for (unsigned i = 0u; i < 2u; ++i) {
- assert(!puglShow(test.view));
- while (test.state != EXPOSED) {
- tick(test.world);
- }
-
- assert(puglGetVisible(test.view));
- assert(!puglHide(test.view));
- while (test.state != UNMAPPED) {
- tick(test.world);
- }
- }
-
- // Tear down
- assert(!puglGetVisible(test.view));
- puglFreeView(test.view);
- assert(test.state == DESTROYED);
- puglFreeWorld(test.world);
-
- return 0;
+ PuglTest test = {puglNewWorld(PUGL_PROGRAM, 0),
+ NULL,
+ puglParseTestOptions(&argc, &argv),
+ START};
+
+ // Set up view
+ test.view = puglNewView(test.world);
+ puglSetClassName(test.world, "Pugl Test");
+ puglSetBackend(test.view, puglStubBackend());
+ puglSetHandle(test.view, &test);
+ puglSetEventFunc(test.view, onEvent);
+ puglSetDefaultSize(test.view, 512, 512);
+
+ // Create initially invisible window
+ assert(!puglRealize(test.view));
+ assert(!puglGetVisible(test.view));
+ while (test.state < CREATED) {
+ tick(test.world);
+ }
+
+ // Show and hide window a couple of times
+ for (unsigned i = 0u; i < 2u; ++i) {
+ assert(!puglShow(test.view));
+ while (test.state != EXPOSED) {
+ tick(test.world);
+ }
+
+ assert(puglGetVisible(test.view));
+ assert(!puglHide(test.view));
+ while (test.state != UNMAPPED) {
+ tick(test.world);
+ }
+ }
+
+ // Tear down
+ assert(!puglGetVisible(test.view));
+ puglFreeView(test.view);
+ assert(test.state == DESTROYED);
+ puglFreeWorld(test.world);
+
+ return 0;
}
diff --git a/test/test_stub_hints.c b/test/test_stub_hints.c
index 2bfc86c..1cc1180 100644
--- a/test/test_stub_hints.c
+++ b/test/test_stub_hints.c
@@ -30,51 +30,51 @@
static PuglStatus
onEvent(PuglView* view, const PuglEvent* event)
{
- (void)view;
- (void)event;
+ (void)view;
+ (void)event;
- return PUGL_SUCCESS;
+ return PUGL_SUCCESS;
}
int
main(void)
{
- PuglWorld* const world = puglNewWorld(PUGL_PROGRAM, 0);
- PuglView* const view = puglNewView(world);
-
- // Set up view
- puglSetClassName(world, "Pugl Test");
- puglSetBackend(view, puglStubBackend());
- puglSetEventFunc(view, onEvent);
- puglSetDefaultSize(view, 512, 512);
-
- // Set all relevant hints that support it to PUGL_DONT_CARE
- assert(!puglSetViewHint(view, PUGL_RED_BITS, PUGL_DONT_CARE));
- assert(!puglSetViewHint(view, PUGL_GREEN_BITS, PUGL_DONT_CARE));
- assert(!puglSetViewHint(view, PUGL_BLUE_BITS, PUGL_DONT_CARE));
- assert(!puglSetViewHint(view, PUGL_ALPHA_BITS, PUGL_DONT_CARE));
- assert(!puglSetViewHint(view, PUGL_REFRESH_RATE, PUGL_DONT_CARE));
-
- // Realize view and print all hints for debugging convenience
- assert(!puglRealize(view));
- printViewHints(view);
-
- // Check that no relevant hints are set to PUGL_DONT_CARE
- assert(puglGetViewHint(view, PUGL_USE_COMPAT_PROFILE) != PUGL_DONT_CARE);
- assert(puglGetViewHint(view, PUGL_USE_DEBUG_CONTEXT) != PUGL_DONT_CARE);
- assert(puglGetViewHint(view, PUGL_CONTEXT_VERSION_MAJOR) != PUGL_DONT_CARE);
- assert(puglGetViewHint(view, PUGL_CONTEXT_VERSION_MINOR) != PUGL_DONT_CARE);
- assert(puglGetViewHint(view, PUGL_RED_BITS) != PUGL_DONT_CARE);
- assert(puglGetViewHint(view, PUGL_GREEN_BITS) != PUGL_DONT_CARE);
- assert(puglGetViewHint(view, PUGL_BLUE_BITS) != PUGL_DONT_CARE);
- assert(puglGetViewHint(view, PUGL_ALPHA_BITS) != PUGL_DONT_CARE);
- assert(puglGetViewHint(view, PUGL_RESIZABLE) != PUGL_DONT_CARE);
- assert(puglGetViewHint(view, PUGL_IGNORE_KEY_REPEAT) != PUGL_DONT_CARE);
- assert(puglGetViewHint(view, PUGL_REFRESH_RATE) != PUGL_DONT_CARE);
-
- // Tear down
- puglFreeView(view);
- puglFreeWorld(world);
-
- return 0;
+ PuglWorld* const world = puglNewWorld(PUGL_PROGRAM, 0);
+ PuglView* const view = puglNewView(world);
+
+ // Set up view
+ puglSetClassName(world, "Pugl Test");
+ puglSetBackend(view, puglStubBackend());
+ puglSetEventFunc(view, onEvent);
+ puglSetDefaultSize(view, 512, 512);
+
+ // Set all relevant hints that support it to PUGL_DONT_CARE
+ assert(!puglSetViewHint(view, PUGL_RED_BITS, PUGL_DONT_CARE));
+ assert(!puglSetViewHint(view, PUGL_GREEN_BITS, PUGL_DONT_CARE));
+ assert(!puglSetViewHint(view, PUGL_BLUE_BITS, PUGL_DONT_CARE));
+ assert(!puglSetViewHint(view, PUGL_ALPHA_BITS, PUGL_DONT_CARE));
+ assert(!puglSetViewHint(view, PUGL_REFRESH_RATE, PUGL_DONT_CARE));
+
+ // Realize view and print all hints for debugging convenience
+ assert(!puglRealize(view));
+ printViewHints(view);
+
+ // Check that no relevant hints are set to PUGL_DONT_CARE
+ assert(puglGetViewHint(view, PUGL_USE_COMPAT_PROFILE) != PUGL_DONT_CARE);
+ assert(puglGetViewHint(view, PUGL_USE_DEBUG_CONTEXT) != PUGL_DONT_CARE);
+ assert(puglGetViewHint(view, PUGL_CONTEXT_VERSION_MAJOR) != PUGL_DONT_CARE);
+ assert(puglGetViewHint(view, PUGL_CONTEXT_VERSION_MINOR) != PUGL_DONT_CARE);
+ assert(puglGetViewHint(view, PUGL_RED_BITS) != PUGL_DONT_CARE);
+ assert(puglGetViewHint(view, PUGL_GREEN_BITS) != PUGL_DONT_CARE);
+ assert(puglGetViewHint(view, PUGL_BLUE_BITS) != PUGL_DONT_CARE);
+ assert(puglGetViewHint(view, PUGL_ALPHA_BITS) != PUGL_DONT_CARE);
+ assert(puglGetViewHint(view, PUGL_RESIZABLE) != PUGL_DONT_CARE);
+ assert(puglGetViewHint(view, PUGL_IGNORE_KEY_REPEAT) != PUGL_DONT_CARE);
+ assert(puglGetViewHint(view, PUGL_REFRESH_RATE) != PUGL_DONT_CARE);
+
+ // Tear down
+ puglFreeView(view);
+ puglFreeWorld(world);
+
+ return 0;
}
diff --git a/test/test_timer.c b/test/test_timer.c
index 0b77396..18518ec 100644
--- a/test/test_timer.c
+++ b/test/test_timer.c
@@ -50,112 +50,110 @@ static const uintptr_t timerId = 1u;
static const double timerPeriod = 1 / 60.0;
typedef enum {
- START,
- EXPOSED,
+ START,
+ EXPOSED,
} State;
typedef struct {
- PuglWorld* world;
- PuglView* view;
- PuglTestOptions opts;
- size_t numAlarms;
- State state;
+ PuglWorld* world;
+ PuglView* view;
+ PuglTestOptions opts;
+ size_t numAlarms;
+ State state;
} PuglTest;
static PuglStatus
onEvent(PuglView* view, const PuglEvent* event)
{
- PuglTest* test = (PuglTest*)puglGetHandle(view);
+ PuglTest* test = (PuglTest*)puglGetHandle(view);
- if (test->opts.verbose) {
- printEvent(event, "Event: ", true);
- }
+ if (test->opts.verbose) {
+ printEvent(event, "Event: ", true);
+ }
- switch (event->type) {
- case PUGL_EXPOSE:
- test->state = EXPOSED;
- break;
+ switch (event->type) {
+ case PUGL_EXPOSE:
+ test->state = EXPOSED;
+ break;
- case PUGL_TIMER:
- assert(event->timer.id == timerId);
- ++test->numAlarms;
- break;
+ case PUGL_TIMER:
+ assert(event->timer.id == timerId);
+ ++test->numAlarms;
+ break;
- default:
- break;
- }
+ default:
+ break;
+ }
- return PUGL_SUCCESS;
+ return PUGL_SUCCESS;
}
static double
roundPeriod(const double period)
{
- return floor(period * 1000.0) / 1000.0; // Round down to milliseconds
+ return floor(period * 1000.0) / 1000.0; // Round down to milliseconds
}
int
main(int argc, char** argv)
{
- PuglTest app = {puglNewWorld(PUGL_PROGRAM, 0),
- NULL,
- puglParseTestOptions(&argc, &argv),
- 0,
- START};
-
- // Set up view
- app.view = puglNewView(app.world);
- puglSetClassName(app.world, "Pugl Test");
- puglSetBackend(app.view, puglStubBackend());
- puglSetHandle(app.view, &app);
- puglSetEventFunc(app.view, onEvent);
- puglSetDefaultSize(app.view, 512, 512);
-
- // Create and show window
- assert(!puglRealize(app.view));
- assert(!puglShow(app.view));
- while (app.state != EXPOSED) {
- assert(!puglUpdate(app.world, timeout));
- }
-
- // Register a timer with a longer period first
- assert(!puglStartTimer(app.view, timerId, timerPeriod * 2.0));
-
- // Replace it with the one we want (to ensure timers are replaced)
- assert(!puglStartTimer(app.view, timerId, timerPeriod));
-
- const double startTime = puglGetTime(app.world);
-
- puglUpdate(app.world, 1.0);
-
- // Calculate the actual period of the timer
- const double endTime = puglGetTime(app.world);
- const double duration = endTime - startTime;
- const double expectedPeriod = roundPeriod(timerPeriod);
- const double actualPeriod = roundPeriod(duration / (double)app.numAlarms);
- const double difference = fabs(actualPeriod - expectedPeriod);
-
- if (difference > tolerance) {
- fprintf(stderr,
- "error: Period not within %f of %f\n",
- tolerance,
- expectedPeriod);
- fprintf(stderr, "note: Actual period %f\n", actualPeriod);
- }
-
- assert(difference <= tolerance);
-
- // Deregister timer and tick once to synchronize
- assert(!puglStopTimer(app.view, timerId));
- puglUpdate(app.world, 0.0);
-
- // Update for a half second and check that we receive no more alarms
- app.numAlarms = 0;
- puglUpdate(app.world, 0.5);
- assert(app.numAlarms == 0);
-
- puglFreeView(app.view);
- puglFreeWorld(app.world);
-
- return 0;
+ PuglTest app = {puglNewWorld(PUGL_PROGRAM, 0),
+ NULL,
+ puglParseTestOptions(&argc, &argv),
+ 0,
+ START};
+
+ // Set up view
+ app.view = puglNewView(app.world);
+ puglSetClassName(app.world, "Pugl Test");
+ puglSetBackend(app.view, puglStubBackend());
+ puglSetHandle(app.view, &app);
+ puglSetEventFunc(app.view, onEvent);
+ puglSetDefaultSize(app.view, 512, 512);
+
+ // Create and show window
+ assert(!puglRealize(app.view));
+ assert(!puglShow(app.view));
+ while (app.state != EXPOSED) {
+ assert(!puglUpdate(app.world, timeout));
+ }
+
+ // Register a timer with a longer period first
+ assert(!puglStartTimer(app.view, timerId, timerPeriod * 2.0));
+
+ // Replace it with the one we want (to ensure timers are replaced)
+ assert(!puglStartTimer(app.view, timerId, timerPeriod));
+
+ const double startTime = puglGetTime(app.world);
+
+ puglUpdate(app.world, 1.0);
+
+ // Calculate the actual period of the timer
+ const double endTime = puglGetTime(app.world);
+ const double duration = endTime - startTime;
+ const double expectedPeriod = roundPeriod(timerPeriod);
+ const double actualPeriod = roundPeriod(duration / (double)app.numAlarms);
+ const double difference = fabs(actualPeriod - expectedPeriod);
+
+ if (difference > tolerance) {
+ fprintf(
+ stderr, "error: Period not within %f of %f\n", tolerance, expectedPeriod);
+ fprintf(stderr, "note: Actual period %f\n", actualPeriod);
+ }
+
+ assert(difference <= tolerance);
+
+ // Deregister timer and tick once to synchronize
+ assert(!puglStopTimer(app.view, timerId));
+ puglUpdate(app.world, 0.0);
+
+ // Update for a half second and check that we receive no more alarms
+ app.numAlarms = 0;
+ puglUpdate(app.world, 0.5);
+ assert(app.numAlarms == 0);
+
+ puglFreeView(app.view);
+ puglFreeWorld(app.world);
+
+ return 0;
}
diff --git a/test/test_update.c b/test/test_update.c
index b35e96e..89de0b6 100644
--- a/test/test_update.c
+++ b/test/test_update.c
@@ -37,89 +37,89 @@ static const double timeout = -1.0;
#endif
typedef enum {
- START,
- EXPOSED1,
- UPDATED,
- EXPOSED2,
+ START,
+ EXPOSED1,
+ UPDATED,
+ EXPOSED2,
} State;
typedef struct {
- PuglWorld* world;
- PuglView* view;
- PuglTestOptions opts;
- State state;
+ PuglWorld* world;
+ PuglView* view;
+ PuglTestOptions opts;
+ State state;
} PuglTest;
static PuglStatus
onEvent(PuglView* view, const PuglEvent* event)
{
- PuglTest* test = (PuglTest*)puglGetHandle(view);
-
- if (test->opts.verbose) {
- printEvent(event, "Event: ", true);
- }
-
- switch (event->type) {
- case PUGL_EXPOSE:
- switch (test->state) {
- case START:
- test->state = EXPOSED1;
- break;
- case UPDATED:
- test->state = EXPOSED2;
- break;
- default:
- break;
- }
- break;
-
- case PUGL_UPDATE:
- if (test->state == EXPOSED1) {
- puglPostRedisplay(view);
- test->state = UPDATED;
- }
- break;
-
- default:
- break;
- }
-
- return PUGL_SUCCESS;
+ PuglTest* test = (PuglTest*)puglGetHandle(view);
+
+ if (test->opts.verbose) {
+ printEvent(event, "Event: ", true);
+ }
+
+ switch (event->type) {
+ case PUGL_EXPOSE:
+ switch (test->state) {
+ case START:
+ test->state = EXPOSED1;
+ break;
+ case UPDATED:
+ test->state = EXPOSED2;
+ break;
+ default:
+ break;
+ }
+ break;
+
+ case PUGL_UPDATE:
+ if (test->state == EXPOSED1) {
+ puglPostRedisplay(view);
+ test->state = UPDATED;
+ }
+ break;
+
+ default:
+ break;
+ }
+
+ return PUGL_SUCCESS;
}
int
main(int argc, char** argv)
{
- PuglTest app = {puglNewWorld(PUGL_PROGRAM, 0),
- NULL,
- puglParseTestOptions(&argc, &argv),
- START};
-
- // Set up view
- app.view = puglNewView(app.world);
- puglSetClassName(app.world, "Pugl Test");
- puglSetBackend(app.view, puglStubBackend());
- puglSetHandle(app.view, &app);
- puglSetEventFunc(app.view, onEvent);
- puglSetDefaultSize(app.view, 512, 512);
-
- // Create and show window
- assert(!puglRealize(app.view));
- assert(!puglShow(app.view));
-
- // Tick until an expose happens
- while (app.state < EXPOSED1) {
- assert(!puglUpdate(app.world, timeout));
- assert(app.state != UPDATED);
- }
-
- // Tick once and ensure the update and the expose it posted both happened
- assert(!puglUpdate(app.world, 0.0));
- assert(app.state == EXPOSED2);
-
- // Tear down
- puglFreeView(app.view);
- puglFreeWorld(app.world);
-
- return 0;
+ PuglTest app = {puglNewWorld(PUGL_PROGRAM, 0),
+ NULL,
+ puglParseTestOptions(&argc, &argv),
+ START};
+
+ // Set up view
+ app.view = puglNewView(app.world);
+ puglSetClassName(app.world, "Pugl Test");
+ puglSetBackend(app.view, puglStubBackend());
+ puglSetHandle(app.view, &app);
+ puglSetEventFunc(app.view, onEvent);
+ puglSetDefaultSize(app.view, 512, 512);
+
+ // Create and show window
+ assert(!puglRealize(app.view));
+ assert(!puglShow(app.view));
+
+ // Tick until an expose happens
+ while (app.state < EXPOSED1) {
+ assert(!puglUpdate(app.world, timeout));
+ assert(app.state != UPDATED);
+ }
+
+ // Tick once and ensure the update and the expose it posted both happened
+ assert(!puglUpdate(app.world, 0.0));
+ assert(app.state == EXPOSED2);
+
+ // Tear down
+ puglFreeView(app.view);
+ puglFreeWorld(app.world);
+
+ return 0;
}
diff --git a/test/test_utils.h b/test/test_utils.h
index 7a91535..2464737 100644
--- a/test/test_utils.h
+++ b/test/test_utils.h
@@ -29,328 +29,328 @@
#include <string.h>
#ifdef __GNUC__
-# define PUGL_LOG_FUNC(fmt, arg1) __attribute__((format(printf, fmt, arg1)))
+# define PUGL_LOG_FUNC(fmt, arg1) __attribute__((format(printf, fmt, arg1)))
#else
-# define PUGL_LOG_FUNC(fmt, arg1)
+# define PUGL_LOG_FUNC(fmt, arg1)
#endif
typedef struct {
- int samples;
- int doubleBuffer;
- int sync;
- bool continuous;
- bool help;
- bool ignoreKeyRepeat;
- bool resizable;
- bool verbose;
- bool errorChecking;
+ int samples;
+ int doubleBuffer;
+ int sync;
+ bool continuous;
+ bool help;
+ bool ignoreKeyRepeat;
+ bool resizable;
+ bool verbose;
+ bool errorChecking;
} PuglTestOptions;
PUGL_LOG_FUNC(1, 2)
static int
logError(const char* fmt, ...)
{
- fprintf(stderr, "error: ");
+ fprintf(stderr, "error: ");
- va_list args; // NOLINT
- va_start(args, fmt);
- vfprintf(stderr, fmt, args);
- va_end(args);
+ va_list args; // NOLINT
+ va_start(args, fmt);
+ vfprintf(stderr, fmt, args);
+ va_end(args);
- return 1;
+ return 1;
}
static inline int
printModifiers(const uint32_t mods)
{
- return fprintf(stderr, "Modifiers:%s%s%s%s\n",
- (mods & PUGL_MOD_SHIFT) ? " Shift" : "",
- (mods & PUGL_MOD_CTRL) ? " Ctrl" : "",
- (mods & PUGL_MOD_ALT) ? " Alt" : "",
- (mods & PUGL_MOD_SUPER) ? " Super" : "");
+ return fprintf(stderr,
+ "Modifiers:%s%s%s%s\n",
+ (mods & PUGL_MOD_SHIFT) ? " Shift" : "",
+ (mods & PUGL_MOD_CTRL) ? " Ctrl" : "",
+ (mods & PUGL_MOD_ALT) ? " Alt" : "",
+ (mods & PUGL_MOD_SUPER) ? " Super" : "");
}
static inline const char*
crossingModeString(const PuglCrossingMode mode)
{
- switch (mode) {
- case PUGL_CROSSING_NORMAL:
- return "normal";
- case PUGL_CROSSING_GRAB:
- return "grab";
- case PUGL_CROSSING_UNGRAB:
- return "ungrab";
- }
+ switch (mode) {
+ case PUGL_CROSSING_NORMAL:
+ return "normal";
+ case PUGL_CROSSING_GRAB:
+ return "grab";
+ case PUGL_CROSSING_UNGRAB:
+ return "ungrab";
+ }
- return "unknown";
+ return "unknown";
}
static inline const char*
scrollDirectionString(const PuglScrollDirection direction)
{
- switch (direction) {
- case PUGL_SCROLL_UP:
- return "up";
- case PUGL_SCROLL_DOWN:
- return "down";
- case PUGL_SCROLL_LEFT:
- return "left";
- case PUGL_SCROLL_RIGHT:
- return "right";
- case PUGL_SCROLL_SMOOTH:
- return "smooth";
- }
+ switch (direction) {
+ case PUGL_SCROLL_UP:
+ return "up";
+ case PUGL_SCROLL_DOWN:
+ return "down";
+ case PUGL_SCROLL_LEFT:
+ return "left";
+ case PUGL_SCROLL_RIGHT:
+ return "right";
+ case PUGL_SCROLL_SMOOTH:
+ return "smooth";
+ }
- return "unknown";
+ return "unknown";
}
static inline int
printEvent(const PuglEvent* event, const char* prefix, const bool verbose)
{
-#define FFMT "%6.1f"
-#define PFMT FFMT " " FFMT
+#define FFMT "%6.1f"
+#define PFMT FFMT " " FFMT
#define PRINT(fmt, ...) fprintf(stderr, fmt, __VA_ARGS__)
- switch (event->type) {
- case PUGL_NOTHING:
- return 0;
- case PUGL_KEY_PRESS:
- return PRINT("%sKey press code %3u key U+%04X\n",
- prefix,
- event->key.keycode,
- event->key.key);
- case PUGL_KEY_RELEASE:
- return PRINT("%sKey release code %3u key U+%04X\n",
- prefix,
- event->key.keycode,
- event->key.key);
- case PUGL_TEXT:
- return PRINT("%sText entry code %3u char U+%04X (%s)\n",
- prefix,
- event->text.keycode,
- event->text.character,
- event->text.string);
- case PUGL_BUTTON_PRESS:
- case PUGL_BUTTON_RELEASE:
- return (PRINT("%sMouse %u %s at " PFMT " ",
- prefix,
- event->button.button,
- (event->type == PUGL_BUTTON_PRESS) ? "down" : "up ",
- event->button.x,
- event->button.y) +
- printModifiers(event->scroll.state));
- case PUGL_SCROLL:
- return (PRINT("%sScroll %5.1f %5.1f (%s) at " PFMT " ",
- prefix,
- event->scroll.dx,
- event->scroll.dy,
- scrollDirectionString(event->scroll.direction),
- event->scroll.x,
- event->scroll.y) +
- printModifiers(event->scroll.state));
- case PUGL_POINTER_IN:
- return PRINT("%sMouse enter at " PFMT " (%s)\n",
- prefix,
- event->crossing.x,
- event->crossing.y,
- crossingModeString(event->crossing.mode));
- case PUGL_POINTER_OUT:
- return PRINT("%sMouse leave at " PFMT " (%s)\n",
- prefix,
- event->crossing.x,
- event->crossing.y,
- crossingModeString(event->crossing.mode));
- case PUGL_FOCUS_IN:
- return PRINT("%sFocus in (%s)\n",
- prefix,
- crossingModeString(event->crossing.mode));
- case PUGL_FOCUS_OUT:
- return PRINT("%sFocus out (%s)\n",
- prefix,
- crossingModeString(event->crossing.mode));
- case PUGL_CLIENT:
- return PRINT("%sClient %" PRIXPTR " %" PRIXPTR "\n",
- prefix,
- event->client.data1,
- event->client.data2);
- case PUGL_LOOP_ENTER:
- return PRINT("%sLoop enter\n", prefix);
- case PUGL_LOOP_LEAVE:
- return PRINT("%sLoop leave\n", prefix);
- default:
- break;
- }
+ switch (event->type) {
+ case PUGL_NOTHING:
+ return 0;
+ case PUGL_KEY_PRESS:
+ return PRINT("%sKey press code %3u key U+%04X\n",
+ prefix,
+ event->key.keycode,
+ event->key.key);
+ case PUGL_KEY_RELEASE:
+ return PRINT("%sKey release code %3u key U+%04X\n",
+ prefix,
+ event->key.keycode,
+ event->key.key);
+ case PUGL_TEXT:
+ return PRINT("%sText entry code %3u char U+%04X (%s)\n",
+ prefix,
+ event->text.keycode,
+ event->text.character,
+ event->text.string);
+ case PUGL_BUTTON_PRESS:
+ case PUGL_BUTTON_RELEASE:
+ return (PRINT("%sMouse %u %s at " PFMT " ",
+ prefix,
+ event->button.button,
+ (event->type == PUGL_BUTTON_PRESS) ? "down" : "up ",
+ event->button.x,
+ event->button.y) +
+ printModifiers(event->scroll.state));
+ case PUGL_SCROLL:
+ return (PRINT("%sScroll %5.1f %5.1f (%s) at " PFMT " ",
+ prefix,
+ event->scroll.dx,
+ event->scroll.dy,
+ scrollDirectionString(event->scroll.direction),
+ event->scroll.x,
+ event->scroll.y) +
+ printModifiers(event->scroll.state));
+ case PUGL_POINTER_IN:
+ return PRINT("%sMouse enter at " PFMT " (%s)\n",
+ prefix,
+ event->crossing.x,
+ event->crossing.y,
+ crossingModeString(event->crossing.mode));
+ case PUGL_POINTER_OUT:
+ return PRINT("%sMouse leave at " PFMT " (%s)\n",
+ prefix,
+ event->crossing.x,
+ event->crossing.y,
+ crossingModeString(event->crossing.mode));
+ case PUGL_FOCUS_IN:
+ return PRINT(
+ "%sFocus in (%s)\n", prefix, crossingModeString(event->crossing.mode));
+ case PUGL_FOCUS_OUT:
+ return PRINT(
+ "%sFocus out (%s)\n", prefix, crossingModeString(event->crossing.mode));
+ case PUGL_CLIENT:
+ return PRINT("%sClient %" PRIXPTR " %" PRIXPTR "\n",
+ prefix,
+ event->client.data1,
+ event->client.data2);
+ case PUGL_LOOP_ENTER:
+ return PRINT("%sLoop enter\n", prefix);
+ case PUGL_LOOP_LEAVE:
+ return PRINT("%sLoop leave\n", prefix);
+ default:
+ break;
+ }
- if (verbose) {
- switch (event->type) {
- case PUGL_CREATE:
- return fprintf(stderr, "%sCreate\n", prefix);
- case PUGL_DESTROY:
- return fprintf(stderr, "%sDestroy\n", prefix);
- case PUGL_MAP:
- return fprintf(stderr, "%sMap\n", prefix);
- case PUGL_UNMAP:
- return fprintf(stderr, "%sUnmap\n", prefix);
- case PUGL_UPDATE:
- return fprintf(stderr, "%sUpdate\n", prefix);
- case PUGL_CONFIGURE:
- return PRINT("%sConfigure " PFMT " " PFMT "\n",
- prefix,
- event->configure.x,
- event->configure.y,
- event->configure.width,
- event->configure.height);
- case PUGL_EXPOSE:
- return PRINT("%sExpose " PFMT " " PFMT "\n",
- prefix,
- event->expose.x,
- event->expose.y,
- event->expose.width,
- event->expose.height);
- case PUGL_CLOSE:
- return PRINT("%sClose\n", prefix);
- case PUGL_MOTION:
- return PRINT("%sMouse motion at " PFMT "\n",
- prefix,
- event->motion.x,
- event->motion.y);
- case PUGL_TIMER:
- return PRINT("%sTimer %" PRIuPTR "\n", prefix, event->timer.id);
- default:
- return PRINT("%sUnknown event type %d\n", prefix, (int)event->type);
- }
- }
+ if (verbose) {
+ switch (event->type) {
+ case PUGL_CREATE:
+ return fprintf(stderr, "%sCreate\n", prefix);
+ case PUGL_DESTROY:
+ return fprintf(stderr, "%sDestroy\n", prefix);
+ case PUGL_MAP:
+ return fprintf(stderr, "%sMap\n", prefix);
+ case PUGL_UNMAP:
+ return fprintf(stderr, "%sUnmap\n", prefix);
+ case PUGL_UPDATE:
+ return fprintf(stderr, "%sUpdate\n", prefix);
+ case PUGL_CONFIGURE:
+ return PRINT("%sConfigure " PFMT " " PFMT "\n",
+ prefix,
+ event->configure.x,
+ event->configure.y,
+ event->configure.width,
+ event->configure.height);
+ case PUGL_EXPOSE:
+ return PRINT("%sExpose " PFMT " " PFMT "\n",
+ prefix,
+ event->expose.x,
+ event->expose.y,
+ event->expose.width,
+ event->expose.height);
+ case PUGL_CLOSE:
+ return PRINT("%sClose\n", prefix);
+ case PUGL_MOTION:
+ return PRINT("%sMouse motion at " PFMT "\n",
+ prefix,
+ event->motion.x,
+ event->motion.y);
+ case PUGL_TIMER:
+ return PRINT("%sTimer %" PRIuPTR "\n", prefix, event->timer.id);
+ default:
+ return PRINT("%sUnknown event type %d\n", prefix, (int)event->type);
+ }
+ }
#undef PRINT
#undef PFMT
#undef FFMT
- return 0;
+ return 0;
}
static inline const char*
puglViewHintString(const PuglViewHint hint)
{
- switch (hint) {
- case PUGL_USE_COMPAT_PROFILE:
- return "Use compatible profile";
- case PUGL_USE_DEBUG_CONTEXT:
- return "Use debug context";
- case PUGL_CONTEXT_VERSION_MAJOR:
- return "Context major version";
- case PUGL_CONTEXT_VERSION_MINOR:
- return "Context minor version";
- case PUGL_RED_BITS:
- return "Red bits";
- case PUGL_GREEN_BITS:
- return "Green bits";
- case PUGL_BLUE_BITS:
- return "Blue bits";
- case PUGL_ALPHA_BITS:
- return "Alpha bits";
- case PUGL_DEPTH_BITS:
- return "Depth bits";
- case PUGL_STENCIL_BITS:
- return "Stencil bits";
- case PUGL_SAMPLES:
- return "Samples";
- case PUGL_DOUBLE_BUFFER:
- return "Double buffer";
- case PUGL_SWAP_INTERVAL:
- return "Swap interval";
- case PUGL_RESIZABLE:
- return "Resizable";
- case PUGL_IGNORE_KEY_REPEAT:
- return "Ignore key repeat";
- case PUGL_REFRESH_RATE:
- return "Refresh rate";
- case PUGL_NUM_VIEW_HINTS:
- return "Unknown";
- }
+ switch (hint) {
+ case PUGL_USE_COMPAT_PROFILE:
+ return "Use compatible profile";
+ case PUGL_USE_DEBUG_CONTEXT:
+ return "Use debug context";
+ case PUGL_CONTEXT_VERSION_MAJOR:
+ return "Context major version";
+ case PUGL_CONTEXT_VERSION_MINOR:
+ return "Context minor version";
+ case PUGL_RED_BITS:
+ return "Red bits";
+ case PUGL_GREEN_BITS:
+ return "Green bits";
+ case PUGL_BLUE_BITS:
+ return "Blue bits";
+ case PUGL_ALPHA_BITS:
+ return "Alpha bits";
+ case PUGL_DEPTH_BITS:
+ return "Depth bits";
+ case PUGL_STENCIL_BITS:
+ return "Stencil bits";
+ case PUGL_SAMPLES:
+ return "Samples";
+ case PUGL_DOUBLE_BUFFER:
+ return "Double buffer";
+ case PUGL_SWAP_INTERVAL:
+ return "Swap interval";
+ case PUGL_RESIZABLE:
+ return "Resizable";
+ case PUGL_IGNORE_KEY_REPEAT:
+ return "Ignore key repeat";
+ case PUGL_REFRESH_RATE:
+ return "Refresh rate";
+ case PUGL_NUM_VIEW_HINTS:
+ return "Unknown";
+ }
- return "Unknown";
+ return "Unknown";
}
static inline void
printViewHints(const PuglView* view)
{
- for (int i = 0; i < PUGL_NUM_VIEW_HINTS; ++i) {
- const PuglViewHint hint = (PuglViewHint)i;
- fprintf(stderr,
- "%s: %d\n",
- puglViewHintString(hint),
- puglGetViewHint(view, hint));
- }
+ for (int i = 0; i < PUGL_NUM_VIEW_HINTS; ++i) {
+ const PuglViewHint hint = (PuglViewHint)i;
+ fprintf(stderr,
+ "%s: %d\n",
+ puglViewHintString(hint),
+ puglGetViewHint(view, hint));
+ }
}
static inline void
puglPrintTestUsage(const char* prog, const char* posHelp)
{
- printf("Usage: %s [OPTION]... %s\n\n"
- " -a Enable anti-aliasing\n"
- " -c Continuously animate and draw\n"
- " -d Directly draw to window (no double-buffering)\n"
- " -e Enable platform error-checking\n"
- " -f Fast drawing, explicitly disable vertical sync\n"
- " -h Display this help\n"
- " -i Ignore key repeat\n"
- " -v Print verbose output\n"
- " -r Resizable window\n"
- " -s Explicitly enable vertical sync\n",
- prog, posHelp);
+ printf("Usage: %s [OPTION]... %s\n\n"
+ " -a Enable anti-aliasing\n"
+ " -c Continuously animate and draw\n"
+ " -d Directly draw to window (no double-buffering)\n"
+ " -e Enable platform error-checking\n"
+ " -f Fast drawing, explicitly disable vertical sync\n"
+ " -h Display this help\n"
+ " -i Ignore key repeat\n"
+ " -v Print verbose output\n"
+ " -r Resizable window\n"
+ " -s Explicitly enable vertical sync\n",
+ prog,
+ posHelp);
}
static inline PuglTestOptions
puglParseTestOptions(int* pargc, char*** pargv)
{
- PuglTestOptions opts = {
- 0,
- PUGL_TRUE,
- PUGL_DONT_CARE,
- false,
- false,
- false,
- false,
- false,
- false,
- };
+ PuglTestOptions opts = {
+ 0,
+ PUGL_TRUE,
+ PUGL_DONT_CARE,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ };
- char** const argv = *pargv;
- int i = 1;
- for (; i < *pargc; ++i) {
- if (!strcmp(argv[i], "-a")) {
- opts.samples = 4;
- } else if (!strcmp(argv[i], "-c")) {
- opts.continuous = true;
- } else if (!strcmp(argv[i], "-d")) {
- opts.doubleBuffer = PUGL_FALSE;
- } else if (!strcmp(argv[i], "-e")) {
- opts.errorChecking = PUGL_TRUE;
- } else if (!strcmp(argv[i], "-f")) {
- opts.sync = PUGL_FALSE;
- } else if (!strcmp(argv[i], "-h")) {
- opts.help = true;
- return opts;
- } else if (!strcmp(argv[i], "-i")) {
- opts.ignoreKeyRepeat = true;
- } else if (!strcmp(argv[i], "-r")) {
- opts.resizable = true;
- } else if (!strcmp(argv[i], "-s")) {
- opts.sync = PUGL_TRUE;
- } else if (!strcmp(argv[i], "-v")) {
- opts.verbose = true;
- } else if (argv[i][0] != '-') {
- break;
- } else {
- opts.help = true;
- logError("Unknown option: %s\n", argv[i]);
- }
- }
+ char** const argv = *pargv;
+ int i = 1;
+ for (; i < *pargc; ++i) {
+ if (!strcmp(argv[i], "-a")) {
+ opts.samples = 4;
+ } else if (!strcmp(argv[i], "-c")) {
+ opts.continuous = true;
+ } else if (!strcmp(argv[i], "-d")) {
+ opts.doubleBuffer = PUGL_FALSE;
+ } else if (!strcmp(argv[i], "-e")) {
+ opts.errorChecking = PUGL_TRUE;
+ } else if (!strcmp(argv[i], "-f")) {
+ opts.sync = PUGL_FALSE;
+ } else if (!strcmp(argv[i], "-h")) {
+ opts.help = true;
+ return opts;
+ } else if (!strcmp(argv[i], "-i")) {
+ opts.ignoreKeyRepeat = true;
+ } else if (!strcmp(argv[i], "-r")) {
+ opts.resizable = true;
+ } else if (!strcmp(argv[i], "-s")) {
+ opts.sync = PUGL_TRUE;
+ } else if (!strcmp(argv[i], "-v")) {
+ opts.verbose = true;
+ } else if (argv[i][0] != '-') {
+ break;
+ } else {
+ opts.help = true;
+ logError("Unknown option: %s\n", argv[i]);
+ }
+ }
- *pargc -= i;
- *pargv += i;
+ *pargc -= i;
+ *pargv += i;
- return opts;
+ return opts;
}
#endif // TEST_TEST_UTILS_H