From: Bruno Haible Date: Mon, 4 Dec 2006 13:31:45 +0000 (+0000) Subject: New module 'term-ostream-tests'. X-Git-Tag: v0.17~611 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=70623d8ff3ac939f06c006eb804e84e4cc104efc;p=thirdparty%2Fgettext.git New module 'term-ostream-tests'. --- diff --git a/gnulib-local/ChangeLog b/gnulib-local/ChangeLog index b24c90bd2..5a713bac9 100644 --- a/gnulib-local/ChangeLog +++ b/gnulib-local/ChangeLog @@ -1,3 +1,14 @@ +2006-12-01 Bruno Haible + + * modules/term-ostream-tests: New file. + * tests/test-term-ostream.c: New file. + * tests/test-term-ostream-xterm: New file. + * tests/test-term-ostream-xterm.out: New file. + * tests/test-term-ostream-xterm-16color.out: New file. + * tests/test-term-ostream-xterm-88color.out: New file. + * tests/test-term-ostream-xterm-256color.out: New file. + * Makefile.am (EXTRA_DIST): Add the new files. + 2006-12-02 Bruno Haible * lib/term-ostream.oo.c (term_ostream_create): Recognize also the diff --git a/gnulib-local/Makefile.am b/gnulib-local/Makefile.am index 3e51dbd3f..ff1182893 100644 --- a/gnulib-local/Makefile.am +++ b/gnulib-local/Makefile.am @@ -298,10 +298,17 @@ modules/relocatable \ modules/relocwrapper \ modules/termcap \ modules/term-ostream \ +modules/term-ostream-tests \ modules/vasprintf.diff \ modules/wait-process.diff \ modules/xalloc \ modules/xalloc-die \ modules/xerror \ modules/xgetcwd \ -modules/xreadlink +modules/xreadlink \ +tests/test-term-ostream.c \ +tests/test-term-ostream-xterm \ +tests/test-term-ostream-xterm.out \ +tests/test-term-ostream-xterm-16color.out \ +tests/test-term-ostream-xterm-88color.out \ +tests/test-term-ostream-xterm-256color.out diff --git a/gnulib-local/modules/term-ostream-tests b/gnulib-local/modules/term-ostream-tests new file mode 100644 index 000000000..06bb1db64 --- /dev/null +++ b/gnulib-local/modules/term-ostream-tests @@ -0,0 +1,17 @@ +Files: +tests/test-term-ostream.c +tests/test-term-ostream-xterm +tests/test-term-ostream-xterm.out +tests/test-term-ostream-xterm-16color.out +tests/test-term-ostream-xterm-88color.out +tests/test-term-ostream-xterm-256color.out + +Depends-on: + +configure.ac: + +Makefile.am: +TESTS += test-term-ostream-xterm +TESTS_ENVIRONMENT += srcdir='$(srcdir)' +check_PROGRAMS += test-term-ostream +test_term_ostream_LDADD = $(LIBTERMCAP) $(LDADD) diff --git a/gnulib-local/tests/test-term-ostream-xterm b/gnulib-local/tests/test-term-ostream-xterm new file mode 100755 index 000000000..2b7c7479f --- /dev/null +++ b/gnulib-local/tests/test-term-ostream-xterm @@ -0,0 +1,15 @@ +#!/bin/sh + +tmpfiles="" +trap 'rm -fr $tmpfiles' 1 2 3 15 + +tmpfiles="$tmpfiles out" +TERM=xterm ./test-term-ostream > out + +: ${DIFF=diff} +${DIFF} ${srcdir}/test-term-ostream-xterm.out out > /dev/null +result=$? + +rm -fr $tmpfiles + +exit $result diff --git a/gnulib-local/tests/test-term-ostream-xterm-16color.out b/gnulib-local/tests/test-term-ostream-xterm-16color.out new file mode 100644 index 000000000..3c13e71f4 --- /dev/null +++ b/gnulib-local/tests/test-term-ostream-xterm-16color.out @@ -0,0 +1,131 @@ +Colors (foreground/background): + |black |blue |green |cyan |red |magenta|yellow |white |default +black | Words | Words | Words | Words | Words | Words | Words | Words | Words  +blue | Words | Words | Words | Words | Words | Words | Words | Words | Words  +green | Words | Words | Words | Words | Words | Words | Words | Words | Words  +cyan | Words | Words | Words | Words | Words | Words | Words | Words | Words  +red | Words | Words | Words | Words | Words | Words | Words | Words | Words  +magenta| Words | Words | Words | Words | Words | Words | Words | Words | Words  +yellow | Words | Words | Words | Words | Words | Words | Words | Words | Words  +white | Words | Words | Words | Words | Words | Words | Words | Words | Words  +default| Words | Words | Words | Words | Words | Words | Words | Words | Words + +Colors (hue/saturation): +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +    +    +    +    +    +    +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   + +Weights: +normal, bold, default + +Postures: +normal, italic, default + +Text decorations: +normal, underlined, default + diff --git a/gnulib-local/tests/test-term-ostream-xterm-256color.out b/gnulib-local/tests/test-term-ostream-xterm-256color.out new file mode 100644 index 000000000..792b2470d --- /dev/null +++ b/gnulib-local/tests/test-term-ostream-xterm-256color.out @@ -0,0 +1,131 @@ +Colors (foreground/background): + |black |blue |green |cyan |red |magenta|yellow |white |default +black | Words | Words | Words | Words | Words | Words | Words | Words | Words  +blue | Words | Words | Words | Words | Words | Words | Words | Words | Words  +green | Words | Words | Words | Words | Words | Words | Words | Words | Words  +cyan | Words | Words | Words | Words | Words | Words | Words | Words | Words  +red | Words | Words | Words | Words | Words | Words | Words | Words | Words  +magenta| Words | Words | Words | Words | Words | Words | Words | Words | Words  +yellow | Words | Words | Words | Words | Words | Words | Words | Words | Words  +white | Words | Words | Words | Words | Words | Words | Words | Words | Words  +default| Words | Words | Words | Words | Words | Words | Words | Words | Words + +Colors (hue/saturation): +       +       +       +          +       +      +       +       +      +      +       +       +       +      +         +      +      +      +      +      +      +         +      +       +       +       +      +      +       +       +      +      +         +      +      +      +      +      +      +         +      +      +       +       +      +      +       +       +       +      +         +      +      +      +      +      +      +         +      +       +       +        +       +       +        +        +       +       +          +       +       +       +       +       +       +          +       +       +        +        +       +       +        +        +        +       +          +       +       +       +       +       +       +          +       +        +        +        +       +       +        +        +       +       +          +       +       +       + +Weights: +normal, bold, default + +Postures: +normal, italic, default + +Text decorations: +normal, underlined, default + diff --git a/gnulib-local/tests/test-term-ostream-xterm-88color.out b/gnulib-local/tests/test-term-ostream-xterm-88color.out new file mode 100644 index 000000000..5adb82d05 --- /dev/null +++ b/gnulib-local/tests/test-term-ostream-xterm-88color.out @@ -0,0 +1,131 @@ +Colors (foreground/background): + |black |blue |green |cyan |red |magenta|yellow |white |default +black | Words | Words | Words | Words | Words | Words | Words | Words | Words  +blue | Words | Words | Words | Words | Words | Words | Words | Words | Words  +green | Words | Words | Words | Words | Words | Words | Words | Words | Words  +cyan | Words | Words | Words | Words | Words | Words | Words | Words | Words  +red | Words | Words | Words | Words | Words | Words | Words | Words | Words  +magenta| Words | Words | Words | Words | Words | Words | Words | Words | Words  +yellow | Words | Words | Words | Words | Words | Words | Words | Words | Words  +white | Words | Words | Words | Words | Words | Words | Words | Words | Words  +default| Words | Words | Words | Words | Words | Words | Words | Words | Words + +Colors (hue/saturation): +             +             +           +           +            +     +     +     +     +     +     +     +     +     +     +     +           +             +             +          +     +     +     +     +     +     +     +     +     +     +     +            +         +             +          +             +             +            +           +                +            +     +     +     +     +     +     +     +     +     +     +     +            +             +             +            +     +     +     +     +     +     +     +     +     +     +     +            +                 +            +             +              +              +             +                +             +           +      +      +      +     +     +     +     +     +     +     +     +            +             +             +            +     +     +     +     +     +     +     +     +     +     +     +          +            +               +            +             + +Weights: +normal, bold, default + +Postures: +normal, italic, default + +Text decorations: +normal, underlined, default + diff --git a/gnulib-local/tests/test-term-ostream-xterm.out b/gnulib-local/tests/test-term-ostream-xterm.out new file mode 100644 index 000000000..c569f9c40 --- /dev/null +++ b/gnulib-local/tests/test-term-ostream-xterm.out @@ -0,0 +1,131 @@ +Colors (foreground/background): + |black |blue |green |cyan |red |magenta|yellow |white |default +black | Words | Words | Words | Words | Words | Words | Words | Words | Words  +blue | Words | Words | Words | Words | Words | Words | Words | Words | Words  +green | Words | Words | Words | Words | Words | Words | Words | Words | Words  +cyan | Words | Words | Words | Words | Words | Words | Words | Words | Words  +red | Words | Words | Words | Words | Words | Words | Words | Words | Words  +magenta| Words | Words | Words | Words | Words | Words | Words | Words | Words  +yellow | Words | Words | Words | Words | Words | Words | Words | Words | Words  +white | Words | Words | Words | Words | Words | Words | Words | Words | Words  +default| Words | Words | Words | Words | Words | Words | Words | Words | Words + +Colors (hue/saturation): +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   +   + +Weights: +normal, bold, default + +Postures: +normal, italic, default + +Text decorations: +normal, underlined, default + diff --git a/gnulib-local/tests/test-term-ostream.c b/gnulib-local/tests/test-term-ostream.c new file mode 100644 index 000000000..e0a61ab32 --- /dev/null +++ b/gnulib-local/tests/test-term-ostream.c @@ -0,0 +1,213 @@ +/* Test for the term-ostream API. */ + +#include + +#include "term-ostream.h" + +#include +#include + +int +main () +{ + static struct { const char *name; term_color_t c; int r; int g; int b; } + colors[] = + { + { "black", -2, 0, 0, 0 }, + { "blue", -2, 0, 0, 255 }, + { "green", -2, 0, 255, 0 }, + { "cyan", -2, 0, 255, 255 }, + { "red", -2, 255, 0, 0 }, + { "magenta", -2, 255, 0, 255 }, + { "yellow", -2, 255, 255, 0 }, + { "white", -2, 255, 255, 255 }, + { "default", COLOR_DEFAULT } + }; + term_ostream_t stream; + int i, row, col; + + stream = term_ostream_create (1, "stdout"); + + for (i = 0; i < 8; i++) + colors[i].c = + term_ostream_rgb_to_color (stream, colors[i].r, colors[i].g, colors[i].b); + + ostream_write_str (stream, "Colors (foreground/background):\n"); + ostream_write_str (stream, " "); + for (col = 0; col <= 8; col++) + { + const char *name = colors[col].name; + ostream_write_str (stream, "|"); + ostream_write_str (stream, name); + ostream_write_mem (stream, " ", 7 - strlen (name)); + } + ostream_write_str (stream, "\n"); + for (row = 0; row <= 8; row++) + { + const char *name = colors[row].name; + ostream_write_str (stream, name); + ostream_write_mem (stream, " ", 7 - strlen (name)); + for (col = 0; col <= 8; col++) + { + term_color_t row_color = colors[row].c; + term_color_t col_color = colors[col].c; + + ostream_write_str (stream, "|"); + term_ostream_set_color (stream, row_color); + term_ostream_set_bgcolor (stream, col_color); + if (!(term_ostream_get_color (stream) == row_color + && term_ostream_get_bgcolor (stream) == col_color)) + abort (); + ostream_write_str (stream, " Words "); + term_ostream_set_color (stream, COLOR_DEFAULT); + term_ostream_set_bgcolor (stream, COLOR_DEFAULT); + if (!(term_ostream_get_color (stream) == COLOR_DEFAULT + && term_ostream_get_bgcolor (stream) == COLOR_DEFAULT)) + abort (); + } + ostream_write_str (stream, "\n"); + } + ostream_write_str (stream, "\n"); + + ostream_write_str (stream, "Colors (hue/saturation):\n"); + /* Hue from 0 to 1. */ + for (row = 0; row <= 17; row++) + { + for (col = 0; col <= 64; col++) + { + int r = 255; + int b = (int) (255.0f / 64.0f * col + 0.5f); + int g = b + (int) (row / 17.0f * (r - b) + 0.5f); + term_color_t c = term_ostream_rgb_to_color (stream, r, g, b); + term_ostream_set_bgcolor (stream, c); + ostream_write_str (stream, " "); + term_ostream_set_bgcolor (stream, COLOR_DEFAULT); + } + ostream_write_str (stream, "\n"); + } + /* Hue from 1 to 2. */ + for (row = 17; row >= 0; row--) + { + for (col = 0; col <= 64; col++) + { + int g = 255; + int b = (int) (255.0f / 64.0f * col + 0.5f); + int r = b + (int) (row / 17.0f * (g - b) + 0.5f); + term_color_t c = term_ostream_rgb_to_color (stream, r, g, b); + term_ostream_set_bgcolor (stream, c); + ostream_write_str (stream, " "); + term_ostream_set_bgcolor (stream, COLOR_DEFAULT); + } + ostream_write_str (stream, "\n"); + } + /* Hue from 2 to 3. */ + for (row = 0; row <= 17; row++) + { + for (col = 0; col <= 64; col++) + { + int g = 255; + int r = (int) (255.0f / 64.0f * col + 0.5f); + int b = r + (int) (row / 17.0f * (g - r) + 0.5f); + term_color_t c = term_ostream_rgb_to_color (stream, r, g, b); + term_ostream_set_bgcolor (stream, c); + ostream_write_str (stream, " "); + term_ostream_set_bgcolor (stream, COLOR_DEFAULT); + } + ostream_write_str (stream, "\n"); + } + /* Hue from 3 to 4. */ + for (row = 17; row >= 0; row--) + { + for (col = 0; col <= 64; col++) + { + int b = 255; + int r = (int) (255.0f / 64.0f * col + 0.5f); + int g = r + (int) (row / 17.0f * (b - r) + 0.5f); + term_color_t c = term_ostream_rgb_to_color (stream, r, g, b); + term_ostream_set_bgcolor (stream, c); + ostream_write_str (stream, " "); + term_ostream_set_bgcolor (stream, COLOR_DEFAULT); + } + ostream_write_str (stream, "\n"); + } + /* Hue from 4 to 5. */ + for (row = 0; row <= 17; row++) + { + for (col = 0; col <= 64; col++) + { + int b = 255; + int g = (int) (255.0f / 64.0f * col + 0.5f); + int r = g + (int) (row / 17.0f * (b - g) + 0.5f); + term_color_t c = term_ostream_rgb_to_color (stream, r, g, b); + term_ostream_set_bgcolor (stream, c); + ostream_write_str (stream, " "); + term_ostream_set_bgcolor (stream, COLOR_DEFAULT); + } + ostream_write_str (stream, "\n"); + } + /* Hue from 5 to 6. */ + for (row = 17; row >= 0; row--) + { + for (col = 0; col <= 64; col++) + { + int r = 255; + int g = (int) (255.0f / 64.0f * col + 0.5f); + int b = g + (int) (row / 17.0f * (r - g) + 0.5f); + term_color_t c = term_ostream_rgb_to_color (stream, r, g, b); + term_ostream_set_bgcolor (stream, c); + ostream_write_str (stream, " "); + term_ostream_set_bgcolor (stream, COLOR_DEFAULT); + } + ostream_write_str (stream, "\n"); + } + ostream_write_str (stream, "\n"); + + ostream_write_str (stream, "Weights:\n"); + term_ostream_set_weight (stream, WEIGHT_NORMAL); + if (term_ostream_get_weight (stream) != WEIGHT_NORMAL) + abort (); + ostream_write_str (stream, "normal, "); + term_ostream_set_weight (stream, WEIGHT_BOLD); + if (term_ostream_get_weight (stream) != WEIGHT_BOLD) + abort (); + ostream_write_str (stream, "bold, "); + term_ostream_set_weight (stream, WEIGHT_DEFAULT); + if (term_ostream_get_weight (stream) != WEIGHT_DEFAULT) + abort (); + ostream_write_str (stream, "default \n"); + ostream_write_str (stream, "\n"); + + ostream_write_str (stream, "Postures:\n"); + term_ostream_set_posture (stream, POSTURE_NORMAL); + if (term_ostream_get_posture (stream) != POSTURE_NORMAL) + abort (); + ostream_write_str (stream, "normal, "); + term_ostream_set_posture (stream, POSTURE_ITALIC); + if (term_ostream_get_posture (stream) != POSTURE_ITALIC) + abort (); + ostream_write_str (stream, "italic, "); + term_ostream_set_posture (stream, POSTURE_DEFAULT); + if (term_ostream_get_posture (stream) != POSTURE_DEFAULT) + abort (); + ostream_write_str (stream, "default \n"); + ostream_write_str (stream, "\n"); + + ostream_write_str (stream, "Text decorations:\n"); + term_ostream_set_underline (stream, UNDERLINE_OFF); + if (term_ostream_get_underline (stream) != UNDERLINE_OFF) + abort (); + ostream_write_str (stream, "normal, "); + term_ostream_set_underline (stream, UNDERLINE_ON); + if (term_ostream_get_underline (stream) != UNDERLINE_ON) + abort (); + ostream_write_str (stream, "underlined, "); + term_ostream_set_underline (stream, UNDERLINE_DEFAULT); + if (term_ostream_get_underline (stream) != UNDERLINE_DEFAULT) + abort (); + ostream_write_str (stream, "default \n"); + ostream_write_str (stream, "\n"); + + ostream_free (stream); + + return 0; +}