diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/Makefile | 25 | ||||
-rw-r--r-- | test/main.c | 13 | ||||
-rw-r--r-- | test/main.o | bin | 0 -> 1184 bytes | |||
-rw-r--r-- | test/test1.c | 99 | ||||
-rw-r--r-- | test/test1.o | bin | 0 -> 4536 bytes | |||
-rwxr-xr-x | test/tests | bin | 0 -> 57360 bytes |
6 files changed, 137 insertions, 0 deletions
diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 0000000..d9b319d --- /dev/null +++ b/test/Makefile @@ -0,0 +1,25 @@ +# See LICENSE file for copyright and license details. + +NAME = tests +CC = cc +SRC != find * -name '*.c' +OBJ = ${SRC:.c=.o} + +LIB = x11 utils log + +CFLAGS != pkg-config --cflags ${LIB} +LFLAGS != pkg-config --libs ${LIB} + +CFLAGS += -I../build/include +LFLAGS += ../build/debug/static/libcherry.a + +all: init-lib ${OBJ} ${NAME} + +.c.o: + ${CC} ${CFLAGS} -c $< -o $@ + +init-lib: + cd ../ && make debug-static + +${NAME}: + ${CC} ${LFLAGS} ${OBJ} -o $@ diff --git a/test/main.c b/test/main.c new file mode 100644 index 0000000..2f62598 --- /dev/null +++ b/test/main.c @@ -0,0 +1,13 @@ +/* See LICENSE file for copyright and license details. */ + +#include <stdlib.h> + +int test1(int, char **); + +int +main(int argc, char** argv) +{ + test1(argc, argv); + + return EXIT_SUCCESS; +} diff --git a/test/main.o b/test/main.o Binary files differnew file mode 100644 index 0000000..daafba8 --- /dev/null +++ b/test/main.o diff --git a/test/test1.c b/test/test1.c new file mode 100644 index 0000000..c2bbfac --- /dev/null +++ b/test/test1.c @@ -0,0 +1,99 @@ +/* See LICENSE file for copyright and license details. */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <X11/Xlib.h> +#include <X11/Xutil.h> + +#include <cherry/application.h> +#include <cherry/event.h> +#include <cherry/window.h> + +static void +app_deactivated(CherryApplication *app, void *data) +{ + printf("Deactivated\n"); +} + +int +listener1(CherryWindow *w, CherryEvent evt) +{ + char hello[] = "Example 1"; + char hi[] = "Hi!"; + + KeySym mykey; + char text[10]; + int i; + + switch (evt.event_id) { + case WINDOW_DELETED: + printf("Listener1\n"); + cherry_window_dispose_on_exit(w); + break; + case WINDOW_EXPOSED: + XDrawImageString(evt.display, + evt.window, + w->gc, + 50, 50, + hello, strlen(hello)); + break; + case MOUSE_BUTTON_PRESSED: + XDrawImageString(evt.display, + evt.window, + w->gc, + evt.mouse.x, evt.mouse.y, + hi, strlen(hi)); + break; + case KEY_PRESSED: + i = XLookupString(&evt.key.xkey, text, 10, &mykey, 0); + if (i == 1 && text[0] == 'q') cherry_window_dispose_on_exit(w); + break; + } + + return 0; +} + + int +listener2(CherryWindow *w, CherryEvent evt) +{ + switch (evt.event_id) { + case WINDOW_DELETED: + printf("Listener2\n"); + break; + } + + return 0; +} + +static void +app_activated(CherryApplication *app, void *data) +{ + CherryWindow *w = cherry_window_new(); + cherry_window_set_title(w, "Hello from another World!"); + cherry_window_set_dimension(w, 350, 250); + cherry_window_set_position(w, 200, 300); + cherry_window_set_listener(w, listener1); + + CherryWindow *w2 = cherry_window_new(); + cherry_window_set_title(w2, "The second window"); + cherry_window_set_dimension(w2, 350, 250); + cherry_window_set_position(w2, 500, 300); + cherry_window_set_listener(w2, listener2); + + /* show up window */ + cherry_window_set_visible(w, 1); + cherry_window_set_visible(w2, 1); +} + +int +test1(int argc, char **argv) +{ + puts("Running test1..."); + + CherryApplication *app = cherry_application_new("Just a test!"); + cherry_application_set_activated_listener(app, app_activated, NULL); + cherry_application_set_deactivated_listener(app, app_deactivated, NULL); + + return cherry_application_run(app, argc, argv); +} diff --git a/test/test1.o b/test/test1.o Binary files differnew file mode 100644 index 0000000..4ee7562 --- /dev/null +++ b/test/test1.o diff --git a/test/tests b/test/tests Binary files differnew file mode 100755 index 0000000..12ad8b0 --- /dev/null +++ b/test/tests |