Commit Graph

2474 Commits

Author SHA1 Message Date
Michael Catanzaro
85b53d6317 Merge branch 'data-input-stream-optimisation' into 'main'
gdatainputstream: Use memchr() for the multi-stop-char case too

See merge request GNOME/glib!4352
2024-10-17 15:42:03 +00:00
Philip Withnall
50ccb04c71
tests: Fix 1-byte overread in data-input-stream tests
Commit 760a6f647 rearranged how the lengths are calculated for the test
data and added `escape_data_string()` so they could be printed safely.

Unfortunately there was a miscount in the length of the first test
vector in `test_read_upto()`: there are 31 bytes in the string literal,
plus one nul terminator which is added by the compiler. The quoted
string length was 32 bytes. This should be fine (explicitly including
the nul delimiter), but then `escape_data_string()` adds another byte to
the length because it assumes the nul delimiter has *not* been included
in the count.

Changing the string length from 32 to 31 breaks the tests, as the final
component of the data is then the wrong length, so add an additional
explicit nul byte to the string literal so that it matches the length.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-10-17 11:42:49 +01:00
Alan Coopersmith
b6004c70cc tests: add casts to avoid -Wformat errors on 32-bit Solaris builds
For historical reasons, pid_t & mode_t are defined as long instead
of int for 32-bit processes in the Solaris headers, and even though
they are the same size, gcc issues -Wformat headers if you try to
print them with "%d" and "%u" instead of "%ld" & "%lu".

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2024-10-14 18:29:29 -07:00
Philip Withnall
9f70c964a0
gdatainputstream: Fix length return value on UTF-8 validation failure
The method was correctly returning an error from
`g_data_input_stream_read_line_utf8()` if the line contained invalid
UTF-8, but it wasn’t correctly setting the returned line length to 0.
This could have caused problems if callers were basing subsequent logic
on the length and not the return value nullness or `GError`.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

oss-fuzz#372819437
2024-10-12 13:02:27 +01:00
Philip Withnall
066fefafa0
tests: Use g_assert_*() rather than g_assert() in GDataInputStream tests
It won’t get compiled out with `G_DISABLE_ASSERT`.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-10-12 12:56:00 +01:00
Philip Withnall
6b15af3c4c
gio: Use g_steal_handle_id() with signal unsubscriptions
This makes no functional changes, but does tidy the code up a bit and
means `g_steal_handle_id()` gets a bit more testing.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-10-08 13:57:30 +01:00
Christian Hergert
760a6f6477 gio/tests: add test for single escape character
Converts the existing test to a loop and adds another test case which
tests a single stop character, \0 in this case.
2024-10-04 12:46:11 -07:00
Julian Sparber
c8e80132d8 tests: Add tests for launching default for file/uri via XDG portal 2024-10-01 19:03:37 +02:00
Julian Sparber
59877f5cc6 tests: Add launch context to g_app_info_launch_uris() tests
This ensure that `g_app_info_launch_uris()` uses and set the correct
activation token.
2024-10-01 18:25:52 +02:00
Philip Withnall
2b5d3b5831 Merge branch 'fake-document-portal-in-process' into 'main'
tests: Move fake-document-portal subprocess inside dbus-appinfo test

See merge request GNOME/glib!4311
2024-10-01 15:38:30 +00:00
Philip Withnall
6b2cc430e0
tests: Run dbus-appinfo tests with G_TEST_OPTION_ISOLATE_DIRS
Eliminate any possibility of them accidentally using the user’s
actual home directory.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-10-01 15:22:46 +01:00
Philip Withnall
d7e368f206
tests: Move fake-document-portal subprocess inside dbus-appinfo test
For the reasons given in
https://gitlab.gnome.org/GNOME/glib/-/merge_requests/4176#note_2233317,
it’s best to not rely on subprocesses when writing tests. Spawning a
subprocess can go wrong, getting feedback and assertion data from a
subprocess is a pain, and making sure the subprocess is killed properly
at the end of the test is hard to get right.

For tests where we are trying to mock a D-Bus service, it’s much more
reliable to run that service in-process (either in the main thread or in
a separate thread).

So, do that for the `fake-document-portal` former subprocess in the
`dbus-appinfo` test: move it to a worker thread.

This speeds the test up, simplifies the build slightly, and should make
the test run more reliable.

