soylent r165 - trunk/libsoylent/test



Author: svenp
Date: Tue Jun 17 21:33:48 2008
New Revision: 165
URL: http://svn.gnome.org/viewvc/soylent?rev=165&view=rev

Log:
refactored test suite to better work with make check
added useful test-utility functions

Added:
   trunk/libsoylent/test/test-playground.c
      - copied, changed from r162, /trunk/libsoylent/test/playground.c
   trunk/libsoylent/test/test.h-old
      - copied, changed from r162, /trunk/libsoylent/test/test.h
Removed:
   trunk/libsoylent/test/playground.c
Modified:
   trunk/libsoylent/test/Makefile.am
   trunk/libsoylent/test/test.c
   trunk/libsoylent/test/test.h

Modified: trunk/libsoylent/test/Makefile.am
==============================================================================
--- trunk/libsoylent/test/Makefile.am	(original)
+++ trunk/libsoylent/test/Makefile.am	Tue Jun 17 21:33:48 2008
@@ -1,16 +1,23 @@
 #
 
-TESTS = test
+TESTS = test_playground test_book
 
-noinst_PROGRAMS = test
+noinst_PROGRAMS = test_playground test_book
 
-test_SOURCES = \
+test_playground_SOURCES = \
 	test.h \
 	test.c \
-	init.c \
-	playground.c
+	test-playground.c
 
-test_CFLAGS = $(WARN_CFLAGS) $(TEST_CFLAGS)
-test_LDADD = $(top_builddir)/libsoylent/libsoylent.la $(TEST_LIBS)
+test_playground_CFLAGS = $(WARN_CFLAGS) $(TEST_CFLAGS)
+test_playground_LDADD = $(top_builddir)/libsoylent/libsoylent.la $(TEST_LIBS)
+
+test_book_SOURCES = \
+	test.h \
+	test.c \
+	test-book.c
+
+test_book_CFLAGS = $(WARN_CFLAGS) $(TEST_CFLAGS)
+test_book_LDADD = $(top_builddir)/libsoylent/libsoylent.la $(TEST_LIBS)
 
 AM_CPPFLAGS = -I$(top_srcdir)

Copied: trunk/libsoylent/test/test-playground.c (from r162, /trunk/libsoylent/test/playground.c)
==============================================================================
--- /trunk/libsoylent/test/playground.c	(original)
+++ trunk/libsoylent/test/test-playground.c	Tue Jun 17 21:33:48 2008
@@ -1,16 +1,17 @@
-//
+/**/
 
 #include "test.h"
 
-#include <libsoylent/soylent.h>
-
-void
-playground (void)
+int
+main (int argc, char **argv)
 {
-	Test *test = test_init ("Playground");
-	
-	SlEntity *entity = sl_entity_new ();
-	g_print ("%s\n", (gchar *) sl_entity_get (entity, "x"));
-	
-	test_succeded (test);
+  test_init ("Playground");
+  
+  test_soylent_init ();
+  
+  test_print ("foo\n");
+  SlEntity *entity = sl_entity_new ();
+  g_print ("%s\n", (gchar *) sl_entity_get (entity, "x"));
+  
+  test_success ();
 }

Modified: trunk/libsoylent/test/test.c
==============================================================================
--- trunk/libsoylent/test/test.c	(original)
+++ trunk/libsoylent/test/test.c	Tue Jun 17 21:33:48 2008
@@ -1,77 +1,10 @@
-//
+/**/
 
 #include "config.h"
 #include "test.h"
 
-#include <libsoylent/soylent.h>
-
-#include <stdlib.h>
-
-/* TODO: split in multiple test binaries */
-
-int
-main (int argc, char **argv)
-{
-	tests = NULL;
-	
-	// TODO: why does this macro not work?
-	//g_print("Welcome to libsoylent Test v%s\n\n", LIBSOYLENT_VERSION);
-	g_print ("Welcome to libsoylent Test v0.0.1!\n\n");
-	
-	/* --- tests --- */
-	init ();
-	playground ();
-	/* insert more tests here... */
-	/* --- */
-	
-	g_print ("\n");
-	g_print ("Test results:\n");
-	
-	int tests_count = g_list_length (tests);
-	int success_count = 0;
-	GList *tests_iter = tests;
-	for (; tests_iter != NULL; tests_iter = tests_iter->next)
-    {
-  		Test *test = tests_iter->data;
-  		
-  		gchar result_char = ' ';
-  		if (test->succeded)
-        {
-  			  result_char = 'X';
-  			  success_count++;
-  		  }
-  		
-  		g_print("  [%c] %s\n", result_char, test->name);
-    }
-	
-	g_print ("\n");
-	g_print ("%d / %d tests succeded\n", success_count, tests_count);
-	
-	g_list_free (tests);
-	
-	if (success_count != tests_count)
-    {
-		  return EXIT_FAILURE;
-	  }
-	
-	return EXIT_SUCCESS;
-}
-
-Test
-*test_init (const gchar *name)
-{
-	Test *test = g_new (Test, 1);
-	test->name = (gchar *) name;
-	test->succeded = FALSE;
-	tests = g_list_append (tests, test);
-	
-	g_print ("Running test %s...\n", name);
-	
-	return test;
-}
-
 void
-test_succeded (Test *test)
+test_soylent_init (void)
 {
-	test->succeded = TRUE;
+  sl_init ();
 }

Modified: trunk/libsoylent/test/test.h
==============================================================================
--- trunk/libsoylent/test/test.h	(original)
+++ trunk/libsoylent/test/test.h	Tue Jun 17 21:33:48 2008
@@ -4,21 +4,22 @@
 #define TEST_H
 
 #include <glib.h>
+#include <stdlib.h>
+#include <libsoylent/soylent.h>
 
-typedef struct _Test Test;
+#define test_init(name) test_name = name; \
+                        g_print ("running test %s...\n", test_name)
+#define test_success()  g_print ("test %s succeded\n", test_name); \
+                        return EXIT_SUCCESS
+#define test_fail(...)  g_print ("test %s failed: ", test_name); \
+                        g_print (__VA_ARGS__); \
+                        g_print ("\n"); \
+                        return EXIT_FAILURE
+#define test_print(...) g_print ("  "); \
+                        g_print (__VA_ARGS__)
 
-struct _Test
-{
-	gchar *name;
-	gboolean succeded;
-};
+const gchar *test_name;
 
-GList *tests;
-
-Test *test_init (const gchar *name);
-void test_succeded (Test *test);
-
-void init (void);
-void playground (void);
+void test_soylent_init (void);
 
 #endif

Copied: trunk/libsoylent/test/test.h-old (from r162, /trunk/libsoylent/test/test.h)
==============================================================================
--- /trunk/libsoylent/test/test.h	(original)
+++ trunk/libsoylent/test/test.h-old	Tue Jun 17 21:33:48 2008
@@ -4,6 +4,7 @@
 #define TEST_H
 
 #include <glib.h>
+#include <stdlib.h>
 
 typedef struct _Test Test;
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]