Fix nightly test warnings; exposed bugs are on the bug tracker.
[bertos.git] / bertos / mware / sprintf_test.c
index 1bcedfd35175f289618f6494422d83f27d0019b4..56c2af7db2c660479e4108a5d6b379df9540e9b2 100644 (file)
  * \brief sprintf() implementation based on _formatted_write()
  *
  * \version $Id$
- * \author Bernardo Innocenti <bernie@develer.com>
+ * \author Bernie Innocenti <bernie@codewiz.org>
  */
 
-#include "sprintf.c"
-#include "formatwr.c"
-#include "hex.c"
+#include "formatwr.h"
 #include <cfg/compiler.h>
-#include <mware/pgm.h>
+#include <cfg/test.h>
+#include <cfg/debug.h>
+
+#include <cpu/pgm.h>
+
 #include <stdio.h>
 
-#include <assert.h> /* assert() */
 #include <string.h> /* strcmp() */
 
 
-int main(UNUSED_ARG(int, argc), UNUSED_ARG(char **,argv))
+int sprintf_testSetup(void)
+{
+       kdbg_init();
+       return 0;
+}
+
+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);
+       snprintf(buf, sizeof buf, "%S", (const wchar_t *)test_string_pgm);
+       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");
@@ -80,17 +90,24 @@ int main(UNUSED_ARG(int, argc), UNUSED_ARG(char **,argv))
        TEST("%-8.2f", -123.456,    "-123.46 ");
        TEST("%8.0f",  -123.456,    "    -123");
 
-#undef TEST
 
        /*
         * Stress tests.
         */
-       snprintf(buf, sizeof buf, "%s", NULL);
-       assert(strcmp(buf, "<NULL>") == 0);
+       snprintf(buf, sizeof buf, "%s", (char *)(NULL));
+       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;
 }
 
+int sprintf_testTearDown(void)
+{
+       return 0;
+}
+
+TEST_MAIN(sprintf);