+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,
--- /dev/null
+/** 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);
+}
--- /dev/null
+/** 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');
+}
--- /dev/null
+/** 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);
+}
--- /dev/null
+/** 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);
+}
--- /dev/null
+/** 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]);
+}
--- /dev/null
+/** 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);
+
+}