mirror of https://github.com/GNOME/gimp.git
libgimpcolor/Makefile.am added a simple unit test framework for the color
2004-07-23 Sven Neumann <sven@gimp.org> * libgimpcolor/Makefile.am * libgimpcolor/test-color-parser.c: added a simple unit test framework for the color parser. * libgimpcolor/gimprgb-parse.c: fixed parsing of rgba() values. * libgimpmath/test-md5.c: minor cleanup.
This commit is contained in:
parent
1b5c6356c3
commit
516c5bf44c
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
|||
2004-07-23 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* libgimpcolor/Makefile.am
|
||||
* libgimpcolor/test-color-parser.c: added a simple unit test
|
||||
framework for the color parser.
|
||||
|
||||
* libgimpcolor/gimprgb-parse.c: fixed parsing of rgba() values.
|
||||
|
||||
* libgimpmath/test-md5.c: minor cleanup.
|
||||
|
||||
2004-07-23 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* libgimpcolor/gimprgb-parse.c (gimp_rgba_parse_css): added support
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
Makefile
|
||||
Makefile.in
|
||||
makefile.mingw
|
||||
test-color-parser
|
||||
*.lo
|
||||
_libs
|
||||
.libs
|
||||
|
|
|
@ -97,6 +97,26 @@ libgimpcolor_2_0_la_DEPENDENCIES = $(gimpcolor_def) $(libgimpbase)
|
|||
|
||||
libgimpcolor_2_0_la_LIBADD = $(GLIB_LIBS) $(libm)
|
||||
|
||||
|
||||
#
|
||||
# test programs, not to be built by default and never installed
|
||||
#
|
||||
|
||||
TESTS = test-color-parser$(EXEEXT)
|
||||
|
||||
EXTRA_PROGRAMS = test-color-parser
|
||||
|
||||
test_color_parser_DEPENDENCIES = \
|
||||
$(top_builddir)/libgimpcolor/libgimpcolor-$(GIMP_API_VERSION).la
|
||||
|
||||
test_color_parser_LDADD = \
|
||||
$(GLIB_LIBS) \
|
||||
$(test_color_parser_DEPENDENCIES)
|
||||
|
||||
|
||||
CLEANFILES = $(EXTRA_PROGRAMS)
|
||||
|
||||
|
||||
install-data-local: install-ms-lib install-libtool-import-lib
|
||||
|
||||
uninstall-local: uninstall-ms-lib uninstall-libtool-import-lib
|
||||
|
|
|
@ -524,7 +524,7 @@ else if (css[3] == '(')
|
|||
while (*end && *end != ',' && *end != '%' && *end != ')')
|
||||
end++;
|
||||
|
||||
if (*end == '%')
|
||||
if (i == 3 || *end == '%')
|
||||
{
|
||||
values[i] = g_ascii_strtod (css, (gchar **) &end);
|
||||
|
||||
|
|
|
@ -0,0 +1,101 @@
|
|||
/* unit tests for the color parsing routines in gimprgb-parse.c
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "gimpcolor.h"
|
||||
|
||||
|
||||
#define DBL(c) ((gdouble)(c) / 255.0)
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
const gchar *str;
|
||||
gboolean alpha;
|
||||
gboolean fail;
|
||||
const gdouble r;
|
||||
const gdouble g;
|
||||
const gdouble b;
|
||||
const gdouble a;
|
||||
} ColorSample;
|
||||
|
||||
static const ColorSample samples[] =
|
||||
{
|
||||
{ "#000000", FALSE, FALSE, 0.0, 0.0, 0.0, 0.0 },
|
||||
{ "#FFff00", FALSE, FALSE, 1.0, 1.0, 0.0, 0.0 },
|
||||
{ "#6495ed", FALSE, FALSE, DBL(100), DBL(149), DBL(237), 0.0 },
|
||||
{ "#fff", FALSE, FALSE, 1.0, 1.0, 1.0, 0.0 },
|
||||
{ "#64649595eded", FALSE, FALSE, 1.0, 1.0, 0.0, 0.0 },
|
||||
{ "rgb(0,0,0)", FALSE, FALSE, 0.0, 0.0, 0.0, 0.0 },
|
||||
{ "rgb(100,149,237)", FALSE, FALSE, DBL(100), DBL(149), DBL(237), 0.0 },
|
||||
{ "rgba(100%,0,100%,0.5)", TRUE, FALSE, 255.0, 0.0, 255.0, 0.5 },
|
||||
{ "rgb(100%,149,20%)", FALSE, FALSE, 1.0, DBL(149), 0.2, 0.0 },
|
||||
{ "red", FALSE, FALSE, 1.0, 0.0, 0.0, 0.0 },
|
||||
{ "cornflowerblue", FALSE, FALSE, DBL(100), DBL(149), DBL(237), 0.0 }
|
||||
};
|
||||
|
||||
|
||||
static gint
|
||||
check_failure (const ColorSample *sample,
|
||||
gboolean success,
|
||||
GimpRGB *rgb)
|
||||
{
|
||||
if (success && sample->fail)
|
||||
{
|
||||
g_print ("Parser succeeded for sample \"%s\" but should have failed!\n"
|
||||
" parsed color: (%g, %g, %g, %g)\n",
|
||||
sample->str, rgb->r, rgb->g, rgb->b, rgb->a);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!success && !sample->fail)
|
||||
{
|
||||
g_print ("Parser failed for sample \"%s\" but should have succeeded!\n"
|
||||
" parsed color: (%g, %g, %g, %g)\n",
|
||||
sample->str, rgb->r, rgb->g, rgb->b, rgb->a);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
gint failures = 0;
|
||||
gint i;
|
||||
|
||||
g_print ("Testing the GIMP color parser ...\n\n");
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (samples); i++)
|
||||
{
|
||||
GimpRGB rgb = { 0.0, 0.0, 0.0, 0.0 };
|
||||
gboolean success;
|
||||
|
||||
if (samples[i].alpha)
|
||||
success = gimp_rgba_parse_css (&rgb, samples[i].str, -1);
|
||||
else
|
||||
success = gimp_rgb_parse_css (&rgb, samples[i].str, -1);
|
||||
|
||||
failures += check_failure (samples + i, success, &rgb);
|
||||
}
|
||||
|
||||
if (failures)
|
||||
{
|
||||
g_print ("%d out of %d samples failed!\n\n",
|
||||
failures, G_N_ELEMENTS (samples));
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_print ("All %d samples passed.\n\n", G_N_ELEMENTS (samples));
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
|
@ -3,12 +3,16 @@
|
|||
* as given in section A.5 of RFC 1321, reproduced below.
|
||||
*/
|
||||
|
||||
#include <glib.h>
|
||||
#include "config.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "gimpmd5.h"
|
||||
|
||||
|
||||
static const gchar * test[7][2] =
|
||||
{
|
||||
{ "", "d41d8cd98f00b204e9800998ecf8427e" },
|
||||
|
@ -41,6 +45,7 @@ main (void)
|
|||
|
||||
g_snprintf (buf, 3, "%02x", digest[j]);
|
||||
g_print (buf);
|
||||
|
||||
if (strncmp (buf, test[i][1] + j*2, 2))
|
||||
correct = FALSE;
|
||||
}
|
||||
|
@ -48,13 +53,14 @@ main (void)
|
|||
|
||||
if (!correct)
|
||||
{
|
||||
g_print
|
||||
("\nWRONG digest!! Please report to http://bugzilla.gnome.org/\n");
|
||||
return 1;
|
||||
g_print ("\nWRONG digest!! "
|
||||
"Please report to http://bugzilla.gnome.org/\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
g_print ("\nLooks good.\n\n");
|
||||
return 0;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue