From: spth Date: Sun, 19 Apr 2009 11:19:29 +0000 (+0000) Subject: Added some regression tests from patch #2321830 X-Git-Url: https://git.gag.com/?p=fw%2Fsdcc;a=commitdiff_plain;h=b641ef75173e02b781c1b994d37645116e175706 Added some regression tests from patch #2321830 git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@5435 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index 39b443a5..5c781d61 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2009-04-19 Philipp Klaus Krause + + * support/regression/tests/strtok.c, + support/regression/tests/strstr.c, + support/regression/tests/strspn.c, + support/regression/tests/strncmp.c, + support/regression/tests/strcpy.c, + support/regression/tests/strcmp.c: + Added some regression tests by Ruud van Silfhout from patch #2321830. + 2009-04-13 Borut Razem * device/lib/Makefile.in, device/lib/ds390/Makefile.in, diff --git a/support/regression/tests/strcmp.c b/support/regression/tests/strcmp.c new file mode 100644 index 00000000..f9c57dd1 --- /dev/null +++ b/support/regression/tests/strcmp.c @@ -0,0 +1,23 @@ +/** tests for strcmp +*/ +#include +#include + +static void +teststrcmp(void) +{ + int result = strcmp("", ""); + ASSERT( result == 0); + + result = strcmp("", "a"); + ASSERT( result < 0); + + result = strcmp("a", ""); + ASSERT( result > 0); + + result = strcmp("ab", "ab"); + ASSERT( result == 0); + + result = strcmp("aa", "ab"); + ASSERT( result < 0); +} diff --git a/support/regression/tests/strcpy.c b/support/regression/tests/strcpy.c new file mode 100644 index 00000000..f0ce9fe1 --- /dev/null +++ b/support/regression/tests/strcpy.c @@ -0,0 +1,23 @@ +/** tests for strcpy +*/ +#include +#include + +static void +teststrcpy(void) +{ + static char empty[] = ""; + static char string[] = "\1\2\0\3"; + char buf[40] = "abcdefghijklmnopqrstuvwxyz"; + + char * result = strcpy(buf, empty); + ASSERT( strlen(buf) == 0); + ASSERT( result == buf); + + result = strcpy(buf, string); + ASSERT( result == buf); + ASSERT( strlen(buf) == 2); + ASSERT( buf[0] == '\1'); + ASSERT( buf[1] == '\2'); + ASSERT( buf[3] == 'd'); +} diff --git a/support/regression/tests/strncmp.c b/support/regression/tests/strncmp.c new file mode 100644 index 00000000..79d53bdc --- /dev/null +++ b/support/regression/tests/strncmp.c @@ -0,0 +1,16 @@ +/** tests for strncmp +*/ +#include +#include + +static void +teststrncmp(void) +{ + ASSERT( strncmp("", "", 0) == 0); + ASSERT( strncmp("ab", "ab", 0) == 0); + ASSERT( strncmp("a", "a", 2) == 0); + ASSERT( strncmp("aa", "ab", 1) == 0); + ASSERT( strncmp("aa", "ab", 2) < 0); + ASSERT( strncmp("abc", "abd", 2) == 0); + ASSERT( strncmp("abc", "abc", 3) == 0); +} diff --git a/support/regression/tests/strspn.c b/support/regression/tests/strspn.c new file mode 100644 index 00000000..8401a239 --- /dev/null +++ b/support/regression/tests/strspn.c @@ -0,0 +1,16 @@ +/** tests for strspn +*/ +#include +#include + +static void +teststrspn(void) +{ + ASSERT( strspn("aabbcd", "ab") == 4); + ASSERT( strspn("abbacd", "") == 0); + ASSERT( strspn("abbacd", "ac") == 1); + ASSERT( strspn("abbacd", "x") == 0); + ASSERT( strspn("abbacd", "c") == 0); + ASSERT( strspn("abbacd", "cba") == 5); + ASSERT( strspn("abbacd", "cdba") == 6); +} diff --git a/support/regression/tests/strstr.c b/support/regression/tests/strstr.c new file mode 100644 index 00000000..da85f140 --- /dev/null +++ b/support/regression/tests/strstr.c @@ -0,0 +1,18 @@ +/** tests for strstr +*/ +#include +#include + +static void +teststrstr(void) +{ + char *a = "aabbcd"; + ASSERT( strstr(a, "\0\1") == a); + ASSERT( strstr(a, "") == a); + ASSERT( strstr(a, "ab") == &a[1]); + ASSERT( strstr(a, "abc") == NULL); + ASSERT( strstr(a, "abbc") == &a[1]); + ASSERT( strstr("", "abbc") == NULL); +/* ASSERT( strstr("", "") == a); should work, but it doesn't */ + ASSERT( strstr(a, "cd") == &a[4]); +} diff --git a/support/regression/tests/strtok.c b/support/regression/tests/strtok.c new file mode 100644 index 00000000..7f325391 --- /dev/null +++ b/support/regression/tests/strtok.c @@ -0,0 +1,27 @@ +/** tests for strtok +*/ +#include +#include + +static void +teststrtok(void) +{ + static char str[] = "?a???b,,,#c"; + const char str2[] = "axaaba"; + char *token = strtok(str, "?"); // 'token' points to the token "a" + ASSERT( token == &str[1] && 0 == strcmp(token,"a")); + token = strtok(NULL, ","); // 'token' points to the token "??b" + ASSERT( token == &str[3]&& 0 == strcmp(token,"??b")); + token = strtok(NULL, "#,"); // 'token' points to the token "c" + ASSERT( token == &str[10] && 0 == strcmp(token,"c")); + token = strtok(NULL, "?"); // 'token' is a null pointer + ASSERT( token == NULL); + + token = strtok (str2, "ab"); + ASSERT( token && 0 == strcmp (token, "x")); + token = strtok(NULL, "ab"); + ASSERT( token == NULL); + token = strtok(NULL, "a"); + ASSERT( token == NULL); + +}