gmime r1204 - trunk/tests



Author: fejj
Date: Sun Jan 27 16:20:35 2008
New Revision: 1204
URL: http://svn.gnome.org/viewvc/gmime?rev=1204&view=rev

Log:
cleanup auto-generated stream test data on success



Modified:
   trunk/tests/test-streams.c
   trunk/tests/testsuite.c
   trunk/tests/testsuite.h

Modified: trunk/tests/test-streams.c
==============================================================================
--- trunk/tests/test-streams.c	(original)
+++ trunk/tests/test-streams.c	Sun Jan 27 16:20:35 2008
@@ -516,7 +516,7 @@
 }
 
 static int
-gen_test_data (const char *datadir)
+gen_test_data (const char *datadir, char **stream_name)
 {
 	GMimeStream *istream, *ostream, *stream;
 	char input[256], output[256], *name, *p;
@@ -544,6 +544,8 @@
 	if ((fd = mkstemp (input)) == -1)
 		return -1;
 	
+	*stream_name = g_strdup (name);
+	
 	*p++ = G_DIR_SEPARATOR;
 	p = g_stpcpy (p, name);
 	*p++ = ':';
@@ -588,6 +590,7 @@
 {
 	const char *datadir = "data/streams";
 	gboolean gen_data = TRUE;
+	char *stream_name = NULL;
 	struct dirent *dent;
 	char path[256], *p;
 	DIR *dir, *outdir;
@@ -611,7 +614,7 @@
 	strcpy (p, "output");
 	
 	if (!(outdir = opendir (path))) {
-		if (gen_test_data (datadir) == -1 ||
+		if (gen_test_data (datadir, &stream_name) == -1 ||
 		    !(outdir = opendir (path)))
 			goto exit;
 		
@@ -621,7 +624,7 @@
 	p = g_stpcpy (p, "input");
 	
 	if (!(dir = opendir (path))) {
-		if (!gen_data || gen_test_data (datadir) == -1 ||
+		if (!gen_data || gen_test_data (datadir, &stream_name) == -1 ||
 		    !(dir = opendir (path))) {
 			closedir (outdir);
 			goto exit;
@@ -641,7 +644,7 @@
 		
 		rewinddir (dir);
 		
-		if (gen_data && gen_test_data (datadir) == -1)
+		if (gen_data && gen_test_data (datadir, &stream_name) == -1)
 			goto exit;
 	}
 	
@@ -658,6 +661,27 @@
 		test_stream_buffer_gets (path);
 	}
 	
+	if (gen_data && stream_name && testsuite_total_errors () == 0) {
+		/* since all tests were successful, unlink the generated test data */
+		strcpy (p, stream_name);
+		unlink (path);
+		
+		p = g_stpcpy (path, datadir);
+		*p++ = G_DIR_SEPARATOR;
+		p = g_stpcpy (p, "output");
+		*p++ = G_DIR_SEPARATOR;
+		
+		rewinddir (outdir);
+		while ((dent = readdir (outdir))) {
+			if (!strncmp (dent->d_name, stream_name, strlen (stream_name))) {
+				strcpy (p, dent->d_name);
+				unlink (path);
+			}
+		}
+		
+		g_free (stream_name);
+	}
+	
 	closedir (outdir);
 	closedir (dir);
 	

Modified: trunk/tests/testsuite.c
==============================================================================
--- trunk/tests/testsuite.c	(original)
+++ trunk/tests/testsuite.c	Sun Jan 27 16:20:35 2008
@@ -280,6 +280,12 @@
 	total_tests++;
 }
 
+int
+testsuite_total_errors (void)
+{
+	return total_errors;
+}
+
 
 Exception *
 exception_new (const char *fmt, ...)

Modified: trunk/tests/testsuite.h
==============================================================================
--- trunk/tests/testsuite.h	(original)
+++ trunk/tests/testsuite.h	Sun Jan 27 16:20:35 2008
@@ -43,6 +43,8 @@
 void testsuite_check_warn (const char *fmt, ...);
 void testsuite_check_passed (void);
 
+int testsuite_total_errors (void);
+
 
 /*#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
 #define G_GNUC_NORETURN __attribute__((noreturn))



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