X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fmware%2Fsprintf_test.c;h=caf952a65729859dae40dfe9c6c1809d01e3d84f;hb=97e93eec653e38a04e94e5191bdbf5ea48edde96;hp=8bcbabffd606255c4fc68cb690849b1f9a482c1f;hpb=bb31ab5597a5a4299204f8c674f129506e0acdfe;p=bertos.git diff --git a/bertos/mware/sprintf_test.c b/bertos/mware/sprintf_test.c index 8bcbabff..caf952a6 100644 --- a/bertos/mware/sprintf_test.c +++ b/bertos/mware/sprintf_test.c @@ -30,13 +30,14 @@ * * --> * + * notest: avr + * notest: arm * \brief sprintf() implementation based on _formatted_write() * - * \version $Id$ * \author Bernie Innocenti */ - +#include "formatwr.h" #include #include #include @@ -47,28 +48,31 @@ #include /* strcmp() */ -#warning FIXME:Review and refactor this test.. -#if (ARCH & ARCH_UNITTEST) -#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); + 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"); @@ -91,14 +95,20 @@ int main(void) /* * Stress tests. */ - snprintf(buf, sizeof buf, "%s", NULL); - assert(strcmp(buf, "") == 0); + snprintf(buf, sizeof buf, "%s", (char *)(NULL)); + if (strcmp(buf, "") != 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; +} +TEST_MAIN(sprintf);