Commit Graph

1951 Commits

Author SHA1 Message Date
Philip Withnall
8e185e12c9 tests: Fix a flaky wait in converter-stream
Rather than waiting for a fixed period of time, poll in a loop until the
condition the test is expecting is true.

A better solution would be to use a `GSource` and wait until that’s
dispatched. But doing so might affect the behaviour of the
`GInputStream` under test, so busy-wait instead.

Fixes this CI failure: https://gitlab.gnome.org/GNOME/glib/-/jobs/1630758

```
(some socket debug output)
Bail out! GLib-GIO:ERROR:../gio/tests/converter-stream.c:1037:test_converter_pollable: assertion failed (res == -1): (1 == -1)
```

I could not reproduce the failure remotely with a few hundred
invocations of the test, so it might only present itself on BSD, which
presumably has different socket timing behaviour from Linux.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-11-22 13:22:25 +00:00
Philip Withnall
40037ebbfc tests: Use g_assert_*() rather than g_assert() in converter-stream.c
`g_assert()` is compiled out with `G_DISABLE_ASSERT`.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-11-22 13:20:17 +00:00
Alexander Kanavin
e161c62292 gio/tests/codegen.py: bump timeout to 100 seconds
This may be necessary on overloaded CI systems.
2021-11-18 14:07:11 +01:00
Philip Withnall
b09ccc4635 Merge branch 'fix_all_warnings' into 'main'
Fix final warnings in Windows code

See merge request GNOME/glib!2323
2021-11-17 15:15:46 +00:00
Emmanuel Fleury
22037bfab2 Fix set but unused parameter warning in gio/tests/gio-du.c
gio/tests/gio-du.c: In function 'main':
gio/tests/gio-du.c:74:11: error: parameter 'argc' set but not used
   74 | main (int argc, char **argv)
      |       ~~~~^~~~
2021-11-17 14:40:38 +01:00
Hristo Venev
9bd4730008 gsubprocess: Add G_SUBPROCESS_FLAGS_SEARCH_PATH_FROM_ENVP 2021-11-17 12:27:46 +00:00
Philip Withnall
511c5f5bf0 tests: Wait for gdbus-testserver to die when killing it
This was previously done (by commit 63038d1e4c) in one of the cases
where `kill_test_service()` was called — but not the other.

This meant that one instance of `gdbus-testserver` could still be
around when (as it happens, due to the order of the tests) the
`/gdbus/proxy/no-match-rule` test was run. It would start a second
instance of `gdbus-testserver`, which would exit early due to the test
name still being owned on the bus. The first (killed) instance of
`gdbus-testserver` would then exit, leaving no test servers running, and
hence the new test would fail.

This was being seen as frequent CI failures, particularly on FreeBSD
(must have slightly different timing for process signalling and
termination from Linux).

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-11-16 22:47:15 +00:00
Philip Withnall
4eafbaba94 tests: Fix two small leaks in the actions test
These are known leaks, as they were being done in tests which were
checking precondition failures.

However, since we know what happens when the failures occur, we can
still free the input data reliably, so do that.

This improves the valgrind output for `actions` to show zero definite
leaks.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-11-16 14:03:36 +00:00
Philip Withnall
c8fa295f6a tests: Drop arbitrary and flaky waits from actions tests
The `actions` test previously waited an arbitrary 100ms for various
D-Bus messages to be sent/received, before checking the results of those
messages.

Normally, this would work, but on heavily loaded CI systems, it would
sometimes fail. For example,
https://gitlab.gnome.org/GNOME/glib/-/jobs/1611701.

Fix that by waiting for the condition being checked to evaluate to true,
rather than waiting an arbitrary period of time. On faster machines,
this will speed the tests up too.

Assume that the global default `GMainContext` is in use, so a
`GMainContext*` pointer doesn’t have to be passed around.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-11-16 14:01:24 +00:00
Lubomir Rintel
a107a328e4 gdbusproxy: Add G_DBUS_PROXY_FLAGS_NO_MATCH_RULE flag
D-Bus has an upper limit on number of Match rules and it's rather easy to hit
with a big number of proxies with signal subscriptions. This happens with
NetworkManager with hundreds of devices or connection settings. By passing
G_DBUS_SIGNAL_FLAGS_NO_MATCH_RULE to g_dbus_connection_signal_subscribe(), the
user can call AddMatch with a less granular match instead of a match per every
proxy.

Tests subsequently added by Philip Withnall.

Fixes: #1109
2021-11-04 11:44:18 +00:00
Michael Catanzaro
caf777984b Merge branch '2426-delayed-settings-null-handling' into 'main'
gdelayedsettingsbackend: Fix applying after calling g_settings_reset()

Closes #2426

See merge request GNOME/glib!2161
2021-11-03 18:03:21 +00:00
Philip Withnall
7be79cb840 Merge branch '2310-xdgmime-leaks' into 'main'
gcontenttype: Ignore intentional one-time leaks from xdgmime

Closes #2310

See merge request GNOME/glib!2268
2021-11-03 15:42:20 +00:00
Philip Withnall
34ce204fd7 tests: Add D-Bus object/subtree unregistration tests
These tests cover the fixes from the previous two commits.

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

Helps: #2400
2021-10-28 14:53:48 +01:00
Philip Withnall
0101ccba16 gsettings: Clarify that g_settings_get_child() inherits delay-apply
Previously, the delay-apply status of the parent `GSettings` object
would be partially inherited: `settings->priv->backend` in the child
`GSettings` object would point to a `GDelayedSettingsBackend`, but
`settings->priv->delayed` would be `NULL`.

The expectation from https://bugzilla.gnome.org/show_bug.cgi?id=720891
was that `get_child()` would fully inherit delay-apply status.

So, ensure that `settings->priv->delayed` is correctly set to point to
the delayed backend when constructing any `GSettings`. Update the tests
to work again (presumably the inverted test was an oversight in the
original changes).

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

Fixes: #2426
2021-10-26 14:25:51 +01:00
Philip Withnall
05523b7503 tests: Use a helper macro to drop redundant code in gsettings test
This introduces no functional changes.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-10-26 13:38:22 +01:00
Philip Withnall
8b443c3556 gdelayedsettingsbackend: Fix applying after calling g_settings_reset()
`g_settings_reset()` changes the value of the setting to `NULL`;
`add_to_tree()` was not handling that correctly.

Add a unit test.

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

Fixes: #2426
2021-10-26 13:38:22 +01:00
Guido Günther
7665b748bb gappinfo: Add launch-started signal
Emit this when we're about to spawn or DBus activate a GAppInfo.  This
allows lauchers to keep the appinfo associated with a startup id.

We use a GVariant to allow for future exansion of the supplied data.
2021-10-04 10:29:08 +02:00
Philip Withnall
f31e5e6c66 tests: Re-enable contenttype tests under AddressSanitizer
This is a partial revert of commit
f378352051, as the previous commits have
silenced the AddressSanitizer warnings for `GContentType`.

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

Fixes: #2310
2021-09-27 13:14:00 +01:00
James Westman
f6ddce4b16 g_output_stream_write_all: Allow NULL empty buffer 2021-09-21 10:40:14 +00:00
Philip Withnall
4f62fdfd29 tests: Fix subsequent tests after first power-profile test failure
If the first power-profile installed test fails (for example, because
xdg-desktop-portal isn’t available), correctly tear down the dbusmock
object, or it will cause setUp() to fail when the next test in the suite
is run.

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

Helps: #2481
2021-09-06 18:57:06 +01:00
Philip Withnall
d051ef1611 gpowerprofilemonitorportal: Set property value by default
When first creating the monitor, correctly set its property value to the
value from the portal, rather than waiting for the portal value to
change to set it.

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

Fixes: #2481
2021-09-06 18:56:12 +01:00
Bastien Nocera
e1819c42fb gio: Fix conditions in memory-monitor test
We were lucky that this worked in some cases (the test is racy), but we
should actually run the condition check each loop, rather than when the
function is called.

Spotted by Martin Pitt:
96a8c02d24 (r54773831)
2021-09-06 14:46:15 +02:00
Simon McVittie
052e335500 tests: Make use of g_test_fail_message()
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-08-19 09:49:11 +01:00
Simon McVittie
26fbd14954 tests: Use g_test_skip_printf()
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-08-19 09:41:08 +01:00
Philip Withnall
ae486f6dc6 Merge branch 'wip/pwithnall/gdbus-names-livelock' into 'main'
tests: Add missing wakeup calls to gdbus-names test

