Fix lib/replace
authorMartin Schwenke <martin@meltin.net>
Thu, 10 Nov 2011 04:07:55 +0000 (15:07 +1100)
committerMartin Schwenke <martin@meltin.net>
Fri, 11 Nov 2011 03:29:36 +0000 (14:29 +1100)
Warnings are generated when compiling strptime.c.  Why is it being
compiled on Linux?  strptime(3) has been in glibc for 15 years!

It turns out that some of the test fragments were being looked for in
lib/replace/test/ and some in lib/replace/tests/.  In addition,
test*/strptime.c was missing.

Move the tests to lib/replace/test/ for consistency with upstream
(Samba) and copy in test/strptime.c from Samba.  Tweak repdir.m4 to
handle the directory rename.

Signed-off-by: Martin Schwenke <martin@meltin.net>
lib/replace/repdir.m4
lib/replace/test/os2_delete.c [moved from lib/replace/tests/os2_delete.c with 100% similarity]
lib/replace/test/shared_mmap.c [moved from lib/replace/tests/shared_mmap.c with 100% similarity]
lib/replace/test/strptime.c [new file with mode: 0644]
lib/replace/test/testsuite.c [moved from lib/replace/tests/testsuite.c with 100% similarity]

index bbd111f621755a6395e6d5e5fc6ae65732309e62..f53a4c297455d9cadc0c3df846f91fe1c9c18124 100644 (file)
@@ -1,7 +1,7 @@
 AC_CACHE_CHECK([for broken readdir],libreplace_cv_READDIR_NEEDED,[
        AC_TRY_RUN([
 #define test_readdir_os2_delete main
-#include "$libreplacedir/tests/os2_delete.c"],
+#include "$libreplacedir/test/os2_delete.c"],
        [libreplace_cv_READDIR_NEEDED=no],
        [libreplace_cv_READDIR_NEEDED=yes],
        [libreplace_cv_READDIR_NEEDED="assuming not"])
@@ -34,7 +34,7 @@ AC_CACHE_CHECK([for replacing readdir using getdirentries()],libreplace_cv_READD
 #define _LIBREPLACE_REPLACE_H
 #include "$libreplacedir/repdir_getdirentries.c"
 #define test_readdir_os2_delete main
-#include "$libreplacedir/tests/os2_delete.c"],
+#include "$libreplacedir/test/os2_delete.c"],
        [libreplace_cv_READDIR_GETDIRENTRIES=yes],
        [libreplace_cv_READDIR_GETDIRENTRIES=no])
 ])
@@ -57,7 +57,7 @@ AC_CACHE_CHECK([for replacing readdir using getdents()],libreplace_cv_READDIR_GE
 #error _donot_use_getdents_replacement_anymore
 #include "$libreplacedir/repdir_getdents.c"
 #define test_readdir_os2_delete main
-#include "$libreplacedir/tests/os2_delete.c"],
+#include "$libreplacedir/test/os2_delete.c"],
        [libreplace_cv_READDIR_GETDENTS=yes],
        [libreplace_cv_READDIR_GETDENTS=no])
 ])
