1/** 2 * Test that MonitorLayout config works 3 */ 4 5#include "ctwm.h" 6 7#include <stdio.h> 8 9#include "ctwm_main.h" 10#include "ctwm_test.h" 11#include "r_layout.h" 12#include "screen.h" 13 14 15/** 16 * Callback: after the config file gets parsed, make sure we got the info 17 * we expected out of it. 18 */ 19static int 20check_monitor_layout(void) 21{ 22 // Guard against things that shouldn't happen 23 if(Scr == NULL) { 24 fprintf(stderr, "BUG: Scr == NULL\n"); 25 return 1; 26 } 27 if(Scr->Layout == NULL) { 28 fprintf(stderr, "BUG: Scr->Layout == NULL\n"); 29 return 1; 30 } 31 32 // Debug/dev 33 if(0) { 34 RLayoutPrint(Scr->Layout); 35 return 1; 36 } 37 38 39 // We should have 2 monitors... 40 const int nmons = RLayoutNumMonitors(Scr->Layout); 41 if(nmons != 3) { 42 fprintf(stderr, "Expected 3 monitors, got %d\n", nmons); 43 return 1; 44 } 45 46 47 // Check the names and sizes. 48 // XXX We maybe should have better accessors for this, than grubbing 49 // in the structs, but... 50 char **names = Scr->Layout->names; 51 52 if(strcmp(names[0], "One") != 0) { 53 fprintf(stderr, "First monitor should be 'One', not '%s'\n", names[0]); 54 return 1; 55 } 56 if(strcmp(names[1], "Two") != 0) { 57 fprintf(stderr, "Second monitor should be 'Two', not '%s'\n", names[1]); 58 return 1; 59 } 60 if(names[2] != NULL) { 61 fprintf(stderr, "Third monitor should be unnamed, not '%s'\n", names[2]); 62 return 1; 63 } 64 65 66 RAreaList *mons = Scr->Layout->monitors; 67 68#define CHK_MON_VAL(mon, fld, val) do { \ 69 if(mons[0].areas[mon].fld != val) { \ 70 fprintf(stderr, "Monitor %d %s should be %d, not %d\n", mon, \ 71 #fld, val, mons[0].areas[mon].fld); \ 72 return 1; \ 73 } \ 74 } while(0) 75 76 CHK_MON_VAL(0, x, 0); 77 CHK_MON_VAL(0, y, 0); 78 CHK_MON_VAL(0, width, 1024); 79 CHK_MON_VAL(0, height, 768); 80 81 CHK_MON_VAL(1, x, 1024); 82 CHK_MON_VAL(1, y, 0); 83 CHK_MON_VAL(1, width, 768); 84 CHK_MON_VAL(1, height, 1024); 85 86 CHK_MON_VAL(2, x, 1792); 87 CHK_MON_VAL(2, y, 0); 88 CHK_MON_VAL(2, width, 800); 89 CHK_MON_VAL(2, height, 600); 90 91 92 93 // OK, everything was good. 94 fprintf(stdout, "OK\n"); 95 return 0; 96} 97 98 99 100/* 101 * Connect up our callback and kick off ctwm. 102 * 103 * XXX Args should be more locally controlled; x-ref test_m4. 104 */ 105int 106main(int argc, char *argv[]) 107{ 108 // Connect up 109 TEST_POSTPARSE(check_monitor_layout); 110 111 return ctwm_main(argc, argv); 112} 113