diff options
author | Mateusz Majewski <m.majewski2@samsung.com> | 2024-02-02 14:38:53 +0100 |
---|---|---|
committer | Mateusz Majewski <m.majewski2@samsung.com> | 2024-02-02 14:38:53 +0100 |
commit | 7aeea53a95c4f3688b9ad6b6cf3375e100132653 (patch) | |
tree | d1fe9c62350d27859d955baa3d620af5aa6ecc35 /gio | |
parent | 616046c637d6316c3dd0513eb2046db0a427d1cc (diff) | |
download | glib-7aeea53a95c4f3688b9ad6b6cf3375e100132653.tar.gz glib-7aeea53a95c4f3688b9ad6b6cf3375e100132653.tar.bz2 glib-7aeea53a95c4f3688b9ad6b6cf3375e100132653.zip |
Imported Upstream version 2.74.1
Diffstat (limited to 'gio')
-rw-r--r-- | gio/gdbus-2.0/codegen/meson.build | 2 | ||||
-rw-r--r-- | gio/gio-launch-desktop.c | 4 | ||||
-rw-r--r-- | gio/glocalfileinfo.c | 322 | ||||
-rw-r--r-- | gio/glocalfileoutputstream.c | 3 | ||||
-rw-r--r-- | gio/gosxcontenttype.m | 15 | ||||
-rw-r--r-- | gio/gtask.c | 2 | ||||
-rw-r--r-- | gio/meson.build | 24 | ||||
-rw-r--r-- | gio/tests/appinfo-test-actions.desktop | 6 | ||||
-rw-r--r-- | gio/tests/contenttype.c | 4 | ||||
-rw-r--r-- | gio/tests/desktop-app-info.c | 23 | ||||
-rw-r--r-- | gio/tests/file-thumbnail.c | 427 | ||||
-rw-r--r-- | gio/tests/file.c | 55 | ||||
-rw-r--r-- | gio/tests/g-file-info.c | 16 | ||||
-rw-r--r-- | gio/tests/gmenumodel.c | 6 | ||||
-rw-r--r-- | gio/tests/meson.build | 104 | ||||
-rw-r--r-- | gio/tests/services/meson.build | 1 | ||||
-rw-r--r-- | gio/tests/unix-streams.c | 4 |
17 files changed, 823 insertions, 195 deletions
diff --git a/gio/gdbus-2.0/codegen/meson.build b/gio/gdbus-2.0/codegen/meson.build index f0a256898..16abd97d6 100644 --- a/gio/gdbus-2.0/codegen/meson.build +++ b/gio/gdbus-2.0/codegen/meson.build @@ -32,6 +32,7 @@ gdbus_codegen_built_files = [] gdbus_codegen_built_files += configure_file(input : 'config.py.in', output : 'config.py', install_dir : codegen_dir, + install_tag : 'bin-devel', configuration : gdbus_codegen_conf) foreach f : gdbus_codegen_files @@ -39,5 +40,6 @@ foreach f : gdbus_codegen_files # and then install it too so that it can be used after installation gdbus_codegen_built_files += configure_file(input : f, output : f, install_dir : codegen_dir, + install_tag : 'bin-devel', copy : true) endforeach diff --git a/gio/gio-launch-desktop.c b/gio/gio-launch-desktop.c index 26b9ae1a1..47717b987 100644 --- a/gio/gio-launch-desktop.c +++ b/gio/gio-launch-desktop.c @@ -121,8 +121,8 @@ journal_stream_fd (const char *identifier, /* Arbitrary large size for the sending buffer, from systemd */ int large_buffer_size = 8 * 1024 * 1024; - G_STATIC_ASSERT (LOG_EMERG == 0 && "Linux ABI defines LOG_EMERG"); - G_STATIC_ASSERT (LOG_DEBUG == 7 && "Linux ABI defines LOG_DEBUG"); + G_STATIC_ASSERT (LOG_EMERG == 0 && sizeof "Linux ABI defines LOG_EMERG"); + G_STATIC_ASSERT (LOG_DEBUG == 7 && sizeof "Linux ABI defines LOG_DEBUG"); fd = socket (AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0); diff --git a/gio/glocalfileinfo.c b/gio/glocalfileinfo.c index 6f186957a..661d2266a 100644 --- a/gio/glocalfileinfo.c +++ b/gio/glocalfileinfo.c @@ -1388,7 +1388,7 @@ get_content_type (const char *basename, int fd, errsv; sniff_length = _g_unix_content_type_get_sniff_len (); - if (sniff_length > 4096) + if (sniff_length == 0 || sniff_length > 4096) sniff_length = 4096; #ifdef O_NOATIME @@ -1426,8 +1426,10 @@ get_thumbnail_attributes (const char *path, { GChecksum *checksum; char *uri; - char *filename; + char *filename = NULL; char *basename; + const char *size_dirs[4] = { "xx-large", "x-large", "large", "normal" }; + gsize i; uri = g_filename_to_uri (path, NULL, NULL); @@ -1437,11 +1439,18 @@ get_thumbnail_attributes (const char *path, basename = g_strconcat (g_checksum_get_string (checksum), ".png", NULL); g_checksum_free (checksum); - filename = g_build_filename (g_get_user_cache_dir (), - "thumbnails", "large", basename, - NULL); + for (i = 0; i < G_N_ELEMENTS (size_dirs); i++) + { + filename = g_build_filename (g_get_user_cache_dir (), + "thumbnails", size_dirs[i], basename, + NULL); + if (g_file_test (filename, G_FILE_TEST_IS_REGULAR)) + break; + + g_clear_pointer (&filename, g_free); + } - if (g_file_test (filename, G_FILE_TEST_IS_REGULAR)) + if (filename) { _g_file_info_set_attribute_byte_string_by_id (info, G_FILE_ATTRIBUTE_ID_THUMBNAIL_PATH, filename); _g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_THUMBNAIL_IS_VALID, @@ -1449,33 +1458,18 @@ get_thumbnail_attributes (const char *path, } else { - g_free (filename); filename = g_build_filename (g_get_user_cache_dir (), - "thumbnails", "normal", basename, + "thumbnails", "fail", + "gnome-thumbnail-factory", + basename, NULL); if (g_file_test (filename, G_FILE_TEST_IS_REGULAR)) { - _g_file_info_set_attribute_byte_string_by_id (info, G_FILE_ATTRIBUTE_ID_THUMBNAIL_PATH, filename); + _g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_THUMBNAILING_FAILED, TRUE); _g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_THUMBNAIL_IS_VALID, thumbnail_verify (filename, uri, stat_buf)); } - else - { - g_free (filename); - filename = g_build_filename (g_get_user_cache_dir (), - "thumbnails", "fail", - "gnome-thumbnail-factory", - basename, - NULL); - - if (g_file_test (filename, G_FILE_TEST_IS_REGULAR)) - { - _g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_THUMBNAILING_FAILED, TRUE); - _g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_THUMBNAIL_IS_VALID, - thumbnail_verify (filename, uri, stat_buf)); - } - } } g_free (basename); g_free (filename); @@ -2447,6 +2441,26 @@ set_symlink (char *filename, } #endif +#if defined (HAVE_UTIMES) || defined (HAVE_UTIMENSAT) || defined(G_OS_WIN32) +static int +lazy_stat (const char *filename, + GStatBuf *statbuf, + gboolean *called_stat) +{ + int res; + + if (*called_stat) + return 0; + + res = g_stat (filename, statbuf); + + if (res == 0) + *called_stat = TRUE; + + return res; +} +#endif + #if defined (G_OS_WIN32) /* From * https://support.microsoft.com/en-ca/help/167296/how-to-convert-a-unix-time-t-to-a-win32-filetime-or-systemtime @@ -2552,6 +2566,8 @@ set_mtime_atime (const char *filename, FILETIME *p_mtime = NULL; FILETIME *p_atime = NULL; DWORD gle; + GStatBuf statbuf; + gboolean got_stat = FALSE; /* ATIME */ if (atime_value) @@ -2560,31 +2576,45 @@ set_mtime_atime (const char *filename, return FALSE; val_usec = 0; val_nsec = 0; - if (atime_usec_value && - !get_uint32 (atime_usec_value, &val_usec, error)) - return FALSE; + } + else + { + if (lazy_stat (filename, &statbuf, &got_stat) == 0) + { + val = statbuf.st_atime; +#if defined (HAVE_STRUCT_STAT_ST_ATIMENSEC) + val_nsec = statbuf.st_atimensec; +#elif defined (HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC) + val_nsec = statbuf.st_atim.tv_nsec; +#endif + } + } - /* Convert to nanoseconds. Clamp the usec value if it’s going to overflow, - * as %G_MAXINT32 will trigger a ‘too big’ error in - * _g_win32_unix_time_to_filetime() anyway. */ - val_nsec = (val_usec > G_MAXINT32 / 1000) ? G_MAXINT32 : (val_usec * 1000); + if (atime_usec_value && + !get_uint32 (atime_usec_value, &val_usec, error)) + return FALSE; - if (atime_nsec_value && - !get_uint32 (atime_nsec_value, &val_nsec, error)) - return FALSE; - if (val_nsec > 0) - { - if (!_g_win32_unix_time_to_filetime (val, val_nsec, &atime, error)) - return FALSE; - } - else - { - if (!_g_win32_unix_time_to_filetime (val, val_usec, &atime, error)) - return FALSE; - } - p_atime = &atime; + /* Convert to nanoseconds. Clamp the usec value if it’s going to overflow, + * as %G_MAXINT32 will trigger a ‘too big’ error in + * _g_win32_unix_time_to_filetime() anyway. */ + val_nsec = (val_usec > G_MAXINT32 / 1000) ? G_MAXINT32 : (val_usec * 1000); + + if (atime_nsec_value && + !get_uint32 (atime_nsec_value, &val_nsec, error)) + return FALSE; + if (val_nsec > 0) + { + if (!_g_win32_unix_time_to_filetime (val, val_nsec, &atime, error)) + return FALSE; + } + else + { + if (!_g_win32_unix_time_to_filetime (val, val_usec, &atime, error)) + return FALSE; } + p_atime = &atime; + /* MTIME */ if (mtime_value) { @@ -2592,30 +2622,43 @@ set_mtime_atime (const char *filename, return FALSE; val_usec = 0; val_nsec = 0; - if (mtime_usec_value && - !get_uint32 (mtime_usec_value, &val_usec, error)) - return FALSE; + } + else + { + if (lazy_stat (filename, &statbuf, &got_stat) == 0) + { + val = statbuf.st_mtime; +#if defined (HAVE_STRUCT_STAT_ST_MTIMENSEC) + val_nsec = statbuf.st_mtimensec; +#elif defined (HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC) + val_nsec = statbuf.st_mtim.tv_nsec; +#endif + } + } + + if (mtime_usec_value && + !get_uint32 (mtime_usec_value, &val_usec, error)) + return FALSE; - /* Convert to nanoseconds. Clamp the usec value if it’s going to overflow, - * as %G_MAXINT32 will trigger a ‘too big’ error in - * _g_win32_unix_time_to_filetime() anyway. */ - val_nsec = (val_usec > G_MAXINT32 / 1000) ? G_MAXINT32 : (val_usec * 1000); + /* Convert to nanoseconds. Clamp the usec value if it’s going to overflow, + * as %G_MAXINT32 will trigger a ‘too big’ error in + * _g_win32_unix_time_to_filetime() anyway. */ + val_nsec = (val_usec > G_MAXINT32 / 1000) ? G_MAXINT32 : (val_usec * 1000); - if (mtime_nsec_value && - !get_uint32 (mtime_nsec_value, &val_nsec, error)) - return FALSE; - if (val_nsec > 0) - { - if (!_g_win32_unix_time_to_filetime (val, val_nsec, &mtime, error)) - return FALSE; - } - else - { - if (!_g_win32_unix_time_to_filetime (val, val_usec, &mtime, error)) - return FALSE; - } - p_mtime = &mtime; + if (mtime_nsec_value && + !get_uint32 (mtime_nsec_value, &val_nsec, error)) + return FALSE; + if (val_nsec > 0) + { + if (!_g_win32_unix_time_to_filetime (val, val_nsec, &mtime, error)) + return FALSE; + } + else + { + if (!_g_win32_unix_time_to_filetime (val, val_usec, &mtime, error)) + return FALSE; } + p_mtime = &mtime; filename_utf16 = g_utf8_to_utf16 (filename, -1, NULL, NULL, error); @@ -2660,25 +2703,6 @@ set_mtime_atime (const char *filename, return res; } #elif defined (HAVE_UTIMES) || defined (HAVE_UTIMENSAT) -static int -lazy_stat (char *filename, - struct stat *statbuf, - gboolean *called_stat) -{ - int res; - - if (*called_stat) - return 0; - - res = g_stat (filename, statbuf); - - if (res == 0) - *called_stat = TRUE; - - return res; -} - - static gboolean set_mtime_atime (char *filename, const GFileAttributeValue *mtime_value, @@ -2691,57 +2715,37 @@ set_mtime_atime (char *filename, { int res; guint64 val = 0; - guint32 val_usec = 0; - guint32 val_nsec = 0; - struct stat statbuf; + GStatBuf statbuf; gboolean got_stat = FALSE; - struct timeval times[2] = { {0, 0}, {0, 0} }; #ifdef HAVE_UTIMENSAT struct timespec times_n[2] = { {0, 0}, {0, 0} }; -#endif /* ATIME */ if (atime_value) { if (!get_uint64 (atime_value, &val, error)) return FALSE; - times[0].tv_sec = val; -#if defined (HAVE_UTIMENSAT) times_n[0].tv_sec = val; -#endif } else { if (lazy_stat (filename, &statbuf, &got_stat) == 0) { - times[0].tv_sec = statbuf.st_atime; + times_n[0].tv_sec = statbuf.st_atime; #if defined (HAVE_STRUCT_STAT_ST_ATIMENSEC) - times[0].tv_usec = statbuf.st_atimensec / 1000; -#if defined (HAVE_UTIMENSAT) times_n[0].tv_nsec = statbuf.st_atimensec; -#endif /* HAVE_UTIMENSAT */ #elif defined (HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC) - times[0].tv_usec = statbuf.st_atim.tv_nsec / 1000; -#if defined (HAVE_UTIMENSAT) times_n[0].tv_nsec = statbuf.st_atim.tv_nsec; -#endif /* HAVE_UTIMENSAT */ #endif } } - - if (atime_usec_value) - { - if (!get_uint32 (atime_usec_value, &val_usec, error)) - return FALSE; - times[0].tv_usec = val_usec; - } if (atime_nsec_value) { + guint32 val_nsec = 0; + if (!get_uint32 (atime_nsec_value, &val_nsec, error)) return FALSE; -#if defined (HAVE_UTIMENSAT) times_n[0].tv_nsec = val_nsec; -#endif } /* MTIME */ @@ -2749,58 +2753,100 @@ set_mtime_atime (char *filename, { if (!get_uint64 (mtime_value, &val, error)) return FALSE; - times[1].tv_sec = val; -#if defined (HAVE_UTIMENSAT) times_n[1].tv_sec = val; -#endif } else { if (lazy_stat (filename, &statbuf, &got_stat) == 0) { - times[1].tv_sec = statbuf.st_mtime; #if defined (HAVE_STRUCT_STAT_ST_MTIMENSEC) - times[1].tv_usec = statbuf.st_mtimensec / 1000; -#if defined (HAVE_UTIMENSAT) times_n[1].tv_nsec = statbuf.st_mtimensec; -#endif /* HAVE_UTIMENSAT */ #elif defined (HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC) - times[1].tv_usec = statbuf.st_mtim.tv_nsec / 1000; -#if defined (HAVE_UTIMENSAT) times_n[1].tv_nsec = statbuf.st_mtim.tv_nsec; -#endif /* HAVE_UTIMENSAT */ #endif } } - - if (mtime_usec_value) - { - if (!get_uint32 (mtime_usec_value, &val_usec, error)) - return FALSE; - times[1].tv_usec = val_usec; - } + if (mtime_nsec_value) { + guint32 val_nsec = 0; + if (!get_uint32 (mtime_nsec_value, &val_nsec, error)) return FALSE; -#if defined (HAVE_UTIMENSAT) times_n[1].tv_nsec = val_nsec; + } + + res = utimensat (AT_FDCWD, filename, times_n, 0); + +#else /* HAVE_UTIMES */ + + struct timeval times[2] = { {0, 0}, {0, 0} }; + + /* ATIME */ + if (atime_value) + { + if (!get_uint64 (atime_value, &val, error)) + return FALSE; + + times[0].tv_sec = val; + } + else + { + if (lazy_stat (filename, &statbuf, &got_stat) == 0) + { + times[0].tv_sec = statbuf.st_atime; +#if defined (HAVE_STRUCT_STAT_ST_ATIMENSEC) + times[0].tv_usec = statbuf.st_atimensec / 1000; +#elif defined (HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC) + times[0].tv_usec = statbuf.st_atim.tv_nsec / 1000; #endif + } } - - res = utimes (filename, times); - if (res == -1) + + if (atime_usec_value) { - int errsv = errno; + guint32 val_usec = 0; - g_set_error (error, G_IO_ERROR, - g_io_error_from_errno (errsv), - _("Error setting modification or access time: %s"), - g_strerror (errsv)); - return FALSE; + if (!get_uint32 (atime_usec_value, &val_usec, error)) + return FALSE; + + times[0].tv_usec = val_usec; } - res = utimensat (AT_FDCWD, filename, times_n, 0); + /* MTIME */ + if (mtime_value) + { + if (!get_uint64 (mtime_value, &val, error)) + return FALSE; + + times[1].tv_sec = val; + } + else + { + if (lazy_stat (filename, &statbuf, &got_stat) == 0) + { + times[1].tv_sec = statbuf.st_mtime; +#if defined (HAVE_STRUCT_STAT_ST_MTIMENSEC) + times[1].tv_usec = statbuf.st_mtimensec / 1000; +#elif defined (HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC) + times[1].tv_usec = statbuf.st_mtim.tv_nsec / 1000; +#endif + } + } + + if (mtime_usec_value) + { + guint32 val_usec = 0; + + if (!get_uint32 (mtime_usec_value, &val_usec, error)) + return FALSE; + + times[1].tv_usec = val_usec; + } + + res = utimes (filename, times); +#endif + if (res == -1) { int errsv = errno; diff --git a/gio/glocalfileoutputstream.c b/gio/glocalfileoutputstream.c index 400934be1..3ce987fba 100644 --- a/gio/glocalfileoutputstream.c +++ b/gio/glocalfileoutputstream.c @@ -1194,7 +1194,8 @@ handle_overwrite_open (const char *filename, if (replace_destination_set) { g_close (fd, NULL); - + fd = -1; + if (g_unlink (filename) != 0) { errsv = errno; diff --git a/gio/gosxcontenttype.m b/gio/gosxcontenttype.m index 6119bbcae..fad028038 100644 --- a/gio/gosxcontenttype.m +++ b/gio/gosxcontenttype.m @@ -58,13 +58,18 @@ create_cfstring_from_cstr (const gchar *cstr) static gchar * create_cstr_from_cfstring (CFStringRef str) { + CFIndex length; + CFIndex maxlen; + gchar *buffer; + Boolean success; + g_return_val_if_fail (str != NULL, NULL); - CFIndex length = CFStringGetLength (str); - CFIndex maxlen = CFStringGetMaximumSizeForEncoding (length, kCFStringEncodingUTF8); - gchar *buffer = g_malloc (maxlen + 1); - Boolean success = CFStringGetCString (str, (char *) buffer, maxlen, - kCFStringEncodingUTF8); + length = CFStringGetLength (str); + maxlen = CFStringGetMaximumSizeForEncoding (length, kCFStringEncodingUTF8); + buffer = g_malloc (maxlen + 1); + success = CFStringGetCString (str, (char *) buffer, maxlen, + kCFStringEncodingUTF8); CFRelease (str); if (success) return buffer; diff --git a/gio/gtask.c b/gio/gtask.c index 774cba793..e8c2ef282 100644 --- a/gio/gtask.c +++ b/gio/gtask.c @@ -1136,7 +1136,7 @@ g_task_get_context (GTask *task) * * Gets @task's #GCancellable * - * Returns: (transfer none): @task's #GCancellable + * Returns: (nullable) (transfer none): @task's #GCancellable * * Since: 2.36 */ diff --git a/gio/meson.build b/gio/meson.build index fdd2528df..14f0d8259 100644 --- a/gio/meson.build +++ b/gio/meson.build @@ -800,13 +800,15 @@ if have_bash endif install_data([ - 'completion/gapplication', - 'completion/gdbus', - 'completion/gio', - 'completion/gsettings', - 'completion/gresource' - ], - install_dir: bash_comp_inst_dir) + 'completion/gapplication', + 'completion/gdbus', + 'completion/gio', + 'completion/gsettings', + 'completion/gresource' + ], + install_dir: bash_comp_inst_dir, + install_tag: 'bin', + ) endif if enable_dtrace @@ -1017,10 +1019,14 @@ executable('gsettings', 'gsettings-tool.c', link_args : noseh_link_args, dependencies : [libgio_dep, libgobject_dep, libgmodule_dep, libglib_dep]) install_data('gschema.dtd', - install_dir : join_paths(get_option('datadir'), schemas_subdir)) + install_dir : get_option('datadir') / schemas_subdir, + install_tag : 'devel', +) install_data(['gschema.loc', 'gschema.its'], - install_dir : join_paths(get_option('datadir'), 'gettext/its')) + install_dir : get_option('datadir') / 'gettext' / 'its', + install_tag : 'devel', +) executable('gdbus', 'gdbus-tool.c', install : true, diff --git a/gio/tests/appinfo-test-actions.desktop b/gio/tests/appinfo-test-actions.desktop index 86e3bcfc0..65f3216a9 100644 --- a/gio/tests/appinfo-test-actions.desktop +++ b/gio/tests/appinfo-test-actions.desktop @@ -5,12 +5,12 @@ Exec=true [Desktop Action frob] Name=Frobnicate -Exec=touch frob +Exec=sh -c '[ -d "$G_TEST_TMPDIR" ] && touch "$G_TEST_TMPDIR/frob"' [Desktop Action tweak] Name=Tweak -Exec=touch tweak +Exec=sh -c '[ -d "$G_TEST_TMPDIR" ] && touch "$G_TEST_TMPDIR/tweak"' [Desktop Action twiddle] Name=Twiddle -Exec=touch twiddle +Exec=sh -c '[ -d "$G_TEST_TMPDIR" ] && touch "$G_TEST_TMPDIR/twiddle"' diff --git a/gio/tests/contenttype.c b/gio/tests/contenttype.c index 6cfd366ff..7fd97f453 100644 --- a/gio/tests/contenttype.c +++ b/gio/tests/contenttype.c @@ -252,10 +252,10 @@ test_icon (void) names = g_themed_icon_get_names (G_THEMED_ICON (icon)); #ifdef __APPLE__ g_assert_true (g_strv_contains (names, "text-*")); +#elif defined(G_OS_WIN32) + g_assert_cmpuint (g_strv_length ((GStrv) names), >, 0); #else -#ifndef G_OS_WIN32 g_assert_true (g_strv_contains (names, "text-plain")); -#endif g_assert_true (g_strv_contains (names, "text-x-generic")); #endif } diff --git a/gio/tests/desktop-app-info.c b/gio/tests/desktop-app-info.c index 6d3f4e853..87bf39dc7 100644 --- a/gio/tests/desktop-app-info.c +++ b/gio/tests/desktop-app-info.c @@ -551,7 +551,11 @@ test_actions (void) const char *expected[] = { "frob", "tweak", "twiddle", "broken", NULL }; const gchar * const *actions; GDesktopAppInfo *appinfo; + const gchar *tmpdir; gchar *name; + gchar *frob_path; + gchar *tweak_path; + gchar *twiddle_path; appinfo = g_desktop_app_info_new_from_filename (g_test_get_filename (G_TEST_DIST, "appinfo-test-actions.desktop", NULL)); g_assert_nonnull (appinfo); @@ -576,17 +580,28 @@ test_actions (void) g_assert_true (g_utf8_validate (name, -1, NULL)); g_free (name); - unlink ("frob"); unlink ("tweak"); unlink ("twiddle"); + tmpdir = g_getenv ("G_TEST_TMPDIR"); + g_assert_nonnull (tmpdir); + frob_path = g_build_filename (tmpdir, "frob", NULL); + tweak_path = g_build_filename (tmpdir, "tweak", NULL); + twiddle_path = g_build_filename (tmpdir, "twiddle", NULL); + + g_assert_false (g_file_test (frob_path, G_FILE_TEST_EXISTS)); + g_assert_false (g_file_test (tweak_path, G_FILE_TEST_EXISTS)); + g_assert_false (g_file_test (twiddle_path, G_FILE_TEST_EXISTS)); g_desktop_app_info_launch_action (appinfo, "frob", NULL); - wait_for_file ("frob", "tweak", "twiddle"); + wait_for_file (frob_path, tweak_path, twiddle_path); g_desktop_app_info_launch_action (appinfo, "tweak", NULL); - wait_for_file ("tweak", "frob", "twiddle"); + wait_for_file (tweak_path, frob_path, twiddle_path); g_desktop_app_info_launch_action (appinfo, "twiddle", NULL); - wait_for_file ("twiddle", "frob", "tweak"); + wait_for_file (twiddle_path, frob_path, tweak_path); + g_free (frob_path); + g_free (tweak_path); + g_free (twiddle_path); g_object_unref (appinfo); } diff --git a/gio/tests/file-thumbnail.c b/gio/tests/file-thumbnail.c new file mode 100644 index 000000000..5fd265f36 --- /dev/null +++ b/gio/tests/file-thumbnail.c @@ -0,0 +1,427 @@ +/* Unit tests for GFile thumbnails + * GIO - GLib Input, Output and Streaming Library + * + * Copyright (C) 2022 Marco Trevisan + * + * SPDX-License-Identifier: LGPL-2.1-or-later + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, see <http://www.gnu.org/licenses/>. + * + * Author: Marco Trevisan <marco.trevisan@canonical.com> + */ + +#include <gio/gio.h> + +#define THUMBNAIL_FAIL_SIZE "fail" + +#define THUMBNAILS_ATTRIBS ( \ + G_FILE_ATTRIBUTE_THUMBNAIL_PATH "," \ + G_FILE_ATTRIBUTE_THUMBNAILING_FAILED "," \ + G_FILE_ATTRIBUTE_THUMBNAIL_IS_VALID "," \ +) + +/* Must be kept in order, for priority */ +static const char * SIZES_NAMES[] = { + "normal", + "large", + "x-large", + "xx-large", +}; + +static GFile * +get_thumbnail_src_file (const gchar *name) +{ + const gchar *thumbnail_path; + thumbnail_path = g_test_get_filename (G_TEST_DIST, "thumbnails", + name, NULL); + + g_assert_true (g_file_test (thumbnail_path, G_FILE_TEST_IS_REGULAR)); + + return g_file_new_for_path (thumbnail_path); +} + +static gchar * +get_thumbnail_basename (GFile *source) +{ + GChecksum *checksum; + gchar *uri = g_file_get_uri (source); + gchar *basename; + + checksum = g_checksum_new (G_CHECKSUM_MD5); + g_checksum_update (checksum, (const guchar *) uri, strlen (uri)); + + basename = g_strconcat (g_checksum_get_string (checksum), ".png", NULL); + + g_checksum_free (checksum); + g_free (uri); + + return basename; +} + +static GFile * +get_expected_thumbnail_file (GFile *source, + const gchar *size) +{ + GFile *file; + gchar *basename; + + basename = get_thumbnail_basename (source); + file = g_file_new_build_filename (g_get_user_cache_dir (), + "thumbnails", + size, + basename, + NULL); + g_free (basename); + return file; +} + +static GFile * +get_failed_thumbnail_file (GFile *source) +{ + GFile *file; + gchar *basename; + + basename = get_thumbnail_basename (source); + file = g_file_new_build_filename (g_get_user_cache_dir (), + "thumbnails", THUMBNAIL_FAIL_SIZE, + "gnome-thumbnail-factory", + basename, + NULL); + g_free (basename); + return file; +} + +static gboolean +check_thumbnail_exists (GFile *source, + const gchar *size) +{ + GFile *thumbnail; + gboolean ret; + + thumbnail = get_expected_thumbnail_file (source, size); + g_assert_nonnull (thumbnail); + + ret = g_file_query_exists (thumbnail, NULL); + g_clear_object (&thumbnail); + + return ret; +} + +static gboolean +check_failed_thumbnail_exists (GFile *source) +{ + GFile *thumbnail; + gboolean ret; + + thumbnail = get_failed_thumbnail_file (source); + g_assert_nonnull (thumbnail); + + ret = g_file_query_exists (thumbnail, NULL); + g_clear_object (&thumbnail); + + return ret; +} + +static GFile * +create_thumbnail (GFile *source, + const gchar *size) +{ + GFile *thumbnail; + GFile *thumbnail_dir; + GError *error = NULL; + gchar *thumbnail_path; + + /* TODO: This is just a stub implementation to create a fake thumbnail file + * We should implement a real thumbnail generator, but we don't care here. + */ + + if (!size || g_strcmp0 (size, THUMBNAIL_FAIL_SIZE) == 0) + thumbnail = get_failed_thumbnail_file (source); + else + thumbnail = get_expected_thumbnail_file (source, size); + + thumbnail_dir = g_file_get_parent (thumbnail); + + if (!g_file_query_exists (thumbnail_dir, NULL)) + { + g_file_make_directory_with_parents (thumbnail_dir, NULL, &error); + g_assert_no_error (error); + g_clear_error (&error); + } + + g_file_copy (source, thumbnail, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &error); + g_assert_no_error (error); + + g_assert_true (g_file_query_exists (thumbnail, NULL)); + thumbnail_path = g_file_get_path (thumbnail); + g_test_message ("Created test thumbnail at %s", thumbnail_path); + + g_clear_object (&thumbnail_dir); + g_clear_error (&error); + g_free (thumbnail_path); + + return thumbnail; +} + +static GFile * +create_thumbnail_from_test_file (const gchar *source_name, + const gchar *size, + GFile **out_source) +{ + GFile *thumbnail; + GFile *source = get_thumbnail_src_file (source_name); + + thumbnail = create_thumbnail (source, size); + + if (!size || g_strcmp0 (size, THUMBNAIL_FAIL_SIZE) == 0) + { + g_assert_true (check_failed_thumbnail_exists (source)); + } + else + { + g_assert_false (check_failed_thumbnail_exists (source)); + g_assert_true (check_thumbnail_exists (source, size)); + } + + if (out_source) + *out_source = g_steal_pointer (&source); + + g_clear_object (&source); + + return thumbnail; +} + +static void +test_valid_thumbnail_size (gconstpointer data) +{ + GFile *source; + GFile *thumbnail; + GFile *f; + GError *error = NULL; + GFileInfo *info; + const gchar *size = data; + + thumbnail = create_thumbnail_from_test_file ("valid.png", size, &source); + info = g_file_query_info (source, THUMBNAILS_ATTRIBS, G_FILE_QUERY_INFO_NONE, + NULL, &error); + g_assert_no_error (error); + + g_assert_true (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH)); + g_assert_true (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_THUMBNAIL_IS_VALID)); + g_assert_false (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_THUMBNAILING_FAILED)); + + f = g_file_new_for_path (g_file_info_get_attribute_byte_string (info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH)); + g_assert_cmpstr ( + g_file_peek_path (f), + ==, + g_file_peek_path (thumbnail) + ); + + /* TODO: We can't really test this without having a proper thumbnail created + g_assert_true ( + g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_THUMBNAIL_IS_VALID)); + */ + + g_clear_object (&source); + g_clear_object (&thumbnail); + g_clear_error (&error); + g_clear_object (&info); + g_clear_object (&f); +} + +static void +test_unknown_thumbnail_size (gconstpointer data) +{ + GFile *source; + GFile *thumbnail; + GError *error = NULL; + GFileInfo *info; + const gchar *size = data; + + thumbnail = create_thumbnail_from_test_file ("valid.png", size, &source); + info = g_file_query_info (source, THUMBNAILS_ATTRIBS, G_FILE_QUERY_INFO_NONE, + NULL, &error); + g_assert_no_error (error); + + g_assert_false (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH)); + g_assert_false (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_THUMBNAIL_IS_VALID)); + g_assert_false (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_THUMBNAILING_FAILED)); + + g_clear_object (&source); + g_clear_object (&thumbnail); + g_clear_error (&error); + g_clear_object (&info); +} + +static void +test_failed_thumbnail (void) +{ + GFile *source; + GFile *thumbnail; + GError *error = NULL; + GFileInfo *info; + + thumbnail = create_thumbnail_from_test_file ("valid.png", NULL, &source); + info = g_file_query_info (source, THUMBNAILS_ATTRIBS, G_FILE_QUERY_INFO_NONE, + NULL, &error); + g_assert_no_error (error); + + g_assert_false (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH)); + g_assert_true (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_THUMBNAIL_IS_VALID)); + g_assert_true (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_THUMBNAILING_FAILED)); + + g_assert_false ( + g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_THUMBNAIL_IS_VALID)); + g_assert_true ( + g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_THUMBNAILING_FAILED)); + + g_clear_object (&source); + g_clear_object (&thumbnail); + g_clear_error (&error); + g_clear_object (&info); +} + +static void +test_thumbnails_size_priority (void) +{ + GPtrArray *sized_thumbnails; + GError *error = NULL; + GFileInfo *info; + GFile *source; + GFile *failed_thumbnail; + gsize i; + + failed_thumbnail = create_thumbnail_from_test_file ("valid.png", NULL, &source); + sized_thumbnails = g_ptr_array_new_with_free_func (g_object_unref); + + /* Checking that each thumbnail with higher priority override the previous */ + for (i = 0; i < G_N_ELEMENTS (SIZES_NAMES); i++) + { + GFile *thumbnail = create_thumbnail (source, SIZES_NAMES[i]); + GFile *f; + + g_ptr_array_add (sized_thumbnails, thumbnail); + + info = g_file_query_info (source, THUMBNAILS_ATTRIBS, + G_FILE_QUERY_INFO_NONE, NULL, &error); + g_assert_no_error (error); + + g_assert_true (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH)); + g_assert_true (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_THUMBNAIL_IS_VALID)); + g_assert_false (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_THUMBNAILING_FAILED)); + + f = g_file_new_for_path (g_file_info_get_attribute_byte_string (info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH)); + g_assert_cmpstr ( + g_file_peek_path (f), + ==, + g_file_peek_path (thumbnail) + ); + + g_clear_object (&info); + g_clear_object (&f); + } + + g_assert_cmpuint (sized_thumbnails->len, ==, G_N_ELEMENTS (SIZES_NAMES)); + + /* Now removing them in the inverse order, to check this again */ + for (i = G_N_ELEMENTS (SIZES_NAMES); i > 1; i--) + { + GFile *thumbnail = g_ptr_array_index (sized_thumbnails, i - 1); + GFile *less_priority_thumbnail = g_ptr_array_index (sized_thumbnails, i - 2); + GFile *f; + + g_file_delete (thumbnail, NULL, &error); + g_assert_no_error (error); + + info = g_file_query_info (source, THUMBNAILS_ATTRIBS, + G_FILE_QUERY_INFO_NONE, NULL, &error); + g_assert_no_error (error); + + g_assert_true (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH)); + g_assert_true (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_THUMBNAIL_IS_VALID)); + g_assert_false (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_THUMBNAILING_FAILED)); + + f = g_file_new_for_path (g_file_info_get_attribute_byte_string (info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH)); + g_assert_cmpstr ( + g_file_peek_path (f), + ==, + g_file_peek_path (less_priority_thumbnail) + ); + + g_clear_object (&info); + g_clear_object (&f); + } + + /* And now let's remove the last valid one, so that failed should have priority */ + g_file_delete (G_FILE (g_ptr_array_index (sized_thumbnails, 0)), NULL, &error); + g_assert_no_error (error); + + info = g_file_query_info (source, THUMBNAILS_ATTRIBS, G_FILE_QUERY_INFO_NONE, + NULL, &error); + g_assert_no_error (error); + + g_assert_false (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH)); + g_assert_true (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_THUMBNAIL_IS_VALID)); + g_assert_true (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_THUMBNAILING_FAILED)); + + g_assert_false ( + g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_THUMBNAIL_IS_VALID)); + g_assert_true ( + g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_THUMBNAILING_FAILED)); + + g_clear_object (&info); + + /* Removing the failed thumbnail too, so no thumbnail should be available */ + g_file_delete (failed_thumbnail, NULL, &error); + g_assert_no_error (error); + + info = g_file_query_info (source, THUMBNAILS_ATTRIBS, G_FILE_QUERY_INFO_NONE, + NULL, &error); + g_assert_no_error (error); + + g_assert_false (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH)); + g_assert_false (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_THUMBNAIL_IS_VALID)); + g_assert_false (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_THUMBNAILING_FAILED)); + + g_clear_object (&source); + g_clear_pointer (&sized_thumbnails, g_ptr_array_unref); + g_clear_object (&failed_thumbnail); + g_clear_error (&error); + g_clear_object (&info); +} + + +int +main (int argc, + char *argv[]) +{ + gsize i; + + g_test_init (&argc, &argv, G_TEST_OPTION_ISOLATE_DIRS, NULL); + + for (i = 0; i < G_N_ELEMENTS (SIZES_NAMES); i++) + { + gchar *test_path; + + test_path = g_strconcat ("/file-thumbnail/valid/", SIZES_NAMES[i], NULL); + g_test_add_data_func (test_path, SIZES_NAMES[i], test_valid_thumbnail_size); + g_free (test_path); + } + + g_test_add_data_func ("/file-thumbnail/unknown/super-large", "super-large", test_unknown_thumbnail_size); + g_test_add_func ("/file-thumbnail/fail", test_failed_thumbnail); + g_test_add_func ("/file-thumbnail/size-priority", test_thumbnails_size_priority); + + return g_test_run (); +} diff --git a/gio/tests/file.c b/gio/tests/file.c index 9a15f9726..79c6d57bb 100644 --- a/gio/tests/file.c +++ b/gio/tests/file.c @@ -1,3 +1,5 @@ +#include "config.h" + #include <locale.h> #include <string.h> #include <stdio.h> @@ -2470,10 +2472,14 @@ get_size_from_du (const gchar *path, guint64 *size) GError *error = NULL; gchar *du_path = NULL; - /* If we can’t find du, don’t try and run the test. */ +#ifndef HAVE_COCOA du_path = g_find_program_in_path ("du"); +#endif + + /* If we can’t find du, don’t try and run the test. */ if (du_path == NULL) return FALSE; + g_free (du_path); du = g_subprocess_new (G_SUBPROCESS_FLAGS_STDOUT_PIPE, @@ -3523,6 +3529,44 @@ test_query_default_handler_uri (void) } static void +test_query_zero_length_content_type (void) +{ + GFile *empty_file; + GFileInfo *file_info; + GError *error = NULL; + GFileIOStream *iostream; + + g_test_bug ("https://bugzilla.gnome.org/show_bug.cgi?id=755795"); + /* This is historic behaviour. See: + * - https://gitlab.gnome.org/GNOME/glib/-/blob/2.74.0/gio/glocalfileinfo.c#L1360-1369 + * - https://bugzilla.gnome.org/show_bug.cgi?id=755795 */ + g_test_summary ("empty files should always be considered text/plain"); + + empty_file = g_file_new_tmp ("empty-file-XXXXXX", &iostream, &error); + g_assert_no_error (error); + + g_io_stream_close (G_IO_STREAM (iostream), NULL, &error); + g_assert_no_error (error); + g_clear_object (&iostream); + + file_info = + g_file_query_info (empty_file, + G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, + G_FILE_QUERY_INFO_NONE, + NULL, &error); + g_assert_no_error (error); + +#ifndef HAVE_COCOA + g_assert_cmpstr (g_file_info_get_content_type (file_info), ==, "text/plain"); +#else + g_assert_cmpstr (g_file_info_get_content_type (file_info), ==, "public.text"); +#endif + + g_clear_object (&file_info); + g_clear_object (&empty_file); +} + +static void test_query_default_handler_file (void) { GError *error = NULL; @@ -3549,6 +3593,9 @@ test_query_default_handler_file (void) NULL, NULL, &error); g_assert_no_error (error); + g_output_stream_flush (output_stream, NULL, &error); + g_assert_no_error (error); + g_output_stream_close (output_stream, NULL, &error); g_assert_no_error (error); g_clear_object (&iostream); @@ -3574,6 +3621,9 @@ test_query_default_handler_file (void) NULL, NULL, &error); g_assert_no_error (error); + g_output_stream_flush (output_stream, NULL, &error); + g_assert_no_error (error); + g_output_stream_close (output_stream, NULL, &error); g_assert_no_error (error); g_clear_object (&iostream); @@ -3770,7 +3820,7 @@ main (int argc, char *argv[]) { setlocale (LC_ALL, ""); - g_test_init (&argc, &argv, NULL); + g_test_init (&argc, &argv, G_TEST_OPTION_ISOLATE_DIRS, NULL); g_test_add_func ("/file/basic", test_basic); g_test_add_func ("/file/build-filename", test_build_filename); @@ -3812,6 +3862,7 @@ main (int argc, char *argv[]) g_test_add_func ("/file/writev/async_all-cancellation", test_writev_async_all_cancellation); g_test_add_func ("/file/build-attribute-list-for-copy", test_build_attribute_list_for_copy); g_test_add_func ("/file/move_async", test_move_async); + g_test_add_func ("/file/query-zero-length-content-type", test_query_zero_length_content_type); g_test_add_func ("/file/query-default-handler-file", test_query_default_handler_file); g_test_add_func ("/file/query-default-handler-file-async", test_query_default_handler_file_async); g_test_add_func ("/file/query-default-handler-uri", test_query_default_handler_uri); diff --git a/gio/tests/g-file-info.c b/gio/tests/g-file-info.c index 427ebffcc..d9ad04583 100644 --- a/gio/tests/g-file-info.c +++ b/gio/tests/g-file-info.c @@ -282,6 +282,15 @@ test_g_file_info_access_time (void) NULL, &error); g_assert_no_error (error); + if (!g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_TIME_ACCESS)) + { + g_test_skip ("Skipping testing access time as it’s not supported by the kernel"); + g_file_delete (file, NULL, NULL); + g_clear_object (&file); + g_clear_object (&info); + return; + } + /* Check the access time is retrievable. */ dt = g_file_info_get_access_date_time (info); g_assert_nonnull (dt); @@ -408,9 +417,7 @@ test_g_file_info_creation_time (void) NULL, &error); g_assert_no_error (error); - /* Check the creation time is retrievable. */ - dt = g_file_info_get_creation_date_time (info); - if (!dt) + if (!g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_TIME_CREATED)) { g_test_skip ("Skipping testing creation time as it’s not supported by the kernel"); g_clear_object (&io_stream); @@ -420,6 +427,9 @@ test_g_file_info_creation_time (void) return; } + /* Check the creation time is retrievable. */ + dt = g_file_info_get_creation_date_time (info); + /* Try again with microsecond precision. */ g_clear_object (&info); info = g_file_query_info (file, diff --git a/gio/tests/gmenumodel.c b/gio/tests/gmenumodel.c index 492daf8c4..618a29eae 100644 --- a/gio/tests/gmenumodel.c +++ b/gio/tests/gmenumodel.c @@ -1318,6 +1318,7 @@ test_attribute_iter (void) iter = g_menu_model_iterate_item_attributes (G_MENU_MODEL (menu), 0); while (g_menu_attribute_iter_get_next (iter, &name, &v)) g_hash_table_insert (found, g_strdup (name), v); + g_object_unref (iter); g_assert_cmpint (g_hash_table_size (found), ==, 6); @@ -1363,19 +1364,23 @@ test_links (void) item = g_menu_item_new ("test2", NULL); g_menu_item_set_link (item, "submenu", m); g_menu_prepend_item (menu, item); + g_object_unref (item); item = g_menu_item_new ("test1", NULL); g_menu_item_set_link (item, "section", m); g_menu_insert_item (menu, 0, item); + g_object_unref (item); item = g_menu_item_new ("test3", NULL); g_menu_item_set_link (item, "wallet", m); g_menu_insert_item (menu, 1000, item); + g_object_unref (item); item = g_menu_item_new ("test4", NULL); g_menu_item_set_link (item, "purse", m); g_menu_item_set_link (item, "purse", NULL); g_menu_append_item (menu, item); + g_object_unref (item); g_assert_cmpint (g_menu_model_get_n_items (G_MENU_MODEL (menu)), ==, 4); @@ -1456,6 +1461,7 @@ test_convenience (void) g_object_unref (m1); g_object_unref (m2); + g_object_unref (sub); } static void diff --git a/gio/tests/meson.build b/gio/tests/meson.build index c3e4e4cb3..e7fa812c4 100644 --- a/gio/tests/meson.build +++ b/gio/tests/meson.build @@ -27,6 +27,8 @@ if cc.has_header('pty.h') endif endif +test_cpp_args = test_c_args + if host_machine.system() == 'windows' common_gio_tests_deps += [iphlpapi_dep, winsock2, cc.find_library ('secur32')] endif @@ -61,6 +63,7 @@ gio_tests = { 'data-input-stream' : {}, 'data-output-stream' : {}, 'error': {}, + 'file-thumbnail' : {}, 'fileattributematcher' : {}, 'filter-streams' : {}, 'giomodule' : { @@ -130,8 +133,19 @@ if have_cxx gio_tests += { 'cxx' : { 'source' : ['cxx.cpp'], + 'suite': ['C++'], }, } + + foreach std, arg: cxx_standards + gio_tests += { + 'cxx-@0@'.format(std) : { + 'source' : ['cxx.cpp'], + 'suite' : ['cpp'], + 'cpp_args' : [arg], + }, + } + endforeach endif test_extra_programs = { @@ -213,7 +227,7 @@ if host_machine.system() != 'windows' } # LD_PRELOAD modules don't work so well with AddressSanitizer - if have_rtld_next and get_option('b_sanitize') == 'none' + if have_rtld_next and get_option('default_library') != 'static' and get_option('b_sanitize') == 'none' gio_tests += { 'gsocketclient-slow' : { 'depends' : [ @@ -222,6 +236,7 @@ if host_machine.system() != 'windows' name_prefix : '', dependencies: libdl_dep, install_dir : installed_tests_execdir, + install_tag : 'tests', install: installed_tests_enabled, ) ], @@ -419,6 +434,7 @@ if host_machine.system() != 'windows' c_args : test_c_args, dependencies : common_gio_tests_deps, install_dir : installed_tests_execdir, + install_tag : 'tests', install : installed_tests_enabled) gio_tests += { @@ -544,6 +560,7 @@ foreach appinfo_test_desktop_file : appinfo_test_desktop_files input: appinfo_test_desktop_file + '.in', output: appinfo_test_desktop_file, install_dir: installed_tests_execdir, + install_tag: 'tests', configuration: cdata, ) else @@ -566,11 +583,24 @@ if installed_tests_enabled 'org.gtk.test.dbusappinfo.flatpak.desktop', 'test1.overlay', install_dir : installed_tests_execdir, + install_tag : 'tests', + ) + install_subdir('x-content', + install_dir : installed_tests_execdir, + install_tag : 'tests', + ) + install_subdir('desktop-files', + install_dir : installed_tests_execdir, + install_tag : 'tests', + ) + install_subdir('thumbnails', + install_dir : installed_tests_execdir, + install_tag : 'tests', + ) + install_subdir('cert-tests', + install_dir : installed_tests_execdir, + install_tag : 'tests', ) - install_subdir('x-content', install_dir : installed_tests_execdir) - install_subdir('desktop-files', install_dir : installed_tests_execdir) - install_subdir('thumbnails', install_dir : installed_tests_execdir) - install_subdir('cert-tests', install_dir : installed_tests_execdir) cdata = configuration_data() cdata.set('installed_tests_dir', installed_tests_execdir) @@ -579,10 +609,17 @@ if installed_tests_enabled input: installed_tests_template, output: 'static-link.test', install_dir: installed_tests_metadir, + install_tag: 'tests', configuration: cdata ) - install_subdir('static-link', install_dir : installed_tests_execdir) - install_data('static-link.py', install_dir : installed_tests_execdir) + install_subdir('static-link', + install_dir : installed_tests_execdir, + install_tag : 'tests', + ) + install_data('static-link.py', + install_dir : installed_tests_execdir, + install_tag : 'tests', + ) monitor_tests = [ 'memory-monitor-dbus', @@ -600,6 +637,7 @@ if installed_tests_enabled input: installed_tests_template_tap, output: monitor_test + '.test', install_dir: installed_tests_metadir, + install_tag: 'tests', configuration: cdata ) cdata = configuration_data() @@ -608,6 +646,7 @@ if installed_tests_enabled input: monitor_test + '.py.in', output: monitor_test + '.py', install_dir : installed_tests_execdir, + install_tag : 'tests', configuration: cdata, ) endforeach @@ -617,24 +656,27 @@ if meson.can_run_host_binaries() compiler_type = '--compiler=@0@'.format(cc.get_id()) - plugin_resources_c = custom_target('plugin-resources.c', - input : 'test4.gresource.xml', - output : 'plugin-resources.c', - command : [glib_compile_resources, - compiler_type, - '--target=@OUTPUT@', - '--sourcedir=' + meson.current_source_dir(), - '--internal', - '--generate-source', - '--c-name', '_g_plugin', - '@INPUT@']) + if get_option('default_library') != 'static' + plugin_resources_c = custom_target('plugin-resources.c', + input : 'test4.gresource.xml', + output : 'plugin-resources.c', + command : [glib_compile_resources, + compiler_type, + '--target=@OUTPUT@', + '--sourcedir=' + meson.current_source_dir(), + '--internal', + '--generate-source', + '--c-name', '_g_plugin', + '@INPUT@']) - shared_module('resourceplugin', 'resourceplugin.c', plugin_resources_c, - link_args : export_dynamic_ldflags, - dependencies : common_gio_tests_deps, - install_dir : installed_tests_execdir, - install : installed_tests_enabled - ) + shared_module('resourceplugin', 'resourceplugin.c', plugin_resources_c, + link_args : export_dynamic_ldflags, + dependencies : common_gio_tests_deps, + install_dir : installed_tests_execdir, + install_tag : 'tests', + install : installed_tests_enabled + ) + endif # referenced by test2.gresource.xml big_test_resource = custom_target( @@ -654,6 +696,7 @@ if meson.can_run_host_binaries() '--internal', '@INPUT@'], install_dir : installed_tests_execdir, + install_tag : 'tests', install : installed_tests_enabled) test_resources2_c = custom_target('test_resources2.c', @@ -766,6 +809,7 @@ if meson.can_run_host_binaries() '--internal', '@INPUT@'], install_dir : installed_tests_execdir, + install_tag : 'tests', install : installed_tests_enabled) # Create resource data file @@ -847,15 +891,18 @@ foreach test_name, extra_args : gio_tests input: installed_tests_template_tap, output: test_name + '.test', install_dir: installed_tests_metadir, + install_tag: 'tests', configuration: test_conf ) endif exe = executable(test_name, [source, extra_sources], c_args : test_c_args + extra_args.get('c_args', []), + cpp_args : test_cpp_args + extra_args.get('cpp_args', []), dependencies : common_gio_tests_deps + extra_args.get('dependencies', []), install_rpath : extra_args.get('install_rpath', ''), install_dir: installed_tests_execdir, + install_tag: 'tests', install: install, ) @@ -885,6 +932,7 @@ foreach program_name, extra_args : test_extra_programs c_args : test_c_args, dependencies : common_gio_tests_deps + extra_args.get('dependencies', []), install_dir : installed_tests_execdir, + install_tag : 'tests', install : install, ) endforeach @@ -902,6 +950,7 @@ foreach test_name : python_tests install_data( files(test_name), install_dir: installed_tests_execdir, + install_tag: 'tests', install_mode: 'rwxr-xr-x', ) @@ -913,6 +962,7 @@ foreach test_name : python_tests input: installed_tests_template_tap, output: test_name + '.test', install_dir: installed_tests_metadir, + install_tag: 'tests', configuration: test_conf, ) endif @@ -923,8 +973,12 @@ if installed_tests_enabled install_data( files('taptestrunner.py'), install_dir: installed_tests_execdir, + install_tag: 'tests', ) endif subdir('services') -subdir('modules') + +if get_option('default_library') != 'static' + subdir('modules') +endif diff --git a/gio/tests/services/meson.build b/gio/tests/services/meson.build index fd5117e23..b6a901bc5 100644 --- a/gio/tests/services/meson.build +++ b/gio/tests/services/meson.build @@ -25,6 +25,7 @@ foreach service_file : dbus_service_files ) install_data(meson.current_build_dir() / service_file + '.to-install', install_dir: installed_tests_execdir / 'services', + install_tag: 'tests', rename: [service_file], ) endif diff --git a/gio/tests/unix-streams.c b/gio/tests/unix-streams.c index 407a67dbd..e32e2861d 100644 --- a/gio/tests/unix-streams.c +++ b/gio/tests/unix-streams.c @@ -146,7 +146,9 @@ main_thread_skipped (GObject *source, GAsyncResult *res, gpointer user_data) if (g_cancellable_is_cancelled (main_cancel)) { + g_assert_error (err, G_IO_ERROR, G_IO_ERROR_CANCELLED); do_main_cancel (out); + g_clear_error (&err); return; } @@ -180,6 +182,7 @@ main_thread_read (GObject *source, GAsyncResult *res, gpointer user_data) if (g_cancellable_is_cancelled (main_cancel)) { + g_assert_error (err, G_IO_ERROR, G_IO_ERROR_CANCELLED); do_main_cancel (out); g_clear_error (&err); return; @@ -217,6 +220,7 @@ main_thread_wrote (GObject *source, GAsyncResult *res, gpointer user_data) if (g_cancellable_is_cancelled (main_cancel)) { + g_assert_error (err, G_IO_ERROR, G_IO_ERROR_CANCELLED); do_main_cancel (out); g_clear_error (&err); return; |