In particular, it provides a pattern for future `fake-*-portal` tests to
be built off. This is particularly useful for more complex portals,
where data needs to be relayed back from the mock portal service to the
unit test to check that the code under test has behaved properly. That’s
a pain to do from a subprocess.

Delete the `org.freedesktop.portal.Documents.service` file because we no
longer need to rely on D-Bus service activation within the test, as
we’re setting up the mock service thread explicitly now.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-10-01 15:22:40 +01:00
Arjan Molenaar
fd6c1f34da macos: Fix URL launcher
URLs should be provided to the AppInfo.launch_uris() function.
2024-09-27 21:45:33 +02:00
Philip Withnall
d7bb4664e7
tests: Add a way to get the mock session bus address in tests
This is better than using `g_getenv ("DBUS_SESSION_BUS_ADDRESS")` as it
will fail more explicitly if the mock bus somehow isn’t running.

This will be used in an upcoming commit.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-09-27 17:08:21 +01:00
Ting-Wei Lan
095fd5a06b tests: FreeBSD doesn't use glibc
FreeBSD has its own libc implementation. It is maintained as a part of
the operating system, not a copy of glibc.
2024-09-27 11:41:33 +08:00
Christian Hergert
0f95b18a7b gio: use g_variant_builder_init_static()
All uses of g_variant_builder_init() in gio are safe to translate to the
new g_variant_builder_init_static() alternative as the type will outlive
the call to g_variant_builder_end() (or is already static in nature).
2024-09-26 12:48:16 +01:00
Gleb Popov
697118dfd5 Adapt testfilemonitor.c for libinotify-kqueue backend
The backend mimics inotify but is still subject to kevent idionsyncracies.
2024-09-19 09:55:01 +03:00
Philip Withnall
e888e7d497
tests: Add some explicit float → int casts
This avoids some false positive warnings from `-Wfloat-conversion`.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-09-17 23:54:55 +01:00
Philip Withnall
7a7d8d548a Merge branch 'wfloat-conversion' into 'main'
build: Enable -Wfloat-conversion and fix warnings

See merge request GNOME/glib!4126
2024-09-17 17:57:11 +00:00
Philip Withnall
acd4a78173 Merge branch '3465-gresource-error-allocations' into 'main'
gresource: Reduce allocations in g_resources_*() functions

Closes #3465

See merge request GNOME/glib!4242
2024-09-17 13:34:06 +00:00
Philip Withnall
b5cab7c6b9
tests: Add g_resource_has_children() test for empty path
To get the code branch coverage up to 100% because it’s not that hard.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-09-12 22:53:26 +01:00
Matthias Clasen
a14241c895 resource: Add g_resource[s]_has_children
These functions avoid allocating the children array when it is
not needed.
2024-09-12 21:15:55 +01:00
Benjamin Gilbert
51e3e7d9ae build: Bump Meson dependency to 1.4.0
Meson 1.5.1 is available in the fd.o SDK and in Debian testing, so the
glib Meson policy says we can update.  Update the minimum only as far as
1.4.0 because we don't yet have a need for 1.5.0.

This allows us to:

- Use file.full_path() to avoid deprecation warnings on str.format(file).
- Set c_std=gnu99,c99 to avoid deprecation warnings with gnu99 on MSVC.

Update all the CI builds to use the latest 1.4.x patch release, 1.4.2.

The FreeBSD runner cannot be updated via `gitlab-ci.yml`, so will be
broken for now.

Similarly, the macOS build will not work unless `-Dc_std=gnu99` is
specified at configure time, due to
https://github.com/mesonbuild/meson/issues/13639.
2024-09-12 19:15:05 +01:00
Philip Withnall
b2d8394f17
tests: Add more coverage for GResource overlays
Test more API entry points with overlays.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3465
2024-09-09 17:39:39 +01:00
Philip Withnall
c5e196f0c0
tests: Add more G_RESOURCE_ERROR_NOT_FOUND unit tests
Add coverage for handling of this situation for more API entry points.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3465
2024-09-09 17:38:55 +01:00
Philip Withnall
7ed386a10b
tests: Add test for decompression failure in GResource
This was one of the code paths not currently covered by unit tests, so
let’s add a test for it.

