summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2012-04-18 11:37:16 +0200
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2012-05-09 12:14:10 +0200
commitbb29e6e5e47ad09b77ae2fe6c75f22f96d1758f5 (patch)
treede3521a34d8b03bc7ed042c04ae64da5e8cef34b
parent7b906d5254a92064e9036f8bd1db8e13381f22c3 (diff)
add test-tls-certificate
-rw-r--r--tests/dbus/Makefile.am3
-rw-r--r--tests/dbus/tls-certificate.c115
2 files changed, 118 insertions, 0 deletions
diff --git a/tests/dbus/Makefile.am b/tests/dbus/Makefile.am
index 79d89ec91..4300db8c0 100644
--- a/tests/dbus/Makefile.am
+++ b/tests/dbus/Makefile.am
@@ -60,6 +60,7 @@ tests_list = \
test-text-channel \
test-text-mixin \
test-text-respawn \
+ test-tls-certificate \
test-unsupported-interface
if ENABLE_INSTALLED_TESTS
@@ -257,6 +258,8 @@ test_debug_client_SOURCES = debug-client.c
test_room_list_SOURCES = room-list.c
+test_tls_certificate_SOURCES = tls-certificate.c
+
check_c_sources = *.c
include $(top_srcdir)/tools/check-coding-style.mk
check-local: check-coding-style
diff --git a/tests/dbus/tls-certificate.c b/tests/dbus/tls-certificate.c
new file mode 100644
index 000000000..e3b003b9d
--- /dev/null
+++ b/tests/dbus/tls-certificate.c
@@ -0,0 +1,115 @@
+/* Tests of TpTLSCertificate
+ *
+ * Copyright © 2012 Collabora Ltd. <http://www.collabora.co.uk/>
+ *
+ * Copying and distribution of this file, with or without modification,
+ * are permitted in any medium without royalty provided the copyright
+ * notice and this notice are preserved.
+ */
+
+#include "config.h"
+
+#include <string.h>
+
+#include <telepathy-glib/telepathy-glib.h>
+
+#include "tests/lib/contacts-conn.h"
+#include "tests/lib/tls-certificate.h"
+#include "tests/lib/util.h"
+
+typedef struct {
+ GMainLoop *mainloop;
+ TpDBusDaemon *dbus;
+
+ /* Service side objects */
+ TpBaseConnection *base_connection;
+ TpTestsTLSCertificate *service_cert;
+
+ /* Client side objects */
+ TpConnection *connection;
+ TpTLSCertificate *cert;
+
+ GError *error /* initialized where needed */;
+ gint wait;
+} Test;
+
+
+static void
+setup (Test *test,
+ gconstpointer data)
+{
+ gchar *path;
+ GPtrArray *chain_data;
+ GArray *cert;
+
+ test->mainloop = g_main_loop_new (NULL, FALSE);
+ test->dbus = tp_tests_dbus_daemon_dup_or_die ();
+
+ test->error = NULL;
+
+ /* Create (service and client sides) connection objects */
+ tp_tests_create_and_connect_conn (TP_TESTS_TYPE_CONTACTS_CONNECTION,
+ "me@test.com", &test->base_connection, &test->connection);
+
+ path = g_strdup_printf ("%s/TlsCertificate",
+ tp_proxy_get_object_path (test->connection));
+
+ chain_data = g_ptr_array_new_with_free_func ((GDestroyNotify) g_array_unref);
+
+ cert = g_array_new (TRUE, TRUE, sizeof (guchar));
+ g_array_append_vals (cert, "BADGER", 6);
+ g_ptr_array_add (chain_data, cert);
+
+ test->service_cert = g_object_new (TP_TESTS_TYPE_TLS_CERTIFICATE,
+ "object-path", path,
+ "certificate-type", "x509",
+ "certificate-chain-data", chain_data,
+ "dbus-daemon", test->dbus,
+ NULL);
+
+ g_ptr_array_unref (chain_data);
+
+ test->cert = tp_tls_certificate_new (TP_PROXY (test->connection), path,
+ &test->error);
+ g_assert_no_error (test->error);
+
+ g_free (path);
+}
+
+static void
+teardown (Test *test,
+ gconstpointer data)
+{
+ g_clear_error (&test->error);
+
+ tp_clear_object (&test->dbus);
+ g_main_loop_unref (test->mainloop);
+ test->mainloop = NULL;
+
+ tp_clear_object (&test->service_cert);
+ tp_clear_object (&test->cert);
+
+ tp_tests_connection_assert_disconnect_succeeds (test->connection);
+ g_object_unref (test->connection);
+ g_object_unref (test->base_connection);
+}
+
+static void
+test_creation (Test *test,
+ gconstpointer data G_GNUC_UNUSED)
+{
+ g_assert (TP_IS_TLS_CERTIFICATE (test->cert));
+}
+
+int
+main (int argc,
+ char **argv)
+{
+ tp_tests_init (&argc, &argv);
+ g_test_bug_base ("http://bugs.freedesktop.org/show_bug.cgi?id=");
+
+ g_test_add ("/tls-certificate/creation", Test, NULL, setup,
+ test_creation, teardown);
+
+ return g_test_run ();
+}