1 /****************************************************************************
2 * Copyright (c) 2018 Free Software Foundation, Inc. *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
29 * $Id: color_content.c,v 1.2 2018/12/30 00:52:58 tom Exp $
33 #include <test.priv.h>
47 static MYCOLOR *expected;
50 static struct timeval initial_time;
51 static struct timeval finish_time;
55 failed(const char *msg)
60 ExitProgram(EXIT_FAILURE);
63 static NCURSES_COLOR_T
66 return (NCURSES_COLOR_T) (rand() % 1000);
75 scrollok(stdscr, TRUE);
78 if (!can_change_color())
79 failed("this terminal cannot initialize colors");
84 failed("color limit must be greater than zero");
87 NCURSES_PAIRS_T color;
89 expected = typeCalloc(MYCOLOR, l_opt);
95 for (r = 0; r < 1000; ++r) {
96 for (g = 0; g < 1000; ++g) {
97 for (b = 0; b < 1000; ++b) {
99 init_color(color, r, g, b);
100 expected[color].r = r;
101 expected[color].g = g;
102 expected[color].b = b;
111 for (color = 1; color < l_opt; ++color) {
112 expected[color].r = random_color();
113 expected[color].g = random_color();
114 expected[color].b = random_color();
115 init_color(color, expected[color].r, expected[color].g,
121 failed("This demo requires a color terminal");
123 #if HAVE_GETTIMEOFDAY
124 gettimeofday(&initial_time, 0);
131 NCURSES_PAIRS_T color;
133 for (color = 0; color < l_opt; ++color) {
137 if (color_content(color, &r, &g, &b) == OK) {
139 if (r != expected[color].r)
141 if (g != expected[color].g)
143 if (b != expected[color].b)
149 addch(success ? '.' : '?');
161 #if HAVE_GETTIMEOFDAY
163 seconds(struct timeval *mark)
165 double result = (double) mark->tv_sec;
166 result += ((double) mark->tv_usec / 1e6);
174 static const char *msg[] =
176 "Usage: pair_content [options]"
179 ," -i interactive, showing test-progress"
180 ," -l NUM test NUM color pairs, rather than terminal description"
181 ," -n do not initialize color pairs"
182 ," -r COUNT repeat for given count"
183 ," -s initialize pairs sequentially rather than random"
186 for (n = 0; n < SIZEOF(msg); n++)
187 fprintf(stderr, "%s\n", msg[n]);
188 ExitProgram(EXIT_FAILURE);
192 main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
197 while ((i = getopt(argc, argv, "il:nr:s")) != -1) {
203 if ((l_opt = atoi(optarg)) <= 0)
210 if ((r_opt = atoi(optarg)) <= 0)
227 for (repeat = 0; repeat < r_opt; ++repeat) {
239 #if HAVE_GETTIMEOFDAY
240 gettimeofday(&finish_time, 0);
241 printw("%.03f seconds",
242 seconds(&finish_time)
243 - seconds(&initial_time));
247 ExitProgram(EXIT_SUCCESS);