This tests what happens when a structurally valid GResource file, but
with a corrupt entry for a compressed file, is loaded.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3465
2024-09-09 17:37:52 +01:00
Philip Withnall
f1c639c7dc
tests: Re-indent block in resources test
It was slightly over-indented.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-09-09 17:36:24 +01:00
Philip Withnall
27c02a0be4
tests: Test against a sample mtab file in unix-mounts for getmntent()
The test in `unix-mounts` to see whether `g_unix_mounts_get_from_file()`
can parse an example file was working fine when GLib is built with
libmount, but not when built without it (and hence typically using
`getmntent()`).

This is because libmount supports mountinfo files (like
`/proc/self/mountinfo`), but `getmntent()` only supports mount files
(like `/proc/mounts`). The test was written only with the former.

So, change the test to use mount files when GLib is built without
libmount support.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Fixes: #3456
2024-08-27 12:13:35 +01:00
Philip Withnall
ce71da63ba
Revert "gio/tests/cancellable: Explain failure on GCancellableSource tests on valgrind"
This reverts commit 365411ea32.

Since commit 3a07b2abd4, issue 2309 has
been fixed, so we should no longer have failures from valgrind here.
2024-08-20 13:02:43 +01:00
Philip Withnall
71cd903118
tests: Run expected-to-hang cancellable tests in subprocesses
These tests are expected to cause a thread to deadlock. That seems to be
fine with glibc on Linux, but the glibc version on FreeBSD can detect
the deadlock, and aborts the whole test process with:
```
GLib (gthread-posix.c): Unexpected error from C library during 'pthread_mutex_lock': Resource deadlock avoided.  Aborting.
```

This is fair enough.

To avoid this causing the test suite to fail, run those two tests in
subprocesses. This also means we’re not carrying a deadlocked thread
around for the rest of the test suite.

Improves on commit 62192925b6.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-08-20 13:02:36 +01:00
Philip Withnall
f4aceb0e91 Merge branch 'wip/pwithnall/unix-mount-tests' into 'main'
gunixmounts: Add mount point/entry getters from files and add tests based on them

See merge request GNOME/glib!4163
2024-08-15 14:25:52 +00:00
Philip Withnall
04ee011171
tests: Add tests for handling of fstab and mtab files
While GLib doesn’t parse these files, it does provide API to access the
fields from them, and does implement some logic based on options fields
in them. It would be nice to be able to test that, and get coverage of
the methods for `GUnixMountPoint` and `GUnixMountEntry`.
2024-08-14 15:52:02 +01:00
Arjan Molenaar
2ad61ed0ee Fix formatting issues 2024-08-10 19:42:32 +02:00
Arjan Molenaar
d23c781e7b macos: Tune launch results for CI
It looks like we have no Finder running.
2024-08-10 19:34:29 +02:00
Arjan Molenaar
1053c016d9 macos: Add test case for invalid scheme
You may not always know which schemes are available.

The library should not bail out, but only show
an informal message. It's the responsibility of
the application to deal with invalid URI schemes.
2024-08-10 19:34:29 +02:00
Arjan Molenaar
fac8a8c8d8 macos: Add test for async launcher
The test brings a Finder window to the front. It's not ideal,
but I have no better idea at the moment. It would be cool if we
can make the test case register itself as handler for a particular
uri scheme, but I have no idea how to do that.
2024-08-10 19:34:29 +02:00
Marco Trevisan (Treviño)
3a07b2abd4 GCancellable: Use per-instance mutex logic instead of global critical sections
GCancellable is meant to be used in multi-thread operations but all the
cancellable instances were sharing a single mutex to synchronize them
which can be less optimal when many instances are in place.
Especially when we're doing a lock/unlock dances that may leave another
thread to take the control of a critical section in an unexpected way.

This in fact was leading to some races in GCancellableSources causing
leaks because we were assuming that the "cancelled" callback was always
called before our dispose implementation.

As per this, use per-instance mutexes.

The lock is also now used only to protect the calls that may interact
with cancelled state or that depends on that, as per this we can just
reduce it to the cancel and reset case, other than to the connect one to
prevent the race that we could have when connecting to a cancellable
that is reset from another thread.

We don't really need to release the locks during callbacks now as they
are per instance, and there's really no function that we allowed to call
during a ::cancelled signal callback that may require an unlocked state.
This could been done in case with a recursive lock, that is easy enough
to implement but not really needed for this case.

