2006-03-20 Mikael Hallendal <micke@imendio.com>
authorhallski <hallski>
Mon, 20 Mar 2006 14:19:13 +0000
changeset 131 f67d47083e3a
parent 130 b88a70fb8525
child 132 8c9c1629f691
2006-03-20 Mikael Hallendal <micke@imendio.com> * Makefile.am: * acinclude.m4: * configure.in: * tests/.cvsignore: * tests/Makefile.am: * tests/test-objects.[ch]: - Started to add support for the Check unit test framework.
ChangeLog
Makefile.am
acinclude.m4
configure.in
tests/.cvsignore
tests/Makefile.am
tests/test-objects.c
tests/test-objects.h
--- a/ChangeLog	Mon Mar 20 10:53:45 2006 +0000
+++ b/ChangeLog	Mon Mar 20 14:19:13 2006 +0000
@@ -1,3 +1,13 @@
+2006-03-20  Mikael Hallendal  <micke@imendio.com>
+
+	* Makefile.am:
+	* acinclude.m4:
+	* configure.in:
+	* tests/.cvsignore:
+	* tests/Makefile.am:
+	* tests/test-objects.[ch]:
+	- Started to add support for the Check unit test framework.
+
 2006-03-20  Mikael Hallendal  <micke@imendio.com>
 
 	* loudmouth/lm-connection.c: Fixes LM-16.
--- a/Makefile.am	Mon Mar 20 10:53:45 2006 +0000
+++ b/Makefile.am	Mon Mar 20 14:19:13 2006 +0000
@@ -1,4 +1,4 @@
-SUBDIRS = loudmouth docs examples
+SUBDIRS = loudmouth docs examples tests
 
 EXTRA_DIST =			\
 	loudmouth-1.0.pc.in     \
--- a/acinclude.m4	Mon Mar 20 10:53:45 2006 +0000
+++ b/acinclude.m4	Mon Mar 20 14:19:13 2006 +0000
@@ -1,6 +1,6 @@
 dnl Turn on the additional warnings last, so -Werror doesn't affect other tests.
 
-AC_DEFUN([LM_COMPILE_WARNINGS],[
+AC_DEFUN([IDT_COMPILE_WARNINGS],[
    if test -f $srcdir/autogen.sh; then
 	default_compile_warnings="error"
     else
@@ -59,6 +59,136 @@
     AC_SUBST(WARN_CFLAGS)
 ])
 
+AC_DEFUN([IDT_PATH_CHECK],
+[
+  AC_ARG_WITH(check,
+  [  --with-check=PATH       prefix where check is installed [default=auto]])
+ 
+  min_check_version=ifelse([$1], ,0.8.2,$1)
+
+  AC_MSG_CHECKING(for check - version >= $min_check_version)
+
+  if test x$with_check = xno; then
+    AC_MSG_RESULT(disabled)
+    ifelse([$3], , AC_MSG_ERROR([disabling check is not supported]), [$3])
+  else
+    if test "x$with_check" != x; then
+      CHECK_CFLAGS="-I$with_check/include"
+      CHECK_LIBS="-L$with_check/lib -lcheck"
+    else
+      CHECK_CFLAGS=""
+      CHECK_LIBS="-lcheck"
+    fi
+
+    ac_save_CFLAGS="$CFLAGS"
+    ac_save_LIBS="$LIBS"
+
+    CFLAGS="$CFLAGS $CHECK_CFLAGS"
+    LIBS="$CHECK_LIBS $LIBS"
+
+    rm -f conf.check-test
+    AC_TRY_RUN([
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <check.h>
+
+int main ()
+{
+  int major, minor, micro;
+  char *tmp_version;
+
+  system ("touch conf.check-test");
+
+  /* HP/UX 9 (%@#!) writes to sscanf strings */
+  tmp_version = strdup("$min_check_version");
+  if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, &micro) != 3) {
+     printf("%s, bad version string\n", "$min_check_version");
+     return 1;
+   }
+    
+  if ((CHECK_MAJOR_VERSION != check_major_version) ||
+      (CHECK_MINOR_VERSION != check_minor_version) ||
+      (CHECK_MICRO_VERSION != check_micro_version))
+    {
+      printf("\n*** The check header file (version %d.%d.%d) does not match\n",
+	     CHECK_MAJOR_VERSION, CHECK_MINOR_VERSION, CHECK_MICRO_VERSION);
+      printf("*** the check library (version %d.%d.%d).\n",
+	     check_major_version, check_minor_version, check_micro_version);
+      return 1;
+    }
+
+  if ((check_major_version > major) ||
+      ((check_major_version == major) && (check_minor_version > minor)) ||
+      ((check_major_version == major) && (check_minor_version == minor) && (check_micro_version >= micro)))
+    {
+      return 0;
+    }
+  else
+    {
+      printf("\n*** An old version of check (%d.%d.%d) was found.\n",
+             check_major_version, check_minor_version, check_micro_version);
+      printf("*** You need a version of check being at least %d.%d.%d.\n", major, minor, micro);
+      printf("***\n"); 
+      printf("*** If you have already installed a sufficiently new version, this error\n");
+      printf("*** probably means that the wrong copy of the check library and header\n");
+      printf("*** file is being found. Rerun configure with the --with-check=PATH option\n");
+      printf("*** to specify the prefix where the correct version was installed.\n");
+    }
+
+  return 1;
+}
+],, no_check=yes, [echo $ac_n "cross compiling; assumed OK... $ac_c"])
+
+    CFLAGS="$ac_save_CFLAGS"
+    LIBS="$ac_save_LIBS"
+
+    if test "x$no_check" = x ; then
+      AC_MSG_RESULT(yes)
+      ifelse([$2], , :, [$2])
+    else
+      AC_MSG_RESULT(no)
+      if test -f conf.check-test ; then
+        :
+      else
+        echo "*** Could not run check test program, checking why..."
+        CFLAGS="$CFLAGS $CHECK_CFLAGS"
+        LIBS="$CHECK_LIBS $LIBS"
+        AC_TRY_LINK([
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <check.h>
+], ,  [ echo "*** The test program compiled, but did not run. This usually means"
+        echo "*** that the run-time linker is not finding check. You'll need to set your"
+        echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
+        echo "*** to the installed location  Also, make sure you have run ldconfig if that"
+        echo "*** is required on your system"
+	echo "***"
+        echo "*** If you have an old version installed, it is best to remove it, although"
+        echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"],
+      [ echo "*** The test program failed to compile or link. See the file config.log for"
+        echo "*** the exact error that occured." ])
+      
+        CFLAGS="$ac_save_CFLAGS"
+        LIBS="$ac_save_LIBS"
+      fi
+
+      CHECK_CFLAGS=""
+      CHECK_LIBS=""
+
+      rm -f conf.check-test
+      ifelse([$3], , AC_MSG_ERROR([check not found]), [$3])
+    fi
+
+    AC_SUBST(CHECK_CFLAGS)
+    AC_SUBST(CHECK_LIBS)
+
+    rm -f conf.check-test
+
+  fi
+])
+
 dnl Autoconf macros for libgnutls
 dnl $id$
                                                                                 
--- a/configure.in	Mon Mar 20 10:53:45 2006 +0000
+++ b/configure.in	Mon Mar 20 14:19:13 2006 +0000
@@ -13,7 +13,7 @@
 
 AM_PATH_GLIB_2_0
 
-LM_COMPILE_WARNINGS
+IDT_COMPILE_WARNINGS
 
 changequote(,)dnl
 if test "x$GCC" = "xyes"; then
@@ -39,6 +39,11 @@
 
 PKG_CHECK_MODULES(LOUDMOUTH, glib-2.0 >= $GLIB2_REQUIRED)
 
+# Check Unit test framework (defined in acinclude.m4)
+IDT_PATH_CHECK(0.9.2, have_check=yes, have_check=no)
+
+AM_CONDITIONAL(HAVE_CHECK, test x$have_check = xyes)
+
 dnl +--------------------+
 dnl | Check for gtk-doc. |-------------------------------
 dnl +--------------------+
@@ -185,6 +190,7 @@
 docs/reference/Makefile
 loudmouth/Makefile
 examples/Makefile
+tests/Makefile
 loudmouth-1.0.pc
 loudmouth.spec])
 
