Added some regression tests from patch #2321830
authorspth <spth@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 19 Apr 2009 11:19:29 +0000 (11:19 +0000)
committerspth <spth@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 19 Apr 2009 11:19:29 +0000 (11:19 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@5435 4a8a32a2-be11-0410-ad9d-d568d2c75423

ChangeLog
support/regression/tests/strcmp.c [new file with mode: 0644]
support/regression/tests/strcpy.c [new file with mode: 0644]
support/regression/tests/strncmp.c [new file with mode: 0644]
support/regression/tests/strspn.c [new file with mode: 0644]
support/regression/tests/strstr.c [new file with mode: 0644]
support/regression/tests/strtok.c [new file with mode: 0644]

index 39b443a5f0957e877e73771cd6005304acc3307c..5c781d6162d1dd53406943a85a617f480ad1b29b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2009-04-19 Philipp Klaus Krause <pkk AT spth.de>
+
+       * 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 <borut.razem AT siol.net>
 
        * 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 (file)
index 0000000..f9c57dd
--- /dev/null
@@ -0,0 +1,23 @@
+/** tests for strcmp
+*/
+#include <testfwk.h>
+#include <string.h>
+
+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 (file)
index 0000000..f0ce9fe
--- /dev/null
@@ -0,0 +1,23 @@
+/** tests for strcpy
+*/
+#include <testfwk.h>
+#include <string.h>
+
+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 (file)
index 0000000..79d53bd
--- /dev/null
@@ -0,0 +1,16 @@
+/** tests for strncmp
+*/
+#include <testfwk.h>
+#include <string.h>
+
+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 (file)
index 0000000..8401a23
--- /dev/null
@@ -0,0 +1,16 @@
+/** tests for strspn
+*/
+#include <testfwk.h>
+#include <string.h>
+
+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 (file)
index 0000000..da85f14
--- /dev/null
@@ -0,0 +1,18 @@
+/** tests for strstr
+*/
+#include <testfwk.h>
+#include <string.h>
+
+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 (file)
index 0000000..7f32539
--- /dev/null
@@ -0,0 +1,27 @@
+/** tests for strtok
+*/
+#include <testfwk.h>
+#include <string.h>
+
+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);
+
+}