summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLassi Syrjala <lassi.syrjala@nokia.com>2010-06-01 16:22:40 +0300
committerLassi Syrjala <lassi.syrjala@nokia.com>2010-06-01 16:22:40 +0300
commit025ba1e7087ca6626bc771e280e38ae3ca0f4303 (patch)
treea50cd26430170279e6c0ff97d06f17de19ce2a9a /tests
The codebase for telepathy-ring 2.0.0
Telepathy-ring is now licensed under the LGPL (see COPYING for details) and ported over to Ofono backend. At the initial stage, the features of the 2.x.x series are not on par with the previous 1.x.x series.
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am12
-rw-r--r--tests/test-common.c95
-rw-r--r--tests/test-common.h34
-rwxr-xr-xtests/tp-monitor48
-rw-r--r--tests/unitcheck.py24
5 files changed, 213 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644
index 0000000..7357aff
--- /dev/null
+++ b/tests/Makefile.am
@@ -0,0 +1,12 @@
+AM_CFLAGS = $(ERROR_CFLAGS) \
+ @GLIB_CFLAGS@ @DBUS_CFLAGS@ \
+ -I$(top_srcdir) @CHECK_CFLAGS@
+
+noinst_LTLIBRARIES = libtestcommon.la
+
+libtestcommon_la_SOURCES = \
+ test-common.c test-common.h
+
+tools_dir = $(top_srcdir)/tools
+
+MOSTLYCLEANFILES = $(BUILT_SOURCES)
diff --git a/tests/test-common.c b/tests/test-common.c
new file mode 100644
index 0000000..9fbc301
--- /dev/null
+++ b/tests/test-common.c
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2009 Nokia Corporation. All rights reserved.
+ * @author Andres Salomon <dilinger@collabora.co.uk>
+ */
+
+#include "config.h"
+#include "test-common.h"
+
+#include <glib.h>
+#include <check.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+static void usage(int err, const char *argv0)
+{
+ fprintf(err == EXIT_FAILURE ? stderr : stdout,
+ "Usage: %s [args]\n"
+ "[args]:\n"
+ " -h display this help menu\n"
+ " -o <file> XML log (check format)\n"
+ " -t <testcase> which test case to run\n"
+ " (-t may be listed multiple times)\n"
+ "\n", argv0);
+ exit(err);
+}
+
+struct common_args *parse_common_args(int argc, char *const argv[])
+{
+ int opt, all_tests = 0;
+ struct common_args *args;
+
+ args = calloc(1, sizeof(*args));
+ if (!args)
+ return NULL;
+
+ while ((opt = getopt(argc, argv, "ho:t:")) != -1) {
+ switch (opt) {
+ case 'h':
+ usage(EXIT_SUCCESS, argv[0]);
+ break;
+
+ case 'o':
+ args->xml = strdup(optarg);
+ break;
+
+ case 't':
+ /* check for magic strings that tell us to run all tests */
+ if (strcmp(optarg, "*") == 0 || strcmp(optarg, "all") == 0) {
+ all_tests = 1;
+ if (args->tests) {
+ g_slist_foreach(args->tests, (GFunc) g_free, NULL);
+ g_slist_free(args->tests);
+ args->tests = NULL;
+ }
+ }
+ if (all_tests)
+ break;
+
+ /* only running some tests; pay attention to which ones */
+ args->tests = g_slist_prepend(args->tests, strdup(optarg));
+ break;
+
+ default:
+ usage(EXIT_FAILURE, argv[0]);
+ }
+ }
+
+ return args;
+}
+
+void free_common_args(struct common_args *args)
+{
+ if (args->xml)
+ free(args->xml);
+ g_slist_foreach(args->tests, (GFunc) g_free, NULL);
+ g_slist_free(args->tests);
+ free(args);
+}
+
+void filter_add_tcases(Suite *suite, struct test_cases *tests, GSList *filter)
+{
+ struct test_cases *i;
+
+ for (i = tests; i->tcase_callback != NULL; i++) {
+ if ((!filter && i->default_on) ||
+ g_slist_find_custom(filter, i->tcase_name,
+ (GCompareFunc) g_ascii_strcasecmp))
+ suite_add_tcase(suite, i->tcase_callback());
+ else
+ printf("skipping test %s\n", i->tcase_name);
+ }
+}
diff --git a/tests/test-common.h b/tests/test-common.h
new file mode 100644
index 0000000..bed43a3
--- /dev/null
+++ b/tests/test-common.h
@@ -0,0 +1,34 @@
+#ifndef _TEST_COMMON_H
+#define _TEST_COMMON_H
+
+#include <glib.h>
+#include <check.h>
+
+struct common_args {
+ char *xml; /* file to save XML check output to */
+ GSList *tests; /* list of tests to run;
+ * empty list means run all tests */
+};
+
+struct common_args *parse_common_args(int argc, char *const argv[]);
+void free_common_args(struct common_args *args);
+
+
+typedef TCase *(*tcase_func)(void);
+
+struct test_cases {
+ tcase_func tcase_callback;
+ const char *tcase_name;
+ int default_on;
+};
+
+#define DECLARE_TEST_CASE(tc_func) \
+ { .tcase_name = (#tc_func), .tcase_callback = (tc_func), .default_on = 1 }
+#define DECLARE_TEST_CASE_OFF_BY_DEFAULT(tc_func) \
+ { .tcase_name = (#tc_func), .tcase_callback = (tc_func), .default_on = 0 }
+#define LAST_TEST_CASE \
+ { .tcase_name = NULL, .tcase_callback = NULL }
+
+void filter_add_tcases(Suite *suite, struct test_cases *tests, GSList *filter);
+
+#endif
diff --git a/tests/tp-monitor b/tests/tp-monitor
new file mode 100755
index 0000000..caf977a
--- /dev/null
+++ b/tests/tp-monitor
@@ -0,0 +1,48 @@
+#!/bin/sh
+
+filter="
+
+interface='com.Nokia.Telepathy.Channel.Interface.DialStrings'
+interface='com.Nokia.Telepathy.Connection.Interface.Forwarding'
+interface='com.nokia.Telepathy.Channel.Interface.Emergency'
+interface='com.nokia.Telepathy.Connection.Interface.Emergency'
+interface='com.nokia.Telepathy.Connection.Interface.StoredMessages'
+interface='org.freedesktop.Telepathy.Channel.Interface.Conference.DRAFT'
+interface='org.freedesktop.Telepathy.Channel.Interface.MergeableConference.DRAFT'
+interface='org.freedesktop.Telepathy.Channel.Interface.Splittable.DRAFT'
+
+interface='org.freedesktop.Telepathy.Channel'
+interface='org.freedesktop.Telepathy.Channel.Interface.ChatState'
+interface='org.freedesktop.Telepathy.Channel.Interface.DTMF'
+interface='org.freedesktop.Telepathy.Channel.Interface.Group'
+interface='org.freedesktop.Telepathy.Channel.Interface.Hold'
+interface='org.freedesktop.Telepathy.Channel.Interface.Hold'
+interface='org.freedesktop.Telepathy.Channel.Interface.MediaSignalling'
+interface='org.freedesktop.Telepathy.Channel.Interface.Messages'
+interface='org.freedesktop.Telepathy.Channel.Interface.Password'
+interface='org.freedesktop.Telepathy.Channel.Interface.Transfer'
+interface='org.freedesktop.Telepathy.Channel.Type.ContactList'
+interface='org.freedesktop.Telepathy.Channel.Type.ContactSearch'
+interface='org.freedesktop.Telepathy.Channel.Type.RoomList'
+interface='org.freedesktop.Telepathy.Channel.Type.StreamedMedia'
+interface='org.freedesktop.Telepathy.Channel.Type.Text'
+interface='org.freedesktop.Telepathy.Channel.Type.Tubes'
+interface='org.freedesktop.Telepathy.ChannelHandler'
+interface='org.freedesktop.Telepathy.Connection'
+interface='org.freedesktop.Telepathy.Connection.Interface.Aliasing'
+interface='org.freedesktop.Telepathy.Connection.Interface.Avatars'
+interface='org.freedesktop.Telepathy.Connection.Interface.Capabilities'
+interface='org.freedesktop.Telepathy.Connection.Interface.ContactInfo'
+interface='org.freedesktop.Telepathy.Connection.Interface.Forwarding'
+interface='org.freedesktop.Telepathy.Connection.Interface.Presence'
+interface='org.freedesktop.Telepathy.Connection.Interface.Privacy'
+interface='org.freedesktop.Telepathy.Connection.Interface.Renaming'
+interface='org.freedesktop.Telepathy.Connection.Interface.Requests'
+interface='org.freedesktop.Telepathy.ConnectionManager'
+interface='org.freedesktop.Telepathy.Media.SessionHandler'
+interface='org.freedesktop.Telepathy.Media.StreamHandler'
+interface='org.freedesktop.Telepathy.MissionControl'
+interface='org.freedesktop.Telepathy.Properties'
+"
+
+dbus-monitor "$@" $filter
diff --git a/tests/unitcheck.py b/tests/unitcheck.py
new file mode 100644
index 0000000..1793ac7
--- /dev/null
+++ b/tests/unitcheck.py
@@ -0,0 +1,24 @@
+from unittest import *
+
+class CheckResult (TestResult):
+
+ successes = () # Immutable
+
+ def addSuccess(self, test):
+ if not self.successes:
+ self.successes = []
+ self.successes.append(test)
+
+
+class _CheckCase:
+
+ def defaultTestResult(self):
+ return CheckResult()
+
+
+class CheckCase (_CheckCase, TestCase):
+ pass
+
+
+class FunctionCheckCase (_CheckCase, FunctionTestCase):
+ pass