@@ -198,6 +204,7 @@
         compiler:                 ${CC}
         Enable SSL                ${enable_ssl}
         Enable Debug:             ${enable_debug}
+	Enable Unit Tests:        ${have_check}
 
         Now type 'make' to build Loudmouth
 "
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/.cvsignore	Mon Mar 20 14:19:13 2006 +0000
@@ -0,0 +1,5 @@
+Makefile
+Makefile.in
+test-objects
+.deps
+.libs
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/Makefile.am	Mon Mar 20 14:19:13 2006 +0000
@@ -0,0 +1,24 @@
+TESTS =                                       \
+	test-objects
+
+test_objects_SOURCES =                        \
+	test-objects.c                        \
+	test-objects.h
+
+if HAVE_CHECK
+noinst_PROGRAMS = $(TESTS)
+endif
+
+AM_CPPFLAGS =                                 \
+	-I.                                   \
+	-I$(top_srcdir)                       \
+	-DLM_COMPILATION                      \
+	-DRUNTIME_ENDIAN                      \
+	$(LM_CFLAGS)                          \
+	@CHECK_CFLAGS@
+
+LIBS =                                        \
+	$(LM_LIBS)                            \
+	@CHECK_LIBS@                          \
+	$(top_builddir)/loudmouth/libloudmouth-1.la
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-objects.c	Mon Mar 20 14:19:13 2006 +0000
@@ -0,0 +1,50 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2006 Imendio AB
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <stdlib.h>
+
+#include "test-objects.h"
+
+Suite *
+create_lm_objects_suite ()
+{
+	Suite *suite;
+
+	suite = suite_create ("LmObjects");
+
+	return suite;
+}
+
+int 
+main (int argc, char **argv)
+{
+	SRunner *srunner;
+	int      nf;
+
+	srunner = srunner_create (create_lm_objects_suite ());
+
+	srunner_run_all (srunner, CK_NORMAL);
+	nf = srunner_ntests_failed (srunner);
+
+	srunner_free (srunner);
+
+	return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-objects.h	Mon Mar 20 14:19:13 2006 +0000
@@ -0,0 +1,28 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2006 Imendio AB
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+ #ifndef __TEST_OBJECT_H__
+ #define __TEST_OBJECT_H__
+
+#include <check.h>
+
+Suite *create_lm_objects_suite (void);
+
+ #endif /* __TEST_OBJECT_H__ */