See merge request GNOME/glib!2157
2021-08-17 13:25:55 +00:00
Bastien Nocera
2e9842cafc gio: Simplify memory monitor tests by using assertEventually() helper
assertEventually is a helper used in a number of projects that use
dbusmock.

See https://github.com/martinpitt/python-dbusmock/issues/82
2021-08-13 01:32:31 +02:00
Bastien Nocera
66acea8418 gio: Remove left-over debug statement from memory monitor portal test 2021-08-13 01:32:31 +02:00
Bastien Nocera
18eb29897d gio: Add GPowerProfileMonitor tests
Tests both the portal and direct D-Bus variants.
2021-08-13 01:32:31 +02:00
Guido Günther
791218a5f5 GNotification: Allow to set a category
Some backends like the FDO one allow to set a category. This helps the
notification daemon to select a proper feedback type.
2021-08-02 19:26:38 +02:00
Patrick Griffis
889bdb994f Add GPowerProfileMonitor 2021-07-28 15:56:02 +02:00
Bastien Nocera
2e500304e3 tests: Remove unused constant in GMemoryMonitor test 2021-07-28 15:04:46 +02:00
GOUJON Évan
dd69955e58 gio/tests/async-splice-output-stream: Fix a memory leak 2021-07-23 22:21:23 +02:00
Ross Burton
289f8be1b3 gio/tests/g-file-info: don't assume million-in-one events don't happen
The modification time test creates a file, gets the modification time in
seconds, then gets the modification time in microseconds and assumes
that the difference between the two has to be above 0.

As rare as this may be, it can happen:

$ stat g-file-info-test-50A450 -c %y
2021-07-06 18:24:56.000000767 +0100

Change the test to simply assert that the difference not negative to
handle this case.
2021-07-06 19:32:54 +01:00
Philip Withnall
323c5d7e21 tests: Add some missing main context iterations to gdbus-names
These were missing from the test before the previous commit ported from
`GMainLoop` to `GMainContext`.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-06-21 14:16:03 +01:00
Philip Withnall
32e8e4ad91 tests: Port gdbus-names test entirely to GMainContext
It makes combination exit conditions a lot easier than when using
`g_main_loop_quit()` from different callbacks.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-06-21 14:15:55 +01:00
Philip Withnall
f6fdc9b5f2 Merge branch 'mcatanzaro/readable-private-key' into 'main'
gtlscertificate: make private key properties readable

See merge request GNOME/glib!2087
2021-06-16 11:01:40 +00:00
Philip Withnall
4d6dbe0904 Merge branch 'g_dbus' into 'main'
gdbus: Add g_dbus_is_error_name() symbol for g_dbus_is_interface_name()

Closes #402

See merge request GNOME/glib!2156
2021-06-16 10:58:04 +00:00
nitinosiris
a70df97c63 Added test case for g_dbus_is_error_name 2021-06-16 08:06:03 +05:30
Michael Catanzaro
c50e543e9d gtlscertificate: make private key properties readable
WebKit wants these private key properties to be readable in order to
implement a deserialization function. Currently they are read-only
because at the time GTlsCertificate was originally designed, the plan
was to support PKCS#11-backed private keys: private keys that are stored
on a smartcard, where the private key is completely unreadable. The
design goal was to support both memory-backed and smartcard-backed
private keys with the same GTlsCertificate API, abstracting away the
implementation differences such that code using GTlsCertificate doesn't
need to know the difference.

The original PKCS#11 implementation was never fully baked and at some
point in the past I deleted it all. It has since been replaced with a
new implementation, including a GTlsCertificate:private-key-pkcs11-uri
property, which is readable. So our current API already exposes the
differences between normal private keys and PKCS#11-backed private keys.
The point of making the private-key and private-key-pem properties
write-only was to avoid exposing this difference.

Do we have to make this API function readable? No, because WebKit could
be just as well served if we were to expose serialize and deserialize
functions instead. But WebKit needs to support serializing and
deserializing the non-private portion of GTlsCertificate with older
versions of GLib anyway, so we can do whatever is nicest for GLib. And I
think making this property readable is nicest, since the original design
reason for it to not be readable is now obsolete. The disadvantage to
this approach is that it's now possible for an application to read the
private-key or private-key-pem property, receive NULL, and think "this
certificate must not have a private key," which would be incorrect if
the private-key-pkcs11-uri property is set. That seems like a minor
risk, but it should be documented.
2021-06-15 16:06:52 -05:00
Simon McVittie
e0b6b8037d Distinguish more clearly between wait status and exit status
On Unix platforms, wait() and friends yield an integer that encodes
how the process exited. Confusingly, this is usually not the same as
the integer passed to exit() or returned from main(): conceptually it's
an integer encoding of this tagged union:

    enum { EXITED, SIGNALLED, ... } tag;
    union {
        int exit_status;         /* if EXITED */
        struct {
            int terminating_signal;
            bool core_dumped;
        } terminating_signal;    /* if SIGNALLED */
        ...
    } detail;

Meanwhile, on Windows, wait statuses and exit statuses are
interchangeable.

I find that it's clearer what is going on if we are consistent about
referring to the result of wait() as a "wait status", and the value
passed to exit() as an "exit status".

GSubprocess already gets this right: g_subprocess_get_status() returns
the wait status, while g_subprocess_get_exit_status() genuinely returns
the exit status. However, the GSpawn family of APIs has tended to
conflate the two.

Confusingly, g_spawn_check_exit_status() has always checked a wait
status, and it would not be correct to pass an exit status to it; so
let's deprecate it in favour of g_spawn_check_wait_status(), which
does the same thing that g_spawn_check_exit_status() always did.
Code that needs backwards-compatibility with older GLib can use:

    #if !GLIB_CHECK_VERSION(2, 69, 0)
    #define g_spawn_check_wait_status(x) (g_spawn_check_exit_status (x))
    #endif

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-06-15 14:33:14 +01:00
Simon McVittie
f2be22ca52 subprocess test: Check wait status correctly
Confusingly, g_spawn_check_exit_status() takes a wait status, not an
exit status, so passing g_subprocess_get_exit_status() to it is
incorrect (although both encodings happen to use 0 to encode success
and a nonzero value to encode failure, so in practice this probably
had the desired effect).

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-06-15 14:32:33 +01:00
Philip Withnall
bd8d139a77 tests: Add missing wakeup calls to gdbus-names.c
Following on from the previous commit, some explicit
`g_main_context_wakeup()` calls were missing from the test code which
only uses `GMainContext`.

Add them, and also add some assertions to check that these functions are
being called in the expected thread (as the code comments say).

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-06-15 13:48:03 +01:00
Philip Withnall
1ed67a9c44 gapplication: Expose zero-valued numbers in handle-local-options
This is a bit of a compromise. Since the option parsing in
`GApplication` is built on `GOptionContext`, there’s no way to
reliably indicate that a given option was passed by the user, other than
by its value changing. If the default value is zero, but the user
explicitly passed zero, nothing changes, so it’s not obvious that the
option was explicitly provided.

When just `GOptionContext` is being used, this is fine, as that’s
obvious what will happen from the way the API is built. With
`GApplication::handle-local-options`, though, the `GVariantDict`
provided by GLib to the callback claims to only contain the values of
the options provided by the user, and no defaults.

It’s not actually possible for GLib to do that reliably.

Previously, GLib was dropping all numeric values which were zero valued
(i.e. the defaults), as they *could* have been the defaults. It seems
like a slightly better behaviour to instead *not* drop those numeric
values, and err on the side of reporting some defaults as user-provided
(even if they weren’t) rather than dropping some user-provided values
which happen to be the defaults.

This adds a test for the case of parsing a double; the cases for
integers are analogous.

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

Fixes: #2329
2021-06-15 13:04:21 +01:00
Philip Withnall
8530a6a8e4 tests: Add missing wakeup calls to gdbus-names test
The tests in `gdbus-names.c` use a mixture of `GMainLoop` and iterating
a `GMainContext` directly. Some of the helper functions based around the
`OwnNameData` struct use the `loop` `GMainLoop` even when called from
tests like `watch_with_different_context()` which themselves use
`GMainContext` directly.

Thus, it’s possible for the `GMainLoop` to not be running, while the
test is iterating on `g_main_context_iteration()`. In this case,
`g_main_loop_quit()` is a no-op and will not wake up the `GMainContext`.
This causes the test to livelock in around 1 in 1200 test runs.

