summaryrefslogtreecommitdiff
path: root/source3/lib/replace/test/strptime.c
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2007-04-15 20:12:09 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:19:21 -0500
commit2f1aafa2a7e36298cc1e0e593b30fac1ab278596 (patch)
tree80803c500daca5d859afeea4917f859a71d577a5 /source3/lib/replace/test/strptime.c
parent3e819bd22c199f9cdf68c0f6258b4be17674a129 (diff)
downloadsamba-2f1aafa2a7e36298cc1e0e593b30fac1ab278596.tar.gz
samba-2f1aafa2a7e36298cc1e0e593b30fac1ab278596.tar.bz2
samba-2f1aafa2a7e36298cc1e0e593b30fac1ab278596.zip
r22221: merge from samba4:
- libreplace unsetenv() and strptime() replacements metze (This used to be commit 057c1c04d09b48c713ebc0b334cabcefc02561e9)
Diffstat (limited to 'source3/lib/replace/test/strptime.c')
-rw-r--r--source3/lib/replace/test/strptime.c152
1 files changed, 152 insertions, 0 deletions
diff --git a/source3/lib/replace/test/strptime.c b/source3/lib/replace/test/strptime.c
new file mode 100644
index 0000000000..434b5d0933
--- /dev/null
+++ b/source3/lib/replace/test/strptime.c
@@ -0,0 +1,152 @@
+
+#ifdef LIBREPLACE_CONFIGURE_TEST_STRPTIME
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+
+#define true 1
+#define false 0
+
+/* make printf a no-op */
+#define printf if(0) printf
+
+#else /* LIBREPLACE_CONFIGURE_TEST_STRPTIME */
+
+#include "replace.h"
+#include "system/time.h"
+
+#endif /* LIBREPLACE_CONFIGURE_TEST_STRPTIME */
+
+int libreplace_test_strptime(void)
+{
+ const char *s = "20070414101546Z";
+ char *ret;
+ struct tm t, 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;
+ }
+
+ if (memcmp(&t, &t2, sizeof(t)) == 0) {
+ printf("failure: strptime [\n"
+ "result differs if the format string has a 'Z' at the end\n"
+ "]\n");
+ return false;
+ }
+
+ 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