Merge branch 'w32' into 'main'

Various win32 tests fixes

See merge request GNOME/glib!2569
This commit is contained in:
Philip Withnall 2022-03-23 16:44:16 +00:00
commit 628c8ec0fd
5 changed files with 83 additions and 8 deletions

View File

@ -1069,7 +1069,7 @@ set_info_from_stat (GFileInfo *info,
_g_file_info_set_attribute_uint64_by_id (info, G_FILE_ATTRIBUTE_ID_TIME_CREATED, statbuf->st_birthtim);
#elif defined (G_OS_WIN32)
_g_file_info_set_attribute_uint64_by_id (info, G_FILE_ATTRIBUTE_ID_TIME_CREATED, statbuf->st_ctim.tv_sec);
_g_file_info_set_attribute_uint64_by_id (info, G_FILE_ATTRIBUTE_ID_TIME_CREATED_USEC, statbuf->st_ctim.tv_nsec / 1000);
_g_file_info_set_attribute_uint32_by_id (info, G_FILE_ATTRIBUTE_ID_TIME_CREATED_USEC, statbuf->st_ctim.tv_nsec / 1000);
#endif
if (_g_file_attribute_matcher_matches_id (attribute_matcher,

View File

@ -118,9 +118,11 @@ test_getenv (void)
data = g_getenv ("foo=bar");
if (data != NULL)
g_assert_cmpstr (data, ==, "baz");
else
{
data = g_getenv ("foo");
g_assert_cmpstr (data, ==, "bar=baz");
}
if (g_test_undefined ())
{

View File

@ -749,9 +749,7 @@ test_mkdir_with_parents (void)
g_assert_cmpint (g_mkdir_with_parents ("./test", 0), ==, 0);
g_remove ("./test");
#ifdef G_OS_WIN32
g_assert_cmpint (g_mkdir_with_parents ("\\Windows\\b\\c", 0), ==, -1);
#else
#ifndef G_OS_WIN32
g_assert_cmpint (g_mkdir_with_parents ("/usr/b/c", 0), ==, -1);
/* EPERM may be returned if the filesystem as a whole is read-only */
if (errno != EPERM)

View File

@ -93,8 +93,12 @@ test_read_write (void)
status = g_io_channel_set_flags (gio_r, G_IO_FLAG_NONBLOCK, &local_error);
if (status == G_IO_STATUS_ERROR)
{
#ifdef G_OS_WIN32
g_test_message ("FIXME: not implemented on win32");
#else
/* Errors should not happen */
g_assert_no_error (local_error);
#endif
g_clear_error (&local_error);
}
buffer = g_string_sized_new (buffer_size_bytes);

View File

@ -34,6 +34,18 @@
#include "glib/gunidecomp.h"
#ifdef G_OS_WIN32
#include <windows.h>
#endif
static void
save_and_clear_env (const char *name,
char **save)
{
*save = g_strdup (g_getenv (name));
g_unsetenv (name);
}
/* Test that g_unichar_validate() returns the correct value for various
* ASCII and Unicode alphabetic, numeric, and other, codepoints. */
static void
@ -481,15 +493,29 @@ test_turkish_strupdown (void)
"\xcc\x87" /* COMBINING DOT ABOVE (U+307) */
"\xc4\xb1" /* LATIN SMALL LETTER DOTLESS I (U+131) */
"\xc4\xb0"; /* LATIN CAPITAL LETTER I WITH DOT ABOVE (U+130) */
char *oldlocale;
char *old_lc_all, *old_lc_messages, *old_lang;
#ifdef G_OS_WIN32
LCID old_lcid;
#endif
char *oldlocale = g_strdup (setlocale (LC_ALL, "tr_TR"));
/* interferes with g_win32_getlocale() */
save_and_clear_env ("LC_ALL", &old_lc_all);
save_and_clear_env ("LC_MESSAGES", &old_lc_messages);
save_and_clear_env ("LANG", &old_lang);
oldlocale = g_strdup (setlocale (LC_ALL, "tr_TR"));
if (oldlocale == NULL)
{
g_test_skip ("locale tr_TR not available");
return;
}
#ifdef G_OS_WIN32
old_lcid = GetThreadLocale ();
SetThreadLocale (MAKELCID (MAKELANGID (LANG_TURKISH, SUBLANG_TURKISH_TURKEY), SORT_DEFAULT));
#endif
str_up = g_utf8_strup (str, strlen (str));
str_down = g_utf8_strdown (str, strlen (str));
/* i => LATIN CAPITAL LETTER I WITH DOT ABOVE,
@ -508,7 +534,19 @@ test_turkish_strupdown (void)
g_free (str_down);
setlocale (LC_ALL, oldlocale);
#ifdef G_OS_WIN32
SetThreadLocale (old_lcid);
#endif
g_free (oldlocale);
if (old_lc_all)
g_setenv ("LC_ALL", old_lc_all, TRUE);
if (old_lc_messages)
g_setenv ("LC_MESSAGES", old_lc_messages, TRUE);
if (old_lang)
g_setenv ("LANG", old_lang, TRUE);
g_free (old_lc_all);
g_free (old_lc_messages);
g_free (old_lang);
}
/* Test that g_utf8_casefold() returns the correct value for various
@ -548,6 +586,17 @@ test_casemap_and_casefold (void)
const char *expected;
char *convert;
char *current_locale = setlocale (LC_CTYPE, NULL);
char *old_lc_all, *old_lc_messages, *old_lang;
#ifdef G_OS_WIN32
LCID old_lcid;
old_lcid = GetThreadLocale ();
#endif
/* interferes with g_win32_getlocale() */
save_and_clear_env ("LC_ALL", &old_lc_all);
save_and_clear_env ("LC_MESSAGES", &old_lc_messages);
save_and_clear_env ("LANG", &old_lang);
filename = g_test_build_filename (G_TEST_DIST, "casemap.txt", NULL);
infile = fopen (filename, "r");
@ -575,6 +624,15 @@ test_casemap_and_casefold (void)
}
}
#ifdef G_OS_WIN32
if (strstr (locale, "lt_LT"))
SetThreadLocale (MAKELCID (MAKELANGID (LANG_LITHUANIAN, SUBLANG_LITHUANIAN), SORT_DEFAULT));
else if (strstr (locale, "tr_TR"))
SetThreadLocale (MAKELCID (MAKELANGID (LANG_TURKISH, SUBLANG_TURKISH_TURKEY), SORT_DEFAULT));
else
SetThreadLocale (old_lcid);
#endif
test = strings[1];
/* gen-casemap-txt.py uses an empty string when a single
@ -627,6 +685,19 @@ test_casemap_and_casefold (void)
fclose (infile);
g_free (filename);
if (old_lc_all)
g_setenv ("LC_ALL", old_lc_all, TRUE);
if (old_lc_messages)
g_setenv ("LC_MESSAGES", old_lc_messages, TRUE);
if (old_lang)
g_setenv ("LANG", old_lang, TRUE);
g_free (old_lc_all);
g_free (old_lc_messages);
g_free (old_lang);
#ifdef G_OS_WIN32
SetThreadLocale (old_lcid);
#endif
}
/* Test that g_unichar_ismark() returns the correct value for various