Fix this by adding an explicit `g_main_context_wakeup()` call after each
`g_main_loop_quit()` call. A more comprehensive fix would be to port all
the tests in this file to iterating `GMainContext` directly, and drop
all the `GMainLoop` usage, but I don’t have time for that right now.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-06-15 13:01:28 +01:00
Philip Withnall
e522768ef4 tests: Allow GResource external data tests to use llvm-objcopy
Relax the requirement for the test to only be compiled/run under gcc,
since a version of LLVM was released which supports `--add-symbol`.

`objcopy` should be overrideable to be `llvm-objcopy` by using a machine
file as per https://mesonbuild.com/Machine-files.html#binaries.

Suggested and tested by Grigory Vasilyev.

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

Fixes: #2423
2021-06-14 14:49:59 +01:00
Philip Withnall
de74a70b7e Merge branch 'try-tls-binding-tests-again' into 'main'
Revert "tests: Deactivate tls-bindings test suite for windows"

See merge request GNOME/glib!2130
2021-06-10 12:46:12 +00:00
Ross Wollman
4d3618cbd1 tls: expose SAN details on GTlsCertificate
This changeset exposes

* `dns-names`
* `ip-addresses`

on GTlsCertificate provided by the underlying TLS Backend.

See https://gitlab.gnome.org/GNOME/glib-networking/-/merge_requests/165 for the corresponding glib-networking changes.

Relates: https://gitlab.gnome.org/GNOME/glib/-/merge_requests/2113
Relates: https://gitlab.gnome.org/GNOME/glib-networking/-/merge_requests/156/diffs
Relates: https://github.com/microsoft/playwright/issues/6759
2021-06-10 00:54:45 +00:00
Philip Withnall
4fd789c160 tests: Add missing setlocale() call to file tests
This ensures that non-ASCII characters in the test output are printed
correctly in the logs.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-06-07 12:44:58 +01:00
Philip Withnall
b1ebb72522 glocalfileoutputstream: Fix ETag check when replacing through a symlink
Since commit 87e19535fe, the ETag check when writing out a file through
a symlink (following the symlink) has been incorrectly using the ETag
value of the symlink, rather than the target file. This is incorrect
because the ETag should represent the file content, not its metadata or
links to it.

Fix that, and add a unit test.

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

Fixes: #2417
2021-06-07 12:44:52 +01:00
Philip Withnall
b407d46c9a Merge branch '2416-tls-certificate-fix-invalid-read' into 'master'
tests/tls-certificate: Add a unit test

Closes #2416

See merge request GNOME/glib!2136
2021-06-07 08:36:12 +00:00
Peter Bloomfield
f0a1671161 tests/tls-certificate: Add context to the new test
Add a comment to `pem_parser_no_sentinel()` to explain what it is
testing and how it works.
2021-06-05 10:14:24 -04:00
Peter Bloomfield
b9d07813d8 tests/tls-certificate: Add a unit test
Test whether g_tls_certificate_new_from_pem() can handle a
non-nul-terminated PEM.

Helps https://gitlab.gnome.org/GNOME/glib/-/issues/2416
2021-06-04 20:40:16 -04:00
Christian Persch
2632ed7a69 gsettings: Resolve child schemas from the parent's schema source 2021-06-04 12:09:24 +00:00
Gaël Bonithon
df500c68a4 inotify: Fix a memory leak
Fixes: #2311
2021-06-03 19:04:48 +02:00
Philip Withnall
e02b905b4b Revert "tests: Deactivate tls-bindings test suite for windows"
This reverts commit 7f2fef5c26.

There have been some changes to the gitlab-ci-win32-runner pre-clone
script which should be more successful at killing the remaining
processes after this test. See
https://gitlab.gnome.org/GNOME/glib/-/merge_requests/2008#note_1127126
2021-06-03 13:01:29 +01:00
Michael Catanzaro
7a51163cf9 Merge branch 'feature/cert-info' into 'master'
tls: expose cert details on GTlsCertificate

See merge request GNOME/glib!2113
2021-06-01 20:25:21 +00:00
Ross A. Wollman
a17c28790a tls: expose cert details on GTlsCertificate
This changeset exposes

* `not-valid-before`
* `not-valid-after`
* `subject-name`
* `issuer-name`

on GTlsCertificate provided by the underlying TLS Backend.

In order to make use of these changes,
see the related [glib-networking MR][glib-networking].

This change aims to help populate more of the [`Certificate`][wk-cert]
info in the WebKit Inspector Protocol on Linux.

This changeset stems from work in Microsoft Playwright to [add more info
into its HAR capture][pw] generated from the Inspector Protocol events
and will bring feature parity across WebKit platforms.

[wk-cert]: 8afe31a018/Source/JavaScriptCore/inspector/protocol/Security.json
[pw]: https://github.com/microsoft/playwright/pull/6631
[glib-networking]: https://gitlab.gnome.org/GNOME/glib-networking/-/merge_requests/156
2021-06-01 16:24:33 +00:00
Emmanuel Fleury
aace697d7e Fix missing initializer warning in gio/tests/gdbus-exit-on-close.c
gio/tests/gdbus-exit-on-close.c:52:14: warning: missing field 'bug' initializer
      { NULL }
             ^
2021-05-27 10:16:52 +02:00
Emmanuel Fleury
652a7b7db1 Fix missing initializer warnings in gio/tests/socket.c
gio/tests/socket.c:505:36: warning: missing field 'size' initializer
    GOutputVector v[7] = { { NULL, }, };
                                   ^
gio/tests/socket.c:630:37: warning: missing field 'vectors' initializer
    GOutputMessage m[3] = { { NULL, }, };
                                    ^
gio/tests/socket.c:631:37: warning: missing field 'vectors' initializer
    GInputMessage im[3] = { { NULL, }, };
                                    ^
gio/tests/socket.c:632:36: warning: missing field 'size' initializer
    GOutputVector v[7] = { { NULL, }, };
                                   ^
gio/tests/socket.c:633:36: warning: missing field 'size' initializer
    GInputVector iv[7] = { { NULL, }, };
                                   ^
gio/tests/socket.c:871:32: warning: missing field 'vectors' initializer
    GInputMessage im = { NULL, };
                               ^
gio/tests/socket.c:872:31: warning: missing field 'size' initializer
    GInputVector iv = { NULL, };
                              ^
2021-05-27 10:16:52 +02:00
Philip Withnall
7e9585177d tests: Drop use of g_test_bug_base()
Include the base URI in the `g_test_bug()` calls instead. This resolves
inconsistencies between the old bug base (bugzilla.gnome.org) and the
new bug base (gitlab.gnome.org). It also has the advantage that the URI
passed to `g_test_bug()` is now clickable in the code editor, rather
than being split across two locations.

See https://gitlab.gnome.org/GNOME/glib/-/merge_requests/275#note_303175

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-05-13 22:16:27 +01:00
Emmanuel Fleury
e952248dc2 Use G_OPTION_ENTRY_NULL to avoid missing initializer warnings 2021-05-13 20:16:46 +00:00
Emmanuel Fleury
4301110174 Fix missing initializer warning in gio/tests/socket-client.c
gio/tests/socket-client.c:37:8: warning: missing field 'short_name' initializer
  {NULL}
       ^
2021-05-13 12:57:14 +02:00
Emmanuel Fleury
689b9b545f Fix missing initializer warning in gio/tests/socket-server.c
gio/tests/socket-server.c:43:8: warning: missing field 'short_name' initializer
  {NULL}
       ^
2021-05-13 12:57:14 +02:00
Emmanuel Fleury
e3453f39dd Fix missing initializer in gio/tests/fake-service-name.c
gio/tests/fake-service-name.c:55:1: error: missing initializer for field ‘padding’ of ‘GDBusInterfaceVTable’ {aka ‘const struct _GDBusInterfaceVTable’}
   55 | };
      | ^
2021-05-06 22:54:53 +02:00
Emmanuel Fleury
180c1a18d9 Fix several missing initializer warnings in gio/tests/basic-application.c
gio/tests/basic-application.c: In function ‘startup’:
gio/tests/basic-application.c:57:5: error: missing initializer for field ‘padding’ of ‘GActionEntry’ {aka ‘struct _GActionEntry’}
   57 |     { "new", new_activated, NULL, NULL, NULL },
      |     ^
