Commit Graph

2020 Commits

Author SHA1 Message Date
Philip Withnall
59fc26cbaa gio: Add some missing license and copyright headers
These headers have all been written manually, by looking through the git
log for each file and noting the copyright of each significant
contribution.

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

Helps: #1415
2022-07-05 12:30:46 +01:00
Philip Withnall
41691cc4c8 Merge branch 'more-spdx' into 'main'
Add more SPDX license headers

See merge request GNOME/glib!2706
2022-07-05 11:06:49 +00:00
Philip Withnall
bd56345f23 Merge branch 'move_assert-msg-test' into 'main'
Convert tests/assert-msg-test* to glib/tests/assert-msg-test*

Closes #1434

See merge request GNOME/glib!2767
2022-06-28 10:41:59 +00:00
Philip Withnall
164d3759fb Merge branch 'mcatanzaro/#2597' into 'main'
Avoid crashing when GProxyResolver returns weird results, and related fixes

Closes #2597

See merge request GNOME/glib!2742
2022-06-28 10:33:33 +00:00
Emmanuel Fleury
5699b7b169 Fix some coding style issues in python tests pointed out by black and flake8 2022-06-28 11:19:21 +01:00
Michael Catanzaro
1738fad172 proxyaddressenumerator: set error parameter more thoughtfully
It doesn't make sense for a proxy resolver to return NULL without an
error on the first call. Whereas a DNS resolver would do this to
indicate that a query completed successfully but found no results, a
proxy resolver should return "direct://" instead. Therefore, if we are
going to return NULL, we ought to have an error as well. Let's make sure
this actually happens by adding some fallback errors just in case
GProxyResolver feeds us weird results.

Additionally, we should not return any errors except
G_IO_ERROR_CANCELLED after the very first iteration. This is an API
contract of GSocketAddressEnumerator. Let's add some checks to ensure
this.

Note that we have inadequate test coverage for GProxyAddressEnumerator.
It's tested here only via GSocketClient. We could do a bit better by
testing it directly as well. For example, I've added tests to see what
happens when GProxyResolver returns both a valid and an invalid URI, but
it's not so interesting here because GSocketClient always uses the valid
result and ignores the error from GProxyAddressEnumerator.

Fixes #2597
2022-06-27 15:10:05 -05:00
Michael Catanzaro
4667f5980a proxy-test: fix check for simple:// URI scheme
This has no practical impact, since it's only a test, and none of the
test code would have hit this bug, but the GTestProxyResolver's check to
see if the URI scheme is simple:// currently only compares the first
four bytes of the string, so it's actually only checking for the "simp"
and would match anything else after that, e.g. "simpleton://". This is
surely not intended.
2022-06-27 14:23:51 -05:00
Philip Withnall
087272777b tests: Fix incorrect basename comparison in gsubprocess test
This was causing intermittent failures on macOS, depending on whether
the tmpdir ended with a `/` or `/some-dir`. `g_strrstr()` is not the
right function to use to extract a basename from a path, for this
reason.

When it failed, the macOS test was failing with:
```
ok 16 /gsubprocess/env
Bail out! GLib-GIO:ERROR:../gio/tests/gsubprocess.c:1507:test_cwd: assertion failed (basename == tmp_lineend_basename): ("/T\n" == "/\n")
```

The test now passes reliably, which means that it can be removed from
the list of expected failures on macOS.

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

Helps: #1392
2022-06-27 15:02:55 +01:00
Philip Withnall
059a5fd4da tests: Skip various default handler tests on macOS
They are not currently supported by `gosxappinfo.m`.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-06-24 12:43:18 +01:00
Philip Withnall
a98bd895d5 tests: Fix a path comparison in the file tests
On macOS the comparison was failing as one of the paths had a trailing
slash while the other didn’t.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-06-24 12:27:45 +01:00
Philip Withnall
191923ce61 Merge branch 'wip/smcv/none-flags' into 'main'
Add a NONE or DEFAULT member to most flags-sets

See merge request GNOME/glib!2576
2022-06-23 16:09:38 +00:00
Philip Withnall
5655af6ada Merge branch 'more-async-gfile' into 'main'
gfile (and GAppInfo): Add some missing async APIs and ensure async calls always use them

