From f80d8f1e4d583167234d79ace0a3ef7081826317 Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Sat, 10 Nov 2012 11:06:57 -0500 Subject: [PATCH] win32: various fixes to test programs Fix a few win32-specific bugs in various tests, and #ifdef out code that is UNIX- or Linux-specific that wouldn't be expected to pass on Windows. https://bugzilla.gnome.org/show_bug.cgi?id=688109 --- glib/tests/fileutils.c | 2 +- glib/tests/gdatetime.c | 5 ++++- glib/tests/keyfile.c | 13 +++++++++++-- glib/tests/mappedfile.c | 4 ++++ glib/tests/uri.c | 25 +++++++++++++------------ glib/tests/utils.c | 17 +++++++++++++++++ 6 files changed, 50 insertions(+), 16 deletions(-) diff --git a/glib/tests/fileutils.c b/glib/tests/fileutils.c index 5f38874..be9acdb 100644 --- a/glib/tests/fileutils.c +++ b/glib/tests/fileutils.c @@ -620,7 +620,7 @@ test_basename (void) g_free (b); b = g_path_get_basename ("///"); - g_assert_cmpstr (b, ==, "/"); + g_assert_cmpstr (b, ==, G_DIR_SEPARATOR_S); g_free (b); b = g_path_get_basename ("/a/b/c/d"); diff --git a/glib/tests/gdatetime.c b/glib/tests/gdatetime.c index 4def53e..b2e6924 100644 --- a/glib/tests/gdatetime.c +++ b/glib/tests/gdatetime.c @@ -678,6 +678,7 @@ test_GDateTime_new_from_unix_utc (void) static void test_GDateTime_get_utc_offset (void) { +#if defined (HAVE_STRUCT_TM_TM_GMTOFF) || defined (HAVE_STRUCT_TM___TM_GMTOFF) GDateTime *dt; GTimeSpan ts; struct tm tm; @@ -694,6 +695,7 @@ test_GDateTime_get_utc_offset (void) g_assert_cmpint (ts, ==, (tm.__tm_gmtoff * G_TIME_SPAN_SECOND)); #endif g_date_time_unref (dt); +#endif } static void @@ -1209,7 +1211,7 @@ test_z (void) static void test_strftime (void) { - /* this is probably going to cause various buggy libcs to explode... */ +#ifdef __linux__ #define TEST_FORMAT \ "a%a A%A b%b B%B c%c C%C d%d e%e F%F g%g G%G h%h H%H I%I j%j m%m M%M " \ "n%n p%p r%r R%R S%S t%t T%T u%u V%V w%w x%x X%X y%y Y%Y z%z Z%Z %%" @@ -1229,6 +1231,7 @@ test_strftime (void) g_date_time_unref (date_time); g_free (dt_str); } +#endif } static void diff --git a/glib/tests/keyfile.c b/glib/tests/keyfile.c index 4c12b57..530fbf1 100644 --- a/glib/tests/keyfile.c +++ b/glib/tests/keyfile.c @@ -1301,11 +1301,18 @@ test_load (void) GKeyFile *file; GError *error; gboolean bools[2] = { TRUE, FALSE }; + gboolean loaded; file = g_key_file_new (); error = NULL; - g_assert (g_key_file_load_from_data_dirs (file, "keyfiletest.ini", NULL, 0, &error)); +#ifdef G_OS_UNIX + /* Uses the value of $XDG_DATA_HOME we set in main() */ + loaded = g_key_file_load_from_data_dirs (file, "keyfiletest.ini", NULL, 0, &error); +#else + loaded = g_key_file_load_from_file (file, SRCDIR "/keyfiletest.ini", 0, &error); +#endif g_assert_no_error (error); + g_assert (loaded); g_key_file_set_locale_string (file, "test", "key4", "de", "Vierter Schlüssel"); g_key_file_set_boolean_list (file, "test", "key5", bools, 2); @@ -1333,7 +1340,7 @@ test_load_fail (void) file = g_key_file_new (); error = NULL; - g_assert (!g_key_file_load_from_file (file, "/", 0, &error)); + g_assert (!g_key_file_load_from_file (file, SRCDIR "/keyfile.c", 0, &error)); g_assert_error (error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_PARSE); g_clear_error (&error); g_assert (!g_key_file_load_from_file (file, "/nosuchfile", 0, &error)); @@ -1566,7 +1573,9 @@ test_roundtrip (void) int main (int argc, char *argv[]) { +#ifdef G_OS_UNIX g_setenv ("XDG_DATA_HOME", SRCDIR, TRUE); +#endif g_test_init (&argc, &argv, NULL); g_test_bug_base ("http://bugzilla.gnome.org/"); diff --git a/glib/tests/mappedfile.c b/glib/tests/mappedfile.c index 3de9393..8d5258d 100644 --- a/glib/tests/mappedfile.c +++ b/glib/tests/mappedfile.c @@ -42,6 +42,7 @@ test_empty (void) g_mapped_file_free (file); } +#ifdef G_OS_UNIX static void test_device (void) { @@ -53,6 +54,7 @@ test_device (void) g_assert (file == NULL); g_error_free (error); } +#endif static void test_nonexisting (void) @@ -173,7 +175,9 @@ main (int argc, char *argv[]) g_test_add_func ("/mappedfile/basic", test_basic); g_test_add_func ("/mappedfile/empty", test_empty); +#ifdef G_OS_UNIX g_test_add_func ("/mappedfile/device", test_device); +#endif g_test_add_func ("/mappedfile/nonexisting", test_nonexisting); g_test_add_func ("/mappedfile/writable", test_writable); g_test_add_func ("/mappedfile/writable_fd", test_writable_fd); diff --git a/glib/tests/uri.c b/glib/tests/uri.c index 828dcac..0fc7657 100644 --- a/glib/tests/uri.c +++ b/glib/tests/uri.c @@ -204,15 +204,16 @@ run_from_uri_tests (void) &error); #ifdef G_OS_WIN32 - { - gchar *p, *slash; - p = from_uri_tests[i].expected_filename = g_strdup (from_uri_tests[i].expected_filename); - while ((slash = strchr (p, '/')) != NULL) - { - *slash = '\\'; - p = slash + 1; - } - } + if (from_uri_tests[i].expected_filename) + { + gchar *p, *slash; + p = from_uri_tests[i].expected_filename = g_strdup (from_uri_tests[i].expected_filename); + while ((slash = strchr (p, '/')) != NULL) + { + *slash = '\\'; + p = slash + 1; + } + } #endif if (res) g_assert_cmpstr (res, ==, from_uri_tests[i].expected_filename); @@ -257,12 +258,12 @@ safe_strcmp_hostname (const gchar *a, const gchar *b) if (b == NULL) b = ""; #ifndef G_OS_WIN32 - return g_strcmp0 (a, b); + return strcmp (a, b); #else - if (g_strcmp0 (a, "localhost") == 0 && b == NULL) + if (strcmp (a, "localhost") == 0 && !*b) return 0; else - return g_strcmp0 (a, b); + return strcmp (a, b); #endif } diff --git a/glib/tests/utils.c b/glib/tests/utils.c index 9d79584..9c89bde 100644 --- a/glib/tests/utils.c +++ b/glib/tests/utils.c @@ -236,6 +236,7 @@ test_find_program (void) { gchar *res; +#ifdef G_OS_UNIX res = g_find_program_in_path ("sh"); g_assert (res != NULL); g_free (res); @@ -243,6 +244,11 @@ test_find_program (void) res = g_find_program_in_path ("/bin/sh"); g_assert (res != NULL); g_free (res); +#else + /* There's not a lot we can search for that would reliably work both + * on real Windows and mingw. + */ +#endif res = g_find_program_in_path ("this_program_does_not_exit"); g_assert (res == NULL); @@ -370,6 +376,7 @@ test_hostname (void) g_assert (name != NULL); } +#ifdef G_OS_UNIX static void test_xdg_dirs (void) { @@ -427,6 +434,7 @@ test_xdg_dirs (void) g_strfreev ((gchar **)dirs); g_free (s); } +#endif static void test_special_dir (void) @@ -508,6 +516,13 @@ main (int argc, g_unsetenv ("TMP"); g_unsetenv ("TEMP"); + /* g_test_init() only calls g_set_prgname() if g_get_prgname() + * returns %NULL, but g_get_prgname() on Windows never returns NULL. + * So we need to do this by hand to make test_appname() work on + * Windows. + */ + g_set_prgname (argv[0]); + g_test_init (&argc, &argv, NULL); g_test_bug_base ("http://bugzilla.gnome.org/"); @@ -526,7 +541,9 @@ main (int argc, g_test_add_func ("/utils/username", test_username); g_test_add_func ("/utils/realname", test_realname); g_test_add_func ("/utils/hostname", test_hostname); +#ifdef G_OS_UNIX g_test_add_func ("/utils/xdgdirs", test_xdg_dirs); +#endif g_test_add_func ("/utils/specialdir", test_special_dir); g_test_add_func ("/utils/specialdir/desktop", test_desktop_special_dir); g_test_add_func ("/utils/clear-pointer", test_clear_pointer); -- 2.7.4