summaryrefslogtreecommitdiff
path: root/gio/tests
diff options
context:
space:
mode:
authorHyunjee Kim <hj0426.kim@samsung.com>2019-12-03 11:00:55 +0900
committerHyunjee Kim <hj0426.kim@samsung.com>2019-12-03 11:00:55 +0900
commit85ef543166f81464323d083c9a21096cc634cad0 (patch)
treea68d53ee7eb4ff2e4f116e5a9fd69fce3d3059f4 /gio/tests
parent68bf5c4184c2899c4b0594930c7112d88f15e199 (diff)
downloadglib-85ef543166f81464323d083c9a21096cc634cad0.tar.gz
glib-85ef543166f81464323d083c9a21096cc634cad0.tar.bz2
glib-85ef543166f81464323d083c9a21096cc634cad0.zip
Imported Upstream version 2.61.2
Diffstat (limited to 'gio/tests')
-rw-r--r--gio/tests/appinfo-test.desktop.in2
-rw-r--r--gio/tests/appinfo.c2
-rw-r--r--gio/tests/contenttype.c84
-rw-r--r--gio/tests/gdbus-addresses.c10
-rw-r--r--gio/tests/gdbus-connection-loss.c3
-rwxr-xr-xgio/tests/gdbus-example-peer.c77
-rw-r--r--gio/tests/gdbus-names.c3
-rw-r--r--gio/tests/gdbus-peer.c110
-rw-r--r--gio/tests/gdbus-threading.c10
-rw-r--r--gio/tests/giomodule.c25
-rw-r--r--gio/tests/glistmodel.c4
-rw-r--r--gio/tests/gsubprocess.c7
-rw-r--r--gio/tests/meson.build27
-rw-r--r--gio/tests/network-address.c28
-rw-r--r--gio/tests/resourceplugin.c11
-rw-r--r--gio/tests/resources.c19
-rw-r--r--gio/tests/send-data.c8
-rw-r--r--gio/tests/testfilemonitor.c138
-rw-r--r--gio/tests/tls-interaction.c10
19 files changed, 419 insertions, 159 deletions
diff --git a/gio/tests/appinfo-test.desktop.in b/gio/tests/appinfo-test.desktop.in
index bc292b135..1f6ff7144 100644
--- a/gio/tests/appinfo-test.desktop.in
+++ b/gio/tests/appinfo-test.desktop.in
@@ -9,7 +9,7 @@ Comment=GAppInfo example
Comment[de]=GAppInfo Beispiel
Exec=@installed_tests_dir@/appinfo-test --option %U %i --name %c --filename %k %m %%
Icon=testicon.svg
-Terminal=true
+Terminal=false
StartupNotify=true
StartupWMClass=appinfo-class
MimeType=image/png;image/jpeg;
diff --git a/gio/tests/appinfo.c b/gio/tests/appinfo.c
index f13698d70..4fec6b379 100644
--- a/gio/tests/appinfo.c
+++ b/gio/tests/appinfo.c
@@ -87,7 +87,7 @@ test_launch_no_app_id (void)
"Comment=GAppInfo example\n"
"Comment[de]=GAppInfo Beispiel\n"
"Icon=testicon.svg\n"
- "Terminal=true\n"
+ "Terminal=false\n"
"StartupNotify=true\n"
"StartupWMClass=appinfo-class\n"
"MimeType=image/png;image/jpeg;\n"
diff --git a/gio/tests/contenttype.c b/gio/tests/contenttype.c
index 2424b8e5f..3696e3662 100644
--- a/gio/tests/contenttype.c
+++ b/gio/tests/contenttype.c
@@ -39,7 +39,7 @@ test_guess (void)
g_free (existing_directory);
expected = g_content_type_from_mime_type ("inode/directory");
g_assert_content_type_equals (expected, res);
- g_assert (uncertain);
+ g_assert_true (uncertain);
g_free (res);
g_free (expected);
@@ -52,7 +52,7 @@ test_guess (void)
res = g_content_type_guess ("foo.txt", data, sizeof (data) - 1, &uncertain);
expected = g_content_type_from_mime_type ("text/plain");
g_assert_content_type_equals (expected, res);
- g_assert (!uncertain);
+ g_assert_false (uncertain);
g_free (res);
g_free (expected);
@@ -61,21 +61,21 @@ test_guess (void)
res = g_content_type_guess ("foo", data, sizeof (data) - 1, &uncertain);
expected = g_content_type_from_mime_type ("text/plain");
g_assert_content_type_equals (expected, res);
- g_assert (!uncertain);
+ g_assert_false (uncertain);
g_free (res);
g_free (expected);
res = g_content_type_guess ("foo.desktop", data, sizeof (data) - 1, &uncertain);
expected = g_content_type_from_mime_type ("application/x-desktop");
g_assert_content_type_equals (expected, res);
- g_assert (!uncertain);
+ g_assert_false (uncertain);
g_free (res);
g_free (expected);
res = g_content_type_guess (NULL, data, sizeof (data) - 1, &uncertain);
expected = g_content_type_from_mime_type ("application/x-desktop");
g_assert_content_type_equals (expected, res);
- g_assert (!uncertain);
+ g_assert_false (uncertain);
g_free (res);
g_free (expected);
@@ -84,14 +84,14 @@ test_guess (void)
res = g_content_type_guess ("test.pot", (guchar *)"ABC abc", 7, &uncertain);
expected = g_content_type_from_mime_type ("text/x-gettext-translation-template");
g_assert_content_type_equals (expected, res);
- g_assert (!uncertain);
+ g_assert_false (uncertain);
g_free (res);
g_free (expected);
res = g_content_type_guess ("test.pot", (guchar *)"msgid \"", 7, &uncertain);
expected = g_content_type_from_mime_type ("text/x-gettext-translation-template");
g_assert_content_type_equals (expected, res);
- g_assert (!uncertain);
+ g_assert_false (uncertain);
g_free (res);
g_free (expected);
@@ -107,7 +107,7 @@ test_guess (void)
res = g_content_type_guess ("test.otf", (guchar *)"OTTO", 4, &uncertain);
expected = g_content_type_from_mime_type ("application/x-font-otf");
g_assert_content_type_equals (expected, res);
- g_assert (!uncertain);
+ g_assert_false (uncertain);
g_free (res);
g_free (expected);
#endif
@@ -115,7 +115,15 @@ test_guess (void)
res = g_content_type_guess (NULL, (guchar *)"%!PS-Adobe-2.0 EPSF-1.2", 23, &uncertain);
expected = g_content_type_from_mime_type ("image/x-eps");
g_assert_content_type_equals (expected, res);
- g_assert (!uncertain);
+ g_assert_false (uncertain);
+ g_free (res);
+ g_free (expected);
+
+ /* The data below would be detected as a valid content type, but shouldn’t be read at all. */
+ res = g_content_type_guess (NULL, (guchar *)"%!PS-Adobe-2.0 EPSF-1.2", 0, &uncertain);
+ expected = g_content_type_from_mime_type ("application/x-zerosize");
+ g_assert_content_type_equals (expected, res);
+ g_assert_false (uncertain);
g_free (res);
g_free (expected);
}
@@ -127,7 +135,7 @@ test_unknown (void)
gchar *str;
unknown = g_content_type_from_mime_type ("application/octet-stream");
- g_assert (g_content_type_is_unknown (unknown));
+ g_assert_true (g_content_type_is_unknown (unknown));
str = g_content_type_get_mime_type (unknown);
g_assert_cmpstr (str, ==, "application/octet-stream");
g_free (str);
@@ -143,8 +151,8 @@ test_subtype (void)
plain = g_content_type_from_mime_type ("text/plain");
xml = g_content_type_from_mime_type ("application/xml");
- g_assert (g_content_type_is_a (xml, plain));
- g_assert (g_content_type_is_mime_type (xml, "text/plain"));
+ g_assert_true (g_content_type_is_a (xml, plain));
+ g_assert_true (g_content_type_is_mime_type (xml, "text/plain"));
g_free (plain);
g_free (xml);
@@ -175,11 +183,11 @@ test_list (void)
types = g_content_types_get_registered ();
- g_assert (g_list_length (types) > 1);
+ g_assert_cmpuint (g_list_length (types), >, 1);
/* just check that some types are in the list */
- g_assert (g_list_find_custom (types, plain, find_mime) != NULL);
- g_assert (g_list_find_custom (types, xml, find_mime) != NULL);
+ g_assert_nonnull (g_list_find_custom (types, plain, find_mime));
+ g_assert_nonnull (g_list_find_custom (types, xml, find_mime));
g_list_free_full (types, g_free);
@@ -193,15 +201,15 @@ test_executable (void)
gchar *type;
type = g_content_type_from_mime_type ("application/x-executable");
- g_assert (g_content_type_can_be_executable (type));
+ g_assert_true (g_content_type_can_be_executable (type));
g_free (type);
type = g_content_type_from_mime_type ("text/plain");
- g_assert (g_content_type_can_be_executable (type));
+ g_assert_true (g_content_type_can_be_executable (type));
g_free (type);
type = g_content_type_from_mime_type ("image/png");
- g_assert (!g_content_type_can_be_executable (type));
+ g_assert_false (g_content_type_can_be_executable (type));
g_free (type);
}
@@ -213,7 +221,7 @@ test_description (void)
type = g_content_type_from_mime_type ("text/plain");
desc = g_content_type_get_description (type);
- g_assert (desc != NULL);
+ g_assert_nonnull (desc);
g_free (desc);
g_free (type);
@@ -227,17 +235,17 @@ test_icon (void)
type = g_content_type_from_mime_type ("text/plain");
icon = g_content_type_get_icon (type);
- g_assert (G_IS_ICON (icon));
+ g_assert_true (G_IS_ICON (icon));
if (G_IS_THEMED_ICON (icon))
{
const gchar *const *names;
names = g_themed_icon_get_names (G_THEMED_ICON (icon));
#ifdef __APPLE__
- g_assert (g_strv_contains (names, "text-*"));
+ g_assert_true (g_strv_contains (names, "text-*"));
#else
- g_assert (g_strv_contains (names, "text-plain"));
- g_assert (g_strv_contains (names, "text-x-generic"));
+ g_assert_true (g_strv_contains (names, "text-plain"));
+ g_assert_true (g_strv_contains (names, "text-x-generic"));
#endif
}
g_object_unref (icon);
@@ -245,15 +253,15 @@ test_icon (void)
type = g_content_type_from_mime_type ("application/rtf");
icon = g_content_type_get_icon (type);
- g_assert (G_IS_ICON (icon));
+ g_assert_true (G_IS_ICON (icon));
if (G_IS_THEMED_ICON (icon))
{
const gchar *const *names;
names = g_themed_icon_get_names (G_THEMED_ICON (icon));
- g_assert (g_strv_contains (names, "application-rtf"));
+ g_assert_true (g_strv_contains (names, "application-rtf"));
#ifndef __APPLE__
- g_assert (g_strv_contains (names, "x-office-document"));
+ g_assert_true (g_strv_contains (names, "x-office-document"));
#endif
}
g_object_unref (icon);
@@ -269,20 +277,20 @@ test_symbolic_icon (void)
type = g_content_type_from_mime_type ("text/plain");
icon = g_content_type_get_symbolic_icon (type);
- g_assert (G_IS_ICON (icon));
+ g_assert_true (G_IS_ICON (icon));
if (G_IS_THEMED_ICON (icon))
{
const gchar *const *names;
names = g_themed_icon_get_names (G_THEMED_ICON (icon));
#ifdef __APPLE__
- g_assert (g_strv_contains (names, "text-*-symbolic"));
- g_assert (g_strv_contains (names, "text-*"));
+ g_assert_true (g_strv_contains (names, "text-*-symbolic"));
+ g_assert_true (g_strv_contains (names, "text-*"));
#else
- g_assert (g_strv_contains (names, "text-plain-symbolic"));
- g_assert (g_strv_contains (names, "text-x-generic-symbolic"));
- g_assert (g_strv_contains (names, "text-plain"));
- g_assert (g_strv_contains (names, "text-x-generic"));
+ g_assert_true (g_strv_contains (names, "text-plain-symbolic"));
+ g_assert_true (g_strv_contains (names, "text-x-generic-symbolic"));
+ g_assert_true (g_strv_contains (names, "text-plain"));
+ g_assert_true (g_strv_contains (names, "text-x-generic"));
#endif
}
g_object_unref (icon);
@@ -290,17 +298,17 @@ test_symbolic_icon (void)
type = g_content_type_from_mime_type ("application/rtf");
icon = g_content_type_get_symbolic_icon (type);
- g_assert (G_IS_ICON (icon));
+ g_assert_true (G_IS_ICON (icon));
if (G_IS_THEMED_ICON (icon))
{
const gchar *const *names;
names = g_themed_icon_get_names (G_THEMED_ICON (icon));
- g_assert (g_strv_contains (names, "application-rtf-symbolic"));
- g_assert (g_strv_contains (names, "application-rtf"));
+ g_assert_true (g_strv_contains (names, "application-rtf-symbolic"));
+ g_assert_true (g_strv_contains (names, "application-rtf"));
#ifndef __APPLE__
- g_assert (g_strv_contains (names, "x-office-document-symbolic"));
- g_assert (g_strv_contains (names, "x-office-document"));
+ g_assert_true (g_strv_contains (names, "x-office-document-symbolic"));
+ g_assert_true (g_strv_contains (names, "x-office-document"));
#endif
}
g_object_unref (icon);
diff --git a/gio/tests/gdbus-addresses.c b/gio/tests/gdbus-addresses.c
index d6a5c2360..173383d83 100644
--- a/gio/tests/gdbus-addresses.c
+++ b/gio/tests/gdbus-addresses.c
@@ -108,14 +108,20 @@ test_unix_address (void)
g_test_skip ("unix transport is not supported on non-Unix platforms");
#else
assert_is_supported_address ("unix:path=/tmp/dbus-test");
+ assert_is_supported_address ("unix:path=/tmp/dbus-test,guid=0");
assert_is_supported_address ("unix:abstract=/tmp/dbus-another-test");
+ assert_is_supported_address ("unix:abstract=/tmp/dbus-another-test,guid=1000");
assert_not_supported_address ("unix:foo=bar");
g_assert_false (g_dbus_is_address ("unix:path=/foo;abstract=/bar"));
assert_is_supported_address ("unix:path=/tmp/concrete;unix:abstract=/tmp/abstract");
assert_is_supported_address ("unix:tmpdir=/tmp");
+ assert_is_supported_address ("unix:dir=/tmp");
assert_not_supported_address ("unix:tmpdir=/tmp,path=/tmp");
assert_not_supported_address ("unix:tmpdir=/tmp,abstract=/tmp/foo");
+ assert_not_supported_address ("unix:tmpdir=/tmp,dir=/tmp");
assert_not_supported_address ("unix:path=/tmp,abstract=/tmp/foo");
+ assert_not_supported_address ("unix:path=/tmp,dir=/tmp");
+ assert_not_supported_address ("unix:abstract=/tmp/foo,dir=/tmp");
assert_not_supported_address ("unix:");
#endif
}
@@ -124,9 +130,11 @@ static void
test_nonce_tcp_address (void)
{
assert_is_supported_address ("nonce-tcp:host=localhost,port=42,noncefile=/foo/bar");
+ assert_is_supported_address ("nonce-tcp:host=localhost,port=42,noncefile=/foo/bar,guid=0");
assert_is_supported_address ("nonce-tcp:host=localhost,port=42,noncefile=/foo/bar,family=ipv6");
assert_is_supported_address ("nonce-tcp:host=localhost,port=42,noncefile=/foo/bar,family=ipv4");
assert_is_supported_address ("nonce-tcp:host=localhost");
+ assert_is_supported_address ("nonce-tcp:host=localhost,guid=1000");
assert_not_supported_address ("nonce-tcp:host=localhost,port=42,noncefile=/foo/bar,family=blah");
assert_not_supported_address ("nonce-tcp:host=localhost,port=420000,noncefile=/foo/bar,family=ipv4");
@@ -144,8 +152,10 @@ static void
test_tcp_address (void)
{
assert_is_supported_address ("tcp:host=localhost");
+ assert_is_supported_address ("tcp:host=localhost,guid=1000");
assert_not_supported_address ("tcp:host=localhost,noncefile=/tmp/foo");
assert_is_supported_address ("tcp:host=localhost,port=42");
+ assert_is_supported_address ("tcp:host=localhost,port=42,guid=1000");
assert_not_supported_address ("tcp:host=localhost,port=-1");
assert_not_supported_address ("tcp:host=localhost,port=420000");
assert_not_supported_address ("tcp:host=localhost,port=42x");
diff --git a/gio/tests/gdbus-connection-loss.c b/gio/tests/gdbus-connection-loss.c
index 9dbbeb2a4..8f7023f3f 100644
--- a/gio/tests/gdbus-connection-loss.c
+++ b/gio/tests/gdbus-connection-loss.c
@@ -136,9 +136,10 @@ main (int argc,
ret = g_test_run();
+ g_object_unref (c);
+
session_bus_down ();
- g_object_unref (c);
g_main_loop_unref (loop);
return ret;
diff --git a/gio/tests/gdbus-example-peer.c b/gio/tests/gdbus-example-peer.c
index bf151cfcf..9d5de32a6 100755
--- a/gio/tests/gdbus-example-peer.c
+++ b/gio/tests/gdbus-example-peer.c
@@ -169,6 +169,74 @@ on_new_connection (GDBusServer *server,
/* ---------------------------------------------------------------------------------------------------- */
+static gboolean
+allow_mechanism_cb (GDBusAuthObserver *observer,
+ const gchar *mechanism,
+ G_GNUC_UNUSED gpointer user_data)
+{
+ /*
+ * In a production GDBusServer that only needs to work on modern Unix
+ * platforms, consider requiring EXTERNAL (credentials-passing),
+ * which is the recommended authentication mechanism for AF_UNIX
+ * sockets:
+ *
+ * if (g_strcmp0 (mechanism, "EXTERNAL") == 0)
+ * return TRUE;
+ *
+ * return FALSE;
+ *
+ * For this example we accept everything.
+ */
+
+ g_print ("Considering whether to accept %s authentication...\n", mechanism);
+ return TRUE;
+}
+
+static gboolean
+authorize_authenticated_peer_cb (GDBusAuthObserver *observer,
+ G_GNUC_UNUSED GIOStream *stream,
+ GCredentials *credentials,
+ G_GNUC_UNUSED gpointer user_data)
+{
+ gboolean authorized = FALSE;
+
+ g_print ("Considering whether to authorize authenticated peer...\n");
+
+ if (credentials != NULL)
+ {
+ GCredentials *own_credentials;
+ gchar *credentials_string = NULL;
+
+ credentials_string = g_credentials_to_string (credentials);
+ g_print ("Peer's credentials: %s\n", credentials_string);
+ g_free (credentials_string);
+
+ own_credentials = g_credentials_new ();
+
+ credentials_string = g_credentials_to_string (own_credentials);
+ g_print ("Server's credentials: %s\n", credentials_string);
+ g_free (credentials_string);
+
+ if (g_credentials_is_same_user (credentials, own_credentials, NULL))
+ authorized = TRUE;
+
+ g_object_unref (own_credentials);
+ }
+
+ if (!authorized)
+ {
+ /* In most servers you'd want to reject this, but for this example
+ * we allow it. */
+ g_print ("A server would often not want to authorize this identity\n");
+ g_print ("Authorizing it anyway for demonstration purposes\n");
+ authorized = TRUE;
+ }
+
+ return authorized;
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
int
main (int argc, char *argv[])
{
@@ -221,6 +289,7 @@ main (int argc, char *argv[])
if (opt_server)
{
+ GDBusAuthObserver *observer;
GDBusServer *server;
gchar *guid;
GMainLoop *loop;
@@ -232,14 +301,20 @@ main (int argc, char *argv[])
if (opt_allow_anonymous)
server_flags |= G_DBUS_SERVER_FLAGS_AUTHENTICATION_ALLOW_ANONYMOUS;
+ observer = g_dbus_auth_observer_new ();
+ g_signal_connect (observer, "allow-mechanism", G_CALLBACK (allow_mechanism_cb), NULL);
+ g_signal_connect (observer, "authorize-authenticated-peer", G_CALLBACK (authorize_authenticated_peer_cb), NULL);
+
error = NULL;
server = g_dbus_server_new_sync (opt_address,
server_flags,
guid,
- NULL, /* GDBusAuthObserver */
+ observer,
NULL, /* GCancellable */
&error);
g_dbus_server_start (server);
+
+ g_object_unref (observer);
g_free (guid);
if (server == NULL)
diff --git a/gio/tests/gdbus-names.c b/gio/tests/gdbus-names.c
index 648b54774..4f95b457a 100644
--- a/gio/tests/gdbus-names.c
+++ b/gio/tests/gdbus-names.c
@@ -472,9 +472,6 @@ test_bus_own_name (void)
g_object_unref (c2);
session_bus_down ();
-
- /* See https://bugzilla.gnome.org/show_bug.cgi?id=711807 */
- g_usleep (1000000);
}
/* ---------------------------------------------------------------------------------------------------- */
diff --git a/gio/tests/gdbus-peer.c b/gio/tests/gdbus-peer.c
index c21b9e9f2..c46340386 100644
--- a/gio/tests/gdbus-peer.c
+++ b/gio/tests/gdbus-peer.c
@@ -53,6 +53,7 @@ static gboolean is_unix = TRUE;
static gboolean is_unix = FALSE;
#endif
+static gchar *tmpdir = NULL;
static gchar *tmp_address = NULL;
static gchar *test_guid = NULL;
static GMutex service_loop_lock;
@@ -267,6 +268,58 @@ on_proxy_signal_received_with_name_set (GDBusProxy *proxy,
/* ---------------------------------------------------------------------------------------------------- */
+static void
+setup_test_address (void)
+{
+ if (is_unix)
+ {
+ g_test_message ("Testing with unix:tmpdir address");
+ if (g_unix_socket_address_abstract_names_supported ())
+ tmp_address = g_strdup ("unix:tmpdir=/tmp/gdbus-test-");
+ else
+ {
+ tmpdir = g_dir_make_tmp ("gdbus-test-XXXXXX", NULL);
+ tmp_address = g_strdup_printf ("unix:tmpdir=%s", tmpdir);
+ }
+ }
+ else
+ tmp_address = g_strdup ("nonce-tcp:");
+}
+
+#ifdef G_OS_UNIX
+static void
+setup_dir_test_address (void)
+{
+ g_test_message ("Testing with unix:dir address");
+ tmpdir = g_dir_make_tmp ("gdbus-test-XXXXXX", NULL);
+ tmp_address = g_strdup_printf ("unix:dir=%s", tmpdir);
+}
+
+static void
+setup_path_test_address (void)
+{
+ g_test_message ("Testing with unix:path address");
+ tmpdir = g_dir_make_tmp ("gdbus-test-XXXXXX", NULL);
+ tmp_address = g_strdup_printf ("unix:path=%s/gdbus-peer-socket", tmpdir);
+}
+#endif
+
+static void
+teardown_test_address (void)
+{
+ g_free (tmp_address);
+ if (tmpdir)
+ {
+ /* Ensuring the rmdir succeeds also ensures any sockets created on the
+ * filesystem are also deleted.
+ */
+ g_assert_cmpint (g_rmdir (tmpdir), ==, 0);
+ g_clear_pointer (&tmpdir, g_free);
+ }
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
static gboolean
on_authorize_authenticated_peer (GDBusAuthObserver *observer,
GIOStream *stream,
@@ -656,7 +709,7 @@ read_all_from_fd (gint fd, gsize *out_len, GError **error)
#endif
static void
-test_peer (void)
+do_test_peer (void)
{
GDBusConnection *c;
GDBusConnection *c2;
@@ -977,6 +1030,27 @@ test_peer (void)
g_thread_join (service_thread);
}
+static void
+test_peer (void)
+{
+ /* Run this test multiple times using different address formats to ensure
+ * they all work.
+ */
+ setup_test_address ();
+ do_test_peer ();
+ teardown_test_address ();
+
+#ifdef G_OS_UNIX
+ setup_dir_test_address ();
+ do_test_peer ();
+ teardown_test_address ();
+
+ setup_path_test_address ();
+ do_test_peer ();
+ teardown_test_address ();
+#endif
+}
+
/* ---------------------------------------------------------------------------------------------------- */
typedef struct
@@ -1116,6 +1190,8 @@ delayed_message_processing (void)
GThread *service_thread;
guint n;
+ setup_test_address ();
+
data = g_new0 (DmpData, 1);
service_thread = g_thread_new ("dmp",
@@ -1160,6 +1236,7 @@ delayed_message_processing (void)
g_main_loop_quit (data->loop);
g_thread_join (service_thread);
dmp_data_free (data);
+ teardown_test_address ();
}
/* ---------------------------------------------------------------------------------------------------- */
@@ -1351,12 +1428,16 @@ test_nonce_tcp (void)
g_error_free (error);
g_assert (c == NULL);
- g_free (nonce_file);
+ /* Recreate the nonce-file so we can ensure the server deletes it when stopped. */
+ g_assert_cmpint (g_creat (nonce_file, 0600), !=, -1);
g_dbus_server_stop (server);
g_object_unref (server);
server = NULL;
+ g_assert_false (g_file_test (nonce_file, G_FILE_TEST_EXISTS));
+ g_free (nonce_file);
+
g_main_loop_quit (service_loop);
g_thread_join (service_thread);
@@ -1616,6 +1697,8 @@ codegen_test_peer (void)
GVariant *value;
const gchar *s;
+ setup_test_address ();
+
/* bring up a server - we run the server in a different thread to avoid deadlocks */
service_thread = g_thread_new ("codegen_test_peer",
codegen_service_thread_func,
@@ -1719,6 +1802,8 @@ codegen_test_peer (void)
g_object_unref (animal1);
g_object_unref (animal2);
g_thread_join (service_thread);
+
+ teardown_test_address ();
}
/* ---------------------------------------------------------------------------------------------------- */
@@ -1730,7 +1815,6 @@ main (int argc,
{
gint ret;
GDBusNodeInfo *introspection_data = NULL;
- gchar *tmpdir = NULL;
g_test_init (&argc, &argv, NULL);
@@ -1740,19 +1824,6 @@ main (int argc,
test_guid = g_dbus_generate_guid ();
- if (is_unix)
- {
- if (g_unix_socket_address_abstract_names_supported ())
- tmp_address = g_strdup ("unix:tmpdir=/tmp/gdbus-test-");
- else
- {
- tmpdir = g_dir_make_tmp ("gdbus-test-XXXXXX", NULL);
- tmp_address = g_strdup_printf ("unix:tmpdir=%s", tmpdir);
- }
- }
- else
- tmp_address = g_strdup ("nonce-tcp:");
-
/* all the tests rely on a shared main loop */
loop = g_main_loop_new (NULL, FALSE);
@@ -1769,13 +1840,6 @@ main (int argc,
g_main_loop_unref (loop);
g_free (test_guid);
g_dbus_node_info_unref (introspection_data);
- if (is_unix)
- g_free (tmp_address);
- if (tmpdir)
- {
- g_rmdir (tmpdir);
- g_free (tmpdir);
- }
return ret;
}
diff --git a/gio/tests/gdbus-threading.c b/gio/tests/gdbus-threading.c
index 3e4dc92e5..ffca6f317 100644
--- a/gio/tests/gdbus-threading.c
+++ b/gio/tests/gdbus-threading.c
@@ -361,13 +361,12 @@ test_method_calls_on_proxy (GDBusProxy *proxy)
SyncThreadData data1;
SyncThreadData data2;
SyncThreadData data3;
- GTimeVal start_time;
- GTimeVal end_time;
+ gint64 start_time, end_time;
guint elapsed_msec;
do_async = (n == 0);
- g_get_current_time (&start_time);
+ start_time = g_get_real_time ();
data1.proxy = proxy;
data1.msec = 40;
@@ -397,10 +396,9 @@ test_method_calls_on_proxy (GDBusProxy *proxy)
g_thread_join (thread2);
g_thread_join (thread3);
- g_get_current_time (&end_time);
+ end_time = g_get_real_time ();
- elapsed_msec = ((end_time.tv_sec * G_USEC_PER_SEC + end_time.tv_usec) -
- (start_time.tv_sec * G_USEC_PER_SEC + start_time.tv_usec)) / 1000;
+ elapsed_msec = (end_time - start_time) / 1000;
//g_debug ("Elapsed time for %s = %d msec", n == 0 ? "async" : "sync", elapsed_msec);
diff --git a/gio/tests/giomodule.c b/gio/tests/giomodule.c
index e832e95d3..b4923eeef 100644
--- a/gio/tests/giomodule.c
+++ b/gio/tests/giomodule.c
@@ -21,6 +21,13 @@
*/
#include <gio/gio.h>
+#include <glibconfig.h>
+
+#ifdef _MSC_VER
+# define MODULE_FILENAME_PREFIX ""
+#else
+# define MODULE_FILENAME_PREFIX "lib"
+#endif
static void
test_extension_point (void)
@@ -76,6 +83,13 @@ test_extension_point (void)
static void
test_module_scan_all (void)
{
+#ifdef GLIB_STATIC_COMPILATION
+ /* The plugin module is statically linked with a separate copy
+ * of GLib so g_io_extension_point_implement won't work. */
+ g_test_skip ("GIOExtensionPoint with dynamic modules isn't supported in static builds.");
+ return;
+#endif
+
if (g_test_subprocess ())
{
GIOExtensionPoint *ep;
@@ -83,7 +97,6 @@ test_module_scan_all (void)
GList *list;
ep = g_io_extension_point_register ("test-extension-point");
g_io_modules_scan_all_in_directory (g_test_get_filename (G_TEST_BUILT, "modules", NULL));
- g_io_modules_scan_all_in_directory (g_test_get_filename (G_TEST_BUILT, "modules/.libs", NULL));
list = g_io_extension_point_get_extensions (ep);
g_assert_cmpint (g_list_length (list), ==, 2);
ext = list->data;
@@ -99,6 +112,12 @@ test_module_scan_all (void)
static void
test_module_scan_all_with_scope (void)
{
+#ifdef GLIB_STATIC_COMPILATION
+ /* Disabled for the same reason as test_module_scan_all. */
+ g_test_skip ("GIOExtensionPoint with dynamic modules isn't supported in static builds.");
+ return;
+#endif
+
if (g_test_subprocess ())
{
GIOExtensionPoint *ep;
@@ -108,11 +127,9 @@ test_module_scan_all_with_scope (void)
ep = g_io_extension_point_register ("test-extension-point");
scope = g_io_module_scope_new (G_IO_MODULE_SCOPE_BLOCK_DUPLICATES);
- g_io_module_scope_block (scope, "libtestmoduleb." G_MODULE_SUFFIX);
+ g_io_module_scope_block (scope, MODULE_FILENAME_PREFIX "testmoduleb." G_MODULE_SUFFIX);
g_io_modules_scan_all_in_directory_with_scope (g_test_get_filename (G_TEST_BUILT, "modules", NULL), scope);
list = g_io_extension_point_get_extensions (ep);
- g_io_modules_scan_all_in_directory_with_scope (g_test_get_filename (G_TEST_BUILT, "modules/.libs", NULL), scope);
- list = g_io_extension_point_get_extensions (ep);
g_assert_cmpint (g_list_length (list), ==, 1);
ext = list->data;
g_assert_cmpstr (g_io_extension_get_name (ext), ==, "test-a");
diff --git a/gio/tests/glistmodel.c b/gio/tests/glistmodel.c
index 2fef4ccbe..b867bd54a 100644
--- a/gio/tests/glistmodel.c
+++ b/gio/tests/glistmodel.c
@@ -77,7 +77,6 @@ test_store_boundaries (void)
store = g_list_store_new (G_TYPE_MENU_ITEM);
item = g_menu_item_new (NULL, NULL);
- g_object_add_weak_pointer (G_OBJECT (item), (gpointer *) &item);
/* remove an item from an empty list */
g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, "*g_sequence*");
@@ -123,8 +122,7 @@ test_store_boundaries (void)
g_assert_cmpuint (g_list_model_get_n_items (G_LIST_MODEL (store)), ==, 1);
g_object_unref (store);
- g_object_unref (item);
- g_assert_null (item);
+ g_assert_finalize_object (item);
}
static void
diff --git a/gio/tests/gsubprocess.c b/gio/tests/gsubprocess.c
index 52b06a2e6..400fa00a1 100644
--- a/gio/tests/gsubprocess.c
+++ b/gio/tests/gsubprocess.c
@@ -66,14 +66,11 @@ test_noop (void)
GError **error = &local_error;
GPtrArray *args;
GSubprocess *proc;
- const gchar *id;
args = get_test_subprocess_args ("noop", NULL);
proc = g_subprocess_newv ((const gchar * const *) args->pdata, G_SUBPROCESS_FLAGS_NONE, error);
g_ptr_array_free (args, TRUE);
g_assert_no_error (local_error);
- id = g_subprocess_get_identifier (proc);
- g_assert_nonnull (id);
g_subprocess_wait_check (proc, NULL, error);
g_assert_no_error (local_error);
@@ -1297,12 +1294,16 @@ test_terminate (void)
GSubprocess *proc;
GPtrArray *args;
GMainLoop *loop;
+ const gchar *id;
args = get_test_subprocess_args ("sleep-forever", NULL);
proc = g_subprocess_newv ((const gchar * const *) args->pdata, G_SUBPROCESS_FLAGS_NONE, error);
g_ptr_array_free (args, TRUE);
g_assert_no_error (local_error);
+ id = g_subprocess_get_identifier (proc);
+ g_assert_nonnull (id);
+
loop = g_main_loop_new (NULL, TRUE);
g_subprocess_wait_async (proc, NULL, on_request_quit_exited, loop);
diff --git a/gio/tests/meson.build b/gio/tests/meson.build
index a0c09444b..3a6b50bb5 100644
--- a/gio/tests/meson.build
+++ b/gio/tests/meson.build
@@ -97,7 +97,7 @@ test_env.set('GIO_LAUNCH_DESKTOP', meson.build_root() + '/gio/gio-launch-desktop
# 1.2.14 required for dbus_message_set_serial
dbus1_dep = dependency('dbus-1', required : false, version : '>= 1.2.14')
if not dbus1_dep.found()
- if cc.get_id() == 'msvc'
+ if cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl'
# MSVC: Search for the DBus library by the configuration, which corresponds
# to the output of CMake builds of DBus. Note that debugoptimized
# is really a Release build with .PDB files.
@@ -382,7 +382,7 @@ test_extra_programs += {
},
}
-if cc.get_id() != 'msvc'
+if cc.get_id() != 'msvc' and cc.get_id() != 'clang-cl'
test_extra_programs += {
# These three are manual-run tests because they need a session bus but don't bring one up themselves
# FIXME: these build but don't seem to work!
@@ -424,13 +424,20 @@ else
endif
foreach appinfo_test_desktop_file : appinfo_test_desktop_files
- configure_file(
- input: appinfo_test_desktop_file + '.in',
- output: appinfo_test_desktop_file,
- install_dir: installed_tests_execdir,
- install: installed_tests_enabled,
- configuration: cdata,
- )
+ if installed_tests_enabled
+ configure_file(
+ input: appinfo_test_desktop_file + '.in',
+ output: appinfo_test_desktop_file,
+ install_dir: installed_tests_execdir,
+ configuration: cdata,
+ )
+ else
+ configure_file(
+ input: appinfo_test_desktop_file + '.in',
+ output: appinfo_test_desktop_file,
+ configuration: cdata,
+ )
+ endif
endforeach
if installed_tests_enabled
@@ -558,7 +565,7 @@ if not meson.is_cross_build() or meson.has_exe_wrapper()
test_generated_txt = configure_file(input : 'test1.txt',
output : 'test-generated.txt',
copy : true,
- install : false)
+ )
resources_extra_sources = [
test_gresource,
diff --git a/gio/tests/network-address.c b/gio/tests/network-address.c
index 0dcd7b292..bda76050a 100644
--- a/gio/tests/network-address.c
+++ b/gio/tests/network-address.c
@@ -820,6 +820,31 @@ test_happy_eyeballs_ipv6_error_ipv6_first (HappyEyeballsFixture *fixture,
}
static void
+test_happy_eyeballs_ipv6_error_ipv4_very_slow (HappyEyeballsFixture *fixture,
+ gconstpointer user_data)
+{
+ AsyncData data = { 0 };
+ GError *ipv6_error;
+
+ g_test_bug ("merge_requests/865");
+ g_test_summary ("Ensure that we successfully return IPv4 results even when they come significantly later than an IPv6 failure.");
+
+ /* If ipv6 fails, ensuring that ipv6 errors before ipv4 finishes, we still get ipv4. */
+
+ data.loop = fixture->loop;
+ ipv6_error = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_TIMED_OUT, "IPv6 Broken");
+ mock_resolver_set_ipv6_error (fixture->mock_resolver, ipv6_error);
+ mock_resolver_set_ipv4_delay_ms (fixture->mock_resolver, SLOW_DELAY_MORE_THAN_TIMEOUT);
+
+ g_socket_address_enumerator_next_async (fixture->enumerator, NULL, got_addr, &data);
+ g_main_loop_run (fixture->loop);
+
+ assert_list_matches_expected (data.addrs, fixture->input_ipv4_results);
+
+ g_error_free (ipv6_error);
+}
+
+static void
test_happy_eyeballs_ipv4_error_ipv4_first (HappyEyeballsFixture *fixture,
gconstpointer user_data)
{
@@ -977,6 +1002,7 @@ main (int argc, char *argv[])
gchar *path;
g_test_init (&argc, &argv, NULL);
+ g_test_bug_base ("https://gitlab.gnome.org/GNOME/glib/");
g_test_add_func ("/network-address/basic", test_basic);
@@ -1031,6 +1057,8 @@ main (int argc, char *argv[])
happy_eyeballs_setup, test_happy_eyeballs_ipv6_error_ipv4_first, happy_eyeballs_teardown);
g_test_add ("/network-address/happy-eyeballs/ipv6-error-ipv6-first", HappyEyeballsFixture, NULL,
happy_eyeballs_setup, test_happy_eyeballs_ipv6_error_ipv6_first, happy_eyeballs_teardown);
+ g_test_add ("/network-address/happy-eyeballs/ipv6-error-ipv4-very-slow", HappyEyeballsFixture, NULL,
+ happy_eyeballs_setup, test_happy_eyeballs_ipv6_error_ipv4_very_slow, happy_eyeballs_teardown);
g_test_add ("/network-address/happy-eyeballs/ipv4-error-ipv6-first", HappyEyeballsFixture, NULL,
happy_eyeballs_setup, test_happy_eyeballs_ipv4_error_ipv6_first, happy_eyeballs_teardown);
g_test_add ("/network-address/happy-eyeballs/ipv4-error-ipv4-first", HappyEyeballsFixture, NULL,
diff --git a/gio/tests/resourceplugin.c b/gio/tests/resourceplugin.c
index b66d54142..fc8d8d2f1 100644
--- a/gio/tests/resourceplugin.c
+++ b/gio/tests/resourceplugin.c
@@ -1,3 +1,14 @@
+/*
+ * Ensure the g_io_module_*() symbols are exported
+ * on all supported compilers without using config.h.
+ * This must be done before including any GLib headers,
+ * since GLIB_AVAILABLE_IN_ALL, which is used to mark the
+ * g_io_module*() symbols, is defined to be _GLIB_EXTERN,
+ * which must be overriden to export the symbols.
+ */
+#include "modules/symbol-visibility.h"
+#define _GLIB_EXTERN GLIB_TEST_EXPORT_SYMBOL
+
#include <gio/gio.h>
void
diff --git a/gio/tests/resources.c b/gio/tests/resources.c
index cb2c00a48..c44d21485 100644
--- a/gio/tests/resources.c
+++ b/gio/tests/resources.c
@@ -18,10 +18,17 @@
#include <string.h>
#include <gio/gio.h>
+#include <glibconfig.h>
#include "gconstructor.h"
#include "test_resources2.h"
#include "digit_test_resources.h"
+#ifdef _MSC_VER
+# define MODULE_FILENAME_PREFIX ""
+#else
+# define MODULE_FILENAME_PREFIX "lib"
+#endif
+
static void
test_resource (GResource *resource)
{
@@ -638,10 +645,18 @@ test_resource_module (void)
GBytes *data;
GError *error;
+#ifdef GLIB_STATIC_COMPILATION
+ /* The resource module is statically linked with a separate copy
+ * of a GLib so g_static_resource_init won't work as expected. */
+ g_test_skip ("Resource modules aren't supported in static builds.");
+ return;
+#endif
+
if (g_module_supported ())
{
- /* For in-tree, this will find the .la file and use it to get to the .so in .libs/ */
- module = g_io_module_new (g_test_get_filename (G_TEST_BUILT, "libresourceplugin", NULL));
+ module = g_io_module_new (g_test_get_filename (G_TEST_BUILT,
+ MODULE_FILENAME_PREFIX "resourceplugin",
+ NULL));
error = NULL;
diff --git a/gio/tests/send-data.c b/gio/tests/send-data.c
index 514442976..a66976fa3 100644
--- a/gio/tests/send-data.c
+++ b/gio/tests/send-data.c
@@ -66,14 +66,14 @@ socket_client_event (GSocketClient *client,
GSocketConnection *connection)
{
static GEnumClass *event_class;
- GTimeVal tv;
+ gint64 now_us;
if (!event_class)
event_class = g_type_class_ref (G_TYPE_SOCKET_CLIENT_EVENT);
- g_get_current_time (&tv);
- printf ("% 12ld.%06ld GSocketClient => %s [%s]\n",
- tv.tv_sec, tv.tv_usec,
+ now_us = g_get_real_time ();
+ g_print ("%" G_GINT64_FORMAT " GSocketClient => %s [%s]\n",
+ now_us,
g_enum_get_value (event_class, event)->value_nick,
connection ? G_OBJECT_TYPE_NAME (connection) : "");
}
diff --git a/gio/tests/testfilemonitor.c b/gio/tests/testfilemonitor.c
index 0fa72d3d9..605795890 100644
--- a/gio/tests/testfilemonitor.c
+++ b/gio/tests/testfilemonitor.c
@@ -9,6 +9,37 @@
* the tests, e.g. the length of timeouts
*/
+typedef struct
+{
+ GFile *tmp_dir;
+} Fixture;
+
+static void
+setup (Fixture *fixture,
+ gconstpointer user_data)
+{
+ gchar *path = NULL;
+ GError *local_error = NULL;
+
+ path = g_dir_make_tmp ("gio-test-testfilemonitor_XXXXXX", &local_error);
+ g_assert_no_error (local_error);
+
+ fixture->tmp_dir = g_file_new_for_path (path);
+
+ g_test_message ("Using temporary directory: %s", path);
+}
+
+static void
+teardown (Fixture *fixture,
+ gconstpointer user_data)
+{
+ GError *local_error = NULL;
+
+ g_file_delete (fixture->tmp_dir, NULL, &local_error);
+ g_assert_no_error (local_error);
+ g_clear_object (&fixture->tmp_dir);
+}
+
typedef enum {
NONE = 0,
INOTIFY = (1 << 1),
@@ -48,36 +79,24 @@ typedef struct
GFileOutputStream *output_stream;
} TestData;
-#if 0
static void
-output_event (RecordedEvent *event)
+output_event (const RecordedEvent *event)
{
if (event->step >= 0)
- g_print (">>>> step %d\n", event->step);
+ g_test_message (">>>> step %d", event->step);
else
{
GTypeClass *class;
class = g_type_class_ref (g_type_from_name ("GFileMonitorEvent"));
- g_print ("%s file=%s other_file=%s\n",
- g_enum_get_value (G_ENUM_CLASS (class), event->event_type)->value_nick,
- event->file,
- event->other_file);
+ g_test_message ("%s file=%s other_file=%s\n",
+ g_enum_get_value (G_ENUM_CLASS (class), event->event_type)->value_nick,
+ event->file,
+ event->other_file);
g_type_class_unref (class);
}
}
-static void
-output_events (GList *list)
-{
- GList *l;
-
- g_print (">>>output events\n");
- for (l = list; l; l = l->next)
- output_event ((RecordedEvent *)l->data);
-}
-#endif
-
/* a placeholder for temp file names we don't want to compare */
static const gchar DONT_CARE[] = "";
@@ -210,9 +229,20 @@ check_expected_events (RecordedEvent *expected,
continue;
}
/* Run above checks under g_assert_* again to provide more useful
- * error messages. */
+ * error messages. Print the expected and actual events first. */
else
{
+ GList *l;
+ gsize j;
+
+ g_test_message ("Recorded events:");
+ for (l = recorded; l != NULL; l = l->next)
+ output_event ((RecordedEvent *) l->data);
+
+ g_test_message ("Expected events:");
+ for (j = 0; j < n_expected; j++)
+ output_event (&expected[j]);
+
g_assert_cmpint (e1->step, ==, e2->step);
g_assert_cmpint (e1->event_type, ==, e2->event_type);
@@ -322,7 +352,8 @@ static RecordedEvent atomic_replace_output[] = {
};
static void
-test_atomic_replace (void)
+test_atomic_replace (Fixture *fixture,
+ gconstpointer user_data)
{
GError *error = NULL;
TestData data;
@@ -330,12 +361,14 @@ test_atomic_replace (void)
data.step = 0;
data.events = NULL;
- data.file = g_file_new_for_path ("atomic_replace_file");
+ data.file = g_file_get_child (fixture->tmp_dir, "atomic_replace_file");
g_file_delete (data.file, NULL, NULL);
data.monitor = g_file_monitor_file (data.file, G_FILE_MONITOR_WATCH_MOVES, NULL, &error);
g_assert_no_error (error);
+ g_test_message ("Using GFileMonitor %s", G_OBJECT_TYPE_NAME (data.monitor));
+
g_file_monitor_set_rate_limit (data.monitor, 200);
g_signal_connect (data.monitor, "changed", G_CALLBACK (monitor_changed), &data);
@@ -345,7 +378,6 @@ test_atomic_replace (void)
g_main_loop_run (data.loop);
- /*output_events (data.events);*/
check_expected_events (atomic_replace_output,
G_N_ELEMENTS (atomic_replace_output),
data.events,
@@ -425,7 +457,8 @@ static RecordedEvent change_output[] = {
};
static void
-test_file_changes (void)
+test_file_changes (Fixture *fixture,
+ gconstpointer user_data)
{
GError *error = NULL;
TestData data;
@@ -433,12 +466,14 @@ test_file_changes (void)
data.step = 0;
data.events = NULL;
- data.file = g_file_new_for_path ("change_file");
+ data.file = g_file_get_child (fixture->tmp_dir, "change_file");
g_file_delete (data.file, NULL, NULL);
data.monitor = g_file_monitor_file (data.file, G_FILE_MONITOR_WATCH_MOVES, NULL, &error);
g_assert_no_error (error);
+ g_test_message ("Using GFileMonitor %s", G_OBJECT_TYPE_NAME (data.monitor));
+
g_file_monitor_set_rate_limit (data.monitor, 200);
g_signal_connect (data.monitor, "changed", G_CALLBACK (monitor_changed), &data);
@@ -448,7 +483,6 @@ test_file_changes (void)
g_main_loop_run (data.loop);
- /*output_events (data.events);*/
check_expected_events (change_output,
G_N_ELEMENTS (change_output),
data.events,
@@ -540,7 +574,8 @@ static RecordedEvent dir_output[] = {
};
static void
-test_dir_monitor (void)
+test_dir_monitor (Fixture *fixture,
+ gconstpointer user_data)
{
GError *error = NULL;
TestData data;
@@ -548,13 +583,15 @@ test_dir_monitor (void)
data.step = 0;
data.events = NULL;
- data.file = g_file_new_for_path ("dir_monitor_test");
+ data.file = g_file_get_child (fixture->tmp_dir, "dir_monitor_test");
g_file_delete (data.file, NULL, NULL);
g_file_make_directory (data.file, NULL, &error);
data.monitor = g_file_monitor_directory (data.file, G_FILE_MONITOR_WATCH_MOVES, NULL, &error);
g_assert_no_error (error);
+ g_test_message ("Using GFileMonitor %s", G_OBJECT_TYPE_NAME (data.monitor));
+
g_file_monitor_set_rate_limit (data.monitor, 200);
g_signal_connect (data.monitor, "changed", G_CALLBACK (monitor_changed), &data);
@@ -564,7 +601,6 @@ test_dir_monitor (void)
g_main_loop_run (data.loop);
- /*output_events (data.events);*/
check_expected_events (dir_output,
G_N_ELEMENTS (dir_output),
data.events,
@@ -635,7 +671,8 @@ static RecordedEvent nodir_output[] = {
};
static void
-test_dir_non_existent (void)
+test_dir_non_existent (Fixture *fixture,
+ gconstpointer user_data)
{
TestData data;
GError *error = NULL;
@@ -643,10 +680,12 @@ test_dir_non_existent (void)
data.step = 0;
data.events = NULL;
- data.file = g_file_new_for_path ("nosuchdir/nosuchfile");
+ data.file = g_file_get_child (fixture->tmp_dir, "nosuchdir/nosuchfile");
data.monitor = g_file_monitor_file (data.file, G_FILE_MONITOR_WATCH_MOVES, NULL, &error);
g_assert_no_error (error);
+ g_test_message ("Using GFileMonitor %s", G_OBJECT_TYPE_NAME (data.monitor));
+
g_file_monitor_set_rate_limit (data.monitor, 200);
g_signal_connect (data.monitor, "changed", G_CALLBACK (monitor_changed), &data);
@@ -659,7 +698,6 @@ test_dir_non_existent (void)
g_main_loop_run (data.loop);
- /*output_events (data.events);*/
check_expected_events (nodir_output,
G_N_ELEMENTS (nodir_output),
data.events,
@@ -742,7 +780,8 @@ static RecordedEvent cross_dir_b_output[] = {
{ -1, NULL, NULL, 3, NONE },
};
static void
-test_cross_dir_moves (void)
+test_cross_dir_moves (Fixture *fixture,
+ gconstpointer user_data)
{
GError *error = NULL;
TestData data[2];
@@ -750,26 +789,30 @@ test_cross_dir_moves (void)
data[0].step = 0;
data[0].events = NULL;
- data[0].file = g_file_new_for_path ("cross_dir_a");
+ data[0].file = g_file_get_child (fixture->tmp_dir, "cross_dir_a");
g_file_delete (data[0].file, NULL, NULL);
g_file_make_directory (data[0].file, NULL, &error);
data[0].monitor = g_file_monitor_directory (data[0].file, 0, NULL, &error);
g_assert_no_error (error);
+ g_test_message ("Using GFileMonitor 0 %s", G_OBJECT_TYPE_NAME (data[0].monitor));
+
g_file_monitor_set_rate_limit (data[0].monitor, 200);
g_signal_connect (data[0].monitor, "changed", G_CALLBACK (monitor_changed), &data[0]);
data[1].step = 0;
data[1].events = NULL;
- data[1].file = g_file_new_for_path ("cross_dir_b");
+ data[1].file = g_file_get_child (fixture->tmp_dir, "cross_dir_b");
g_file_delete (data[1].file, NULL, NULL);
g_file_make_directory (data[1].file, NULL, &error);
data[1].monitor = g_file_monitor_directory (data[1].file, G_FILE_MONITOR_WATCH_MOVES, NULL, &error);
g_assert_no_error (error);
+ g_test_message ("Using GFileMonitor 1 %s", G_OBJECT_TYPE_NAME (data[1].monitor));
+
g_file_monitor_set_rate_limit (data[1].monitor, 200);
g_signal_connect (data[1].monitor, "changed", G_CALLBACK (monitor_changed), &data[1]);
@@ -779,13 +822,6 @@ test_cross_dir_moves (void)
g_main_loop_run (data[0].loop);
-#if 0
- g_print ("monitor a:\n");
- output_events (data[0].events);
- g_print ("monitor b:\n");
- output_events (data[1].events);
-#endif
-
check_expected_events (cross_dir_a_output,
G_N_ELEMENTS (cross_dir_a_output),
data[0].events,
@@ -913,7 +949,8 @@ static RecordedEvent file_hard_links_output[] = {
};
static void
-test_file_hard_links (void)
+test_file_hard_links (Fixture *fixture,
+ gconstpointer user_data)
{
GError *error = NULL;
TestData data;
@@ -930,7 +967,7 @@ test_file_hard_links (void)
data.events = NULL;
/* Create a file which exists and is not a directory. */
- data.file = g_file_new_for_path ("testfilemonitor.db");
+ data.file = g_file_get_child (fixture->tmp_dir, "testfilemonitor.db");
data.output_stream = g_file_replace (data.file, NULL, FALSE,
G_FILE_CREATE_NONE, NULL, &error);
g_assert_no_error (error);
@@ -945,6 +982,8 @@ test_file_hard_links (void)
g_assert_no_error (error);
g_assert_nonnull (data.monitor);
+ g_test_message ("Using GFileMonitor %s", G_OBJECT_TYPE_NAME (data.monitor));
+
/* Change the file a bit. */
g_file_monitor_set_rate_limit (data.monitor, 200);
g_signal_connect (data.monitor, "changed", (GCallback) monitor_changed, &data);
@@ -953,7 +992,6 @@ test_file_hard_links (void)
g_timeout_add (500, file_hard_links_step, &data);
g_main_loop_run (data.loop);
- /* output_events (data.events); */
check_expected_events (file_hard_links_output,
G_N_ELEMENTS (file_hard_links_output),
data.events,
@@ -973,12 +1011,12 @@ main (int argc, char *argv[])
g_test_bug_base ("https://bugzilla.gnome.org/show_bug.cgi?id=");
- g_test_add_func ("/monitor/atomic-replace", test_atomic_replace);
- g_test_add_func ("/monitor/file-changes", test_file_changes);
- g_test_add_func ("/monitor/dir-monitor", test_dir_monitor);
- g_test_add_func ("/monitor/dir-not-existent", test_dir_non_existent);
- g_test_add_func ("/monitor/cross-dir-moves", test_cross_dir_moves);
- g_test_add_func ("/monitor/file/hard-links", test_file_hard_links);
+ g_test_add ("/monitor/atomic-replace", Fixture, NULL, setup, test_atomic_replace, teardown);
+ g_test_add ("/monitor/file-changes", Fixture, NULL, setup, test_file_changes, teardown);
+ g_test_add ("/monitor/dir-monitor", Fixture, NULL, setup, test_dir_monitor, teardown);
+ g_test_add ("/monitor/dir-not-existent", Fixture, NULL, setup, test_dir_non_existent, teardown);
+ g_test_add ("/monitor/cross-dir-moves", Fixture, NULL, setup, test_cross_dir_moves, teardown);
+ g_test_add ("/monitor/file/hard-links", Fixture, NULL, setup, test_file_hard_links, teardown);
return g_test_run ();
}
diff --git a/gio/tests/tls-interaction.c b/gio/tests/tls-interaction.c
index 345656e29..4f0737d7e 100644
--- a/gio/tests/tls-interaction.c
+++ b/gio/tests/tls-interaction.c
@@ -673,18 +673,10 @@ static void
teardown_without_loop (Test *test,
gconstpointer unused)
{
- gpointer weak_pointer = test->interaction;
-
- g_object_add_weak_pointer (weak_pointer, &weak_pointer);
-
g_object_unref (test->connection);
-
g_object_unref (test->password);
- g_object_unref (test->interaction);
-
- g_assert (weak_pointer == NULL);
-
+ g_assert_finalize_object (test->interaction);
}
typedef struct {