svn commit: samba r16316 - in branches/SAMBA_4_0/source/torture/local: .

jelmer at samba.org jelmer at samba.org
Fri Jun 16 22:59:41 GMT 2006


Author: jelmer
Date: 2006-06-16 22:59:40 +0000 (Fri, 16 Jun 2006)
New Revision: 16316

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=16316

Log:
Convert to new torture UI API.

Modified:
   branches/SAMBA_4_0/source/torture/local/util_file.c
   branches/SAMBA_4_0/source/torture/local/util_strlist.c


Changeset:
Modified: branches/SAMBA_4_0/source/torture/local/util_file.c
===================================================================
--- branches/SAMBA_4_0/source/torture/local/util_file.c	2006-06-16 22:48:50 UTC (rev 16315)
+++ branches/SAMBA_4_0/source/torture/local/util_file.c	2006-06-16 22:59:40 UTC (rev 16316)
@@ -23,6 +23,7 @@
 #include "includes.h"
 #include "system/filesys.h"
 #include "torture/torture.h"
+#include "torture/ui.h"
 
 #define TEST_FILENAME "utilfile.test"
 #define TEST_LINE1 "This is list line 1..."
@@ -31,55 +32,49 @@
 
 #define TEST_DATA TEST_LINE1 "\n" TEST_LINE2 "\n" TEST_LINE3
 
-static BOOL test_file_load_save(TALLOC_CTX *mem_ctx)
+static BOOL test_file_load_save(struct torture_context *test, const void *_data)
 {
-	BOOL ret;
 	size_t len;
 	char *data;
 	
-	ret = file_save(TEST_FILENAME, TEST_DATA, strlen(TEST_DATA));
-	if (!ret)
-		return False;
+	torture_assert(test, 
+				   file_save(TEST_FILENAME, TEST_DATA, strlen(TEST_DATA)),
+				   "saving file");
 
-	data = file_load(TEST_FILENAME, &len, mem_ctx);
-	if (!data) 
-		return False;
+	data = file_load(TEST_FILENAME, &len, test);
+	torture_assert(test, data, "loading file");
 
-	if (len != strlen(TEST_DATA))
-		return False;
+	torture_assert(test, len == strlen(TEST_DATA), "Length");
 	
-	if (memcmp(data, TEST_DATA, len) != 0)
-		return False;
+	torture_assert(test, memcmp(data, TEST_DATA, len) == 0, "Contents");
 
 	unlink(TEST_FILENAME);
 
 	return True;
 }
 
