From e04763469d411f8de4bedad0717eb50f2d5c4e1f Mon Sep 17 00:00:00 2001
From: Julien Bonjean <julien@bonjean.info>
Date: Fri, 17 Apr 2009 16:51:49 -0400
Subject: [PATCH] Introduced unit tests (#1146)

---
 sflphone-gtk/Makefile.am            |  2 +-
 sflphone-gtk/configure.ac           |  8 +++++
 sflphone-gtk/tests/Makefile.am      | 31 ++++++++++++++++
 sflphone-gtk/tests/check_config.c   | 41 +++++++++++++++++++++
 sflphone-gtk/tests/check_contacts.c | 55 +++++++++++++++++++++++++++++
 sflphone-gtk/tests/check_dbus.c     | 41 +++++++++++++++++++++
 sflphone-gtk/tests/check_global.c   | 41 +++++++++++++++++++++
 7 files changed, 218 insertions(+), 1 deletion(-)
 create mode 100644 sflphone-gtk/tests/Makefile.am
 create mode 100644 sflphone-gtk/tests/check_config.c
 create mode 100644 sflphone-gtk/tests/check_contacts.c
 create mode 100644 sflphone-gtk/tests/check_dbus.c
 create mode 100644 sflphone-gtk/tests/check_global.c

diff --git a/sflphone-gtk/Makefile.am b/sflphone-gtk/Makefile.am
index 8e9dc0e013..5705a85e23 100644
--- a/sflphone-gtk/Makefile.am
+++ b/sflphone-gtk/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = src pixmaps
+SUBDIRS = src pixmaps tests
 
 ACLOCAL_AMFLAGS = -I m4
 
diff --git a/sflphone-gtk/configure.ac b/sflphone-gtk/configure.ac
index ce4933b6ff..85b9b4d093 100644
--- a/sflphone-gtk/configure.ac
+++ b/sflphone-gtk/configure.ac
@@ -42,6 +42,13 @@ PKG_CHECK_MODULES(DEPS, \
     libebook-1.2 >= 2.22
 )
 
+# This macro is defined in check.m4 and tests if check.h and
+# libcheck.a are installed in your system. It sets CHECK_CFLAGS and
+# CHECK_LIBS accordingly.  
+#  AM_PATH_CHECK([MINIMUM-VERSION,
+#                [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
+AM_PATH_CHECK()
+
 AC_SUBST(DEPS_CFLAGS)
 AC_SUBST(DEPS_LIBS)
 
@@ -54,6 +61,7 @@ src/contacts/Makefile
 src/contacts/addressbook/Makefile
 pixmaps/Makefile
 sflphone.desktop
+tests/Makefile
 ])
 
 
