OSSP CVS Repository

ossp - Check-in [2173]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 2173
Date: 2002-May-29 10:32:53 (local)
2002-May-29 08:32:53 (UTC)
User:thl
Branch:
Comment: ugly hacks to allow lmtp2nntp to compile; comparison does not even work, yet
Tickets:
Inspections:
Files:
ossp-pkg/tai/tai.h      1.1 -> 1.2     2 inserted, 1 deleted
ossp-pkg/tai/tai_lib.c      1.4 -> 1.5     19 inserted, 1 deleted
ossp-pkg/tai/tai_test.c      1.2 -> 1.3     39 inserted, 7 deleted

ossp-pkg/tai/tai.h 1.1 -> 1.2

--- tai.h        2002/04/18 09:10:46     1.1
+++ tai.h        2002/05/29 08:32:53     1.2
@@ -34,7 +34,8 @@
 #include <time.h> /* time_t, struct tm */
 
 typedef enum {
-    TAI_OK = 0,
+    TAI_OK = 0, /* also used for TRUE */
+    TAI_FALSE,
     TAI_ERR_ARG,
     TAI_ERR_USE,
     TAI_ERR_OVF,


ossp-pkg/tai/tai_lib.c 1.4 -> 1.5

--- tai_lib.c    2002/05/01 18:48:34     1.4
+++ tai_lib.c    2002/05/29 08:32:53     1.5
@@ -239,11 +239,29 @@
 
 tai_rc_t tai_op(tai_t *tai, tai_op_t op, ...)
 {
+    tai_rc_t rc = TAI_ERR_IMP;
     va_list ap;
 
     if (tai == NULL)
         return TAI_ERR_ARG;
     va_start(ap, op); 
+    if ((op == TAI_OP_NE) || (op == TAI_OP_EQ) || (op == TAI_OP_LT) || (op == TAI_OP_LE) || (op == TAI_OP_GT) || (op == TAI_OP_GE)) {
+        tai_t *tai1, *tai2;
+        unsigned long s1, s2;
+
+        tai1 = tai;
+        tai2 = (tai_t *)va_arg(ap, void *);
+        s1 = tai1->tai_sec + (60 * tai1->tai_min) + (60 * 60 * tai1->tai_hour) + (60 * 60 * 24 * tai1->tai_yday) + (60 * 60 * 24 * 365 * tai1->tai_year) + tai1->tai_gmtoff;
+        s2 = tai2->tai_sec + (60 * tai2->tai_min) + (60 * 60 * tai2->tai_hour) + (60 * 60 * 24 * tai2->tai_yday) + (60 * 60 * 24 * 365 * tai2->tai_year) + tai2->tai_gmtoff;
+        switch (op) {
+            case TAI_OP_NE: rc = s2 != s1 ? TAI_OK: TAI_FALSE;
+            case TAI_OP_EQ: rc = s2 == s1 ? TAI_OK: TAI_FALSE;
+            case TAI_OP_LT: rc = s2 <  s1 ? TAI_OK: TAI_FALSE;
+            case TAI_OP_LE: rc = s2 <= s1 ? TAI_OK: TAI_FALSE;
+            case TAI_OP_GT: rc = s2 >  s1 ? TAI_OK: TAI_FALSE;
+            case TAI_OP_GE: rc = s2 >= s1 ? TAI_OK: TAI_FALSE;
+        }
+    }
     va_end(ap); 
-    return TAI_ERR_IMP;
+    return rc;
 }


ossp-pkg/tai/tai_test.c 1.2 -> 1.3

--- tai_test.c   2002/05/01 18:48:34     1.2
+++ tai_test.c   2002/05/29 08:32:53     1.3
@@ -123,14 +123,46 @@
     tai_destroy(tm);
 }
 