-static BOOL test_afdgets(TALLOC_CTX *mem_ctx)
+static BOOL test_afdgets(struct torture_context *test, const void *data)
 {
 	int fd;
 	char *line;
 	
-	if (!file_save(TEST_FILENAME, (const void *)TEST_DATA, strlen(TEST_DATA)))
-		return False;
+	torture_assert(test, 
+				   file_save(TEST_FILENAME, (const void *)TEST_DATA, 
+							 strlen(TEST_DATA)),
+				   "saving file");
 
 	fd = open(TEST_FILENAME, O_RDONLY);
 	
-	if (fd == -1) 
-		return False;
+	torture_assert(test, fd != -1, "opening file");
 
-	line = afdgets(fd, mem_ctx, 8);
-	if (strcmp(line, TEST_LINE1) != 0) 
-		return False;
+	line = afdgets(fd, test, 8);
+	torture_assert(test, strcmp(line, TEST_LINE1) == 0, "line 1 mismatch");
 
-	line = afdgets(fd, mem_ctx, 8);
-	if (strcmp(line, TEST_LINE2) != 0) 
-		return False;
+	line = afdgets(fd, test, 8);
+	torture_assert(test, strcmp(line, TEST_LINE2) == 0, "line 2 mismatch");
 
-	line = afdgets(fd, mem_ctx, 8);
-	if (strcmp(line, TEST_LINE3) != 0) 
-		return False;
+	line = afdgets(fd, test, 8);
+	torture_assert(test, strcmp(line, TEST_LINE3) == 0, "line 3 mismatch");
 
 	close(fd);
 
@@ -90,13 +85,13 @@
 
 BOOL torture_local_util_file(struct torture_context *torture) 
 {
-	BOOL ret = True;
-	TALLOC_CTX *mem_ctx = talloc_init("test_util_file");
+	struct torture_suite *suite = torture_suite_create(torture, "util_file");
 
-	ret &= test_file_load_save(mem_ctx);
-	ret &= test_afdgets(mem_ctx);
+	torture_suite_add_simple_tcase(suite, "file_load_save", 
+								   test_file_load_save, NULL);
 
-	talloc_free(mem_ctx);
+	torture_suite_add_simple_tcase(suite, "afdgets", 
+								   test_afdgets, NULL);
 
-	return ret;
+	return torture_run_suite(torture, suite);
 }

Modified: branches/SAMBA_4_0/source/torture/local/util_strlist.c
===================================================================
--- branches/SAMBA_4_0/source/torture/local/util_strlist.c	2006-06-16 22:48:50 UTC (rev 16315)
+++ branches/SAMBA_4_0/source/torture/local/util_strlist.c	2006-06-16 22:59:40 UTC (rev 16316)
@@ -22,6 +22,7 @@
 
 #include "includes.h"
 #include "torture/torture.h"
+#include "torture/ui.h"
 
 static const char *test_lists_shell_strings[] = {
 	"",
@@ -33,50 +34,49 @@
 	NULL
 };
 
-static BOOL test_lists_shell(TALLOC_CTX *mem_ctx)
+static BOOL test_lists_shell(struct torture_context *test, const void *_data)
 {
-	int i;
-	for (i = 0; test_lists_shell_strings[i]; i++) {
-		const char **ret1, **ret2, *tmp;
-		BOOL match = True;
+	const char *data = _data;
+	const char **ret1, **ret2, *tmp;
+	BOOL match = True;
 
-		ret1 = str_list_make_shell(mem_ctx, test_lists_shell_strings[i], " ");
-		tmp = str_list_join_shell(mem_ctx, ret1, ' ');
-		ret2 = str_list_make_shell(mem_ctx, tmp, " ");
-		
-		if ((ret1 == NULL || ret2 == NULL) && ret2 != ret1) {
-			match = False;
-		} else {
-			int j;
-			for (j = 0; ret1[j] && ret2[j]; j++) {
-				if (strcmp(ret1[j], ret2[j]) != 0) {
-					match = False;
-					break;
-				}
-			}
+	ret1 = str_list_make_shell(test, data, " ");
+	tmp = str_list_join_shell(test, ret1, ' ');
+	ret2 = str_list_make_shell(test, tmp, " ");
 
-			if (ret1[j] || ret2[j])
+	if ((ret1 == NULL || ret2 == NULL) && ret2 != ret1) {
+		match = False;
+	} else {
+		int j;
+		for (j = 0; ret1[j] && ret2[j]; j++) {
+			if (strcmp(ret1[j], ret2[j]) != 0) {
 				match = False;
+				break;
+			}
 		}
 
-		if (!match) {
-			printf("str_list_{make,join}_shell: Error double parsing, first run:\n%s\nSecond run: \n%s\n", 
-				   test_lists_shell_strings[i],
-				   tmp);
-			return False;
-		}
+		if (ret1[j] || ret2[j])
+			match = False;
 	}
 
+	if (!match) {
+		torture_fail(test, "str_list_{make,join}_shell: Error double parsing, first run:\n%s\nSecond run: \n%s", data, tmp);
+		return False;
+	}
+
 	return True;
 }
 
 BOOL torture_local_util_strlist(struct torture_context *torture) 
 {
-	BOOL ret = True;
-	TALLOC_CTX *mem_ctx = talloc_init("test_util_strlist");
+	struct torture_suite *suite = torture_suite_create(torture, "util_strlist");
+	int i;
 
-	ret &= test_lists_shell(mem_ctx);
-	talloc_free(mem_ctx);
+	for (i = 0; test_lists_shell_strings[i]; i++) {
+		torture_suite_add_simple_tcase(suite, 
+									   "lists_shell", test_lists_shell,
+									   &test_lists_shell_strings[i]);
+	}
 
-	return ret;
+	return torture_run_suite(torture, suite);
 }



More information about the samba-cvs mailing list