From 226f5aced14a044f9385f0f6e9ec7bbef9aae377 Mon Sep 17 00:00:00 2001
From: batt <batt@38d2e660-2303-0410-9eaa-f027e97ec537>
Date: Fri, 29 Aug 2008 21:45:58 +0000
Subject: [PATCH] Fix sprintf_test.

git-svn-id: https://src.develer.com/svnoss/bertos/trunk@1763 38d2e660-2303-0410-9eaa-f027e97ec537
---
 bertos/mware/formatwr.h     |  4 ++++
 bertos/mware/sprintf_test.c | 44 +++++++++++++++++++++++++------------
 2 files changed, 34 insertions(+), 14 deletions(-)

diff --git a/bertos/mware/formatwr.h b/bertos/mware/formatwr.h
index 865fbfd4..bd66b7e7 100644
--- a/bertos/mware/formatwr.h
+++ b/bertos/mware/formatwr.h
@@ -76,5 +76,9 @@ _formatted_write(
 		va_list ap);
 #endif /* CPU_HARVARD */
 
+int sprintf_testSetup(void);
+int sprintf_testRun(void);
+int sprintf_testTearDown(void);
+
 #endif /* MWARE_FORMATWR_H */
 
diff --git a/bertos/mware/sprintf_test.c b/bertos/mware/sprintf_test.c
index 60958fc5..390b6c31 100644
--- a/bertos/mware/sprintf_test.c
+++ b/bertos/mware/sprintf_test.c
@@ -36,7 +36,7 @@
  * \author Bernie Innocenti <bernie@codewiz.org>
  */
 
-
+#include "formatwr.h"
 #include <cfg/compiler.h>
 #include <cfg/test.h>
 #include <cfg/debug.h>
@@ -47,28 +47,31 @@
 
 #include <string.h> /* strcmp() */
 
-#warning FIXME:Review and refactor this test..
 
-#if UNIT_TEST
-#include "sprintf.c"
-#include "formatwr.c"
-#include "hex.c"
+int sprintf_testSetup(void)
+{
+	kdbg_init();
+	return 0;
+}
 
-int main(void)
+int sprintf_testRun(void)
 {
 	char buf[256];
 	static const char test_string[] = "Hello, world!\n";
 	static const pgm_char test_string_pgm[] = "Hello, world!\n";
 
 	snprintf(buf, sizeof buf, "%s", test_string);
-	assert(strcmp(buf, test_string) == 0);
+	if (strcmp(buf, test_string) != 0)
+		return 1;
 
 	snprintf(buf, sizeof buf, "%S", test_string_pgm);
-	assert(strcmp(buf, test_string_pgm) == 0);
+	if (strcmp(buf, test_string_pgm) != 0)
+		return 2;
 
-#define TEST(FMT, VALUE, EXPECT) do { \
+	#define TEST(FMT, VALUE, EXPECT) do { \
 		snprintf(buf, sizeof buf, FMT, VALUE); \
-		assert(strcmp(buf, EXPECT) == 0); \
+		if (strcmp(buf, EXPECT) != 0) \
+			return -1; \
 	} while (0)
 
 	TEST("%d",       12345,        "12345");
@@ -92,13 +95,26 @@ int main(void)
 	 * Stress tests.
 	 */
 	snprintf(buf, sizeof buf, "%s", NULL);
-	assert(strcmp(buf, "<NULL>") == 0);
+	if (strcmp(buf, "<NULL>") != 0)
+		return 3;
 	snprintf(buf, sizeof buf, "%k");
-	assert(strcmp(buf, "???") == 0);
+	if (strcmp(buf, "???") != 0)
+		return 4;
 	sprintf(NULL, test_string); /* must not crash */
 
 	return 0;
 }
 
-#endif /* _TEST */
+int sprintf_testTearDown(void)
+{
+	return 0;
+}
+
+#if UNIT_TEST
+	#include <drv/kdebug.c>
+	#include "sprintf.c"
+	#include "formatwr.c"
+	#include "hex.c"
+	TEST_MAIN(sprintf);
+#endif /* UNIT_TEST */
 
-- 
2.25.1