-TS_TEST(test_formatting)
+TS_TEST(test_comparing)
 {
-    tai_t *tm;
+    tai_rc_t rv;
+    tai_t *tm1, *tm2;
+    int i;
+    struct {
+        char *date1;
+        char *date2;
+        int   op;
+        int   exp;
+    } table[] = {
+        { "2000-02-22 10:20:30 +0200", "2000-02-22 10:20:31 +0200", TAI_OP_NE, TAI_OK    }, /* 00 */
+        { "2000-02-22 10:20:30 +0200", "2000-02-22 10:20:30 +0200", TAI_OP_NE, TAI_FALSE }, /* 01 */
+        { "2000-02-22 10:20:30 +0200", "2000-02-22 10:20:30 +0200", TAI_OP_EQ, TAI_OK    }, /* 02 */
+        { "2000-02-22 10:20:30 +0200", "2000-02-22 10:20:31 +0200", TAI_OP_EQ, TAI_FALSE }, /* 03 */
+        { "2000-02-22 10:20:30 +0200", "2000-02-22 10:20:20 +0200", TAI_OP_LT, TAI_OK    }, /* 04 */
+        { "2000-02-22 10:20:30 +0200", "2000-02-22 10:20:30 +0200", TAI_OP_LT, TAI_FALSE }, /* 05 */
+        { "2000-02-22 10:20:30 +0200", "2000-02-22 10:20:20 +0200", TAI_OP_LE, TAI_OK    }, /* 06 */
+        { "2000-02-22 10:20:30 +0200", "2000-02-22 10:20:30 +0200", TAI_OP_LE, TAI_OK    }, /* 07 */
+        { "2000-02-22 10:20:30 +0200", "2000-02-22 10:20:31 +0200", TAI_OP_LE, TAI_FALSE }, /* 08 */
+        { "2000-02-22 10:20:30 +0200", "2000-02-22 10:20:31 +0200", TAI_OP_GT, TAI_OK    }, /* 09 */
+        { "2000-02-22 10:20:30 +0200", "2000-02-22 10:20:30 +0200", TAI_OP_GT, TAI_FALSE }, /* 10 */
+        { "2000-02-22 10:20:30 +0200", "2000-02-22 10:20:31 +0200", TAI_OP_GE, TAI_OK    }, /* 11 */
+        { "2000-02-22 10:20:30 +0200", "2000-02-22 10:20:30 +0200", TAI_OP_GE, TAI_OK    }, /* 12 */
+        { "2000-02-22 10:20:30 +0200", "2000-02-22 10:20:20 +0200", TAI_OP_GE, TAI_FALSE }, /* 13 */
+        { NULL, NULL, 0, 0 }
+    };
 
-    ts_test_check(TS_CTX, "time formatting");
-    tai_create(&tm);
-    /* FIXME */
-    tai_destroy(tm);
+    tai_create(&tm1);
+    tai_create(&tm2);
+    ts_test_check(TS_CTX, "time comparing");
+    for (i = 0; table[i].date1 != NULL; i++) {
+        ts_test_log(TS_CTX, "date1=%s, date2=%s, op=%d", table[i].date1, table[i].date2, table[i].op);
+        tai_parse(tm1, table[i].date1, strlen(table[i].date1), "%Y-%m-%d %H:%M:%S %z");
+        tai_parse(tm2, table[i].date2, strlen(table[i].date2), "%Y-%m-%d %H:%M:%S %z");
+        if ((rv = tai_op(tm1, table[i].op, tm2)) != table[i].exp)
+            ts_test_fail(TS_CTX, "#%d: output \"%d\", expected \"%d\"", i, rv, table[i].exp);
+    }
+    tai_destroy(tm2);
+    tai_destroy(tm1);
 }
 
 int main(int argc, char *argv[])
@@ -143,7 +175,7 @@
     ts_suite_test(ts, test_object,       "object handling");
     ts_suite_test(ts, test_importexport, "time import/export");
     ts_suite_test(ts, test_parsing,      "time parsing");
-    ts_suite_test(ts, test_formatting,   "time formatting");
+    ts_suite_test(ts, test_comparing,    "time comparing");
     n = ts_suite_run(ts);
     ts_suite_free(ts);
     return n;

CVSTrac 2.0.1