progman.exe^H^H^H^H
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

tests: Setup a common test harness and exit when Esc is pressed

+111 -59
+5 -5
tests/Makefile
··· 30 30 `pkg-config --cflags ${PKGLIBS}` 31 31 LDFLAGS+= `pkg-config --libs ${PKGLIBS}` 32 32 33 - BIN= border-no-titlebar \ 34 - no-resize 33 + BIN= no-resize \ 34 + win-type-utility 35 35 36 36 all: $(BIN) 37 37 38 38 common.o: ../common.c 39 - 40 39 atom.o: ../atom.c 40 + harness.o: harness.c 41 41 42 - $(BIN): atom.o common.o $(BIN).c 43 - $(CC) $(CFLAGS) -o $@ $@.c atom.o common.o $(LDFLAGS) 42 + $(BIN): atom.o common.o harness.o $(BIN).c 43 + $(CC) $(CFLAGS) -o $@ $@.c atom.o common.o harness.o $(LDFLAGS) 44 44 45 45 clean: 46 46 rm -f $(BIN) *.o
+28 -12
tests/border-no-titlebar.c tests/harness.c
··· 19 19 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 20 */ 21 21 22 - #include <stdlib.h> 23 - #include <stdio.h> 24 - #include <err.h> 25 - #include <X11/Xlib.h> 22 + #include "harness.h" 23 + #include <libgen.h> 26 24 27 - #include "../atom.h" 28 - #include "../common.h" 25 + Window win; 26 + int screen; 29 27 30 28 int 31 29 main(int argc, char **argv) 32 30 { 33 - Window win; 34 31 XEvent ev; 32 + XTextProperty name; 33 + char *title = basename(argv[0]); 35 34 int screen; 36 35 37 36 dpy = XOpenDisplay(NULL); ··· 43 42 44 43 find_supported_atoms(); 45 44 46 - win = XCreateWindow(dpy, root, 0, 0, 200, 100, 0, 45 + win = XCreateWindow(dpy, root, 0, 0, 300, 200, 0, 47 46 DefaultDepth(dpy, screen), CopyFromParent, 48 47 DefaultVisual(dpy, screen), 0, NULL); 49 48 if (!win) 50 49 err(1, "XCreateWindow"); 51 50 51 + if (!XStringListToTextProperty(&title, 1, &name)) 52 + err(1, "!XStringListToTextProperty"); 53 + XSetWMName(dpy, win, &name); 54 + 52 55 XSetWindowBackground(dpy, win, WhitePixel(dpy, screen)); 56 + XSelectInput(dpy, win, KeyPressMask); 53 57 54 - set_atoms(win, net_wm_state, XA_ATOM, &net_wm_state_above, 1); 55 - set_atoms(win, net_wm_wintype, XA_ATOM, &net_wm_type_utility, 1); 58 + setup(argc, argv); 56 59 57 60 XMapWindow(dpy, win); 58 - while (XNextEvent(dpy, &ev)) 59 - ; 61 + 62 + for (;;) { 63 + XNextEvent(dpy, &ev); 64 + 65 + switch (ev.type) { 66 + case KeyPress: { 67 + KeySym kc = lookup_keysym(&ev.xkey); 68 + if (kc == XK_Escape) 69 + exit(0); 70 + break; 71 + } 72 + } 73 + 74 + process_event(&ev); 75 + } 60 76 61 77 return 0; 62 78 }
+36
tests/harness.h
··· 1 + /* 2 + * Copyright 2020 joshua stein <jcs@jcs.org> 3 + * 4 + * Permission is hereby granted, free of charge, to any person obtaining a copy 5 + * of this software and associated documentation files (the "Software"), to 6 + * deal in the Software without restriction, including without limitation the 7 + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 + * sell copies of the Software, and to permit persons to whom the Software is 9 + * furnished to do so, subject to the following conditions: 10 + * 11 + * The above copyright notice and this permission notice shall be included in 12 + * all copies or substantial portions of the Software. 13 + * 14 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 + * AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 18 + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 19 + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 + */ 21 + 22 + #include <stdlib.h> 23 + #include <stdio.h> 24 + #include <err.h> 25 + #include <string.h> 26 + #include <X11/Xlib.h> 27 + #include <X11/Xutil.h> 28 + 29 + #include "../atom.h" 30 + #include "../common.h" 31 + 32 + extern Window win; 33 + extern int screen; 34 + 35 + extern void setup(int, char **); 36 + extern void process_event(XEvent *ev);
+8 -42
tests/no-resize.c
··· 19 19 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 20 */ 21 21 22 - #include <stdlib.h> 23 - #include <stdio.h> 24 - #include <err.h> 25 - #include <string.h> 26 - #include <X11/Xlib.h> 27 - #include <X11/Xutil.h> 22 + #include "harness.h" 28 23 29 - #include "../atom.h" 30 - #include "../common.h" 31 - 32 - int 33 - main(int argc, char **argv) 24 + void 25 + setup(int argc, char **argv) 34 26 { 35 - Window win; 36 - XEvent ev; 37 27 XSizeHints *hints; 38 - char *title = strdup("no-resize"); 39 - XTextProperty name; 40 - int screen; 41 - 42 - dpy = XOpenDisplay(NULL); 43 - if (!dpy) 44 - err(1, "can't open $DISPLAY"); 45 - 46 - screen = DefaultScreen(dpy); 47 - root = RootWindow(dpy, screen); 48 - 49 - find_supported_atoms(); 50 - 51 - win = XCreateWindow(dpy, root, 0, 0, 300, 200, 0, 52 - DefaultDepth(dpy, screen), CopyFromParent, 53 - DefaultVisual(dpy, screen), 0, NULL); 54 - if (!win) 55 - err(1, "XCreateWindow"); 56 - 57 - XSetWindowBackground(dpy, win, WhitePixel(dpy, screen)); 58 28 59 29 hints = XAllocSizeHints(); 60 30 if (!hints) ··· 66 36 hints->max_width = 300; 67 37 hints->max_height = 200; 68 38 69 - if (!XStringListToTextProperty(&title, 1, &name)) 70 - err(1, "!XStringListToTextProperty"); 39 + XSetWMNormalHints(dpy, win, hints); 40 + } 71 41 72 - XSetWMProperties(dpy, win, &name, NULL, NULL, 0, hints, NULL, NULL); 73 - 74 - XMapWindow(dpy, win); 75 - while (XNextEvent(dpy, &ev)) 76 - ; 77 - 78 - return 0; 42 + void 43 + process_event(XEvent *ev) 44 + { 79 45 }
+34
tests/win-type-utility.c
··· 1 + /* 2 + * Copyright 2020 joshua stein <jcs@jcs.org> 3 + * 4 + * Permission is hereby granted, free of charge, to any person obtaining a copy 5 + * of this software and associated documentation files (the "Software"), to 6 + * deal in the Software without restriction, including without limitation the 7 + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 + * sell copies of the Software, and to permit persons to whom the Software is 9 + * furnished to do so, subject to the following conditions: 10 + * 11 + * The above copyright notice and this permission notice shall be included in 12 + * all copies or substantial portions of the Software. 13 + * 14 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 + * AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 18 + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 19 + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 + */ 21 + 22 + #include "harness.h" 23 + 24 + void 25 + setup(int argc, char **argv) 26 + { 27 + set_atoms(win, net_wm_state, XA_ATOM, &net_wm_state_above, 1); 28 + set_atoms(win, net_wm_wintype, XA_ATOM, &net_wm_type_utility, 1); 29 + } 30 + 31 + void 32 + process_event(XEvent *ev) 33 + { 34 + }