gio/tests/basic-application.c:58:5: error: missing initializer for field ‘padding’ of ‘GActionEntry’ {aka ‘struct _GActionEntry’}
   58 |     { "quit", quit_activated, NULL, NULL, NULL },
      |     ^
gio/tests/basic-application.c:59:5: error: missing initializer for field ‘padding’ of ‘GActionEntry’ {aka ‘struct _GActionEntry’}
   59 |     { "action1", action1_activated, NULL, NULL, NULL },
      |     ^
gio/tests/basic-application.c:60:5: error: missing initializer for field ‘padding’ of ‘GActionEntry’ {aka ‘struct _GActionEntry’}
   60 |     { "action2", action2_activated, "b", "false", change_action2 }
      |     ^
2021-04-29 12:40:05 +02:00
Emmanuel Fleury
4a503bdbd7 Fix several missing initializer warnings in gio/tests/dbus-appinfo.c
gio/tests/dbus-appinfo.c:177:3: error: missing initializer for field ‘parameter_type’ of ‘GActionEntry’ {aka ‘const struct _GActionEntry’}
  177 |   { "frob",         test_application_frob              },
      |   ^
gio/tests/dbus-appinfo.c:178:3: error: missing initializer for field ‘parameter_type’ of ‘GActionEntry’ {aka ‘const struct _GActionEntry’}
  178 |   { "tweak",        test_application_tweak             },
      |   ^
gio/tests/dbus-appinfo.c:179:3: error: missing initializer for field ‘parameter_type’ of ‘GActionEntry’ {aka ‘const struct _GActionEntry’}
  179 |   { "twiddle",      test_application_twiddle           },
      |   ^
gio/tests/dbus-appinfo.c:180:3: error: missing initializer for field ‘parameter_type’ of ‘GActionEntry’ {aka ‘const struct _GActionEntry’}
  180 |   { "quit",         test_application_quit              }
      |   ^
2021-04-29 12:40:05 +02:00
Emmanuel Fleury
4ad62f7fab Fix signedness warning in gio/tests/readwrite.c
gio/tests/readwrite.c: In function ‘verify_iostream’:
gio/tests/readwrite.c:77:17: error: comparison of integer expressions of different signedness: ‘gboolean’ {aka ‘int’} and ‘size_t’ {aka ‘long unsigned int’}
   77 |   g_assert (res == strlen (original_data) - 15);
      |                 ^~
2021-04-29 12:40:05 +02:00
Emmanuel Fleury
a965262004 Fix several signedness warnings in gio/tests/unix-streams.c
gio/tests/unix-streams.c: In function ‘test_write_async_wouldblock’:
gio/tests/unix-streams.c:692:17: error: comparison of integer expressions of different signedness: ‘guint’ {aka ‘unsigned int’} and ‘gint’ {aka ‘int’}
  692 |   for (i = 0; i < 4 * pipe_capacity; i++)
      |                 ^
gio/tests/unix-streams.c: In function ‘test_writev_async_wouldblock’:
gio/tests/unix-streams.c:780:17: error: comparison of integer expressions of different signedness: ‘guint’ {aka ‘unsigned int’} and ‘gint’ {aka ‘int’}
  780 |   for (i = 0; i < 4 * pipe_capacity; i++)
      |                 ^
2021-04-29 12:39:51 +02:00
Marco Trevisan (Treviño)
63873c0eb1 application: Unset the registered state after shutting down
An application that has been shut down is still marked as registered
even if its implementation has been already destroyed.

This may lead to unguarded crashes when calling functions that have
assumptions for being used with registered applications.

So, when an application is registered, mark it as unregistered just
before destroying its implementation and after being shut down, so that
we follow the registration process in reversed order.

Added tests
2021-04-27 17:11:10 +02:00
Emmanuel Fleury
59acf6950c Fix missing initializer warning in gio/tests/gdbus-example-server.c
gio/tests/gdbus-example-server.c:280:1: error: missing initializer for field ‘padding’ of ‘GDBusInterfaceVTable’ {aka ‘const struct _GDBusInterfaceVTable’}
  280 | };
      | ^
2021-04-23 10:43:05 +02:00
Emmanuel Fleury
f587095cfc Fix signedness warning in gio/tests/socket-common.c
gio/tests/socket-common.c: In function ‘socket_address_from_string’:
gio/tests/socket-common.c:50:17: error: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’
   50 |   for (i = 0; i < G_N_ELEMENTS (unix_socket_address_types); i++)
      |                 ^
2021-04-23 10:43:05 +02:00
Emmanuel Fleury
bac08a4b26 Fix several missing initializer warnings in gio/tests/gdbus-example-subtree.c
gio/tests/gdbus-example-subtree.c:76:1: error: missing initializer for field ‘padding’ of ‘GDBusInterfaceVTable’ {aka ‘const struct _GDBusInterfaceVTable’}
   76 | };
      | ^
gio/tests/gdbus-example-subtree.c:190:1: error: missing initializer for field ‘padding’ of ‘GDBusInterfaceVTable’ {aka ‘const struct _GDBusInterfaceVTable’}
  190 | };
      | ^
gio/tests/gdbus-example-subtree.c:228:1: error: missing initializer for field ‘get_property’ of ‘GDBusInterfaceVTable’ {aka ‘const struct _GDBusInterfaceVTable’}
  228 | };
      | ^
gio/tests/gdbus-example-subtree.c:325:1: error: missing initializer for field ‘padding’ of ‘GDBusSubtreeVTable’ {aka ‘const struct _GDBusSubtreeVTable’}
  325 | };
      | ^
2021-04-23 10:43:05 +02:00
Emmanuel Fleury
cb0b4b00df Fix missing initializer warning in gio/tests/gnotification-server.c
gio/tests/gnotification-server.c: In function ‘g_notification_server_bus_acquired’:
gio/tests/gnotification-server.c:224:3: error: missing initializer for field ‘padding’ of ‘GDBusInterfaceVTable’ {aka ‘const struct _GDBusInterfaceVTable’}
  224 |   };
      |   ^
2021-04-23 10:43:05 +02:00
Emmanuel Fleury
d255962abb Fix missing initializer warning in gio/tests/gdbus-non-socket.c
gio/tests/gdbus-non-socket.c:116:1: error: missing initializer for field ‘padding’ of ‘GDBusInterfaceVTable’ {aka ‘const struct _GDBusInterfaceVTable’}
  116 | };
      | ^
2021-04-23 10:43:05 +02:00
Emmanuel Fleury
2187406f70 Fix signedness warning in gio/tests/gdbus-proxy.c
gio/tests/gdbus-proxy.c: In function ‘strv_equal’:
gio/tests/gdbus-proxy.c:158:32: error: comparison of integer expressions of different signedness: ‘guint’ {aka ‘unsigned int’} and ‘gint’ {aka ‘int’}
  158 |     res = g_strv_length (strv) == count;
      |                                ^~
2021-04-23 10:43:05 +02:00
Emmanuel Fleury
fd926b1ea7 Fix missing initializer in gio/tests/gdbus-example-peer.c
gio/tests/gdbus-example-peer.c:120:1: error: missing initializer for field ‘padding’ of ‘GDBusInterfaceVTable’ {aka ‘const struct _GDBusInterfaceVTable’}
  120 | };
      | ^
2021-04-15 10:19:29 +02:00
Emmanuel Fleury
1c084ca717 Fix missing initializer warning in gio/tests/gdbus-example-export.c
gio/tests/gdbus-example-export.c:229:1: error: missing initializer for field ‘padding’ of ‘GDBusInterfaceVTable’ {aka ‘const struct _GDBusInterfaceVTable’}
  229 | };
      | ^
2021-04-15 10:19:29 +02:00
Emmanuel Fleury
4d52358fe2 Fix signedness warning in gio/tests/gsettings.c
gio/tests/gsettings.c: In function ‘strv_set_equal’:
gio/tests/gsettings.c:2268:41: error: comparison of integer expressions of different signedness: ‘guint’ {aka ‘unsigned int’} and ‘gint’ {aka ‘int’}
 2268 |     res = g_strv_length ((gchar**)strv) == count;
      |                                         ^~
2021-04-15 10:19:29 +02:00
Emmanuel Fleury
83a9ba7790 Fix missing initializer warning in gio/tests/gdbus-testserver.c
gio/tests/gdbus-testserver.c:806:1: error: missing initializer for field ‘padding’ of ‘GDBusInterfaceVTable’ {aka ‘const struct _GDBusInterfaceVTable’}
  806 | };
      | ^
