libreplace: some systems don't have memmem()
[samba.git] / lib / replace / test / testsuite.c
index 7929f11addf0a660ba9ca6e19ca4d02f420339eb..caa70d68e390b6a047bb4dd3bce0bb8a6c0b8535 100644 (file)
@@ -1015,6 +1015,42 @@ static int test_utimes(void)
        return true;
 }
 
+static int test_memmem(void)
+{
+       char *s;
+
+       printf("test: memmem\n");
+
+       s = memmem("foo", 3, "fo", 2);
+       if (strcmp(s, "foo") != 0) {
+               printf(__location__ ": Failed memmem\n");
+               return false;
+       }
+
+       s = memmem("foo", 3, "", 0);
+       if (strcmp(s, "foo") != 0) {
+               printf(__location__ ": Failed memmem\n");
+               return false;
+       }
+
+       s = memmem("foo", 4, "o", 1);
+       if (strcmp(s, "oo") != 0) {
+               printf(__location__ ": Failed memmem\n");
+               return false;
+       }
+
+       s = memmem("foobarfodx", 11, "fod", 3);
+       if (strcmp(s, "fodx") != 0) {
+               printf(__location__ ": Failed memmem\n");
+               return false;
+       }
+
+       printf("success: memmem\n");
+
+       return true;
+}
+
+
 struct torture_context;
 bool torture_local_replace(struct torture_context *ctx)
 {
@@ -1065,6 +1101,7 @@ bool torture_local_replace(struct torture_context *ctx)
        ret &= test_getifaddrs();
        ret &= test_utime();
        ret &= test_utimes();
+       ret &= test_memmem();
 
        return ret;
 }