diff --git a/lib/replace/test/strptime.c b/lib/replace/test/strptime.c
new file mode 100644 (file)
index 0000000..5bf03f5
--- /dev/null
@@ -0,0 +1,173 @@
+
+#ifdef LIBREPLACE_CONFIGURE_TEST_STRPTIME
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+
+#define true 1
+#define false 0
+
+#ifndef __STRING
+#define __STRING(x)    #x
+#endif
+
+/* make printf a no-op */
+#define printf if(0) printf
+
+#else /* LIBREPLACE_CONFIGURE_TEST_STRPTIME */
+
+#include "replace.h"
+#include "system/time.h"
+#include "replace-test.h"
+
+#endif /* LIBREPLACE_CONFIGURE_TEST_STRPTIME */
+
+int libreplace_test_strptime(void)
+{
+       const char *s = "20070414101546Z";
+       char *ret;
+       struct tm t, t2;
+
+       memset(&t, 0, sizeof(t));
+       memset(&t2, 0, sizeof(t2));
+
+       printf("test: strptime\n");
+
+       ret = strptime(s, "%Y%m%d%H%M%S", &t);
+       if ( ret == NULL ) {
+               printf("failure: strptime [\n"
+                      "returned NULL\n"
+                      "]\n");
+               return false;
+       }
+
+       if ( *ret != 'Z' ) {
+               printf("failure: strptime [\n"
+                      "ret doesn't point to 'Z'\n"
+                      "]\n");
+               return false;
+       }
+
+       ret = strptime(s, "%Y%m%d%H%M%SZ", &t2);
+       if ( ret == NULL ) {
+               printf("failure: strptime [\n"
+                      "returned NULL with Z\n"
+                      "]\n");
+               return false;
+       }
+
+       if ( *ret != '\0' ) {
+               printf("failure: strptime [\n"
+                      "ret doesn't point to '\\0'\n"
+                      "]\n");
+               return false;
+       }
+
+#define CMP_TM_ELEMENT(t1,t2,elem) \
+       if (t1.elem != t2.elem) { \
+               printf("failure: strptime [\n" \
+                      "result differs if the format string has a 'Z' at the end\n" \
+                      "element: %s %d != %d\n" \
+                      "]\n", \
+                      __STRING(elen), t1.elem, t2.elem); \
+               return false; \
+       }
+
+       CMP_TM_ELEMENT(t,t2,tm_sec);
+       CMP_TM_ELEMENT(t,t2,tm_min);
+       CMP_TM_ELEMENT(t,t2,tm_hour);
+       CMP_TM_ELEMENT(t,t2,tm_mday);
+       CMP_TM_ELEMENT(t,t2,tm_mon);
+       CMP_TM_ELEMENT(t,t2,tm_year);
+       CMP_TM_ELEMENT(t,t2,tm_wday);
+       CMP_TM_ELEMENT(t,t2,tm_yday);
+       CMP_TM_ELEMENT(t,t2,tm_isdst);
+
+       if (t.tm_sec != 46) {
+               printf("failure: strptime [\n"
+                      "tm_sec: expected: 46, got: %d\n"
+                      "]\n",
+                      t.tm_sec);
+               return false;
+       }
+
+       if (t.tm_min != 15) {
+               printf("failure: strptime [\n"
+                      "tm_min: expected: 15, got: %d\n"
+                      "]\n",
+                      t.tm_min);
+               return false;
+       }
+
+       if (t.tm_hour != 10) {
+               printf("failure: strptime [\n"
+                      "tm_hour: expected: 10, got: %d\n"
+                      "]\n",
+                      t.tm_hour);
+               return false;
+       }
+
+       if (t.tm_mday != 14) {
+               printf("failure: strptime [\n"
+                      "tm_mday: expected: 14, got: %d\n"
+                      "]\n",
+                      t.tm_mday);
+               return false;
+       }
+
+       if (t.tm_mon != 3) {
+               printf("failure: strptime [\n"
+                      "tm_mon: expected: 3, got: %d\n"
+                      "]\n",
+                      t.tm_mon);
+               return false;
+       }
+
+       if (t.tm_year != 107) {
+               printf("failure: strptime [\n"
+                      "tm_year: expected: 107, got: %d\n"
+                      "]\n",
+                      t.tm_year);
+               return false;
+       }
+
+       if (t.tm_wday != 6) { /* saturday */
+               printf("failure: strptime [\n"
+                      "tm_wday: expected: 6, got: %d\n"
+                      "]\n",
+                      t.tm_wday);
+               return false;
+       }
+
+       if (t.tm_yday != 103) {
+               printf("failure: strptime [\n"
+                      "tm_yday: expected: 103, got: %d\n"
+                      "]\n",
+                      t.tm_yday);
+               return false;
+       }
+
+       /* we don't test this as it depends on the host configuration
+       if (t.tm_isdst != 0) {
+               printf("failure: strptime [\n"
+                      "tm_isdst: expected: 0, got: %d\n"
+                      "]\n",
+                      t.tm_isdst);
+               return false;
+       }*/
+
+       printf("success: strptime\n");
+
+       return true;
+}
+
+#ifdef LIBREPLACE_CONFIGURE_TEST_STRPTIME
+int main (void)
+{
+       int ret;
+       ret = libreplace_test_strptime();
+       if (ret == false) return 1;
+       return 0;
+}
+#endif