In file included from gio/gio.h:53,
                 from gio/tests/gdbus-testserver.c:1:
gdbusconnection.h:395:12: note: ‘padding’ declared here
  395 |   gpointer padding[8];
      |            ^~~~~~~
2021-04-15 10:19:29 +02:00
Emmanuel Fleury
5133acdaff Fix multiple signedness warnings in gio/tests/gdbus-testserver.c
gio/tests/gdbus-testserver.c: In function ‘handle_method_call’:
gio/tests/gdbus-testserver.c:334:23: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘gsize’ {aka ‘long unsigned int’}
  334 |         for (i = 0; i < n_elts; i++)
      |                       ^
gio/tests/gdbus-testserver.c:343:23: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘gsize’ {aka ‘long unsigned int’}
  343 |         for (i = 0; i < n_elts; i++)
      |                       ^
gio/tests/gdbus-testserver.c:352:23: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘gsize’ {aka ‘long unsigned int’}
  352 |         for (i = 0; i < n_elts; i++)
      |                       ^
gio/tests/gdbus-testserver.c:361:23: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘gsize’ {aka ‘long unsigned int’}
  361 |         for (i = 0; i < n_elts; i++)
      |                       ^
gio/tests/gdbus-testserver.c:370:23: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘gsize’ {aka ‘long unsigned int’}
  370 |         for (i = 0; i < n_elts; i++)
      |                       ^
gio/tests/gdbus-testserver.c:379:23: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘gsize’ {aka ‘long unsigned int’}
  379 |         for (i = 0; i < n_elts; i++)
      |                       ^
gio/tests/gdbus-testserver.c:388:23: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘gsize’ {aka ‘long unsigned int’}
  388 |         for (i = 0; i < n_elts; i++)
      |                       ^
gio/tests/gdbus-testserver.c:397:23: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘gsize’ {aka ‘long unsigned int’}
  397 |         for (i = 0; i < n_elts; i++)
      |                       ^
gio/tests/gdbus-testserver.c:406:23: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘gsize’ {aka ‘long unsigned int’}
  406 |         for (i = 0; i < n_elts; i++)
      |                       ^
2021-04-15 10:19:29 +02:00
Emmanuel Fleury
c3c1f6c4b9 Fix signedness warning in gio/tests/mimeapps.c
gio/tests/mimeapps.c: In function ‘strv_equal’:
gio/tests/mimeapps.c:31:32: error: comparison of integer expressions of different signedness: ‘guint’ {aka ‘unsigned int’} and ‘gint’ {aka ‘int’}
   31 |     res = g_strv_length (strv) == count;
      |                                ^~
2021-04-15 10:19:29 +02:00
Emmanuel Fleury
e7aec308e9 Fix signedness warning in gio/tests/proxy-test.c
gio/tests/proxy-test.c: In function ‘do_echo_test’:
gio/tests/proxy-test.c:855:25: error: comparison of integer expressions of different signedness: ‘gssize’ {aka ‘long int’} and ‘gsize’ {aka ‘long unsigned int’}
  855 |   for (total = 0; total < nwrote; total += nread)
      |                         ^
2021-04-15 10:19:29 +02:00
Emmanuel Fleury
8608eccf9a Fix signedness warning in gio/tests/file.c
gio/tests/file.c: In function ‘written_cb’:
gio/tests/file.c:358:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘size_t’ {aka ‘long unsigned int’}
  358 |   if (data->pos < strlen (data->data))
      |                 ^
2021-04-15 10:19:29 +02:00
Emmanuel Fleury
4d1f76ec50 Fix signedness warning in gio/tests/gdbus-test-codegen.c
gio/tests/gdbus-test-codegen.c: In function ‘check_object_manager’:
gio/tests/gdbus-test-codegen.c:2344:20: error: comparison of integer expressions of different signedness: ‘guint’ {aka ‘unsigned int’} and ‘int’
 2344 |   if (om_signal_id != -1)
      |                    ^~
2021-04-15 00:00:22 +02:00
Emmanuel Fleury
34cd8a98c7 Fix signedness warning in gio/tests/testfilemonitor.c
gio/tests/testfilemonitor.c: In function ‘check_expected_events’:
gio/tests/testfilemonitor.c:124:39: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘gsize’ {aka ‘long unsigned int’}
  124 |   for (i = 0, li = 0, l = recorded; i < n_expected && l != NULL;)
      |                                       ^
2021-04-14 23:43:36 +02:00
Emmanuel Fleury
0a741d85a7 Fix signedness warning in gio/tests/socket.c
gio/tests/socket.c: In function ‘test_get_available’:
gio/tests/socket.c:1696:53: error: comparison of integer expressions of different signedness: ‘gssize’ {aka ‘long int’} and ‘long unsigned int’
 1696 |           if (g_socket_get_available_bytes (server) > sizeof (data))
      |                                                     ^
2021-04-14 23:43:25 +02:00
Emmanuel Fleury
5595b65476 Fix multiple missing initializer warnings in gio/tests/gdbus-export.c
gio/tests/gdbus-export.c:130:1: error: missing initializer for field ‘properties’ of ‘GDBusInterfaceInfo’ {aka ‘const struct _GDBusInterfaceInfo’}
  130 | };
      | ^
In file included from gio/gio.h:57,
                 from gio/tests/gdbus-export.c:21:
gio/gdbusintrospection.h:156:25: note: ‘properties’ declared here
  156 |   GDBusPropertyInfo   **properties;
      |                         ^~~~~~~~~~
...
2021-04-14 23:26:15 +02:00
Emmanuel Fleury
60d2cfb6ae Fix missing initializer warning in gio/tests/gdbus-connection.c
gio/tests/gdbus-connection.c:90:1: error: missing initializer for field ‘padding’ of ‘GDBusInterfaceVTable’ {aka ‘const struct _GDBusInterfaceVTable’}
   90 | };
      | ^
2021-04-14 23:26:15 +02:00
Emmanuel Fleury
00323ac0e1 Fix several signedness warnings in gio/tests/actions.c
gio/tests/actions.c: In function ‘strv_set_equal’:
gio/tests/actions.c:177:41: error: comparison of integer expressions of different signedness: ‘guint’ {aka ‘unsigned int’} and ‘gint’ {aka ‘int’}
  177 |     res = g_strv_length ((gchar**)strv) == count;
      |                                         ^~
gio/tests/actions.c: In function ‘test_parse_detailed’:
gio/tests/actions.c:473:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘long unsigned int’
  473 |   for (i = 0; i < G_N_ELEMENTS (testcases); i++)
      |                 ^
2021-04-08 13:24:54 +02:00
Emmanuel Fleury
c3d558df77 Fix multiple missing initializer warnings in gio/tests/actions.c
gio/tests/actions.c: In function ‘test_entries’:
gio/tests/actions.c:375:5: error: missing initializer for field ‘parameter_type’ of ‘GActionEntry’ {aka ‘const struct _GActionEntry’}
  375 |     { "foo",    activate_foo                                     },
      |     ^
In file included from gio/gio.h:31,
                 from gio/tests/actions.c:1:
gio/gactionmap.h:63:16: note: ‘parameter_type’ declared here
   63 |   const gchar *parameter_type;
      |                ^~~~~~~~~~~~~~
...
2021-04-08 13:24:54 +02:00
Emmanuel Fleury
0710429598 Fix missing initializer warning in gio/tests/gdbus-peer-object-manager.c
gio/tests/gdbus-peer-object-manager.c: In function ‘mock_interface_get_vtable’:
gio/tests/gdbus-peer-object-manager.c:111:3: error: missing initializer for field ‘padding’ of ‘GDBusInterfaceVTable’ {aka ‘struct _GDBusInterfaceVTable’}
  111 |   };
      |   ^
2021-04-08 13:24:54 +02:00
Emmanuel Fleury
e3f6d4a08b Fix several missing initializer warnings in gio/tests/gdbus-peer.c
gio/tests/gdbus-peer.c:262:1: error: missing initializer for field ‘padding’ of ‘GDBusInterfaceVTable’ {aka ‘const struct _GDBusInterfaceVTable’}
  262 | };
      | ^
gio/tests/gdbus-peer.c:1263:1: error: missing initializer for field ‘padding’ of ‘GDBusInterfaceVTable’ {aka ‘const struct _GDBusInterfaceVTable’}
 1263 | };
      | ^
