summaryrefslogtreecommitdiff
path: root/tests/cocoa/test_cursor.m
diff options
context:
space:
mode:
Diffstat (limited to 'tests/cocoa/test_cursor.m')
-rw-r--r--tests/cocoa/test_cursor.m53
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/cocoa/test_cursor.m b/tests/cocoa/test_cursor.m
new file mode 100644
index 0000000..0f3ba06
--- /dev/null
+++ b/tests/cocoa/test_cursor.m
@@ -0,0 +1,53 @@
+#import <AppKit/AppKit.h>
+#include <yasl/native.h>
+#include <assert.h>
+
+static void assert_transparent(NSCursor *cursor)
+{
+ assert(cursor);
+ NSBitmapImageRep *bitmap = [NSBitmapImageRep imageRepWithData:cursor.image.TIFFRepresentation];
+ assert(bitmap && bitmap.hasAlpha);
+ for (NSInteger y = 0; y < bitmap.pixelsHigh; y++)
+ for (NSInteger x = 0; x < bitmap.pixelsWide; x++)
+ assert([bitmap colorAtX:x y:y].alphaComponent == 0);
+}
+
+int main(void)
+{
+ @autoreleasepool {
+ struct yasl_display *display = yasl_display_open(NULL, NULL);
+ assert(display);
+ struct yasl_surface_spec spec = {.title = "Cursor test", .size = {320, 240}};
+ struct yasl_surface *surface = yasl_surface_create_toplevel(display, &spec);
+ assert(surface);
+ NSWindow *window = (NSWindow *)yasl_surface_get_native_handle(surface);
+ NSView *view = window.contentView;
+ yasl_surface_set_cursor(surface, YASL_CURSOR_HIDDEN);
+ [view cursorUpdate:nil];
+ NSCursor *hidden = [NSCursor currentCursor];
+ assert_transparent(hidden);
+
+ NSEvent *motion = [NSEvent mouseEventWithType:NSEventTypeMouseMoved
+ location:NSMakePoint(100, 120) modifierFlags:0 timestamp:0
+ windowNumber:window.windowNumber context:nil eventNumber:0 clickCount:0 pressure:0];
+ [view mouseMoved:motion];
+ [view cursorUpdate:nil];
+ assert([NSCursor currentCursor] == hidden);
+ struct yasl_input_event event;
+ bool moved = false;
+ while (yasl_surface_input_poll(surface, &event))
+ if (event.kind == YASL_INPUT_MOUSE && event.mouse.kind == YASL_PTR_MOTION)
+ moved = true;
+ assert(moved);
+
+ [[NSCursor arrowCursor] set]; /* Simulate leaving and re-entering. */
+ [view cursorUpdate:nil];
+ assert([NSCursor currentCursor] == hidden);
+ yasl_surface_set_cursor(surface, YASL_CURSOR_ARROW);
+ [view cursorUpdate:nil];
+ assert([NSCursor currentCursor] == [NSCursor arrowCursor]);
+ yasl_surface_destroy(surface);
+ yasl_display_close(display);
+ }
+ return 0;
+}