See merge request GNOME/glib!2717
2022-06-23 11:49:55 +00:00
Simon McVittie
cc528f6c2e giomodule test: Don't pass a magic number to g_test_trap_subprocess()
This worked, but seems like bad style.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-06-23 10:47:19 +01:00
Simon McVittie
de8672fe0b gtestutils: Add G_TEST_SUBPROCESS_DEFAULT, G_TEST_TRAP_DEFAULT
This makes calls to test subprocesses with default behaviour more
self-documenting.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-06-23 10:47:13 +01:00
Marco Trevisan (Treviño)
8a880e1379 GAppInfo: Make g_app_info_launch_default_for_uri_async fully async
Despite the name, we still used blocking calls to get the default app
for URI, now that we have an async implementation of the API to get the
default implementation for URI scheme, we can remove the blocking calls.
2022-06-22 20:07:30 +02:00
Marco Trevisan (Treviño)
8aee5fc628 GAppInfo: Add async API to get default Application for URI scheme
Make possible to fetch the default application for URI scheme in a
thread without using blocking I/O.
2022-06-22 20:07:30 +02:00
Marco Trevisan (Treviño)
73b29e8f6e gio/tests: Add test case for g_app_info_launch_default_for_uri
We did not check whether this function worked before, so add a simple
test case for it, providing some test functions to make it possible to
reply the same behavior
2022-06-22 20:07:30 +02:00
Marco Trevisan (Treviño)
6fef60b65c GDesktopAppInfo: Ensure that URI scheme is a valid argument 2022-06-22 20:07:30 +02:00
Marco Trevisan (Treviño)
44dbd43170 GAppInfo: Add async API to get default Application for content type
Make possible to fetch the Application for default content type in a
thread without using blocking I/O.
2022-06-22 20:07:30 +02:00
Marco Trevisan (Treviño)
abae8c1f05 gio/tests: Add test cases for g_file_query_default_handler[_async]
Simulating having default handlers, however this is tested only in unix
as windows may behave differently, so let's just skip it for now.
2022-06-22 20:07:30 +02:00
Marco Trevisan (Treviño)
22e951e6ac gfile: Add Async API to create a temporary directory and return as GFile
While it's possible to create a directory synchronously via
g_dir_make_tmp(), there's no such API that performs it asynchronously.

So implement it using GFile, using a thread to perform such task.
2022-06-22 20:07:30 +02:00
Marco Trevisan (Treviño)
fa24391529 gfile: Add API to create a new temporary file asynchronously
Make possible to create a new gfile with a temporary name in async
way, using the same API of g_file_new_tmp().
2022-06-22 20:07:30 +02:00
Marco Trevisan (Treviño)
b64fd312da gerror: Add an utility function to get the GIO Error from GFileError
When GIO functions are using GLib file utils functions we expect to
return a GIO Error, so provide a way to map such error values.
2022-06-22 20:07:25 +02:00
Philip Withnall
75a39114d8 tests: Fix non-TAP output from socket test
This was breaking strict TAP parsers, such as Meson’s.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-06-21 12:50:31 +01:00
Philip Withnall
8dde15a5b3 tests: Fix gengiotypefuncs.py helper script
It seems this script has potentially never worked properly under Python
3. It’s supposed to list all the `_get_type()` functions it can find in
the GIO headers, but since the regex string passed to `re.search()` was
not a Python regex, nothing was matching.

Fix that, and do another few small cleanups to the script.

This makes the `defaultvalue` test not skip all the types.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-06-21 12:50:31 +01:00
Philip Withnall
f977ddf34f tests: Fix non-TAP output from debugcontroller test
When running under a strict TAP parser this was previously producing
problematic non-conforming output.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-06-21 12:50:31 +01:00
Marco Trevisan (Treviño)
e5841beba6 gioerror: Map ENOSYS to G_IO_ERROR_NOT_SUPPORTED
If a wrong syscall is used, we can assume that such feature is not
supported at higher level.
2022-06-15 20:44:10 +02:00
Marco Trevisan (Treviño)
587f5f25d0 gioerror: Map ENETDOWN to G_IO_ERROR_NETWORK_UNREACHABLE 2022-06-15 20:44:10 +02:00
Marco Trevisan (Treviño)
3d6f843097 gioerror: Map ENOMSG, EBADMSG and ENODATA to G_IO_ERROR_INVALID_DATA 2022-06-15 20:44:10 +02:00
Marco Trevisan (Treviño)
19417b1a67 gioerror: Map ENFILE to G_IO_ERROR_TOO_MANY_OPEN_FILES
ENFILE stands for "Too many open files in system", so we can definitely
group it together with EMFILE ("Too many open files").
2022-06-15 20:44:10 +02:00
Marco Trevisan (Treviño)
6bc6b7ef30 gioerror: Map ETXTBSY to G_FILE_ERROR_BUSY
It's a busy text file, but we don't care much about specifics so we
can just return the generic busy error.
2022-06-15 20:44:10 +02:00
Marco Trevisan (Treviño)
d2ca48ad97 gioerror: Add G_IO_ERROR_NO_SUCH_DEVICE to map ENODEV 2022-06-15 20:43:56 +02:00
Marco Trevisan (Treviño)
9e09894414 gioerror: Handle EMLINK error as too-many-links error
This used to be a FreeBSD only error but it's actually defined also in
linux.
2022-06-15 20:41:53 +02:00
Marco Trevisan (Treviño)
35c6c5c663 tests: Add unit test for GIOErrorEnum conversion functions 2022-06-15 20:41:52 +02:00
Marco Trevisan (Treviño)
04718a9692 gfile: Implement interface API to make symbolic links asynchronously
The interface was ready for this API but it was not provided.