2021-04-08 13:24:54 +02:00
Emmanuel Fleury
7c909db13a Fix multiple missing initializer warning in gio/tests/g-file.c
gio/tests/g-file.c: In function ‘test_g_file_new_for_path’:
gio/tests/g-file.c:114:7: error: missing initializer for field ‘path3’ of ‘const struct TestPathsWithOper’
  114 |       {"/", TRUE, 0, "/./"},
      |       ^
gio/tests/g-file.c:115:7: error: missing initializer for field ‘path3’ of ‘const struct TestPathsWithOper’
  115 |       {"//", TRUE, 0, "//"},
      |       ^
...
2021-04-08 13:24:54 +02:00
Emmanuel Fleury
d936ff10e6 Fix several signedness warnings in gio/tests/network-address.c
gio/tests/network-address.c: In function ‘main’:
gio/tests/network-address.c:1194:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘long unsigned int’
 1194 |   for (i = 0; i < G_N_ELEMENTS (host_tests); i++)
      |                 ^
gio/tests/network-address.c:1201:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘long unsigned int’
 1201 |   for (i = 0; i < G_N_ELEMENTS (uri_tests); i++)
      |                 ^
gio/tests/network-address.c:1208:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘long unsigned int’
 1208 |   for (i = 0; i < G_N_ELEMENTS (address_tests); i++)
      |                 ^
gio/tests/network-address.c:1215:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘long unsigned int’
 1215 |   for (i = 0; i < G_N_ELEMENTS (address_tests); i++)
      |                 ^
2021-04-07 10:33:16 +02:00
Emmanuel Fleury
c216f2299d Fix several missing initializer warnings in gio/tests/gsubprocess.c
gio/tests/gsubprocess.c: In function ‘test_communicate_async’:
gio/tests/gsubprocess.c:774:3: error: missing initializer for field ‘running’ of ‘TestAsyncCommunicateData’
  774 |   TestAsyncCommunicateData data = { flags, 0, };
      |   ^~~~~~~~~~~~~~~~~~~~~~~~
gio/tests/gsubprocess.c: In function ‘test_communicate_utf8_async’:
gio/tests/gsubprocess.c:1025:3: error: missing initializer for field ‘running’ of ‘TestAsyncCommunicateData’
 1025 |   TestAsyncCommunicateData data = { flags, 0, };
      |   ^~~~~~~~~~~~~~~~~~~~~~~~
gio/tests/gsubprocess.c: In function ‘test_communicate_utf8_cancelled_async’:
gio/tests/gsubprocess.c:1058:3: error: missing initializer for field ‘running’ of ‘TestAsyncCommunicateData’
 1058 |   TestAsyncCommunicateData data = { flags, 0, };
      |   ^~~~~~~~~~~~~~~~~~~~~~~~
gio/tests/gsubprocess.c: In function ‘test_communicate_utf8_async_invalid’:
gio/tests/gsubprocess.c:1202:3: error: missing initializer for field ‘running’ of ‘TestAsyncCommunicateData’
 1202 |   TestAsyncCommunicateData data = { flags, 0, };
      |   ^~~~~~~~~~~~~~~~~~~~~~~~
2021-04-07 10:33:16 +02:00
Emmanuel Fleury
b07fdb6e4a Fix signedness warning in gio/tests/converter-stream.c:g_expander_converter_convert()
gio/tests/converter-stream.c: In function ‘g_expander_converter_convert’:
gio/tests/converter-stream.c:128:21: error: comparison of integer expressions of different signedness: ‘int’ and ‘gsize’ {aka ‘long unsigned int’}
  128 |       for (i = 0; i < block_size; i++)
      |                     ^
2021-04-07 10:33:16 +02:00
Emmanuel Fleury
56e25d81f6 Fix several signedness warnings in gio/tests/converter-stream.c:g_compressor_converter_convert()
gio/tests/converter-stream.c: In function ‘g_compressor_converter_convert’:
gio/tests/converter-stream.c:234:23: error: comparison of integer expressions of different signedness: ‘long int’ and ‘gsize’ {aka ‘long unsigned int’}
  234 |       if (in_end - in < block_size)
      |                       ^
gio/tests/converter-stream.c:244:21: error: comparison of integer expressions of different signedness: ‘int’ and ‘gsize’ {aka ‘long unsigned int’}
  244 |       for (i = 0; i < block_size; i++)
      |                     ^
gio/tests/converter-stream.c:257:33: error: comparison of integer expressions of different signedness: ‘long int’ and ‘gsize’ {aka ‘long unsigned int’}
  257 |       if (v == 0 && in_end - in == block_size && (flags & G_CONVERTER_INPUT_AT_END) == 0)
      |                                 ^~
2021-04-07 10:33:16 +02:00
Emmanuel Fleury
cc1e7302f3 Fix signedness warning in gio/tests/converter-stream.c:test_expander()
gio/tests/converter-stream.c: In function ‘test_expander’:
gio/tests/converter-stream.c:356:17: error: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’
  356 |   for (i = 0; i < sizeof(unexpanded_data); i++)
      |                 ^
2021-04-07 10:33:16 +02:00
Emmanuel Fleury
d2c0fd468c Fix several signedness warnings in gio/tests/converter-stream.c:test_compressor()
gio/tests/converter-stream.c: In function ‘test_compressor’:
gio/tests/converter-stream.c:445:17: error: comparison of integer expressions of different signedness: ‘int’ and ‘gsize’ {aka ‘long unsigned int’}
  445 |   for (i = 0; i < expanded_size; i++)
      |                 ^
gio/tests/converter-stream.c:454:16: error: comparison of integer expressions of different signedness: ‘int’ and ‘gsize’ {aka ‘long unsigned int’}
  454 |    g_assert (i == expanded_size -1);
      |                ^~
2021-04-07 10:33:16 +02:00
Emmanuel Fleury
29cd18b044 Fix several signedness warnings in gio/tests/converter-stream.c:test_converter_pollable()
gio/tests/converter-stream.c: In function ‘test_converter_pollable’:
gio/tests/converter-stream.c:1077:17: error: comparison of integer expressions of different signedness: ‘int’ and ‘gsize’ {aka ‘long unsigned int’}
 1077 |   for (i = 0; i < expanded_size; i++)
      |                 ^
gio/tests/converter-stream.c:1086:16: error: comparison of integer expressions of different signedness: ‘int’ and ‘gsize’ {aka ‘long unsigned int’}
 1086 |    g_assert (i == expanded_size -1);
      |                ^~
2021-04-07 10:33:16 +02:00
Emmanuel Fleury
eafc764bb2 Fix several signedness warnings in gio/tests/converter-stream.c:main()
gio/tests/converter-stream.c: In function ‘main’:
gio/tests/converter-stream.c:1220:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘long unsigned int’
 1220 |   for (i = 0; i < G_N_ELEMENTS (compressor_tests); i++)
      |                 ^
gio/tests/converter-stream.c:1223:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘long unsigned int’
 1223 |   for (i = 0; i < G_N_ELEMENTS (truncation_tests); i++)
      |                 ^
gio/tests/converter-stream.c:1226:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘long unsigned int’
 1226 |   for (i = 0; i < G_N_ELEMENTS (charset_tests); i++)
      |                 ^
2021-04-05 12:03:51 +02:00
Emmanuel Fleury
88253f171c Fix signedness warning in gio/tests/contenttype.c
gio/tests/contenttype.c: In function ‘test_tree’:
gio/tests/contenttype.c:337:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘long unsigned int’
  337 |   for (i = 0; i < G_N_ELEMENTS (tests); i++)
      |                 ^
2021-04-05 12:03:51 +02:00
Emmanuel Fleury
8bcb2b9e76 Fix several signedness warnings in gio/tests/contexts.c
gio/tests/contexts.c: In function ‘test_context_specific_emit’:
gio/tests/contexts.c:379:21: error: comparison of integer expressions of different signedness: ‘guint’ {aka ‘unsigned int’} and ‘gint32’ {aka ‘int’}
  379 |       for (i = 0; i < g_test_rand_int_range (1, 5); i++)
      |                     ^
gio/tests/contexts.c:383:55: error: comparison of integer expressions of different signedness: ‘int’ and ‘guint’ {aka ‘unsigned int’}
  383 |         while (g_atomic_int_get (&observed_values[i]) != n)
      |                                                       ^~
gio/tests/contexts.c:387:41: error: comparison of integer expressions of different signedness: ‘gint64’ {aka ‘long int’} and ‘guint64’ {aka ‘long unsigned int’}
  387 |             if (g_get_monotonic_time () > expiry)
      |                                         ^
