http://www.tienza.es/crux/src/www.jwz.org/xscreensaver/xscreensaver-5.06.tar.gz
[xscreensaver] / driver / test-screens.c
1 /* test-screens.c --- some test cases for the "monitor sanity" checks.
2  * xscreensaver, Copyright (c) 2008 Jamie Zawinski <jwz@jwz.org>
3  *
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 
10  * implied warranty.
11  */
12
13 #ifdef HAVE_CONFIG_H
14 # include "config.h"
15 #endif
16
17 #include <X11/Xlib.h>
18
19 /* This file doesn't need the Xt headers, so stub these types out... */
20 #undef XtPointer
21 #define XtAppContext void*
22 #define XrmDatabase  void*
23 #define XtIntervalId void*
24 #define XtPointer    void*
25 #define Widget       void*
26
27 #include "xscreensaver.h"
28 #include "visual.h"
29
30 #undef WidthOfScreen
31 #undef HeightOfScreen
32 #define WidthOfScreen(s) 10240
33 #define HeightOfScreen(s) 10240
34
35 #undef screen_number
36 #define screen_number(s) (0)
37
38 #include "screens.c"   /* to get at static void check_monitor_sanity() */
39
40 char *progname = 0;
41 char *progclass = "XScreenSaver";
42
43 const char *blurb(void) { return progname; }
44
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(); }
48
49
50 static const char *
51 failstr (monitor_sanity san)
52 {
53   switch (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   }
61 }
62
63
64 static void
65 test (int testnum, const char *screens, const char *desired)
66 {
67   monitor *monitors[100];
68   char result[2048];
69   char *out = result;
70   int i, nscreens = 0;
71   char *token = strtok (strdup(screens), ",");
72   while (token)
73     {
74       monitor *m = calloc (1, sizeof (monitor));
75       char c;
76       m->id = (testnum * 1000) + nscreens;
77       if (4 != sscanf (token, "%dx%d+%d+%d%c", 
78                       &m->width, &m->height, &m->x, &m->y, &c))
79         {
80           fprintf (stderr, "%s: unparsable geometry: %s\n", blurb(), token);
81           exit (1);
82         }
83       monitors[nscreens] = m;
84       nscreens++;
85       token = strtok (0, ",");
86     }
87   monitors[nscreens] = 0;
88
89   check_monitor_sanity (monitors);
90
91   *out = 0;
92   for (i = 0; i < nscreens; i++)
93     {
94       monitor *m = monitors[i];
95       if (out != result) *out++ = ',';
96       if (m->sanity == S_SANE)
97         sprintf (out, "%dx%d+%d+%d", m->width, m->height, m->x, m->y);
98       else
99         strcpy (out, failstr (m->sanity));
100       out += strlen(out);
101     }
102   *out = 0;
103
104   if (!strcmp (result, desired))
105     fprintf (stderr, "%s: test %2d OK\n", blurb(), testnum);
106   else
107     fprintf (stderr, "%s: test %2d FAILED:\n"
108              "%s:   given: %s\n"
109              "%s:  wanted: %s\n"
110              "%s:     got: %s\n",
111              blurb(), testnum,
112              blurb(), screens, 
113              blurb(), desired, 
114              blurb(), result);
115
116 # if 0
117   {
118     saver_info SI;
119     SI.monitor_layout = monitors;
120     describe_monitor_layout (&SI);
121   }
122 # endif
123
124 }
125
126 static void
127 run_tests(void)
128 {
129   int i = 1;
130 # define A(a)   test (i++, a, a);
131 # define B(a,b) test (i++, a, b)
132
133   A("");
134   A("1024x768+0+0");
135   A("1024x768+0+0,1024x768+1024+0");
136   A("1024x768+0+0,1024x768+0+768");
137   A("1024x768+0+0,1024x768+0+768,1024x768+1024+0");
138
139   B("1024x768+999999+0",
140     "OFF");
141   B("1024x768+-999999+-999999",
142     "OFF");
143   B("1024x768+0+0,1024x768+0+0",
144     "1024x768+0+0,DUP");
145   B("1024x768+0+0,1024x768+0+0,1024x768+0+0",
146     "1024x768+0+0,DUP,DUP");
147   B("1024x768+0+0,1024x768+1024+0,1024x768+0+0",
148     "1024x768+0+0,1024x768+1024+0,DUP");
149   B("1280x1024+0+0,1024x768+0+64,800x600+0+0,640x480+0+0,720x400+0+0",
150     "1280x1024+0+0,ENC,ENC,ENC,ENC");
151   B("1024x768+0+64,1280x1024+0+0,800x600+0+0,640x480+0+0,800x600+0+0,720x400+0+0",
152     "ENC,1280x1024+0+0,ENC,ENC,ENC,ENC");
153   B("1024x768+0+64,1280x1024+0+0,800x600+0+0,640x480+0+0,1280x1024+0+0,720x400+0+0",
154     "ENC,1280x1024+0+0,ENC,ENC,DUP,ENC");
155   B("720x400+0+0,640x480+0+0,800x600+0+0,1024x768+0+64,1280x1024+0+0",
156     "ENC,ENC,ENC,ENC,1280x1024+0+0");
157   B("1280x1024+0+0,800x600+1280+0,800x600+1300+0",
158     "1280x1024+0+0,800x600+1280+0,OVR");
159   B("1280x1024+0+0,800x600+1280+0,800x600+1300+0,1280x1024+0+0,800x600+1280+0",
160     "1280x1024+0+0,800x600+1280+0,OVR,DUP,DUP");
161
162   /*  +-------------+----+  +------+---+   1: 1440x900,  widescreen display
163       |             :    |  | 3+4  :   |   2: 1280x1024, conventional display
164       |     1+2     : 1  |  +......+   |   3: 1024x768,  laptop
165       |             :    |  |  3       |   4: 800x600,   external projector
166       +.............+----+  +----------+
167       |      2      |
168       |             |
169       +-------------+
170    */
171   B("1440x900+0+0,1280x1024+0+0,1024x768+1440+0,800x600+1440+0",
172     "1440x900+0+0,OVR,1024x768+1440+0,ENC");
173   B("800x600+0+0,800x600+0+0,800x600+800+0",
174     "800x600+0+0,DUP,800x600+800+0");
175   B("1600x1200+0+0,1360x768+0+0",
176     "1600x1200+0+0,ENC");
177 }
178
179
180 int
181 main (int argc, char **argv)
182 {
183   char *s;
184   progname = argv[0];
185   s = strrchr(progname, '/');
186   if (s) progname = s+1;
187   if (argc != 1)
188     {
189       fprintf (stderr, "usage: %s\n", argv[0]);
190       exit (1);
191     }
192
193   run_tests();
194
195   exit (0);
196 }