Fixes: #2309, #2313
2024-07-24 00:21:35 +02:00
Marco Trevisan (Treviño)
0a8cb10f22 gio/tests: Ensure that a GCancellableSource can be used muliple times
Closes: #774
2024-07-24 00:21:35 +02:00
Philip Withnall
929f2ae06b
tests: Fix compilation of resolver-parsing test on FreeBSD
This fixes commit cdcb179808.

`dn_comp()` is needed to build fake DNS records for most of the tests in
this file. The new ownership test is no exception.

See https://gitlab.gnome.org/GNOME/glib/-/jobs/4058481

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-07-09 21:41:03 +01:00
Philip Withnall
8d0bf4ed39
tests: Make an error check less specific in gsocketclient-slow
On Linux the error will be `G_IO_ERROR_CONNECTION_REFUSED`, but on macOS
it will be `G_IO_ERROR_TIMED_OUT`. Both errors seem reasonable to me, so
let’s not specifically require one of them.

See: https://gitlab.gnome.org/GNOME/glib/-/merge_requests/4104#note_2161451

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-07-09 17:40:16 +01:00
Philip Withnall
8320085557 Merge branch 'andyholmes/resolver-ownership' into 'main'
gthreadedresolver: ref-sink returned records in lookup_records()

Closes #3393

See merge request GNOME/glib!4110
2024-07-05 06:26:51 +00:00
Andy Holmes
cdcb179808
tests: ensure DNS records are full-reference variants
For each test expected to return valid DNS records, test that the
record variants are not floating references.

Also add an test which checks this explicitly for a simple TXT record.
2024-07-04 17:37:44 -07:00
Benoit Pierre
caf7f8ef49 tests: fix some Windows testsuite failures
Add test dependencies on the 2 spawn helpers required on Windows.
2024-07-04 19:35:47 +00:00
Gleb Popov
6daebde9a6 Fix gsocketclient-slow test on FreeBSD
The "port" variable ends up being 0 even after successful g_socket_bind.
Use g_socket_get_local_address() to actually get a correct port number.
2024-06-30 15:37:22 +03:00
Philip Withnall
ebe609eeef
tests: Rearrange double/int comparisons in srvtarget to avoid casts
By keeping `expected` as a `double` for longer, we avoid having to cast
when populating the elements of `ordering`, to avoid
`-Wfloat-conversion` warnings.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3405
2024-06-28 14:25:38 +01:00
Gary Li
d64336e1a9 g_output_stream_write: Allow NULL buffer if count is 0
We currently fail a buffer != NULL assertion if buffer is NULL and count is 0. Allow this case without critical assertions.

Fixes https://gitlab.gnome.org/GNOME/glib/-/issues/3402
2024-06-26 14:18:41 -04:00
rong wang
478127e074 GLocalFile: support trashing long file name
When the file name is too long (for example, more than 238 bytes on
ext4), this will cause the creation of the .trashinfo file to fail.
Let's shorten the .trashinfo filename in this case, after all the
trash specification only requires unique filenames (see
`Contents of a trash directory` section in
https://specifications.freedesktop.org/trash-spec/trashspec-latest.html).
2024-06-19 10:27:33 +01:00
Philip Withnall
cce6ca8c88
tests: Improve 4GB file loading test to work on i386
This should test the limits of loading 4GB files on i386 platforms, such
as the Hurd CI runner. On such platforms, `sizeof(size_t) == 4`.

This should fix the compiler warning from
https://gitlab.gnome.org/GNOME/glib/-/jobs/3989442:
```
../gio/tests/file.c:2931:51: error: left shift count >= width of type [-Werror=shift-count-overflow]
 2931 | static const gsize testfile_4gb_size = ((gsize) 1 << 32) + (1 << 16); /* 4GB + a bit */
      |                                                   ^~
cc1: all warnings being treated as errors
```

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-06-18 12:58:51 +01:00
Philip Withnall
1f838b061b
tests: Skip >4GB file tests unless running tests in slow/thorough mode
They take too long to include in a normal test run. They’ll still be run
in CI once a week as part of our scheduled slow test job.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-06-17 13:03:08 +01:00
Philip Withnall
a8be45204e tests: Fix a typo in a test name in the file test suite
Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-06-17 13:03:05 +01:00