grim/guifications3

59b11e0f9116
Parents 07f0a21b94fa
Children a54947b5b3d2
start of converting gflib-ui/tests/testcolor.c to gtester

refs #674
--- a/gflib-ui/tests/CMakeLists.txt Mon Dec 20 01:09:11 2010 -0600
+++ b/gflib-ui/tests/CMakeLists.txt Mon Dec 20 01:12:27 2010 -0600
@@ -1,2 +1,14 @@
enable_testing()
+add_executable(testcolor testcolor.c)
+target_link_libraries(testcolor ${GLIB_LIBRARIES} ${GFLIB_LIBRARIES} gflib-ui)
+list(APPEND TESTS testcolor)
+
+set(GTESTER_TESTS "${TESTS}")
+
+add_test(gflib-ui-tests
+ ${GTESTER} -k --verbose -o testgflib-ui.log
+ ${GTESTER_TESTS}
+)
+
+
--- a/gflib-ui/tests/testcolor.c Mon Dec 20 01:09:11 2010 -0600
+++ b/gflib-ui/tests/testcolor.c Mon Dec 20 01:12:27 2010 -0600
@@ -1,6 +1,6 @@
/*
* Guifications - The end-all, be-all notification framework
- * Copyright (C) 2003-2009 Gary Kramlich <grim@reaperworld.com>
+ * Copyright (C) 2003-2010 Gary Kramlich <grim@reaperworld.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -15,86 +15,41 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <stdlib.h>
-#include <string.h>
+#include <gf_lib.h>
+#include <gf_lib_ui.h>
-#include <check.h>
-
-#include <gflib/gf_lib.h>
+/******************************************************************************
+ * Structs
+ *****************************************************************************/
+typedef struct {
+ guint8 red;
+ guint8 green;
+ guint8 blue;
+} TestGfColorRGBData;
/******************************************************************************
- * Color from RGB
+ * Tests
*****************************************************************************/
-#define COLOR_FROM_RGB(r,g,b) { \
- GfColor c; \
- gboolean res; \
- \
- fail_unless(gf_color_from_rgb(&c, (r), (g), (b)) == TRUE, NULL); \
- \
- res = (c.red == (r) && c.green == (g) && c.blue == (b)); \
- fail_unless(res, NULL); \
+static void
+test_gf_color_from_rgb(gconstpointer d) {
+ TestGfColorRGBData **data = (TestGfColorRGBData **)d;
+ GfColor c;
+ gint i = 0;
+
+ do {
+ g_assert(gf_color_from_rgb(&c, data[i]->red, data[i]->green,
+ data[i]->blue) == TRUE);
+
+ g_assert(c.red == data[i]->red &&
+ c.green == data[i]->green &&
+ c.blue == data[i]->blue);
+ i++;
+ } while(data[i]->red != 0 &&
+ data[i]->green != 0 &&
+ data[i]->blue != 0);
}
-START_TEST(test_color_from_rgb_black)
- COLOR_FROM_RGB( 0, 0, 0)
-END_TEST
-
-START_TEST(test_color_from_rgb_dark_red)
- COLOR_FROM_RGB(127, 0, 0)
-END_TEST
-
-START_TEST(test_color_from_rgb_dark_yellow)
- COLOR_FROM_RGB(127, 127, 0)
-END_TEST
-
-START_TEST(test_color_from_rgb_dark_green)
- COLOR_FROM_RGB( 0, 127, 0)
-END_TEST
-
-START_TEST(test_color_from_rgb_dark_cyan)
- COLOR_FROM_RGB( 0, 127, 127)
-END_TEST
-
-START_TEST(test_color_from_rgb_dark_blue)
- COLOR_FROM_RGB( 0, 0, 127)
-END_TEST
-
-START_TEST(test_color_from_rgb_purple)
- COLOR_FROM_RGB(127, 0, 127)
-END_TEST
-
-START_TEST(test_color_from_rgb_gray)
- COLOR_FROM_RGB(127, 127, 127)
-END_TEST
-
-START_TEST(test_color_from_rgb_red)
- COLOR_FROM_RGB(255, 0, 0)
-END_TEST
-
-START_TEST(test_color_from_rgb_yellow)
- COLOR_FROM_RGB(255, 255, 0)
-END_TEST
-
-START_TEST(test_color_from_rgb_green)
- COLOR_FROM_RGB( 0, 255, 0)
-END_TEST
-
-START_TEST(test_color_from_rgb_cyan)
- COLOR_FROM_RGB( 0, 255, 255)
-END_TEST
-
-START_TEST(test_color_from_rgb_blue)
- COLOR_FROM_RGB( 0, 0, 255)
-END_TEST
-
-START_TEST(test_color_from_rgb_magenta)
- COLOR_FROM_RGB(255, 0, 255)
-END_TEST
-
-START_TEST(test_color_from_rgb_white)
- COLOR_FROM_RGB(255, 255, 255)
-END_TEST
-
+#if 0
/******************************************************************************
* Color to RGB
*****************************************************************************/
@@ -476,124 +431,41 @@
START_TEST(test_color_to_html_white)
COLOR_TO_HTML(255, 255, 255, "#ffffff");
END_TEST
-
+#endif
/******************************************************************************
- * Check Stuff
+ * Main
*****************************************************************************/
-Suite *
-color_suite(void) {
- Suite *s = suite_create("GfColor");
- TCase *tc = NULL;
-
- tc = tcase_create("Color from RGB");
- tcase_add_test(tc, test_color_from_rgb_black);
- tcase_add_test(tc, test_color_from_rgb_dark_red);
- tcase_add_test(tc, test_color_from_rgb_dark_yellow);
- tcase_add_test(tc, test_color_from_rgb_dark_green);
- tcase_add_test(tc, test_color_from_rgb_dark_cyan);
- tcase_add_test(tc, test_color_from_rgb_dark_blue);
- tcase_add_test(tc, test_color_from_rgb_purple);
- tcase_add_test(tc, test_color_from_rgb_gray);
- tcase_add_test(tc, test_color_from_rgb_red);
- tcase_add_test(tc, test_color_from_rgb_yellow);
- tcase_add_test(tc, test_color_from_rgb_green);
- tcase_add_test(tc, test_color_from_rgb_cyan);
- tcase_add_test(tc, test_color_from_rgb_blue);
- tcase_add_test(tc, test_color_from_rgb_magenta);
- tcase_add_test(tc, test_color_from_rgb_white);
- suite_add_tcase(s, tc);
-
- tc = tcase_create("Color to RGB");
- tcase_add_test(tc, test_color_to_rgb_black);
- tcase_add_test(tc, test_color_to_rgb_dark_red);
- tcase_add_test(tc, test_color_to_rgb_dark_yellow);
- tcase_add_test(tc, test_color_to_rgb_dark_green);
- tcase_add_test(tc, test_color_to_rgb_dark_cyan);
- tcase_add_test(tc, test_color_to_rgb_dark_blue);
- tcase_add_test(tc, test_color_to_rgb_purple);
- tcase_add_test(tc, test_color_to_rgb_gray);
- tcase_add_test(tc, test_color_to_rgb_red);
- tcase_add_test(tc, test_color_to_rgb_yellow);
- tcase_add_test(tc, test_color_to_rgb_green);
- tcase_add_test(tc, test_color_to_rgb_cyan);
- tcase_add_test(tc, test_color_to_rgb_blue);
- tcase_add_test(tc, test_color_to_rgb_magenta);
- tcase_add_test(tc, test_color_to_rgb_white);
- suite_add_tcase(s, tc);
+gint
+main(gint argc, gchar **argv) {
+ TestGfColorRGBData rgb_data[] = {
+ { 0, 0, 0 },
+ { 127, 0, 0 },
+ { 127, 127, 0 },
+ { 0, 127, 0 },
+ { 0, 127, 127 },
+ { 0, 0, 127 },
+ { 127, 0, 127 },
+ { 127, 127, 127 },
+ { 255, 0, 0 },
+ { 255, 255, 0 },
+ { 0, 255, 0 },
+ { 0, 255, 255 },
+ { 0, 0, 255 },
+ { 255, 0, 255 },
+ { 255, 255, 255 },
+ { 0, 0, 0 }, /* end point */
+ };
- tc = tcase_create("Color from HSV");
- tcase_add_test(tc, test_color_from_hsv_black);
- tcase_add_test(tc, test_color_from_hsv_dark_red);
- tcase_add_test(tc, test_color_from_hsv_dark_yellow);
- tcase_add_test(tc, test_color_from_hsv_dark_green);
- tcase_add_test(tc, test_color_from_hsv_dark_cyan);
- tcase_add_test(tc, test_color_from_hsv_dark_blue);
- tcase_add_test(tc, test_color_from_hsv_purple);
- tcase_add_test(tc, test_color_from_hsv_gray);
- tcase_add_test(tc, test_color_from_hsv_red);
- tcase_add_test(tc, test_color_from_hsv_yellow);
- tcase_add_test(tc, test_color_from_hsv_green);
- tcase_add_test(tc, test_color_from_hsv_cyan);
- tcase_add_test(tc, test_color_from_hsv_blue);
- tcase_add_test(tc, test_color_from_hsv_magenta);
- tcase_add_test(tc, test_color_from_hsv_white);
- suite_add_tcase(s, tc);
+ g_test_init(&argc, &argv, NULL);
- tc = tcase_create("Color to HSV");
- tcase_add_test(tc, test_color_to_hsv_black);
- tcase_add_test(tc, test_color_to_hsv_dark_red);
- tcase_add_test(tc, test_color_to_hsv_dark_yellow);
- tcase_add_test(tc, test_color_to_hsv_dark_green);
- tcase_add_test(tc, test_color_to_hsv_dark_cyan);
- tcase_add_test(tc, test_color_to_hsv_dark_blue);
- tcase_add_test(tc, test_color_to_hsv_purple);
- tcase_add_test(tc, test_color_to_hsv_gray);
- tcase_add_test(tc, test_color_to_hsv_red);
- tcase_add_test(tc, test_color_to_hsv_yellow);
- tcase_add_test(tc, test_color_to_hsv_green);
- tcase_add_test(tc, test_color_to_hsv_cyan);
- tcase_add_test(tc, test_color_to_hsv_blue);
- tcase_add_test(tc, test_color_to_hsv_magenta);
- tcase_add_test(tc, test_color_to_hsv_white);
- suite_add_tcase(s, tc);
+ gf_lib_init(NULL, NULL);
- tc = tcase_create("HTML to Color");
- tcase_add_test(tc, test_html_to_color_black);
- tcase_add_test(tc, test_html_to_color_dark_red);
- tcase_add_test(tc, test_html_to_color_dark_yellow);
- tcase_add_test(tc, test_html_to_color_dark_green);
- tcase_add_test(tc, test_html_to_color_dark_cyan);
- tcase_add_test(tc, test_html_to_color_dark_blue);
- tcase_add_test(tc, test_html_to_color_purple);
- tcase_add_test(tc, test_html_to_color_gray);
- tcase_add_test(tc, test_html_to_color_red);
- tcase_add_test(tc, test_html_to_color_yellow);
- tcase_add_test(tc, test_html_to_color_green);
- tcase_add_test(tc, test_html_to_color_cyan);
- tcase_add_test(tc, test_html_to_color_blue);
- tcase_add_test(tc, test_html_to_color_magenta);
- tcase_add_test(tc, test_html_to_color_white);
- suite_add_tcase(s, tc);
+ /* from rgb tests */
+ g_test_add_data_func("/gfcolor/from_rgb/",
+ rgb_data,
+ test_gf_color_from_rgb);
- tc = tcase_create("Color to HTML");
- tcase_add_test(tc, test_color_to_html_black);
- tcase_add_test(tc, test_color_to_html_dark_red);
- tcase_add_test(tc, test_color_to_html_dark_yellow);
- tcase_add_test(tc, test_color_to_html_dark_green);
- tcase_add_test(tc, test_color_to_html_dark_cyan);
- tcase_add_test(tc, test_color_to_html_dark_blue);
- tcase_add_test(tc, test_color_to_html_purple);
- tcase_add_test(tc, test_color_to_html_gray);
- tcase_add_test(tc, test_color_to_html_red);
- tcase_add_test(tc, test_color_to_html_yellow);
- tcase_add_test(tc, test_color_to_html_green);
- tcase_add_test(tc, test_color_to_html_cyan);
- tcase_add_test(tc, test_color_to_html_blue);
- tcase_add_test(tc, test_color_to_html_magenta);
- tcase_add_test(tc, test_color_to_html_white);
- suite_add_tcase(s, tc);
-
- return s;
+ return g_test_run();
}