1 /* test-screens.c --- some test cases for the "monitor sanity" checks.
2 * xscreensaver, Copyright (c) 2008 Jamie Zawinski <jwz@jwz.org>
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation. No representations are made about the suitability of this
9 * software for any purpose. It is provided "as is" without express or
19 /* This file doesn't need the Xt headers, so stub these types out... */
21 #define XtAppContext void*
22 #define XrmDatabase void*
23 #define XtIntervalId void*
24 #define XtPointer void*
27 #include "xscreensaver.h"
32 #define WidthOfScreen(s) 10240
33 #define HeightOfScreen(s) 10240
36 #define screen_number(s) ((int) s)
38 #include "screens.c" /* to get at static void check_monitor_sanity() */
41 char *progclass = "XScreenSaver";
43 const char *blurb(void) { return progname; }
45 Bool safe_XF86VidModeGetViewPort(Display *d, int i, int *x, int *y) { abort(); }
46 void initialize_screen_root_widget(saver_screen_info *ssi) { abort(); }
47 Visual *get_best_gl_visual (saver_info *si, Screen *sc) { abort(); }
51 failstr (monitor_sanity san)
54 case S_SANE: return "OK";
55 case S_ENCLOSED: return "ENC";
56 case S_DUPLICATE: return "DUP";
57 case S_OVERLAP: return "OVR";
58 case S_OFFSCREEN: return "OFF";
59 case S_DISABLED: return "DIS";
60 default: abort(); break;
66 test (int testnum, const char *screens, const char *desired)
68 monitor *monitors[100];
72 char *token = strtok (strdup(screens), ",");
75 monitor *m = calloc (1, sizeof (monitor));
77 m->id = (testnum * 1000) + nscreens;
78 if (5 == sscanf (token, "%dx%d+%d+%d@%d%c",
79 &m->width, &m->height, &m->x, &m->y,
80 (int *) &m->screen, &c))
82 else if (4 != sscanf (token, "%dx%d+%d+%d%c",
83 &m->width, &m->height, &m->x, &m->y, &c))
85 fprintf (stderr, "%s: unparsable geometry: %s\n", blurb(), token);
88 monitors[nscreens] = m;
90 token = strtok (0, ",");
92 monitors[nscreens] = 0;
94 check_monitor_sanity (monitors);
97 for (i = 0; i < nscreens; i++)
99 monitor *m = monitors[i];
100 if (out != result) *out++ = ',';
101 if (m->sanity == S_SANE)
103 sprintf (out, "%dx%d+%d+%d", m->width, m->height, m->x, m->y);
105 sprintf (out + strlen(out), "@%d", (int) m->screen);
108 strcpy (out, failstr (m->sanity));
113 if (!strcmp (result, desired))
114 fprintf (stderr, "%s: test %2d OK\n", blurb(), testnum);
116 fprintf (stderr, "%s: test %2d FAILED:\n"
128 SI.monitor_layout = monitors;
129 describe_monitor_layout (&SI);
139 # define A(a) test (i++, a, a);
140 # define B(a,b) test (i++, a, b)
144 A("1024x768+0+0,1024x768+1024+0");
145 A("1024x768+0+0,1024x768+0+768");
146 A("1024x768+0+0,1024x768+0+768,1024x768+1024+0");
147 A("800x600+0+0,800x600+0+0@1,800x600+10+0@2");
149 B("1024x768+999999+0",
151 B("1024x768+-999999+-999999",
153 B("1024x768+0+0,1024x768+0+0",
155 B("1024x768+0+0,1024x768+0+0,1024x768+0+0",
156 "1024x768+0+0,DUP,DUP");
157 B("1024x768+0+0,1024x768+1024+0,1024x768+0+0",
158 "1024x768+0+0,1024x768+1024+0,DUP");
159 B("1280x1024+0+0,1024x768+0+64,800x600+0+0,640x480+0+0,720x400+0+0",
160 "1280x1024+0+0,ENC,ENC,ENC,ENC");
161 B("1024x768+0+64,1280x1024+0+0,800x600+0+0,640x480+0+0,800x600+0+0,720x400+0+0",
162 "ENC,1280x1024+0+0,ENC,ENC,ENC,ENC");
163 B("1024x768+0+64,1280x1024+0+0,800x600+0+0,640x480+0+0,1280x1024+0+0,720x400+0+0",
164 "ENC,1280x1024+0+0,ENC,ENC,DUP,ENC");
165 B("720x400+0+0,640x480+0+0,800x600+0+0,1024x768+0+64,1280x1024+0+0",
166 "ENC,ENC,ENC,ENC,1280x1024+0+0");
167 B("1280x1024+0+0,800x600+1280+0,800x600+1300+0",
168 "1280x1024+0+0,800x600+1280+0,OVR");
169 B("1280x1024+0+0,800x600+1280+0,800x600+1300+0,1280x1024+0+0,800x600+1280+0",
170 "1280x1024+0+0,800x600+1280+0,OVR,DUP,DUP");
172 /* +-------------+----+ +------+---+ 1: 1440x900, widescreen display
173 | : | | 3+4 : | 2: 1280x1024, conventional display
174 | 1+2 : 1 | +......+ | 3: 1024x768, laptop
175 | : | | 3 | 4: 800x600, external projector
176 +.............+----+ +----------+
181 B("1440x900+0+0,1280x1024+0+0,1024x768+1440+0,800x600+1440+0",
182 "1440x900+0+0,OVR,1024x768+1440+0,ENC");
183 B("800x600+0+0,800x600+0+0,800x600+800+0",
184 "800x600+0+0,DUP,800x600+800+0");
185 B("1600x1200+0+0,1360x768+0+0",
186 "1600x1200+0+0,ENC");
187 B("1600x1200+0+0,1360x768+0+0,1600x1200+0+0@1,1360x768+0+0@1",
188 "1600x1200+0+0,ENC,1600x1200+0+0@1,ENC");
193 main (int argc, char **argv)
197 s = strrchr(progname, '/');
198 if (s) progname = s+1;
201 fprintf (stderr, "usage: %s\n", argv[0]);