OSSP CVS Repository

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

Check-in Number: 1232
Date: 2001-Oct-31 20:28:49 (local)
2001-Oct-31 19:28:49 (UTC)
User:rse
Branch:
Comment: Rename test suite library name spaces in order to get rid of problems under Sun Solaris 2.x.
Tickets:
Inspections:
Files:
ossp-pkg/sa/sa_test.c      1.9 -> 1.10     19 inserted, 19 deleted
ossp-pkg/sa/ts.c      1.2 -> 1.3     41 inserted, 41 deleted
ossp-pkg/sa/ts.h      1.1 -> 1.2     29 inserted, 27 deleted

ossp-pkg/sa/sa_test.c 1.9 -> 1.10

--- sa_test.c    2001/10/10 15:50:31     1.9
+++ sa_test.c    2001/10/31 19:28:49     1.10
@@ -38,7 +38,7 @@
 #include "ts.h"
 #include "sa.h"
 
-TST_FUNC(test_saa_impexp)
+TS_TEST(test_saa_impexp)
 {
     sa_addr_t *saa;
     sa_rc_t rv;
@@ -62,30 +62,30 @@
         { "unix:", SA_ERR_ARG, NULL }
     };
 
-    tst_check(TST, "sa_addr_create");
+    ts_test_check(TS_CTX, "sa_addr_create");
     if ((rv = sa_addr_create(&saa)) != SA_OK)
