Commit 96f99d33 authored by Paolo Borelli's avatar Paolo Borelli Committed by Paolo Borelli

Bug 539770 - migrate gstrfunc unit tests to gtest

2008-06-24  Paolo Borelli  <pborelli@katamail.com>

	Bug 539770 - migrate gstrfunc unit tests to gtest

	* tests/strfunc-test.c:
	* tests/testglib.c:
	* tests/strtoll-test.c:
	* tests/strtod-test.c:
	* tests/string-test.c:
	* tests/Makefile.am:
	Removed old tests.

	* glib/tests/fileutils.c:
	* glib/tests/strfuncs.c:
	* glib/tests/Makefile.am:
	Added all the old tests migrated to the new unit test framework
	and add new unit tests for some of the functions.


svn path=/trunk/; revision=7097
parent 1289b6d1
2008-06-24 Paolo Borelli <pborelli@katamail.com>
Bug 539770 - migrate gstrfunc unit tests to gtest
* tests/strfunc-test.c:
* tests/testglib.c:
* tests/strtoll-test.c:
* tests/strtod-test.c:
* tests/string-test.c:
* tests/Makefile.am:
Removed old tests.
* glib/tests/fileutils.c:
* glib/tests/strfuncs.c:
* glib/tests/Makefile.am:
Added all the old tests migrated to the new unit test framework
and add new unit tests for some of the functions.
2008-06-23 Kristian Rietveld <kris@imendio.com>
* gobject/glib-mkenums.in: introduce an ENUMPREFIX substitution.
......
......@@ -14,6 +14,14 @@ TEST_PROGS += option-context
option_context_SOURCES = option-context.c
option_context_LDADD = $(progs_ldadd)
TEST_PROGS += fileutils
fileutils_SOURCES = fileutils.c
fileutils_LDADD = $(progs_ldadd)
TEST_PROGS += strfuncs
strfuncs_SOURCES = strfuncs.c
strfuncs_LDADD = $(progs_ldadd) -lm
# some testing of gtester funcitonality
XMLLINT=xmllint
gtester-xmllint-check: # check testreport xml with xmllint if present
......
This diff is collapsed.
This diff is collapsed.
......@@ -137,10 +137,7 @@ test_programs = \
slice-threadinit \
spawn-test \
$(spawn_test_win32_gui) \
strfunc-test \
string-test \
strtod-test \
strtoll-test \
thread-test \
threadpool-test \
tree-test \
......@@ -213,10 +210,7 @@ slice_concurrent_LDADD = $(thread_ldadd)
slice_threadinit_SOURCES = slice-threadinit.c
slice_threadinit_LDADD = $(thread_ldadd)
spawn_test_LDADD = $(progs_ldadd)
strfunc_test_LDADD = $(progs_ldadd)
string_test_LDADD = $(progs_ldadd)
strtod_test_LDADD = $(progs_ldadd) -lm
strtoll_test_LDADD = $(progs_ldadd) -lm
thread_test_LDADD = $(thread_ldadd)
threadpool_test_LDADD = $(thread_ldadd)
tree_test_LDADD = $(progs_ldadd)
......
This diff is collapsed.
......@@ -301,22 +301,6 @@ main (int argc,
g_string_free (string1, TRUE);
g_string_free (string2, TRUE);
g_assert (g_str_has_prefix("foobar", "gazonk") == FALSE);
g_assert (g_str_has_prefix("xyzzy", "xyzzy") == TRUE);
g_assert (g_str_has_prefix("xyzzy", "xy") == TRUE);
g_assert (g_str_has_prefix("xyzzy", "") == TRUE);
g_assert (g_str_has_prefix("xyz", "xyzzy") == FALSE);
g_assert (g_str_has_prefix("", "xyzzy") == FALSE);
g_assert (g_str_has_prefix("", "") == TRUE);
g_assert (g_str_has_suffix("foobar", "gazonk") == FALSE);
g_assert (g_str_has_suffix("xyzzy", "xyzzy") == TRUE);
g_assert (g_str_has_suffix("xyzzy", "zy") == TRUE);
g_assert (g_str_has_suffix("xyzzy", "") == TRUE);
g_assert (g_str_has_suffix("zzy", "xyzzy") == FALSE);
g_assert (g_str_has_suffix("", "xyzzy") == FALSE);
g_assert (g_str_has_suffix("", "") == TRUE);
tmp_string = (gchar *) g_malloc (10);
g_snprintf (tmp_string, 10, "%2$s %1$s", "a", "b");
......
#undef G_DISABLE_ASSERT
#undef G_LOG_DOMAIN
/* for NAN and INFINITY */
#define _ISOC99_SOURCE
#include <glib.h>
#include <locale.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
static char *locales[] = {"sv_SE", "en_US", "fa_IR", "C", "ru_RU"};
void
test_string (char *number, double res, gboolean check_end, int correct_len)
{
double d;
int l;
char *dummy;
/* we try a copy of number, with some free space for malloc before that.
* This is supposed to smash the some wrong pointer calculations. */
dummy = g_malloc (100000);
number = g_strdup (number);
g_free (dummy);
for (l = 0; l < G_N_ELEMENTS (locales); l++)
{
gboolean ok;
char *end = "(unset)";
setlocale (LC_NUMERIC, locales[l]);
d = g_ascii_strtod (number, &end);
ok = isnan (res) ? isnan (d) : (d == res);
if (!ok)
{
g_print ("g_ascii_strtod on \"%s\" for locale %s failed\n", number, locales[l]);
g_print ("expected %f (nan %d) actual %f (nan %d)\n",
res, isnan (res),
d, isnan (d));
}
ok = (end - number) == (check_end ? correct_len : strlen (number));
if (!ok) {
if (end == NULL)
g_print ("g_ascii_strtod on \"%s\" for locale %s endptr was NULL\n",
number, locales[l]);
else if (end >= number && end <= number + strlen (number))
g_print ("g_ascii_strtod on \"%s\" for locale %s endptr was wrong, leftover: \"%s\"\n",
number, locales[l], end);
else
g_print ("g_ascii_strtod on \"%s\" for locale %s endptr was REALLY wrong (number=%p, end=%p)\n",
number, locales[l], number, end);
}
}
g_free (number);
}
static void
test_number (gdouble num, gchar *fmt, gchar *str)
{
int l;
gchar buf[G_ASCII_DTOSTR_BUF_SIZE];
for (l = 0; l < G_N_ELEMENTS (locales); l++)
{
g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, fmt, num);
g_assert (strcmp (buf, str) == 0);
}
}
int
main ()
{
gdouble d, our_nan, our_inf;
char buffer[G_ASCII_DTOSTR_BUF_SIZE];
#ifdef NAN
our_nan = NAN;
#else
/* Do this before any call to setlocale. */
our_nan = atof ("NaN");
#endif
g_assert (isnan (our_nan));
#ifdef INFINITY
our_inf = INFINITY;
#else
our_inf = atof ("Infinity");
#endif
g_assert (our_inf > 1 && our_inf == our_inf / 2);
test_string ("123.123", 123.123, FALSE, 0);
test_string ("123.123e2", 123.123e2, FALSE, 0);
test_string ("123.123e-2", 123.123e-2, FALSE, 0);
test_string ("-123.123", -123.123, FALSE, 0);
test_string ("-123.123e2", -123.123e2, FALSE, 0);
test_string ("-123.123e-2", -123.123e-2, FALSE, 0);
test_string ("5.4", 5.4, TRUE, 3);
test_string ("5.4,5.5", 5.4, TRUE, 3);
test_string ("5,4", 5.0, TRUE, 1);
/* the following are for #156421 */
test_string ("1e1", 1e1, FALSE, 0);
test_string ("NAN", our_nan, FALSE, 0);
test_string ("-nan", -our_nan, FALSE, 0);
test_string ("INF", our_inf, FALSE, 0);
test_string ("-infinity", -our_inf, FALSE, 0);
test_string ("-.75,0", -0.75, TRUE, 4);
d = 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0;
g_assert (d == g_ascii_strtod (g_ascii_dtostr (buffer, sizeof (buffer), d), NULL));
d = -179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0;
g_assert (d == g_ascii_strtod (g_ascii_dtostr (buffer, sizeof (buffer), d), NULL));
d = pow (2.0, -1024.1);
g_assert (d == g_ascii_strtod (g_ascii_dtostr (buffer, sizeof (buffer), d), NULL));
d = -pow (2.0, -1024.1);
g_assert (d == g_ascii_strtod (g_ascii_dtostr (buffer, sizeof (buffer), d), NULL));
/* for #343899 */
test_string (" 0.75", 0.75, FALSE, 0);
test_string (" +0.75", 0.75, FALSE, 0);
test_string (" -0.75", -0.75, FALSE, 0);
test_string ("\f0.75", 0.75, FALSE, 0);
test_string ("\n0.75", 0.75, FALSE, 0);
test_string ("\r0.75", 0.75, FALSE, 0);
test_string ("\t0.75", 0.75, FALSE, 0);
#if 0
/* g_ascii_isspace() returns FALSE for vertical tab, see #59388 */
test_string ("\v0.75", 0.75, FALSE, 0);
#endif
/* for #343899 */
test_number (0.75, "%0.2f", "0.75");
test_number (0.75, "%5.2f", " 0.75");
test_number (-0.75, "%0.2f", "-0.75");
test_number (-0.75, "%5.2f", "-0.75");
test_number (1e99, "%.0e", "1e+99");
return 0;
}
#undef G_DISABLE_ASSERT
#undef G_LOG_DOMAIN
#include <errno.h>
#include <string.h>
#include <glib.h>
static void
test_uint64 (const gchar *str,
const gchar *end,
gint base,
guint64 result,
gint error)
{
guint64 actual;
gchar *endptr = NULL;
gint err;
errno = 0;
actual = g_ascii_strtoull (str, &endptr, base);
err = errno;
g_assert (actual == result);
g_assert (strcmp (end, endptr) == 0);
g_assert (err == error);
}
static void
test_int64 (const gchar *str,
const gchar *end,
gint base,
gint64 result,
gint error)
{
gint64 actual;
gchar *endptr = NULL;
gint err;
errno = 0;
actual = g_ascii_strtoll (str, &endptr, base);
err = errno;
g_assert (actual == result);
g_assert (strcmp (end, endptr) == 0);
g_assert (err == error);
}
int
main (int argc, char *argv[])
{
test_uint64 ("0", "", 10, 0, 0);
test_uint64 ("+0", "", 10, 0, 0);
test_uint64 ("-0", "", 10, 0, 0);
test_uint64 ("18446744073709551615", "", 10, G_MAXUINT64, 0);
test_uint64 ("18446744073709551616", "", 10, G_MAXUINT64, ERANGE);
test_uint64 ("20xyz", "xyz", 10, 20, 0);
test_uint64 ("-1", "", 10, G_MAXUINT64, 0);
test_int64 ("0", "", 10, 0, 0);
test_int64 ("9223372036854775807", "", 10, G_MAXINT64, 0);
test_int64 ("9223372036854775808", "", 10, G_MAXINT64, ERANGE);
test_int64 ("-9223372036854775808", "", 10, G_MININT64, 0);
test_int64 ("-9223372036854775809", "", 10, G_MININT64, ERANGE);
test_int64 ("32768", "", 10, 32768, 0);
test_int64 ("-32768", "", 10, -32768, 0);
test_int64 ("001", "", 10, 1, 0);
test_int64 ("-001", "", 10, -1, 0);
return 0;
}
......@@ -506,85 +506,6 @@ find_first_that(gpointer key,
return (*v == *test);
}
static void
test_g_mkdir_with_parents_1 (const gchar *base)
{
char *p0 = g_build_filename (base, "fum", NULL);
char *p1 = g_build_filename (p0, "tem", NULL);
char *p2 = g_build_filename (p1, "zap", NULL);
FILE *f;
g_remove (p2);
g_remove (p1);
g_remove (p0);
if (g_file_test (p0, G_FILE_TEST_EXISTS))
g_error ("failed, %s exists, cannot test g_mkdir_with_parents\n", p0);
if (g_file_test (p1, G_FILE_TEST_EXISTS))
g_error ("failed, %s exists, cannot test g_mkdir_with_parents\n", p1);
if (g_file_test (p2, G_FILE_TEST_EXISTS))
g_error ("failed, %s exists, cannot test g_mkdir_with_parents\n", p2);
if (g_mkdir_with_parents (p2, 0777) == -1)
g_error ("failed, g_mkdir_with_parents(%s) failed: %s\n", p2, g_strerror (errno));
if (!g_file_test (p2, G_FILE_TEST_IS_DIR))
g_error ("failed, g_mkdir_with_parents(%s) succeeded, but %s is not a directory\n", p2, p2);
if (!g_file_test (p1, G_FILE_TEST_IS_DIR))
g_error ("failed, g_mkdir_with_parents(%s) succeeded, but %s is not a directory\n", p2, p1);
if (!g_file_test (p0, G_FILE_TEST_IS_DIR))
g_error ("failed, g_mkdir_with_parents(%s) succeeded, but %s is not a directory\n", p2, p0);
g_rmdir (p2);
if (g_file_test (p2, G_FILE_TEST_EXISTS))
g_error ("failed, did g_rmdir(%s), but %s is still there\n", p2, p2);
g_rmdir (p1);
if (g_file_test (p1, G_FILE_TEST_EXISTS))
g_error ("failed, did g_rmdir(%s), but %s is still there\n", p1, p1);
f = g_fopen (p1, "w");
if (f == NULL)
g_error ("failed, couldn't create file %s\n", p1);
fclose (f);
if (g_mkdir_with_parents (p1, 0666) == 0)
g_error ("failed, g_mkdir_with_parents(%s) succeeded, even if %s is a file\n", p1, p1);
if (g_mkdir_with_parents (p2, 0666) == 0)
g_error("failed, g_mkdir_with_parents(%s) succeeded, even if %s is a file\n", p2, p1);
g_remove (p2);
g_remove (p1);
g_remove (p0);
}
static void
test_g_mkdir_with_parents (void)
{
gchar *cwd;
if (g_test_verbose())
g_print ("checking g_mkdir_with_parents() in subdir ./hum/");
test_g_mkdir_with_parents_1 ("hum");
g_remove ("hum");
if (g_test_verbose())
g_print ("checking g_mkdir_with_parents() in subdir ./hii///haa/hee/");
test_g_mkdir_with_parents_1 ("hii///haa/hee");
g_remove ("hii/haa/hee");
g_remove ("hii/haa");
g_remove ("hii");
cwd = g_get_current_dir ();
if (g_test_verbose())
g_print ("checking g_mkdir_with_parents() in cwd: %s", cwd);
test_g_mkdir_with_parents_1 (cwd);
g_free (cwd);
}
static void
test_g_parse_debug_string (void)
{
......@@ -1601,7 +1522,6 @@ main (int argc,
g_test_add_func ("/testglib/Relation", relation_test);
g_test_add_func ("/testglib/File Paths", test_paths);
g_test_add_func ("/testglib/File Functions", test_file_functions);
g_test_add_func ("/testglib/Mkdir", test_g_mkdir_with_parents);
g_test_add_func ("/testglib/Parse Debug Strings", test_g_parse_debug_string);
g_test_add_func ("/testglib/GMemChunk (deprecated)", test_mem_chunks);
g_test_add_func ("/testglib/Warnings & Errors", log_warning_error_tests);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment