Commit Graph

1071 Commits

Author SHA1 Message Date
Matthias Clasen
1102e6f9ca Allow property actions to invert booleans
This can be handy when you want to change the sense of a toggle
in the UI without rewriting the underlying logic. Currently, this
is just exposed as a construct-only property. We may add a
convenience wrapper or a special !property syntax for this later.

https://bugzilla.gnome.org/show_bug.cgi?id=728489
2015-06-10 21:59:28 -04:00
Simon McVittie
b701c3c608 Regression test for falling back to autolaunch: and XDG_RUNTIME_DIR/bus
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=747941
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk>
2015-06-09 18:17:25 +01:00
Ryan Lortie
6cf867fb2a gsettings tests: use g_settings_schema_list_keys()
Stop using g_settings_list_keys() because soon it will be deprecated.

https://bugzilla.gnome.org/show_bug.cgi?id=740308
2015-06-05 15:24:02 -04:00
Iain Lane
fe1a2dc196 gdbus tests: wait up to 60s for gdbus-testserver to take its bus name
Previously, we waited up to 0.5s, but that can fail on slow
architectures like ARM; now we wait up to 60s in 0.1s increments.

Patch originally by Simon McVittie <simon.mcvittie@collabora.co.uk>,
modified by Iain Lane to be called earlier, to catch all testcases in a
particular test.

Bug: https://bugzilla.gnome.org/show_bug.cgi?id=724113
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Acked-by: Matthias Clasen <mclasen@redhat.com>
2015-05-14 12:11:57 +01:00
Simon McVittie
3beb67f9f3 gdbus-connection: wait up to 10s to actually send a message
We previously waited 0.25s, which should be enough even on slow machines,
but you never know; but we also now wait in 0.1s increments, so this test
should actually be faster now.

Bug: https://bugzilla.gnome.org/show_bug.cgi?id=724113
Acked-by: Matthias Clasen <mclasen@redhat.com>
2015-05-14 12:11:20 +01:00
Simon McVittie
45dae4b506 tests: replace most g_print() with g_printerr()
I searched all files that mention g_test_run, and replaced most
g_print() calls. This avoids interfering with TAP. Exceptions:

* gio/tests/network-monitor: a manual mode that is run by
  "./network-monitor --watch" is unaffected
* glib/gtester.c: not a test
* glib/gtestutils.c: not a test
* glib/tests/logging.c: specifically exercising g_print()
* glib/tests/markup-parse.c: a manual mode that is run by
  "./markup-parse --cdata-as-text" is unaffected
* glib/tests/testing.c: specifically exercising capture of stdout
  in subprocesses
* glib/tests/utils.c: captures a subprocess's stdout
* glib/tests/testglib.c: exercises an assertion failure in g_print()

Bug: https://bugzilla.gnome.org/show_bug.cgi?id=725981
Reviewed-by: Colin Walters <walters@verbum.org>
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2015-05-11 20:24:56 +01:00
Simon McVittie
064183a633 GFileMonitor test: use g_test_skip() instead of g_print()
This stops it from interfering with structured stdout such as TAP.

Bug: https://bugzilla.gnome.org/show_bug.cgi?id=725981
Reviewed-by: Colin Walters <walters@verbum.org>
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2015-05-11 20:24:52 +01:00
Simon McVittie
bced30cfbb GDBus tests: change progress noise from "if not quiet" to "if verbose"
It seems that even after Bug #711796, these can still interfere
with TAP testing:

PASS: gdbus-proxy-threads 1 /gdbus/proxy/vs-threads
tap-driver.sh: internal error getting exit status
tap-driver.sh: fatal: I/O or internal error

Let's shut them up unless --verbose is used (which would be appropriate
when running them interactively).

Similar symptoms have been seen in Debian:
https://buildd.debian.org/status/fetch.php?pkg=glib2.0&arch=mipsel&ver=2.39.91-1&stamp=1394394568
and in Guix:
https://lists.gnu.org/archive/html/bug-guix/2014-12/msg00002.html

Bug: https://bugzilla.gnome.org/show_bug.cgi?id=725981
Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk>
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2015-05-11 16:16:50 +01:00
Simon McVittie
6f859fe21a gdbus-peer test: let GDBusServer start before notifying main thread
When running the nonce-tcp and tcp-anonymous tests in one run
of gdbus-peer, or running one of them twice via command-line options
"-p /gdbus/tcp-anonymous -p /gdbus/tcp-anonymous", the one run second
would sometimes fail to connect with ECONNRESET.

Adding more debug messages revealed that in the successful case,
g_main_loop_run() was executed in the server thread first:

 # tcp-anonymous: server thread: listening on tcp:host=localhost,port=53517
 # tcp-anonymous: server thread: starting server...
 # tcp-anonymous: server thread: creating main loop...
 # tcp-anonymous: server thread: running main loop...
 # tcp-anonymous: main thread: trying tcp:host=localhost,port=53517...
 # tcp-anonymous: main thread: waiting for server thread...

but in the failing case, the main thread attempted to connect
before the call to g_main_loop_run() in the server thread:

 # tcp-anonymous: server thread: listening on tcp:host=localhost,port=40659
 # tcp-anonymous: server thread: starting server...
 # tcp-anonymous: server thread: creating main loop...
 # tcp-anonymous: main thread: trying tcp:host=localhost,port=40659...
 # tcp-anonymous: server thread: running main loop...

(The log message "creating main loop" was immediately before
create_service_loop(), and "running main loop" was immediately
before g_main_loop_run().)

To ensure that the GDBusServer has a chance to start accepting
connections before the main thread tries to connect to it, do not
tell the main thread about the service_loop immediately, but instead
defer it to an idle.

Bug: https://bugzilla.gnome.org/show_bug.cgi?id=749079
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk>
2015-05-11 14:17:55 +01:00
Simon McVittie
f42d2c1b54 gdbus-serialization: use check_serialization() instead of dbus-daemon
This test originally did not connect to the bus, which meant it was
omitted from commits like 415a8d81 that made sure none of GLib tests
rely on the presence of an existing session bus. (In particular,
Debian autobuilders don't have a session bus.)

When test_double_array() was added, environments like the Debian
autobuilders didn't catch the fact that this test relied on having a
session bus, because it is often skipped in minimal environments
due to its libdbus-1 dependency.

We don't actually need to connect to a dbus-daemon here: it's enough
to convert the message from GVariant to D-Bus serialization, and
back into an in-memory representation through libdbus. That's what
check_serialization() does, and I've verified that when I re-introduce
bug #732754 by reverting commits 627b49b and 2268628 locally, this
test still fails.

Bug: https://bugzilla.gnome.org/show_bug.cgi?id=744895
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: Colin Walters <walters@verbum.org>
2015-05-08 16:03:57 +01:00
Chun-wei Fan
10b5a8befc Fix the thumbnail-verification Test
The third parameter of the thumnail_verify() function had been updated to
const GLocalFileStat, so update the thumbnail-verification test likewise
so that the test works properly on all supported platforms.

https://bugzilla.gnome.org/show_bug.cgi?id=711547
2015-04-22 18:56:50 +08:00
Philip Withnall
c62f7a7d68 tests: Fix various minor memory leaks in gdbus-serialization 2015-04-21 23:55:49 +01:00
Simon McVittie
92331eb10a Distribute summary-xmllang-and-attrs.gschema.xml in tarballs
This is needed for "make distcheck".

Reviewed-by: Matthias Clasen <mclasen@redhat.com>
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=748177
2015-04-20 14:19:52 +01:00
Ryan Lortie
3fa0a051a4 gsettings: add test for repeated <summary> errors
Make sure error handling on repeated <summary> and <description> is
being done properly, not resulting in glib-compile-schemas throwing a
critical.

https://bugzilla.gnome.org/show_bug.cgi?id=747542
2015-04-08 22:35:35 -04:00
Dan Winship
7e8d4145af gdbus: fix deadlock on message cancel/timeout
The gdbus GTask port introduced a deadlock because some code had been
using g_simple_async_result_complete_in_idle() to ensure that the
callback didn't run until after a mutex was unlocked, but in the gtask
version, the callback was being run immediately. Fix it to drop the
mutex before calling g_task_return*(). Also, tweak
tests/gdbus-connection to test this.

https://bugzilla.gnome.org/show_bug.cgi?id=747349
2015-04-06 12:22:07 -04:00
Paolo Borelli
b64e2956f6 Add an event signal to GSocketListener
This allows the caller to know when a socket has been bound so that
it can for instance set the SO_SENDBUF and SO_RECVBUF socket options
before listen is called

https://bugzilla.gnome.org/show_bug.cgi?id=738207
2015-04-04 21:26:15 +02:00
Dan Winship
ec9c248d7d gio: deprecate GSimpleAsyncResult
GTask has been around for a long time now, everything in GLib is using
it, and the run-in-thread deadlock problems should be fixed now.

https://bugzilla.gnome.org/show_bug.cgi?id=661767
2015-04-04 10:16:52 -04:00
Dan Winship
e2655cd455 tests: clean up / ignore some more generated files 2015-04-04 10:00:39 -04:00
Dan Winship
86866a2a6d gtask: remove hardcoded GTask thread-pool size
GTask used a 10-thread thread pool for g_task_run_in_thread() /
g_task_run_in_thread_sync(), but this ran into problems when task
threads blocked waiting for another g_task_run_in_thread_sync()
operation to complete. Previously there was a workaround for this, by
bumping up the thread limit when that case was detected, but deadlocks
could still happen if there were non-GTask threads involved. (Eg, task
A sends a message to thread X and waits for a response, but thread X
needs to complete task B in a thread before returning the response to
task A.)

So, allow GTask's thread pool to be expanded dynamically, by watching
it from the glib worker thread, and growing it (at an
exponentially-decreasing rate) if too much time passes without any
tasks completing. This should solve the deadlocking problems without
causing sudden breakage in apps that assume they can queue huge
numbers of tasks at once without consequences.

https://bugzilla.gnome.org/show_bug.cgi?id=687223
2015-04-04 09:27:50 -04:00
Matthias Clasen
b2734d762f glib-compile-schema: Don't accept duplicate docs
This schema compiler was completely ignoring <summary> and
<description> tags. Unfortunately, there are modules out there
who merge translations for these back in, with xml:lang. And
this is giving dconf-editor a hard time. Since this is not
how translations of schemas are meant to be done, just
reject such schema files.

Also add tests exercising the new error handling.

https://bugzilla.gnome.org/show_bug.cgi?id=747209
2015-04-01 18:55:54 -04:00
Jasper St. Pierre
93c8cbcfcd Update .gitignore 2015-03-18 14:28:14 -07:00
Ryan Lortie
0de16c98f7 ContextSpecificGroup: some fixups
For all of the effort spent ensuring that this algorithm would be
correctly threadsafe, I messed up the order of operations within a
single thread when porting to the new approach.

Fix that up.

Also: fix some overzealous asserting in the testcases.  Since shutdown
is now lazy, we can never surely say !is_running at any particular point
in time.
2015-03-13 17:39:50 -04:00
Philip Withnall
4f1f68e6be gtask: Add a GTask:completed property
This can be used to query whether the task has completed, in the sense
that it has had a result set on it, and has already – or will soon –
invoke its callback function.

Notifications for this property are emitted immediately after the task’s
main callback, in the same main context as that callback. This allows
for multiple bits of code to listen for completion of the GTask, which
opens the door for blocking on cancellation of the GTask and improved
handling of ‘pending’ behaviour.

https://bugzilla.gnome.org/show_bug.cgi?id=743636
2015-03-10 08:37:45 +00:00
Ryan Lortie
8c104a01e1 GContextSpecificGroup: fix deadlock
There was a theoretical deadlock between the worker trying to emit a
signal at the same time as we were waiting for it to shutdown the
notification (while holding the lock).

The deadlock was particularly annoying because we didn't really need to
wait for the shutdown and because it wasn't possible to signals to
arrive while waiting for a start.  Attempting to deal with start and
stop in an asymmetric way could have lead to other weird situations,
however.

Drop the lock while waiting for the worker thread to start.  This means
that we face the possibility of multiple waiters on the cond at the same
time, so we need to make more of a state machine.

https://bugzilla.gnome.org/show_bug.cgi?id=742599
2015-03-02 15:10:46 -05:00
Ryan Lortie
88745c2fa7 tests: add some tests for GContextSpecificGroup
https://bugzilla.gnome.org/show_bug.cgi?id=742599
2015-03-02 15:10:46 -05:00
Ryan Lortie
71642ce766 tests: only chmod autorun.exe on UNIX
We install win32-software/autorun.exe (as test data for mime scanning)
only on UNIX builds, so don't attempt to chmod it on 'make install'
unless we're on UNIX.
2015-03-01 00:50:09 -05:00
Colin Walters
0550708ca7 tests: Add many autoptr tests
I love Emacs keyboard macros, used them to convert the list of
defines cleverly into a list of tests, then iterated and filled in
the necessary constructor arguments.
2015-02-23 10:40:40 -05:00
Colin Walters
52cd62d946 filenumerator: Add g_file_enumerator_iterate()
This is *significantly* more pleasant to use from C (while handling
errors and memory cleanup).

While we're here, change some ugly, leaky code in
tests/desktop-app-info.c to use it, in addition to a test case
in tests/file.c.

https://bugzilla.gnome.org/show_bug.cgi?id=661554
2015-02-20 14:02:05 -05:00
Lars Uebernickel
2b27382596 gapplication: test setting and binding busy state
https://bugzilla.gnome.org/show_bug.cgi?id=744756
2015-02-19 08:39:55 +01:00
Ryan Lortie
07ae2e1278 tests: add GSimpleIOStream async close tests
Just a couple of tests to make sure the two paths are working properly,
without crashes or leaks.

https://bugzilla.gnome.org/show_bug.cgi?id=741630
2015-02-17 16:27:46 -05:00
Ignacio Casal Quinteiro
d4e3b82a93 Add GSimpleIOStream class
GSimpleIOStream represents an object that wraps an input and an output
stream making easy to use them by calling the #GIOStream methods.

https://bugzilla.gnome.org/show_bug.cgi?id=741630
2015-02-17 16:27:46 -05:00
Ryan Lortie
c7f0ea4354 tests: check for NULL before g_object_unref()
delayed_close_free() calls g_object_unref() on a variable that is
expected to possibly contain NULL (as indicated by the fact that the
NULL case is handled in my_slow_close_output_stream_close_async()).

This is dead code right now (due to a bug in GDBus), which is why it
isn't actually causing a failure.  It should still be fixed, however.

https://bugzilla.gnome.org/show_bug.cgi?id=743990
2015-02-17 16:16:52 -05:00
Jasper St. Pierre
56f0c637cf Update .gitignore 2015-02-10 11:50:59 -08:00
Ryan Lortie
26af7c152f tests: add test for GListStore inserted sort
https://bugzilla.gnome.org/show_bug.cgi?id=743927
2015-02-03 15:46:48 +01:00
Ryan Lortie
93982d4a16 giotypefuncs test: tweak _get_type() regexp
Make sure that we only match the _get_type() function name by
restricting the regexp to matching [A-Za-z0-9_].  We were matching on .*
before which means that if we had two _get_type() functions appearing on
a single line then we would get everything in between them included (by
the default rule of '*' being greedy).

This affected G_DECLARE_*_TYPE which puts several uses of _get_type()
into a single line.
2015-01-30 15:30:02 +01:00
Lars Uebernickel
b69beff426 Add GListModel
GListModel is an interface that represents a dynamic list of GObjects.

Also add GListStore, a simple implementation of GListModel that stores
all objects in memory, using a GSequence.

https://bugzilla.gnome.org/show_bug.cgi?id=729351
2015-01-30 15:08:57 +01:00
Paolo Borelli
4f4714285d gsocket: add a testcase that shows a hang on win32
Add a unit test that checks g_socket_new_from_fd by creating
a gsocket, obtaining its fd, duplicating the fd and then creating
a gsocket from the new fd. This shows a hang on win32 since the
gsocket created from the fd never receives the FD_WRITE event
because we wait for the condition without first trying to write
and windows signals the condition only after a EWOULDBLOCK error.

https://bugzilla.gnome.org/show_bug.cgi?id=741707
2015-01-17 15:04:25 +01:00
Dan Winship
b6d1c66c50 gio/tests/socket: fix one of the new tests
One of the recently-added tests was using g_test_cmpstr() on a buffer
containing a string that wasn't necessarily 0-terminated.
2014-12-14 08:04:27 -05:00
Tim-Philipp Müller
ae1b6ecd9d gio/tests/socket: add unit test for g_socket_send_messages()
https://bugzilla.gnome.org/show_bug.cgi?id=719646
2014-12-11 15:10:44 +00:00
Tim-Philipp Müller
3c3fc0e463 gio/tests/socket: add datagram version of test_ip_sync 2014-12-11 15:10:44 +00:00
Tim-Philipp Müller
4864850427 gio/tests/socket: add test for g_socket_send_message() 2014-12-11 15:10:44 +00:00
Ross Lagerwall
7d9816934e gio/tests: Prevent hangs and aborts in socket-listener
Fix two problems:
1) If g_socket_service_stop is called before the accept call is requeued,
then the reference count won't decrease and this code will hang forever:
  while (G_OBJECT (service)->ref_count == ref_count)
    g_main_context_iteration (NULL, TRUE);

2) Sometimes the testcase fails (maybe 1 in 200 times for me):
GLib-GIO:ERROR:socket-listener.c:73:connection_cb: assertion failed
(G_OBJECT (service)->ref_count == 2): (3 == 2)
Aborted (core dumped)

The problem is that depending on ordering, cancellation of the async
listener can require further main context iterations before it releases
the reference on the socket service. Furthermore, in some cases, it
requires at least one iteration.

https://bugzilla.gnome.org/show_bug.cgi?id=712570
2014-12-07 08:40:18 +02:00
Dan Winship
8d08b82109 gio: add network connectivity state to GNetworkMonitor
Add a property to GNetworkMonitor indicating the level of network
connectivity: none/local, limited, stuck behind a portal, or full.

The default implementation just returns none or full depending on the
value of is-available.

https://bugzilla.gnome.org/show_bug.cgi?id=664562
2014-12-05 17:37:41 +01:00
Dan Winship
967fedc0ae gsocket: add G_IO_ERROR_CONNECTION_CLOSED
Add G_IO_ERROR_CONNECTION_CLOSED as an alias for
G_IO_ERROR_BROKEN_PIPE, and also return it on ECONNRESET.

It doesn't really make sense to try to distinguish EPIPE and
ECONNRESET at the GLib level, since the exact choice of which error
gets returned in what conditions depends on the OS. Given that, we
ought to map the two errors to the same value, and since we're already
mapping EPIPE to G_IO_ERROR_BROKEN_PIPE, we need to map ECONNRESET to
that too. But the existing name doesn't really make sense for sockets,
so we add a new name.

https://bugzilla.gnome.org/show_bug.cgi?id=728928
2014-11-29 14:26:42 -05:00
Dan Winship
64f9bf96fd gnetworkaddress: Add g_network_address_new_loopback() constructor
This is a convenience method for creating a GNetworkAddress which is
guaranteed to return IPv4 and IPv6 loopback addresses. The program
cannot guarantee that 'localhost' will resolve to both types of
address, so programs which wish to connect to a local service over
either IPv4 or IPv6 must currently manually create an IPv4 and another
IPv6 socket, and detect which of the two are working. This new API
allows the existing GSocketConnectable machinery to be used to
automate that.

Based on a patch from Philip Withnall.

https://bugzilla.gnome.org/show_bug.cgi?id=732317
2014-11-29 14:22:42 -05:00
Matthias Clasen
7f2f4ab12d Use the new g_strv_contains
No need to keep our own copy of this in the testsuite.
2014-11-27 09:12:42 -05:00
Dan Winship
e784a4ba32 gio/tests: add a socket-listener test
Add a GSocketListener test program. Currently the only test is a
regression test for bug 712570 (based on a standalone bug reproducer
provided by Ross Lagerwall).
2014-11-23 12:33:01 -05:00
Lars Uebernickel
021c4ad050 gapplication: enable --help when app has options
This should already work according to the documentation, but doesn't
because main_options is consumed before the check in
g_application_parse_command_line().

Fix by moving the check for main_options up.

https://bugzilla.gnome.org/show_bug.cgi?id=740157
2014-11-15 17:35:18 +01:00
Dan Winship
0501bf26b9 gio/tests/tls-certificates: fix
da053e34 broke the tls-certificates test by requiring the backend to
implement g_tls_certificate_verify() (which the test TLS backend
didn't). Add a trivial implementation to make the test pass again;
we'll need something more complicated when we add tests that are
supposed to get errors.
2014-10-25 08:52:54 -04:00
Ryan Lortie
b768d0e4ea Add tests for {read,write}_all_async()
https://bugzilla.gnome.org/show_bug.cgi?id=737451
2014-10-21 12:09:57 -04:00