2021-04-05 12:03:51 +02:00
Abanoub Ghadban
1bdfc1a36b gfileinfo: Add tests for get and set {access,creation}_date_time APIs 2021-03-28 23:07:39 +02:00
Frederic Martinsons
7f2fef5c26 tests: Deactivate tls-bindings test suite for windows
Signed-off-by: Frederic Martinsons <frederic.martinsons@sigfox.com>

Helps: #2297
2021-03-23 11:11:45 +00:00
Frederic Martinsons
59e999fd0a Add two test cases which covers disconnection scenario in another thread
1) Check that schedule_call_in_idle code branch of gdbusnamewatching.c
   is working to call vanished handler in the thread which had watched the name
2) Check cancellation of vanished handler if the name is unwatched before
   vanished callback is dispatched.

Closes #2011

Signed-off-by: Frederic Martinsons <frederic.martinsons@sigfox.com>
2021-03-17 08:36:47 +01:00
Frederic Martinsons
2f5f69e969 Use OwnNameData structure when owning a name instead of WatchNameData.
The two structures share some common variable name but it's confusing.

Signed-off-by: Frederic Martinsons <frederic.martinsons@sigfox.com>
2021-03-17 08:36:47 +01:00
Frederic Martinsons
98abfc9da7 Correct memleak introduced by !1885
Signed-off-by: Frederic Martinsons <frederic.martinsons@sigfox.com>
2021-03-17 08:36:47 +01:00
Sebastian Dröge
db0ec9528e Merge branch '2328-file-new-empty-path' into 'master'
glocalvfs: Create a dummy file for g_file_new_for_path("")

Closes #2328

See merge request GNOME/glib!1983
2021-03-11 09:42:19 +00:00
Philip Withnall
519bdf665b Merge branch 'work-out-libutil-soname-at-build-time' into 'master'
gio/tests/{meson.build,pollable.c}: Determine libutil SONAME at build time

See merge request GNOME/glib!1977
2021-03-10 19:35:18 +00:00
Philip Withnall
d52728f994 glocalvfs: Create a dummy file for g_file_new_for_path("")
`""` is not a valid path (`stat()` on it returns `ENOENT`). Previously,
a full `GLocalFile` was being created, which ended up resolving to
`$CWD`, through path canonicalisation. That isn’t right.

Fix it by creating a `GDummyFile` instead, and adding a unit test.

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

Fixes: #2328
2021-03-10 19:10:38 +00:00
Iain Lane
373e46c2b2
gio/tests/{meson.build,pollable.c}: Determine libutil SONAME at build time
Calling `dlopen()` with `libutil.so` makes the installed tests depend on
having glibc's development files installed. To avoid this, we can work
out the runtime library name at build time and `dlopen` that instead.

This approach is [taken from libfprint][1], thanks to Marco Trevisan.

[1]: f401f399a8
2021-03-10 18:04:17 +00:00
Philip Withnall
57a53ec964 gioerror: Add conversion from ENXIO to G_IO_ERROR_NOT_REGULAR_FILE
`ENXIO` can be returned from `open(2)` for special files (FIFOs, device
files and domain sockets) which are not backed by anything.

This fixes the error returned by `g_file_replace()` when trying to
replace such a file, so that it now matches the documentation.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-03-10 17:55:51 +00:00
Philip Withnall
730015a8ed tests: Add comprehensive tests for static behaviour of g_file_replace()
These test all the functionality and combinations of flags I can think
of. They do not cover dynamic behaviour (for example, what would happen
if the source file is deleted by another process part-way through a call
to `g_file_replace()`).

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-03-10 17:55:51 +00:00
Philip Withnall
87e19535fe glocalfileoutputstream: Fix CREATE_REPLACE_DESTINATION with symlinks
The `G_FILE_CREATE_REPLACE_DESTINATION` flag is equivalent to unlinking
the destination file and re-creating it from scratch. That did
previously work, but in the process the code would call `open(O_CREAT)`
on the file. If the file was a dangling symlink, this would create the
destination file (empty). That’s not an intended side-effect, and has
security implications if the symlink is controlled by a lower-privileged
process.

Fix that by not opening the destination file if it’s a symlink, and
adjusting the rest of the code to cope with
 - the fact that `fd == -1` is not an error iff `is_symlink` is true,
 - and that `original_stat` will contain the `lstat()` results for the
   symlink now, rather than the `stat()` results for its target (again,
   iff `is_symlink` is true).

This means that the target of the dangling symlink is no longer created,
which was the bug. The symlink itself continues to be replaced (as
before) with the new file — this is the intended behaviour of
`g_file_replace()`.

The behaviour for non-symlink cases, or cases where the symlink was not
dangling, should be unchanged.

Includes a unit test.

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

Fixes: #2325
2021-03-10 17:55:51 +00:00
Philip Withnall
5f2eae1156 tests: Stop using g_test_bug_base() in file tests
Since a following commit is going to add a new test which references
Gitlab, so it’s best to move the URI bases inside the test cases.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-03-10 16:02:35 +00:00
Chun-wei Fan
cf02c280ff gio/tests/pollable.c: Fix build on non-Linux UNIX
For non-Linux UNIX systems, the label 'close_libutil:' in
'test_pollable_unix_pty()' will have no statement that goes with that
label.  Just do a 'return' on non-Linux UNIX systems.
2021-02-27 10:53:53 +08:00
Simon McVittie
f443144091 Merge branch 'pollable-test-dlopen-leak' into 'master'
tests: Fix leak of dlopened module in pollable test

See merge request GNOME/glib!1936
2021-02-25 18:26:57 +00:00
Philip Withnall
50cf90dc56 tests: Test g_subprocess_launcher_close() doesn’t close too many FDs
Expand an existing unit test to check that the target FD of a
`g_subprocess_launcher_take_fd()` call doesn’t get closed when
`g_subprocess_launcher_close()` is called. Only the source FD should be
closed by the parent process.

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

Helps: #2332
2021-02-19 18:27:00 +00:00
Simon McVittie
ee53840fa6 tests: Use a more realistic language code than sv_SV
Swedish as spoken in El Salvador is not listed in
/usr/share/i18n/SUPPORTED, and in any case is probably not what we meant.
A more plausible language code would be Swedish as spoken in Sweden.

Prompted by improving the Debian packaging of GLib to generate most of
the language codes mentioned in the tests, so that we can have better
test coverage.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-02-14 14:43:12 +00:00
Philip Withnall
2f91caf77e tests: Add a basic test for require-same-user D-Bus auth flag
It’s not feasible to test that the require-same-user flag can cause
authentication to fail, as that would require the build environment to
have two users available. We can, however, test that it passes when
authenticating a client and server running under the same user account.

I have manually tested that the new flag works, by running the following
as user A:
```
`$prefix/gdbus-daemon --print-env &`
gdbus call --session --dest org.freedesktop.DBus --object-path /org/freedesktop/DBus --method org.freedesktop.DBus.ListNames
```

And then running the `gdbus call` command again as user B (with the same
value for `DBUS_SESSION_BUS_ADDRESS` in the environment), which
produces:
```
Error connecting: Unexpected lack of content trying to read a line
```
(an authentication rejection)

Commenting out the use of
`G_DBUS_SERVER_FLAGS_AUTHENTICATION_REQUIRE_SAME_USER` from
`gdbusdaemon.c`, the `gdbus call` command succeeds for both users.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-02-11 16:12:40 +00:00
Philip Withnall
a1db705bc2 Merge branch 'wip/gdbus-flags-from-the-future' into 'master'
gdbus: Reject attempts to set future connection or server flags

See merge request GNOME/glib!1934
2021-02-11 11:53:13 +00:00
Philip Withnall
68ce7a28e1 tests: Add tests for key name handling in the keyfile backend
This tests the two recent commits.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-02-10 22:10:00 +00:00
Philip Withnall
57a5ed3d08 tests: Fix leak of dlopened module in pollable test
Coverity CID: #1446243

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-02-09 11:06:53 +00:00
Simon McVittie
ba25c8a770 gdbus: Reject attempts to set future connection or server flags
The GDBusConnectionFlags and GDBusServerFlags can affect how we carry
out authentication and authorization, either making it more or less
restrictive, so it's desirable to "fail closed" if a program is compiled
against a new version of GLib but run against an old version.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-02-08 13:35:16 +00:00
Simon McVittie
df4501316c tls-interaction: Add test coverage for various ways to set the password
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-02-08 10:22:48 +00:00
Philip Withnall
73b293fd30 gio: Use g_memdup2() instead of g_memdup() in obvious places
Convert all the call sites which use `g_memdup()`’s length argument
trivially (for example, by passing a `sizeof()`), so that they use
`g_memdup2()` instead.

