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
This commit is contained in:
Dan Winship 2012-11-10 11:06:57 -05:00
parent b8c13a01b6
commit f80d8f1e4d
6 changed files with 50 additions and 16 deletions

View File

@ -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");

View File

@ -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

View File

@ -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/");

View File

@ -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);

View File

@ -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
}

View File

@ -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);