X-Git-Url: https://ncurses.scripts.mit.edu/?a=blobdiff_plain;f=test%2Fdemo_new_pair.c;fp=test%2Fdemo_new_pair.c;h=909423e2f531ccd325922725c0ac3e84d532b6c5;hb=1b93a8aeaacc07de6d2aa08e658402b54446f064;hp=bd62a089741ff6d9f768068a5517335eb29d672b;hpb=152c5a605234b7ea36ba3a03ec07e124bb6aac75;p=ncurses.git diff --git a/test/demo_new_pair.c b/test/demo_new_pair.c index bd62a089..909423e2 100644 --- a/test/demo_new_pair.c +++ b/test/demo_new_pair.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2018-2019,2020 Thomas E. Dickey * + * Copyright 2018-2020,2021 Thomas E. Dickey * * Copyright 2017 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * @@ -27,7 +27,7 @@ * authorization. * ****************************************************************************/ /* - * $Id: demo_new_pair.c,v 1.21 2020/02/02 23:34:34 tom Exp $ + * $Id: demo_new_pair.c,v 1.23 2021/01/17 00:11:09 tom Exp $ * * Demonstrate the alloc_pair() function. */ @@ -136,6 +136,7 @@ usage(void) "Repeatedly print using all possible color combinations.", "", "Options:", + " -g use getcchar to check setcchar", " -i use init_pair rather than alloc_pair", " -p start in paged-mode", " -s start in single-step mode", @@ -186,6 +187,7 @@ main(int argc, char *argv[]) }; bool done = FALSE; + bool check_set = FALSE; bool clobber = FALSE; bool hascolor = FALSE; bool use_init = FALSE; @@ -202,8 +204,11 @@ main(int argc, char *argv[]) setlocale(LC_ALL, ""); - while ((ch = getopt(argc, argv, "ipsw")) != -1) { + while ((ch = getopt(argc, argv, "gipsw")) != -1) { switch (ch) { + case 'g': + check_set = TRUE; + break; case 'i': use_init = TRUE; break; @@ -317,7 +322,7 @@ main(int argc, char *argv[]) : make_color(current)); } } else { - my_attrs = next_attr(current); + my_attrs = next_attr(current); my_pair = 0; } if (my_pair < 0) @@ -327,6 +332,39 @@ main(int argc, char *argv[]) setcchar(&temp, wch, my_attrs, (short) my_pair, (use_init ? NULL : (void *) &my_pair)); + + if (check_set) { + int problem = 0; + wchar_t chk_wch[2]; + attr_t chk_attrs = 0; + short chk_pair = 0; + int chk_pair2 = 0; + +#define AllButColor(a) ((a) & (A_ATTRIBUTES & ~A_COLOR)) + + if (getcchar(&temp, NULL, &chk_attrs, &chk_pair, + (use_init ? NULL : (void *) &chk_pair2)) != 2) { + problem = 1; + } else if (getcchar(&temp, chk_wch, &chk_attrs, &chk_pair, + (use_init ? NULL : (void *) &chk_pair2)) != OK) { + problem = 2; + } else if (chk_wch[0] != wch[0]) { + problem = 3; + } else if (AllButColor(my_attrs) != AllButColor(chk_attrs)) { + problem = 4; + } else if (my_pair != chk_pair) { + problem = 4; + } else if (!use_init && (my_pair != chk_pair2)) { + problem = 5; + } + if (problem) { + wch[0] = problem + '0'; + setcchar(&temp, wch, my_attrs, + (short) my_pair, + (use_init ? NULL : (void *) &my_pair)); + } + } + /* * At the end of a page, move the cursor to the home position. */