diff --git a/sflphone-gtk/tests/Makefile.am b/sflphone-gtk/tests/Makefile.am
new file mode 100644
index 0000000000..db54b0b09b
--- /dev/null
+++ b/sflphone-gtk/tests/Makefile.am
@@ -0,0 +1,31 @@
+include ../globals.mak
+
+TESTS = check_global check_contacts check_config check_dbus
+check_PROGRAMS = check_global check_contacts check_config check_dbus
+
+###########################################################
+
+check_global_SOURCES =		check_global.c
+check_global_CFLAGS =		@CHECK_CFLAGS@ @DEPS_CFLAGS@
+check_global_LDADD =		@CHECK_LIBS@
+
+###########################################################
+
+check_contacts_SOURCES =	check_contacts.c
+							$(top_builddir)/src/eds.h
+check_contacts_CFLAGS =		@CHECK_CFLAGS@ @DEPS_CFLAGS@
+check_contacts_LDADD =		@CHECK_LIBS@
+
+###########################################################
+
+check_config_SOURCES =		check_config.c
+check_config_CFLAGS = 		@CHECK_CFLAGS@ @DEPS_CFLAGS@
+check_config_LDADD = 		@CHECK_LIBS@
+
+###########################################################
+
+check_dbus_SOURCES =	check_dbus.c
+check_dbus_CFLAGS = 	@CHECK_CFLAGS@ @DEPS_CFLAGS@
+check_dbus_LDADD = 		@CHECK_LIBS@
+
+###########################################################
diff --git a/sflphone-gtk/tests/check_config.c b/sflphone-gtk/tests/check_config.c
new file mode 100644
index 0000000000..ae41e1a280
--- /dev/null
+++ b/sflphone-gtk/tests/check_config.c
@@ -0,0 +1,41 @@
+/*
+ *  Copyright (C) 2009 Savoir-Faire Linux inc.
+ *  Author: Julien Bonjean <julien.bonjean@savoirfairelinux.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program 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.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <check.h>
+#include <stdlib.h>
+
+Suite *
+config_suite (void)
+{
+  Suite *s = suite_create ("Config");
+
+  return s;
+}
+
+int
+main (void)
+{
+  int number_failed;
+  Suite *s = config_suite ();
+  SRunner *sr = srunner_create (s);
+  srunner_run_all (sr, CK_NORMAL);
+  number_failed = srunner_ntests_failed (sr);
+  srunner_free (sr);
+  return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+}
diff --git a/sflphone-gtk/tests/check_contacts.c b/sflphone-gtk/tests/check_contacts.c
new file mode 100644
index 0000000000..6fcefe6d4e
--- /dev/null
+++ b/sflphone-gtk/tests/check_contacts.c
@@ -0,0 +1,55 @@
+/*
+ *  Copyright (C) 2009 Savoir-Faire Linux inc.
+ *  Author: Julien Bonjean <julien.bonjean@savoirfairelinux.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program 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.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <check.h>
+#include <stdlib.h>
+#include "../src/contacts/addressbook/eds.h"
+
+
+START_TEST (test_eds)
+{
+  fail_unless (5 == 5,"Erreur");
+}
+END_TEST
+
+
+
+Suite *
+contacts_suite (void)
+{
+  Suite *s = suite_create ("Contacts");
+
+  TCase *tc_cases = tcase_create ("EDS");
+  tcase_add_test (tc_cases, test_eds);
+  suite_add_tcase (s, tc_cases);
+
+  return s;
+}
+
+int
+main (void)
+{
+  int number_failed;
+  Suite *s = contacts_suite ();
+  SRunner *sr = srunner_create (s);
+  srunner_run_all (sr, CK_NORMAL);
+  number_failed = srunner_ntests_failed (sr);
+  srunner_free (sr);
+  return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+}
diff --git a/sflphone-gtk/tests/check_dbus.c b/sflphone-gtk/tests/check_dbus.c
new file mode 100644
index 0000000000..67423ee2c2
--- /dev/null
+++ b/sflphone-gtk/tests/check_dbus.c
@@ -0,0 +1,41 @@
+/*
+ *  Copyright (C) 2009 Savoir-Faire Linux inc.
+ *  Author: Julien Bonjean <julien.bonjean@savoirfairelinux.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program 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.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <check.h>
+#include <stdlib.h>
+
+Suite *
+dbus_suite (void)
+{
+  Suite *s = suite_create ("DBus");
+
+  return s;
+}
+
+int
+main (void)
+{
+  int number_failed;
+  Suite *s = dbus_suite ();
+  SRunner *sr = srunner_create (s);
+  srunner_run_all (sr, CK_NORMAL);
+  number_failed = srunner_ntests_failed (sr);
+  srunner_free (sr);
+  return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+}
diff --git a/sflphone-gtk/tests/check_global.c b/sflphone-gtk/tests/check_global.c
new file mode 100644
index 0000000000..5d64a94e93
--- /dev/null
+++ b/sflphone-gtk/tests/check_global.c
@@ -0,0 +1,41 @@
+/*
+ *  Copyright (C) 2009 Savoir-Faire Linux inc.
+ *  Author: Julien Bonjean <julien.bonjean@savoirfairelinux.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program 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.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <check.h>
+#include <stdlib.h>
+
+Suite *
+global_suite (void)
+{
+  Suite *s = suite_create ("Global");
+
+  return s;
+}
+
+int
+main (void)
+{
+  int number_failed;
+  Suite *s = global_suite ();
+  SRunner *sr = srunner_create (s);
+  srunner_run_all (sr, CK_NORMAL);
+  number_failed = srunner_ntests_failed (sr);
+  srunner_free (sr);
+  return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+}
-- 
GitLab