summaryrefslogtreecommitdiff
path: root/gio/tests
diff options
context:
space:
mode:
authorRodrigo Moya <rodrigo@gnome-db.org>2011-01-11 15:59:14 +0100
committerRodrigo Moya <rodrigo@gnome-db.org>2011-01-11 15:59:14 +0100
commitd75842ff4c8c9d78dbd5462409ab2c93600fa9a6 (patch)
tree86def8b54a1cb6db27a3bff6c6e6caada203ad13 /gio/tests
parent65bd1f526d86ce08d6fa4d7d6fc1140198c9aef1 (diff)
parentfabf506b8d5baf8f59fca563e6f1a62be5148112 (diff)
downloadglib-wip/gsettings-list.tar.gz
Merge branch 'master' into wip/gsettings-listwip/gsettings-list
Diffstat (limited to 'gio/tests')
-rw-r--r--gio/tests/.gitignore1
-rw-r--r--gio/tests/Makefile.am4
-rw-r--r--gio/tests/desktop-app-info.c56
-rw-r--r--gio/tests/gdbus-connection.c18
-rw-r--r--gio/tests/io-stream.c185
-rw-r--r--gio/tests/resolver.c40
-rw-r--r--gio/tests/socket-client.c2
-rw-r--r--gio/tests/socket-server.c4
8 files changed, 286 insertions, 24 deletions
diff --git a/gio/tests/.gitignore b/gio/tests/.gitignore
index 0663fefcd..7e201bbb7 100644
--- a/gio/tests/.gitignore
+++ b/gio/tests/.gitignore
@@ -55,6 +55,7 @@ gsettings
gsettings.store
httpd
icons
+io-stream
live-g-file
memory-input-stream
memory-output-stream
diff --git a/gio/tests/Makefile.am b/gio/tests/Makefile.am
index def7392a8..5f49e6cec 100644
--- a/gio/tests/Makefile.am
+++ b/gio/tests/Makefile.am
@@ -18,6 +18,7 @@ progs_ldadd = \
$(top_builddir)/gio/libgio-2.0.la
TEST_PROGS += \
+ io-stream \
actions \
memory-input-stream \
memory-output-stream \
@@ -102,6 +103,9 @@ if OS_WIN32
TEST_PROGS += win32-streams
endif
+io_stream_SOURCES = io-stream.c
+io_stream_LDADD = $(progs_ldadd)
+
actions_LDADD = $(progs_ldadd)
memory_input_stream_SOURCES = memory-input-stream.c
diff --git a/gio/tests/desktop-app-info.c b/gio/tests/desktop-app-info.c
index 9d9e181de..6c6e3135c 100644
--- a/gio/tests/desktop-app-info.c
+++ b/gio/tests/desktop-app-info.c
@@ -82,7 +82,7 @@ test_delete (void)
if (g_file_test ("/usr/share/applications/gedit.desktop", G_FILE_TEST_EXISTS))
{
- info = (GAppInfo*)g_desktop_app_info_new ("gedit.desktop");
+ info = (GAppInfo*)g_desktop_app_info_new_from_filename ("/usr/share/applications/gedit.desktop");
g_assert (info);
res = g_app_info_can_delete (info);
@@ -205,9 +205,6 @@ test_fallback (void)
app = g_list_nth_data (apps, 0);
g_assert (g_app_info_equal (info1, app));
- app = g_list_nth_data (apps, 1);
- g_assert (g_app_info_equal (info2, app));
-
/* check that Test1 is the first recommended app */
recomm = g_app_info_get_recommended_for_type ("text/x-python");
g_assert (recomm != NULL);
@@ -246,6 +243,56 @@ test_fallback (void)
}
static void
+test_last_used (void)
+{
+ GList *applications;
+ GAppInfo *info1, *info2, *default_app;
+ GError *error = NULL;
+
+ info1 = create_app_info ("Test1");
+ info2 = create_app_info ("Test2");
+
+ g_app_info_set_as_default_for_type (info1, "application/x-test", &error);
+ g_assert (error == NULL);
+
+ g_app_info_add_supports_type (info2, "application/x-test", &error);
+ g_assert (error == NULL);
+
+ applications = g_app_info_get_recommended_for_type ("application/x-test");
+ g_assert (g_list_length (applications) == 2);
+
+ /* the first should be the default app now */
+ g_assert (g_app_info_equal (g_list_nth_data (applications, 0), info1));
+ g_assert (g_app_info_equal (g_list_nth_data (applications, 1), info2));
+
+ g_list_free_full (applications, g_object_unref);
+
+ g_app_info_set_as_last_used_for_type (info2, "application/x-test", &error);
+ g_assert (error == NULL);
+
+ applications = g_app_info_get_recommended_for_type ("application/x-test");
+ g_assert (g_list_length (applications) == 2);
+
+ default_app = g_app_info_get_default_for_type ("application/x-test", FALSE);
+ g_assert (g_app_info_equal (default_app, info1));
+
+ /* the first should be the other app now */
+ g_assert (g_app_info_equal (g_list_nth_data (applications, 0), info2));
+ g_assert (g_app_info_equal (g_list_nth_data (applications, 1), info1));
+
+ g_list_free_full (applications, g_object_unref);
+
+ g_app_info_reset_type_associations ("application/x-test");
+
+ g_app_info_delete (info1);
+ g_app_info_delete (info2);
+
+ g_object_unref (info1);
+ g_object_unref (info2);
+ g_object_unref (default_app);
+}
+
+static void
cleanup_dir_recurse (GFile *parent, GFile *root)
{
gboolean res;
@@ -322,6 +369,7 @@ main (int argc,
g_test_add_func ("/desktop-app-info/delete", test_delete);
g_test_add_func ("/desktop-app-info/default", test_default);
g_test_add_func ("/desktop-app-info/fallback", test_fallback);
+ g_test_add_func ("/desktop-app-info/lastused", test_last_used);
result = g_test_run ();
diff --git a/gio/tests/gdbus-connection.c b/gio/tests/gdbus-connection.c
index 866e27cec..5c2939e44 100644
--- a/gio/tests/gdbus-connection.c
+++ b/gio/tests/gdbus-connection.c
@@ -880,6 +880,18 @@ test_connection_filter (void)
m2 = g_dbus_message_copy (m, &error);
g_assert_no_error (error);
+ g_dbus_message_set_serial (m2, data.serial);
+ /* lock the message to test PRESERVE_SERIAL flag. */
+ g_dbus_message_lock (m2);
+ g_dbus_connection_send_message (c, m2, G_DBUS_SEND_MESSAGE_FLAGS_PRESERVE_SERIAL, &data.serial, &error);
+ g_object_unref (m2);
+ g_assert_no_error (error);
+
+ while (data.num_handled == 2)
+ g_thread_yield ();
+
+ m2 = g_dbus_message_copy (m, &error);
+ g_assert_no_error (error);
r = g_dbus_connection_send_message_with_reply_sync (c,
m2,
G_DBUS_SEND_MESSAGE_FLAGS_NONE,
@@ -891,7 +903,7 @@ test_connection_filter (void)
g_assert_no_error (error);
g_assert (r != NULL);
g_object_unref (r);
- g_assert_cmpint (data.num_handled, ==, 3);
+ g_assert_cmpint (data.num_handled, ==, 4);
g_dbus_connection_remove_filter (c, filter_id);
@@ -908,8 +920,8 @@ test_connection_filter (void)
g_assert_no_error (error);
g_assert (r != NULL);
g_object_unref (r);
- g_assert_cmpint (data.num_handled, ==, 3);
- g_assert_cmpint (data.num_outgoing, ==, 3);
+ g_assert_cmpint (data.num_handled, ==, 4);
+ g_assert_cmpint (data.num_outgoing, ==, 4);
/* this is safe; testserver will exit once the bus goes away */
g_assert (g_spawn_command_line_async (SRCDIR "/gdbus-testserver.py", NULL));
diff --git a/gio/tests/io-stream.c b/gio/tests/io-stream.c
new file mode 100644
index 000000000..dbac08bfd
--- /dev/null
+++ b/gio/tests/io-stream.c
@@ -0,0 +1,185 @@
+/* GLib testing framework examples and tests
+ * Copyright (C) 2010 Collabora Ltd.
+ * Authors: Xavier Claessens <xclaesse@gmail.com>
+ *
+ * This work is provided "as is"; redistribution and modification
+ * in whole or in part, in any medium, physical or electronic is
+ * permitted without restriction.
+ *
+ * This work is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * In no event shall the authors or contributors be liable for any
+ * direct, indirect, incidental, special, exemplary, or consequential
+ * damages (including, but not limited to, procurement of substitute
+ * goods or services; loss of use, data, or profits; or business
+ * interruption) however caused and on any theory of liability, whether
+ * in contract, strict liability, or tort (including negligence or
+ * otherwise) arising in any way out of the use of this software, even
+ * if advised of the possibility of such damage.
+ */
+
+#include <glib/glib.h>
+#include <gio/gio.h>
+#include <stdlib.h>
+#include <string.h>
+
+typedef struct
+{
+ GIOStream parent;
+ GInputStream *input_stream;
+ GOutputStream *output_stream;
+} GTestIOStream;
+
+typedef struct
+{
+ GIOStreamClass parent_class;
+} GTestIOStreamClass;
+
+G_DEFINE_TYPE (GTestIOStream, g_test_io_stream, G_TYPE_IO_STREAM);
+
+
+static GInputStream *
+get_input_stream (GIOStream *io_stream)
+{
+ GTestIOStream *self = (GTestIOStream *) io_stream;
+
+ return self->input_stream;
+}
+
+static GOutputStream *
+get_output_stream (GIOStream *io_stream)
+{
+ GTestIOStream *self = (GTestIOStream *) io_stream;
+
+ return self->output_stream;
+}
+
+static void
+finalize (GObject *object)
+{
+ GTestIOStream *self = (GTestIOStream *) object;
+
+ if (self->input_stream != NULL)
+ g_object_unref (self->input_stream);
+
+ if (self->output_stream != NULL)
+ g_object_unref (self->output_stream);
+
+ G_OBJECT_CLASS (g_test_io_stream_parent_class)->finalize (object);
+}
+
+static void
+g_test_io_stream_class_init (GTestIOStreamClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GIOStreamClass *io_class = G_IO_STREAM_CLASS (klass);
+
+ object_class->finalize = finalize;
+
+ io_class->get_input_stream = get_input_stream;
+ io_class->get_output_stream = get_output_stream;
+}
+
+static void
+g_test_io_stream_init (GTestIOStream *self)
+{
+}
+
+static GIOStream *
+g_test_io_stream_new (GInputStream *input, GOutputStream *output)
+{
+ GTestIOStream *self;
+
+ self = g_object_new (g_test_io_stream_get_type (), NULL);
+ self->input_stream = g_object_ref (input);
+ self->output_stream = g_object_ref (output);
+
+ return G_IO_STREAM (self);
+}
+
+typedef struct
+{
+ GMainLoop *main_loop;
+ const gchar *data1;
+ const gchar *data2;
+ GIOStream *iostream1;
+ GIOStream *iostream2;
+} TestCopyChunksData;
+
+static void
+test_copy_chunks_splice_cb (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ TestCopyChunksData *data = user_data;
+ GMemoryOutputStream *ostream;
+ gchar *received_data;
+ GError *error = NULL;
+
+ g_io_stream_splice_finish (res, &error);
+ g_assert_no_error (error);
+
+ ostream = G_MEMORY_OUTPUT_STREAM (((GTestIOStream *) data->iostream1)->output_stream);
+ received_data = g_memory_output_stream_get_data (ostream);
+ g_assert_cmpstr (received_data, ==, data->data2);
+
+ ostream = G_MEMORY_OUTPUT_STREAM (((GTestIOStream *) data->iostream2)->output_stream);
+ received_data = g_memory_output_stream_get_data (ostream);
+ g_assert_cmpstr (received_data, ==, data->data1);
+
+ g_assert (g_io_stream_is_closed (data->iostream1));
+ g_assert (g_io_stream_is_closed (data->iostream2));
+
+ g_main_loop_quit (data->main_loop);
+}
+
+static void
+test_copy_chunks (void)
+{
+ TestCopyChunksData data;
+ GInputStream *istream;
+ GOutputStream *ostream;
+
+ data.main_loop = g_main_loop_new (NULL, FALSE);
+ data.data1 = "abcdefghijklmnopqrstuvwxyz";
+ data.data2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+
+ istream = g_memory_input_stream_new_from_data (data.data1, -1, NULL);
+ ostream = g_memory_output_stream_new (NULL, 0, g_realloc, g_free);
+ data.iostream1 = g_test_io_stream_new (istream, ostream);
+ g_object_unref (istream);
+ g_object_unref (ostream);
+
+ istream = g_memory_input_stream_new_from_data (data.data2, -1, NULL);
+ ostream = g_memory_output_stream_new (NULL, 0, g_realloc, g_free);
+ data.iostream2 = g_test_io_stream_new (istream, ostream);
+ g_object_unref (istream);
+ g_object_unref (ostream);
+
+ g_io_stream_splice_async (data.iostream1, data.iostream2,
+ G_IO_STREAM_SPLICE_CLOSE_STREAM1 | G_IO_STREAM_SPLICE_CLOSE_STREAM2 |
+ G_IO_STREAM_SPLICE_WAIT_FOR_BOTH, G_PRIORITY_DEFAULT,
+ NULL, test_copy_chunks_splice_cb, &data);
+
+ /* We do not hold a ref in data struct, this is to make sure the operation
+ * keeps the iostream objects alive until it finishes */
+ g_object_unref (data.iostream1);
+ g_object_unref (data.iostream2);
+
+ g_main_loop_run (data.main_loop);
+ g_main_loop_unref (data.main_loop);
+}
+
+int
+main (int argc,
+ char *argv[])
+{
+ g_type_init ();
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add_func ("/io-stream/copy-chunks", test_copy_chunks);
+
+ return g_test_run();
+}
diff --git a/gio/tests/resolver.c b/gio/tests/resolver.c
index 64bc67e22..0b2a3fdf6 100644
--- a/gio/tests/resolver.c
+++ b/gio/tests/resolver.c
@@ -41,11 +41,12 @@ static void G_GNUC_NORETURN
usage (void)
{
fprintf (stderr, "Usage: resolver [-t] [-s] [hostname | IP | service/protocol/domain ] ...\n");
- fprintf (stderr, " resolver [-t] [-s] -c [hostname | IP | service/protocol/domain ]\n");
+ fprintf (stderr, " resolver [-t] [-s] -c NUMBER [hostname | IP | service/protocol/domain ]\n");
fprintf (stderr, " Use -t to enable threading.\n");
fprintf (stderr, " Use -s to do synchronous lookups.\n");
fprintf (stderr, " Both together will result in simultaneous lookups in multiple threads\n");
- fprintf (stderr, " Use -c (and only a single resolvable argument) to test GSocketConnectable.\n");
+ fprintf (stderr, " Use -c NUMBER(and only a single resolvable argument) to test GSocketConnectable.\n");
+ fprintf (stderr, " The given NUMBER determines how often the connectable will be enumerated.\n");
exit (1);
}
@@ -360,7 +361,7 @@ do_async_connectable (GSocketAddressEnumerator *enumerator)
}
static void
-do_connectable (const char *arg, gboolean synchronous)
+do_connectable (const char *arg, gboolean synchronous, guint count)
{
char **parts;
GSocketConnectable *connectable;
@@ -400,13 +401,17 @@ do_connectable (const char *arg, gboolean synchronous)
connectable = g_network_address_new (arg, port);
}
- enumerator = g_socket_connectable_enumerate (connectable);
- g_object_unref (connectable);
+ while (count--)
+ {
+ enumerator = g_socket_connectable_enumerate (connectable);
- if (synchronous)
- do_sync_connectable (enumerator);
- else
- do_async_connectable (enumerator);
+ if (synchronous)
+ do_sync_connectable (enumerator);
+ else
+ do_async_connectable (enumerator);
+ }
+
+ g_object_unref (connectable);
}
#ifdef G_OS_UNIX
@@ -434,7 +439,7 @@ int
main (int argc, char **argv)
{
gboolean threaded = FALSE, synchronous = FALSE;
- gboolean use_connectable = FALSE;
+ guint connectable_count = 0;
#ifdef G_OS_UNIX
GIOChannel *chan;
guint watch;
@@ -453,7 +458,11 @@ main (int argc, char **argv)
else if (!strcmp (argv[1], "-s"))
synchronous = TRUE;
else if (!strcmp (argv[1], "-c"))
- use_connectable = TRUE;
+ {
+ connectable_count = atoi (argv[2]);
+ argv++;
+ argc--;
+ }
else
usage ();
@@ -462,7 +471,7 @@ main (int argc, char **argv)
}
g_type_init ();
- if (argc < 2 || (argc > 2 && use_connectable))
+ if (argc < 2 || (argc > 2 && connectable_count))
usage ();
resolver = g_resolver_get_default ();
@@ -488,8 +497,11 @@ main (int argc, char **argv)
nlookups = argc - 1;
loop = g_main_loop_new (NULL, TRUE);
- if (use_connectable)
- do_connectable (argv[1], synchronous);
+ if (connectable_count)
+ {
+ nlookups = connectable_count;
+ do_connectable (argv[1], synchronous, connectable_count);
+ }
else
{
if (threaded && synchronous)
diff --git a/gio/tests/socket-client.c b/gio/tests/socket-client.c
index 61997da0f..6068034af 100644
--- a/gio/tests/socket-client.c
+++ b/gio/tests/socket-client.c
@@ -203,7 +203,7 @@ main (int argc,
if (tls)
{
- GTlsClientConnection *tls_conn;
+ GIOStream *tls_conn;
tls_conn = g_tls_client_connection_new (connection, connectable, &error);
if (!tls_conn)
diff --git a/gio/tests/socket-server.c b/gio/tests/socket-server.c
index f151681f9..a44b158c0 100644
--- a/gio/tests/socket-server.c
+++ b/gio/tests/socket-server.c
@@ -211,7 +211,7 @@ main (int argc,
if (tlscert)
{
- GTlsServerConnection *tls_conn;
+ GIOStream *tls_conn;
tls_conn = g_tls_server_connection_new (connection, tlscert, &error);
if (!tls_conn)
@@ -230,7 +230,7 @@ main (int argc,
}
g_object_unref (connection);
- connection = G_IO_STREAM (tls_conn);
+ connection = tls_conn;
}
if (connection)