-        tst_fail(TST, "sa_addr_create -> %d[%s] (expected %d[%s])", 
+        ts_test_fail(TS_CTX, "sa_addr_create -> %d[%s] (expected %d[%s])", 
                  rv, sa_error(rv), SA_OK, sa_error(SA_OK));
     for (i = 0; i < sizeof(table)/sizeof(table[0]); i++) {
-        tst_check(TST, "sa_addr_u2a(\"%s\")", table[i].in);
+        ts_test_check(TS_CTX, "sa_addr_u2a(\"%s\")", table[i].in);
         if ((rv = sa_addr_u2a(saa, table[i].in)) != table[i].rv)
-            tst_fail(TST, "sa_addr_a2u -> %d[%s] (expected %d[%s])",
+            ts_test_fail(TS_CTX, "sa_addr_a2u -> %d[%s] (expected %d[%s])",
                      rv, sa_error(rv), table[i].rv, sa_error(table[i].rv));
-        tst_check(TST, "sa_addr_a2u");
+        ts_test_check(TS_CTX, "sa_addr_a2u");
         if ((rv = sa_addr_a2u(saa, &cp)) != SA_OK)
-            tst_fail(TST, "sa_addr_u2a -> %d[%s] (expected %d[%s])",
+            ts_test_fail(TS_CTX, "sa_addr_u2a -> %d[%s] (expected %d[%s])",
                      rv, sa_error(rv), SA_OK, sa_error(SA_OK));
         if (table[i].rv == SA_OK)
             if (strcmp(cp, table[i].out) != 0)
-                tst_fail(TST, "sa_addr_a2u -> \"%s\" (expected \"%s\")", cp, table[i].out);
+                ts_test_fail(TS_CTX, "sa_addr_a2u -> \"%s\" (expected \"%s\")", cp, table[i].out);
     }
-    tst_check(tst, "sa_addr_destroy");
+    ts_test_check(TS_CTX, "sa_addr_destroy");
     if ((rv = sa_addr_destroy(saa)) != SA_OK)
-        tst_fail(TST, "sa_addr_destroy -> %d[%s] (expected %d[%s])", 
+        ts_test_fail(TS_CTX, "sa_addr_destroy -> %d[%s] (expected %d[%s])", 
                  rv, sa_error(rv), SA_OK, sa_error(SA_OK));
 }
 
-TST_FUNC(test_saa_match)
+TS_TEST(test_saa_match)
 {
     sa_addr_t *saa1;
     sa_addr_t *saa2;
@@ -120,10 +120,10 @@
             continue;
         if ((rv = sa_addr_u2a(saa2, table[i].acl)) != SA_OK)
             continue;
-        tst_check(TST, "sa_addr_match(\"%s\", \"%s\", %d)", 
+        ts_test_check(TS_CTX, "sa_addr_match(\"%s\", \"%s\", %d)", 
                   table[i].in, table[i].acl, table[i].prefixlen);
         if ((rv = sa_addr_match(saa1, saa2, table[i].prefixlen)) != table[i].rv)
-            tst_fail(TST, "sa_addr_match -> %d[%s] (expected %d[%s])",
+            ts_test_fail(TS_CTX, "sa_addr_match -> %d[%s] (expected %d[%s])",
                      rv, sa_error(rv), table[i].rv, sa_error(table[i].rv));
     }
     sa_addr_destroy(saa1);
@@ -132,14 +132,14 @@
 
 int main(int argc, char *argv[])
 {
-    ts_t *ts;
+    ts_suite_t *ts;
     int n;
 
-    ts = ts_new("OSSP SA (Socket Abstraction Library)");
-    ts_test(ts, test_saa_impexp, "socket address abstraction (import/export)");
-    ts_test(ts, test_saa_match,  "socket address abstraction (matching)");
-    n = ts_run(ts);
-    ts_free(ts);
+    ts = ts_suite_new("OSSP SA (Socket Abstraction Library)");
+    ts_suite_test(ts, test_saa_impexp, "socket address abstraction (import/export)");
+    ts_suite_test(ts, test_saa_match,  "socket address abstraction (matching)");
+    n = ts_suite_run(ts);
+    ts_suite_free(ts);
     return n;
 }
 


ossp-pkg/sa/ts.c 1.2 -> 1.3

--- ts.c 2001/10/10 15:11:42     1.2
+++ ts.c 2001/10/31 19:28:49     1.3
@@ -4,7 +4,7 @@
 **  Copyright (c) 2001 The OSSP Project <http://www.ossp.org/>
 **  Copyright (c) 2001 Cable & Wireless Deutschland <http://www.cw.com/de/>
 **
-**  This file is part of OSSP TS, a test suite library which
+**  This file is part of OSSP TS, a small test suite library which
 **  can be found at http://www.ossp.org/pkg/ts/.
 **
 **  Permission to use, copy, modify, and distribute this software for
@@ -95,23 +95,23 @@
 };
 
 /* test suite test */
-struct tst_st {
-    RING_ENTRY(tst_t)  next;
+struct ts_test_st {
+    RING_ENTRY(ts_test_t)  next;
     char              *title;
-    tst_func_t         func;
+    ts_test_cb_t         func;
     const char        *file;
     int                line;
     RING_HEAD(tstc_t)  checks;
 };
 
 /* test suite */
-struct ts_st {
+struct ts_suite_st {
     char              *title;
-    RING_HEAD(tst_t)   tests;
+    RING_HEAD(ts_test_t)   tests;
 };
 
 /* minimal output-independent vprintf(3) variant which supports %{c,s,d,%} only */
-static int ts_mvxprintf(char *buffer, size_t bufsize, const char *format, va_list ap)
+static int ts_suite_mvxprintf(char *buffer, size_t bufsize, const char *format, va_list ap)
 {
     /* sufficient integer buffer: <available-bits> x log_10(2) + safety */
     char ibuf[((sizeof(int)*8)/3)+10]; 
@@ -189,7 +189,7 @@
 }
 
 /* minimal vasprintf(3) variant which supports %{c,s,d} only */
-static char *ts_mvasprintf(const char *format, va_list ap)
+static char *ts_suite_mvasprintf(const char *format, va_list ap)
 {
     char *buffer;
     int n;
@@ -198,70 +198,70 @@
     if (format == NULL || ap == NULL)
         return NULL;
     ap2 = ap;
-    if ((n = ts_mvxprintf(NULL, 0, format, ap)) == -1)
+    if ((n = ts_suite_mvxprintf(NULL, 0, format, ap)) == -1)
         return NULL;
     if ((buffer = (char *)malloc(n+1)) == NULL)
         return NULL;
-    ts_mvxprintf(buffer, n+1, format, ap2);
+    ts_suite_mvxprintf(buffer, n+1, format, ap2);
     return buffer;
 }
 
 /* minimal asprintf(3) variant which supports %{c,s,d} only */
-static char *ts_masprintf(const char *format, ...)
+static char *ts_suite_masprintf(const char *format, ...)
 {
     va_list ap;
     char *cp;
 
     va_start(ap, format);
-    cp = ts_mvasprintf(format, ap);
+    cp = ts_suite_mvasprintf(format, ap);
     va_end(ap);
     return cp;
 }
 
 /* create test suite */
-ts_t *ts_new(const char *fmt, ...)
+ts_suite_t *ts_suite_new(const char *fmt, ...)
 {
-    ts_t *ts;
+    ts_suite_t *ts;
     va_list ap;
 
-    if ((ts = (ts_t *)malloc(sizeof(ts_t))) == NULL)
+    if ((ts = (ts_suite_t *)malloc(sizeof(ts_suite_t))) == NULL)
         return NULL;
     va_start(ap, fmt);
-    ts->title = ts_mvasprintf(fmt, ap);
-    RING_INIT(&ts->tests, tst_t, next);
+    ts->title = ts_suite_mvasprintf(fmt, ap);
+    RING_INIT(&ts->tests, ts_test_t, next);
     va_end(ap);
     return ts;
 }
 
 /* add test case to test suite */
-void ts_test(ts_t *ts, tst_func_t func, const char *fmt, ...)
+void ts_suite_test(ts_suite_t *ts, ts_test_cb_t func, const char *fmt, ...)
 {
-    tst_t *tst;
+    ts_test_t *tst;
     va_list ap;
 
     if (ts == NULL || func == NULL || fmt == NULL)
         return;
-    if ((tst = (tst_t *)malloc(sizeof(tst_t))) == NULL)
+    if ((tst = (ts_test_t *)malloc(sizeof(ts_test_t))) == NULL)
         return;
     RING_ELEM_INIT(tst, next);
     va_start(ap, fmt);
-    tst->title = ts_mvasprintf(fmt, ap);
+    tst->title = ts_suite_mvasprintf(fmt, ap);
     va_end(ap);
     tst->func = func;
     tst->file = NULL;
     tst->line = 0;
     RING_INIT(&tst->checks, tstc_t, next);
-    RING_INSERT_TAIL(&ts->tests, tst, tst_t, next);
+    RING_INSERT_TAIL(&ts->tests, tst, ts_test_t, next);
     return;
 }
 
 /* run test suite */
-int ts_run(ts_t *ts)
+int ts_suite_run(ts_suite_t *ts)
 {
-    tst_t *tst;
+    ts_test_t *tst;
     tstc_t *tstc;
     tstl_t *tstl;
-    int total_tests, total_tests_failed;
+    int total_tests, total_tests_suite_failed;
     int total_checks, total_checks_failed;
     int test_checks, test_checks_failed;
     const char *file;
@@ -273,7 +273,7 @@
 
     /* init total counters */
     total_tests         = 0;
-    total_tests_failed  = 0;
+    total_tests_suite_failed  = 0;
     total_checks        = 0;
     total_checks_failed = 0;
 
@@ -284,8 +284,8 @@
     fflush(stdout);
 
     /* iterate through all test cases */
-    RING_FOREACH(tst, &ts->tests, tst_t, next) {
-        cp = ts_masprintf(" Test: %s ........................................"
+    RING_FOREACH(tst, &ts->tests, ts_test_t, next) {
+        cp = ts_suite_masprintf(" Test: %s ........................................"
                                     "........................................", tst->title);
         cp[60] = '\0';
         fprintf(stdout, "%s", cp);
@@ -339,7 +339,7 @@
         total_tests++;
         if (test_checks_failed > 0) {
             total_checks_failed += test_checks_failed;
-            total_tests_failed++;
+            total_tests_suite_failed++;
         }
     }
 
@@ -347,9 +347,9 @@
     fprintf(stdout, " __________________________________________________________________\n");
     fprintf(stdout, "\n");
     fprintf(stdout, " Test Summary: %d tests (%d ok, %d failed), %d checks (%d ok, %d failed)\n", 
-            total_tests, (total_tests - total_tests_failed), total_tests_failed, 
+            total_tests, (total_tests - total_tests_suite_failed), total_tests_suite_failed, 
             total_checks, (total_checks - total_checks_failed), total_checks_failed); 
-    if (total_tests_failed > 0)
+    if (total_tests_suite_failed > 0)
         fprintf(stdout, " Test Suite: FAILED\n");
     else
         fprintf(stdout, " Test Suite: OK\n");
@@ -360,15 +360,15 @@
 }
 
 /* destroy test suite */
-void ts_free(ts_t *ts)
+void ts_suite_free(ts_suite_t *ts)
 {
-    tst_t *tst;
+    ts_test_t *tst;
     tstc_t *tstc;
     tstl_t *tstl;
 
     if (ts == NULL)
         return;
-    RING_FOREACH(tst, &ts->tests, tst_t, next) {
+    RING_FOREACH(tst, &ts->tests, ts_test_t, next) {
         RING_FOREACH(tstc, &tst->checks, tstc_t, next) {
             RING_FOREACH(tstl, &tstc->logs, tstl_t, next) {
                 free(tstl->text);
@@ -385,7 +385,7 @@
 }
 
 /* annotate test case with file name and line number */
-tst_t *tst_ctx(tst_t *tst, const char *file, int line)
+ts_test_t *ts_test_ctx(ts_test_t *tst, const char *file, int line)
 {
     if (tst != NULL && file != NULL) {
         tst->file = file;
@@ -395,7 +395,7 @@
 }
 
 /* annotate test case with check */
-void tst_check(tst_t *tst, const char *fmt, ...)
+void ts_test_check(ts_test_t *tst, const char *fmt, ...)
 {
     tstc_t *tstc;
     va_list ap;
@@ -406,7 +406,7 @@
         return;
     va_start(ap, fmt);
     RING_ELEM_INIT(tstc, next);
-    tstc->title = ts_mvasprintf(fmt, ap);
+    tstc->title = ts_suite_mvasprintf(fmt, ap);
     tstc->failed = 0;
     tstc->file = tst->file;
     tstc->line = tst->line;
@@ -417,7 +417,7 @@
 }
 
 /* annotate test case with log message and failure */
-void tst_fail(tst_t *tst, const char *fmt, ...)
+void ts_test_fail(ts_test_t *tst, const char *fmt, ...)
 {
     tstc_t *tstc;
     tstl_t *tstl;
@@ -428,7 +428,7 @@
     if ((tstl = (tstl_t *)malloc(sizeof(tstl_t))) == NULL)
         return;
     va_start(ap, fmt);
-    tstl->text = ts_mvasprintf(fmt, ap);
+    tstl->text = ts_suite_mvasprintf(fmt, ap);
     tstl->file = tst->file;
     tstl->line = tst->line;
     RING_ELEM_INIT(tstl, next);
@@ -440,7 +440,7 @@
 }
 
 /* annotate test case with log message only */
-void tst_log(tst_t *tst, const char *fmt, ...)
+void ts_test_log(ts_test_t *tst, const char *fmt, ...)
 {
     tstc_t *tstc;
     tstl_t *tstl;
@@ -451,7 +451,7 @@
     if ((tstl = (tstl_t *)malloc(sizeof(tstl_t))) == NULL)
         return;
     va_start(ap, fmt);
-    tstl->text = ts_mvasprintf(fmt, ap);
+    tstl->text = ts_suite_mvasprintf(fmt, ap);
     tstl->file = tst->file;
     tstl->line = tst->line;
     RING_ELEM_INIT(tstl, next);


ossp-pkg/sa/ts.h 1.1 -> 1.2

--- ts.h 2001/10/10 15:01:56     1.1
+++ ts.h 2001/10/31 19:28:49     1.2
@@ -4,7 +4,7 @@
 **  Copyright (c) 2001 The OSSP Project <http://www.ossp.org/>
 **  Copyright (c) 2001 Cable & Wireless Deutschland <http://www.cw.com/de/>
 **
-**  This file is part of OSSP TS, a test suite library which
+**  This file is part of OSSP TS, a small test suite library which
 **  can be found at http://www.ossp.org/pkg/ts/.
 **
 **  Permission to use, copy, modify, and distribute this software for
@@ -31,32 +31,34 @@
 #ifndef _TS_H_
 #define _TS_H_
 
-struct ts_st;
-typedef struct ts_st ts_t;
-
-struct tst_st;
-typedef struct tst_st tst_t;
-
-typedef void (*tst_func_t)(tst_t *);
-
-#define TST_FUNC(name) \
-    static void name(tst_t *tst)
-
-#define TST_CTX(tst) \
-    tst_ctx(tst, __FILE__, __LINE__)
-
-#define TST \
-    TST_CTX(tst)
-
-ts_t   *ts_new    (const char *fmt, ...);
-void    ts_test   (ts_t *ts, tst_func_t func, const char *fmt, ...);
-int     ts_run    (ts_t *ts);
-void    ts_free   (ts_t *ts);
-
-tst_t  *tst_ctx   (tst_t *tst, const char *file, int line);
-void    tst_check (tst_t *tst, const char *fmt, ...);
-void    tst_fail  (tst_t *tst, const char *fmt, ...);
-void    tst_log   (tst_t *tst, const char *fmt, ...);
+/* test suite object type */
+struct ts_suite_st;
+typedef struct ts_suite_st ts_suite_t;
+
+/* test object type */
+struct ts_test_st;
+typedef struct ts_test_st ts_test_t;
+
+/* test callback function type */
+typedef void (*ts_test_cb_t)(ts_test_t *);
+
+/* test suite operations */
+ts_suite_t *ts_suite_new  (const char *fmt, ...);
+void        ts_suite_test (ts_suite_t *s, ts_test_cb_t func, const char *fmt, ...);
+int         ts_suite_run  (ts_suite_t *s);
+void        ts_suite_free (ts_suite_t *s);
+
+/* test operations */
+ts_test_t  *ts_test_ctx   (ts_test_t *t, const char *file, int line);
+void        ts_test_check (ts_test_t *t, const char *fmt, ...);
+void        ts_test_fail  (ts_test_t *t, const char *fmt, ...);
+void        ts_test_log   (ts_test_t *t, const char *fmt, ...);
+
+/* test suite short-cut macros */
+#define TS_TEST(name) \
+    static void name(ts_test_t *_t)
+#define TS_CTX \
+    ts_test_ctx(_t, __FILE__, __LINE__)
 
 #endif /* _TS_H_ */
 

CVSTrac 2.0.1