X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=mware%2Fsprintf_test.c;h=390b6c314becd60bd1763ebb24663f736be6a4c4;hb=HEAD;hp=a0706525e89936cd1580da74eab41f7c923f7156;hpb=646a88d7412eec847c282b9b2050b3a37a9af7a5;p=bertos.git diff --git a/mware/sprintf_test.c b/mware/sprintf_test.c deleted file mode 100755 index a0706525..00000000 --- a/mware/sprintf_test.c +++ /dev/null @@ -1,78 +0,0 @@ -/*! - * \file - * - * - * \brief sprintf() implementation based on _formatted_write() - * - * \version $Id$ - * \author Bernardo Innocenti - */ - -/*#* - *#* $Log$ - *#* Revision 1.4 2005/11/04 17:43:27 bernie - *#* Fix for LP64 architectures; Add some more tests. - *#* - *#*/ - -#include "sprintf.c" -#include "formatwr.c" -#include "hex.c" -#include -#include -#include - -#include /* assert() */ -#include /* strcmp() */ - - -int main(UNUSED_ARG(int, argc), UNUSED_ARG(char **,argv)) -{ - 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); - - snprintf(buf, sizeof buf, "%S", test_string_pgm); - assert(strcmp(buf, test_string_pgm) == 0); - -#define TEST(FMT, VALUE, EXPECT) do { \ - snprintf(buf, sizeof buf, FMT, VALUE); \ - assert(strcmp(buf, EXPECT) == 0); \ - } while (0) - - TEST("%d", 12345, "12345"); - TEST("%ld", 123456789L, "123456789"); - TEST("%ld", -12345678L, "-12345678"); - TEST("%lu", 4294967295UL, "4294967295"); - TEST("%hd", -12345, "-12345"); - TEST("%hu", 65535UL, "65535"); - - TEST("%8d", 123, " 123"); - TEST("%8d", -123, " -123"); - TEST("%-8d", -123, "-123 "); - TEST("%08d", -123, "-0000123"); - - TEST("%8.2f", -123.456, " -123.46"); - 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, "") == 0); - snprintf(buf, sizeof buf, "%k"); - assert(strcmp(buf, "???") == 0); - sprintf(NULL, test_string); /* must not crash */ - - return 0; -} -