In almost all of these cases the use of `g_memdup()` would not have
caused problems, but it will soon be deprecated, so best port away from
it.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
Helps: #2319
2021-02-04 14:13:21 +00:00
Sebastian Dröge
e6f506a92c Merge branch 'fix/unix-stream-pollable-detection' into 'master'
gunix: Fix {Input,Output}Stream pollable detection

Closes #1180

See merge request GNOME/glib!1846
2021-02-02 10:46:52 +00:00
Ole André Vadla Ravnås
d7ee70c013 gunix: Fix {Input,Output}Stream pollable detection
For devices such as PTYs, where not being able to cancel a pending read
operation is problematic for many applications.

Fixes: #1180
2021-02-02 11:11:53 +01:00
Simon McVittie
f378352051 tests: Mark tests with AddressSanitizer-detected leaks
Various tests have leaks where it isn't clear whether the data is
intentionally not freed, or leaked due to a bug. If we mark these
tests as TODO, we can skip them under AddressSanitizer and get the
rest to pass, giving us a baseline from which to avoid regressions.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-02-01 11:19:59 +00:00
Simon McVittie
5685546ab1 gio: Don't run gsocketclient-slow test under sanitizers
AddressSanitizer, UndefinedBehaviourSanitizer and probably others
involve adding instrumentation into the code under test, which doesn't
go well with LD_PRELOAD modules that absolutely need to be
self-contained.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-02-01 10:44:35 +00:00
Simon McVittie
5b476d0d9c socket-service test: Don't leak writev vectors
Detected by AddressSanitizer.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-01-29 20:26:02 +00:00
Simon McVittie
de87bcf7ff gdbus-serialization: Don't leak string containing first serialization
We format the message into a string twice, once for each byte-order,
but only return the one corresponding to the last byte-order to the
caller. This means we need to free the first one.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-01-28 21:39:23 +00:00
Sebastian Dröge
fdc192f460 Merge branch 'fix/darwin-nosigpipe-regression' into 'master'
gsocket: Fix SO_NOSIGPIPE regression on Darwin

See merge request GNOME/glib!1894
2021-01-27 07:35:04 +00:00
Frederic Martinsons
d890b1ce5f Extend dbus watching name tests:
- use watcher auto start flag.
  - use watch_name_on_connection_with_closures.
  - use an existing service name for auto start.

Closes #2011

Signed-off-by: Frederic Martinsons <frederic.martinsons@sigfox.com>
2021-01-25 15:00:12 +01:00
Francesco Tamagni
f6ce5739f8 gsocket: Fix SO_NOSIGPIPE regression on Darwin
Where the early call to g_socket_set_option() fails because of
check_socket() failing due to `inited` still being FALSE.

This brings 634b692 back into working order, by fixing the regression
introduced in 39f047e.

Co-authored-by: Ole André Vadla Ravnås <oleavr@gmail.com>
2021-01-21 21:17:24 +01:00
Philip Withnall
8bdd7438e5 Merge branch '968-add-gdbus-obj-path-escape' into 'master'
Add g_dbus_utils_object_path_escape and g_dbus_utils_object_path_unescape

Closes #968

See merge request GNOME/glib!1871
2021-01-20 13:23:25 +00:00
MARTINSONS Frederic
47355c358d Add g_dbus_utils_object_path_escape and g_dbus_utils_object_path_unescape
These two APIs are useful to publish an object which path content is not
controlled (e.g. dynamically built or coming from external source).

Closes #968

(Rebased and tweaked by Frederic Martinsons)

Signed-off-by: Frederic Martinsons <frederic.martinsons@sigfox.com>
2021-01-20 13:23:24 +00:00
Philip Withnall
b6a1fa47fe Merge branch 'settings-test-cleanups' into 'master'
Various memory leak cleanups to GSettings tests

See merge request GNOME/glib!610
2021-01-20 13:15:26 +00:00
Philip Withnall
5cafd748e3 tests: Remove incorrect unref from tls-bindings tests
`g_tls_backend_get_default()` does not return a reference to the
backend, so don’t drop one.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-01-20 12:51:41 +00:00
Philip Withnall
98274e09de tests: Free GSettingsBackend singleton at end of gsettings tests
This makes the tests a whole lot closer to being valgrind-clean, and
revealed a few legitimate memory leaks in amongst the noise caused by
keeping the singleton GSettingsBackend around for the lifetime of the
process.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2021-01-20 12:51:41 +00:00
Krzesimir Nowak
a2525129a7 tests: Update the expected count in file test
We added another desktop file, so update the file count.
2021-01-09 16:00:50 +01:00
Krzesimir Nowak
cdf0a50c69 gdesktopappinfo: Fix validation of XDG_CURRENT_DESKTOP
Split out XDG_CURRENT_DESKTOP handling to a separate function and make
sure that it drops all the invalid entries properly. Earlier a bad
entry could slip through the checks by sitting just after another bad
entry, like in env being set to `invalid1!:invalid2!`, where
`invalid2!` could slip the checks.
2021-01-09 15:39:09 +01:00
Philip Withnall
d90d914fc5 tests: Add more debug information to gdbus-connection-slow
It occasionally fails in CI with output like:
```
196/274 glib:gio / gdbus-connection-slow        FAIL     0.54 s (killed by signal 6 SIGABRT)

--- command ---
G_TEST_BUILDDIR='/builds/pwithnall/glib/_build/gio/tests' G_TEST_SRCDIR='/builds/pwithnall/glib/gio/tests' GIO_MODULE_DIR='' /builds/pwithnall/glib/_build/gio/tests/gdbus-connection-slow
--- stdout ---
\# random seed: R02S4eb186e89e2472eedd11538b37192543
1..2
\# Start of gdbus tests
\# Start of connection tests
Bail out! GLib-GIO:ERROR:../gio/tests/gdbus-connection-slow.c:98:test_connection_flush: assertion failed (error == NULL): Child process killed by signal 11 (g-exec-error-quark, 19)
--- stderr ---
**
GLib-GIO:ERROR:../gio/tests/gdbus-connection-slow.c:98:test_connection_flush: assertion failed (error == NULL): Child process killed by signal 11 (g-exec-error-quark, 19)
cleaning up pid 12991
```

which is not very helpful. Add some more debug output to print the
stdout and stderr of the child process, to hopefully give an insight
into why it’s dying with signal 11 (sigsegv).

I can’t reproduce the sigsegv locally.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-01-07 17:55:21 +00:00
Ole André Vadla Ravnås
9ac3a27f03 gsocket: Fix credentials error-handling on Apple OSes
- When querying a TCP socket, getsockopt() may succeed but the resulting
  `optlen` will be zero. This means we'd previously be reading
  uninitialized stack memory in such cases.
- After a file-descriptor has gone through FD-passing, getsockopt() may
  fail with EINVAL. At least this is the case with TCP sockets.
- While at it also use SOL_LOCAL instead of hard-coding its value.
2021-01-04 12:29:47 +00:00
Emmanuel Fleury
76426c0158 Rewriting the G_GNUC_NORETURN into G_NORETURN macros everywhere 2020-11-25 11:34:05 +00:00
Sebastian Dröge
fa8a39c6c6 Merge branch 'py-fixes' into 'master'
Python formatting improvements

See merge request GNOME/glib!1757
2020-11-20 18:10:40 +00:00
Philip Withnall
f4607def16 tests: Drop unnecessary volatile qualifiers from tests
These variables were already (correctly) accessed atomically. The
`volatile` qualifier doesn’t help with that.

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

Helps: #600
2020-11-20 14:40:19 +00:00
Philip Withnall
7f905ff1fa tests: Fix non-atomic access to some shared variables
And drop the `volatile` qualifier from the variables, as that doesn’t
help with thread safety.

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

Helps: #600
2020-11-20 14:40:19 +00:00
Philip Withnall
fab561f8d0 gobject: Drop use of volatile from get_type() macros
http://isvolatileusefulwiththreads.in/c/

It’s possible that the variables here are only marked as volatile
because they’re arguments to `g_once_*()`. Those arguments will be
modified in a subsequent commit.

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

Helps: #600
2020-11-20 14:40:19 +00:00