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: pair_content.c,v 1.2 2018/12/30 00:54:48 tom Exp $
33 #include <test.priv.h>
46 static MYPAIR *expected;
49 static struct timeval initial_time;
50 static struct timeval finish_time;
54 failed(const char *msg)
59 ExitProgram(EXIT_FAILURE);
62 static NCURSES_COLOR_T
65 return (NCURSES_COLOR_T) (rand() % COLORS);
74 scrollok(stdscr, TRUE);
81 failed("color-pair limit must be greater than one");
86 expected = typeCalloc(MYPAIR, l_opt);
91 for (fg = 0; fg < COLORS; ++fg) {
92 for (bg = 0; bg < COLORS; ++bg) {
94 init_pair(pair, fg, bg);
95 expected[pair].fg = fg;
96 expected[pair].bg = bg;
104 for (pair = 1; (int) pair < l_opt; ++pair) {
105 expected[pair].fg = random_color();
106 expected[pair].bg = random_color();
107 init_pair(pair, expected[pair].fg, expected[pair].bg);
112 failed("This demo requires a color terminal");
114 #if HAVE_GETTIMEOFDAY
115 gettimeofday(&initial_time, 0);
122 NCURSES_PAIRS_T pair;
124 for (pair = 1; (int) pair < l_opt; ++pair) {
127 if (pair_content(pair, &fg, &bg) == OK) {
129 if (fg != expected[pair].fg)
131 if (bg != expected[pair].bg)
137 addch(success ? '.' : '?');
149 #if HAVE_GETTIMEOFDAY
151 seconds(struct timeval *mark)
153 double result = (double) mark->tv_sec;
154 result += ((double) mark->tv_usec / 1e6);
162 static const char *msg[] =
164 "Usage: pair_content [options]"
167 ," -i interactive, showing test-progress"
168 ," -l NUM test NUM color pairs, rather than terminal description"
169 ," -n do not initialize color pairs"
170 ," -r COUNT repeat for given count"
171 ," -s initialize pairs sequentially rather than random"
174 for (n = 0; n < SIZEOF(msg); n++)
175 fprintf(stderr, "%s\n", msg[n]);
176 ExitProgram(EXIT_FAILURE);
180 main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
185 while ((i = getopt(argc, argv, "il:nr:s")) != -1) {
191 if ((l_opt = atoi(optarg)) <= 0)
198 if ((r_opt = atoi(optarg)) <= 0)
215 for (repeat = 0; repeat < r_opt; ++repeat) {
227 #if HAVE_GETTIMEOFDAY
228 gettimeofday(&finish_time, 0);
229 printw("%.03f seconds",
230 seconds(&finish_time)
231 - seconds(&initial_time));
235 ExitProgram(EXIT_SUCCESS);