summaryrefslogtreecommitdiff
path: root/tests/common
diff options
context:
space:
mode:
Diffstat (limited to 'tests/common')
-rw-r--r--tests/common/test_contracts.c9
-rw-r--r--tests/common/test_hello_example.c20
-rw-r--r--tests/common/test_tablet_example.c20
-rw-r--r--tests/common/test_timers.c1
4 files changed, 45 insertions, 5 deletions
diff --git a/tests/common/test_contracts.c b/tests/common/test_contracts.c
index ac0065c..ee6fe61 100644
--- a/tests/common/test_contracts.c
+++ b/tests/common/test_contracts.c
@@ -25,6 +25,14 @@ static void test_timing_clock(void)
assert(stats.max_us == 500.0);
}
+static void test_surface_state(void)
+{
+ /* Reading reported flags does not require a backend query or display. */
+ struct yasl_surface surface = {.state = YASL_STATE_FULLSCREEN | YASL_STATE_ACTIVATED};
+ assert(!yasl_surface_state(NULL));
+ assert(yasl_surface_state(&surface) == (YASL_STATE_FULLSCREEN | YASL_STATE_ACTIVATED));
+}
+
static void test_queue(void)
{
struct input_queue q = {0};
@@ -326,6 +334,7 @@ static void test_errors(void)
int main(void)
{
test_timing_clock();
+ test_surface_state();
test_queue();
test_validation();
test_native();
diff --git a/tests/common/test_hello_example.c b/tests/common/test_hello_example.c
new file mode 100644
index 0000000..6e0318f
--- /dev/null
+++ b/tests/common/test_hello_example.c
@@ -0,0 +1,20 @@
+/* Exercise hello's real frame callback; automated exit belongs in the test. */
+#define main hello_example_main
+#include "../../examples/hello.c"
+#undef main
+
+static void draw_once(void *ud, struct yasl_surface *surface, struct yasl_frame_context *frame)
+{
+ draw(ud, surface, frame);
+ if (!((struct app *)ud)->failed) yasl_surface_destroy(surface);
+}
+
+int main(void)
+{
+ struct app app = {0};
+ struct yasl_app_desc desc = {
+ .app_id = "org.yasl.test.hello", .userdata = &app,
+ .init = init, .event = event, .frame = draw_once,
+ };
+ return yasl_run(&desc) || app.failed ? 1 : 0;
+}
diff --git a/tests/common/test_tablet_example.c b/tests/common/test_tablet_example.c
index 15dde9c..77e79f6 100644
--- a/tests/common/test_tablet_example.c
+++ b/tests/common/test_tablet_example.c
@@ -6,8 +6,20 @@
static void pointer(struct app *app, enum yasl_pointer_kind kind,
enum yasl_pointer_device device, int button, int x, int y, uint16_t pressure)
{
- struct yasl_input_event event = {.kind = YASL_INPUT_MOUSE, .mouse = {
- .kind = kind, .device = device, .button = button, .pos = {x, y}, .pen.pressure = pressure}};
+ struct yasl_event event = {0};
+ if (kind == YASL_PTR_MOTION) {
+ event.type = YASL_EVENT_MOUSE_MOTION;
+ event.mouse_motion.pos = (struct yasl_vector2i){x, y};
+ event.mouse_motion.device = device;
+ event.mouse_motion.pen.pressure = pressure;
+ } else {
+ event.type = YASL_EVENT_MOUSE_BUTTON;
+ event.mouse_button.pos = (struct yasl_vector2i){x, y};
+ event.mouse_button.device = device;
+ event.mouse_button.button = button;
+ event.mouse_button.pressed = kind == YASL_PTR_PRESS;
+ event.mouse_button.pen.pressure = pressure;
+ }
input(app, &event);
}
@@ -38,13 +50,13 @@ int main(void)
pointer(&app, YASL_PTR_PRESS, YASL_PTR_DEV_ERASER, 0, 80, 160, 65535);
assert(app.canvas[(size_t)160 * app.geometry.size.x + 80] == PAPER &&
app.canvas[(size_t)160 * app.geometry.size.x + 130] == INK);
- struct yasl_input_event reset = {.kind = YASL_INPUT_RESET};
+ struct yasl_event reset = {.type = YASL_EVENT_INPUT_RESET};
input(&app, &reset);
pointer(&app, YASL_PTR_MOTION, YASL_PTR_DEV_ERASER, 0, 130, 160, 65535);
assert(!app.down && app.canvas[(size_t)160 * app.geometry.size.x + 130] == INK);
pointer(&app, YASL_PTR_PRESS, YASL_PTR_DEV_MOUSE, 0, 300, 200, 0);
assert(app.canvas[(size_t)200 * app.geometry.size.x + 300] == INK);
- struct yasl_input_event blur = {.kind = YASL_INPUT_FOCUS, .focus.focused = false};
+ struct yasl_event blur = {.type = YASL_EVENT_WINDOW_FOCUS, .focus.focused = false};
input(&app, &blur);
assert(!app.down);
assert(resize_canvas(&app, (struct yasl_geometry){{800, 600}, 240}));
diff --git a/tests/common/test_timers.c b/tests/common/test_timers.c
index f321b2c..8c92158 100644
--- a/tests/common/test_timers.c
+++ b/tests/common/test_timers.c
@@ -4,7 +4,6 @@
#include <assert.h>
#include <stdio.h>
-#include <stdlib.h>
#include <string.h>
struct test_ctx {