So implement this, using a thread that calls the sync API for now.

Add tests.

Helps with: GNOME/glib#157
2022-06-15 19:49:38 +02:00
Marco Trevisan (Treviño)
fe9e35624a gfile: Check that using NULL symlink_value as a programmer error
And also ensure that a null strings gives an error.
2022-06-15 19:49:38 +02:00
Benjamin Otte
51840393b2 liststore: Add tests for n-items property 2022-06-09 17:08:42 +02:00
Philip Withnall
3b87740e3e tests: Fix defined-but-not-used variables if HAVE_OPENPTY is undefined
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-06-07 19:12:46 +01:00
Philip Withnall
14f4b38fb1 tests: NULL-initialise some variables to help scan-build
Dynamically, these will only ever be used after they’ve been initialised
due to correct checking of `use_udp` throughout the test. However,
that’s a global variable and the static analyser is assuming it might
change value. So help it out by NULL-initialising the variables so they
can never be used uninitialised.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-06-07 11:04:25 +01:00
Simon McVittie
36da11550c Merge branch 'leak-fixes' into 'main'
tests: Various small test fixes for valgrind

See merge request GNOME/glib!2711
2022-06-01 17:23:02 +00:00
Philip Withnall
33f36af489 tests: Remove an unnecessary timeout in gnotification test
This is a fallback timeout to abort the test if the expected number of
messages aren’t seen in time. However, when running the test under
valgrind it will take longer and sometimes spuriously trigger the
timeout.

There’s no point in having an abort timeout inside the test: the test
runner (Meson) already provides one for us, which we can adjust with a
multiplier when running under valgrind.

So removes the timeout from within the test. This should fix the
gnotification test under valgrind.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-06-01 15:20:38 +01:00
Philip Withnall
4282f22102 tests: Fix leaks in new GDateTime file info tests
From b7b10cc7e0. My fault!

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-06-01 15:19:59 +01:00
Philip Withnall
972df061a7 Merge branch 'wip/pwithnall/fix-pollable-test' into 'main'
tests: Fix a potential race condition in pollable test

See merge request GNOME/glib!2702
2022-06-01 13:15:32 +00:00
Philip Withnall
26409f19cd Add SPDX license headers for LGPL-2.1-or-later to various files
These have all been added manually, as I’ve finished all the files which
I can automatically detect.

All the license headers in this commit are for LGPL-2.1-or-later, and
all have been double-checked against the license paragraph in the file
header.

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

Helps: #1415
2022-06-01 12:44:23 +01:00
Philip Withnall
95c1d656e2 tests: Fix a potential race condition in pollable test
This may have been causing an intermittent failure of the pollable test
on BSD, where updating the readable status of a socket takes a bit
longer than on Linux.

```
GLib-GIO-DEBUG: 16:06:41.235: GSocketClient: Starting application layer connection
GLib-GIO-DEBUG: 16:06:41.235: GSocketClient: Connection successful!
Bail out! GLib-GIO:ERROR:../gio/tests/pollable.c:73:check_source_readability_callback: assertion failed (readable == expected): (0 == 1)
```

I have not debugged the test on BSD, though, so this is only a guess.

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

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-05-31 13:14:15 +01:00
Philip Withnall
4daa3ca33e tests: Remove global variables from pollable test
This should make each unit test a bit more self-contained and easier to
verify that they’re independent.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-05-31 13:12:06 +01:00
Philip Withnall
ac322a1205 tests: Use g_assert_*() rather than g_assert() in pollable
It won’t get compiled out with `G_DISABLE_ASSERT`.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-05-31 12:57:46 +01:00
Philip Withnall
e5a691e84a tests: Add a test for GFileMonitor deadlocks
This test is opportunistic in that it’s not possible to detect whether
the race condition has been hit (other than by hitting a deadlock).

So the only approach we can take for testing is to loop over the code
which has previously been known to cause a deadlock a number of times.

The number of repetitions is chosen from running the test with the
deadlock fix reverted.

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

Helps: #1941
2022-05-31 12:24:13 +01:00
Philip Withnall
18c0088678 tests: Fix a memory leak when abandoning a file creation time test
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-05-27 17:45:03 +01:00
Philip Withnall
b7b10cc7e0 tests: Add additional tests for nanosecond precision file timestamps
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #369
2022-05-27 17:45:03 +01:00