qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acon...@apache.org
Subject [2/2] qpid-proton git commit: PROTON-1470: C test_tools added test macros for checking pn_condition
Date Tue, 02 May 2017 15:44:48 GMT
PROTON-1470: C test_tools added test macros for checking pn_condition


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/0cf7ea63
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/0cf7ea63
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/0cf7ea63

Branch: refs/heads/master
Commit: 0cf7ea634842d00b4609401aa8a2aa5e187a678a
Parents: 1991745
Author: Alan Conway <aconway@redhat.com>
Authored: Tue May 2 11:18:48 2017 -0400
Committer: Alan Conway <aconway@redhat.com>
Committed: Tue May 2 11:28:14 2017 -0400

----------------------------------------------------------------------
 proton-c/src/tests/proactor.c   | 29 ++++++------
 proton-c/src/tests/test_tools.h | 90 +++++++++++++++++++++---------------
 2 files changed, 66 insertions(+), 53 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/0cf7ea63/proton-c/src/tests/proactor.c
----------------------------------------------------------------------
diff --git a/proton-c/src/tests/proactor.c b/proton-c/src/tests/proactor.c
index b70bf61..01332cb 100644
--- a/proton-c/src/tests/proactor.c
+++ b/proton-c/src/tests/proactor.c
@@ -347,16 +347,14 @@ static void test_abort(test_t *t) {
   pn_proactor_connect(client, pn_connection(), port.host_port);
   /* server transport closes */
   TEST_ETYPE_EQUAL(t, PN_TRANSPORT_CLOSED, PROACTOR_TEST_RUN(pts));
-  if (TEST_CHECK(t, last_condition) && TEST_CHECK(t, pn_condition_is_set(last_condition)))
{
-    TEST_STR_EQUAL(t, "amqp:connection:framing-error", pn_condition_get_name(last_condition));
-    TEST_STR_IN(t, "abort", pn_condition_get_description(last_condition));
-  }
+  TEST_COND_NAME(t, "amqp:connection:framing-error",last_condition);
+  TEST_COND_DESC(t, "abort", last_condition);
+
   /* client transport closes */
   TEST_ETYPE_EQUAL(t, PN_TRANSPORT_CLOSED, PROACTOR_TEST_RUN(pts)); /* client */
-  if (TEST_CHECK(t, last_condition) && TEST_CHECK(t, pn_condition_is_set(last_condition)))
{
-    TEST_STR_EQUAL(t, "amqp:connection:framing-error", pn_condition_get_name(last_condition));
-    TEST_STR_IN(t, "abort", pn_condition_get_description(last_condition));
-  }
+  TEST_COND_NAME(t, "amqp:connection:framing-error", last_condition);
+  TEST_COND_DESC(t, "abort", last_condition);
+
   pn_listener_close(l);
   PROACTOR_TEST_DRAIN(pts);
 
@@ -415,9 +413,8 @@ static void test_refuse(test_t *t) {
 
   /* client transport closes */
   TEST_ETYPE_EQUAL(t, PN_TRANSPORT_CLOSED, PROACTOR_TEST_RUN(pts)); /* client */
-  if (TEST_CHECK(t, last_condition) && TEST_CHECK(t, pn_condition_is_set(last_condition)))
{
-    TEST_STR_EQUAL(t, "amqp:connection:framing-error", pn_condition_get_name(last_condition));
-  }
+  TEST_COND_NAME(t, "amqp:connection:framing-error", last_condition);
+
   pn_listener_close(l.listener);
   PROACTOR_TEST_DRAIN(pts);
 
@@ -551,15 +548,14 @@ static void test_ipv4_ipv6(test_t *t) {
 #define EXPECT_CONNECT(TP, HOST) do {                                   \
     pn_proactor_connect(client, pn_connection(), test_port_use_host(&(TP), (HOST)));
\
     TEST_ETYPE_EQUAL(t, PN_TRANSPORT_CLOSED, PROACTOR_TEST_RUN(pts));   \
-    TEST_CHECK(t, !pn_condition_is_set(last_condition));                 \
+    TEST_COND_EMPTY(t, last_condition);                                 \
     PROACTOR_TEST_DRAIN(pts);                                           \
   } while(0)
 
 #define EXPECT_FAIL(TP, HOST) do {                                      \
     pn_proactor_connect(client, pn_connection(), test_port_use_host(&(TP), (HOST)));
\
     TEST_ETYPE_EQUAL(t, PN_TRANSPORT_CLOSED, PROACTOR_TEST_RUN(pts));   \
-    if (TEST_CHECK(t, pn_condition_is_set(last_condition)))             \
-      TEST_STR_IN(t, "refused", pn_condition_get_description(last_condition)); \
+    TEST_COND_DESC(t, "refused", last_condition);                       \
     PROACTOR_TEST_DRAIN(pts);                                           \
   } while(0)
 
@@ -684,9 +680,10 @@ static void test_ssl(test_t *t) {
   pn_proactor_connect(client, c, port.host_port);
   /* Open ok at both ends */
   TEST_ETYPE_EQUAL(t, PN_CONNECTION_REMOTE_OPEN, PROACTOR_TEST_RUN(pts));
-  TEST_CHECK(t, !pn_condition_is_set(last_condition));
+  TEST_COND_EMPTY(t, last_condition);
   TEST_ETYPE_EQUAL(t, PN_CONNECTION_REMOTE_OPEN, PROACTOR_TEST_RUN(pts));
-  TEST_CHECK(t, !pn_condition_is_set(last_condition));
+  TEST_COND_EMPTY(t, last_condition);
+
   TEST_ETYPE_EQUAL(t, PN_TRANSPORT_CLOSED, PROACTOR_TEST_RUN(pts));
   TEST_ETYPE_EQUAL(t, PN_TRANSPORT_CLOSED, PROACTOR_TEST_RUN(pts));
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/0cf7ea63/proton-c/src/tests/test_tools.h
----------------------------------------------------------------------
diff --git a/proton-c/src/tests/test_tools.h b/proton-c/src/tests/test_tools.h
index c5c8364..0663fc4 100644
--- a/proton-c/src/tests/test_tools.h
+++ b/proton-c/src/tests/test_tools.h
@@ -42,7 +42,7 @@ typedef struct test_t {
 */
 
 void test_vlogf_(test_t *t, const char *prefix, const char* expr,
-                        const char* file, int line, const char *fmt, va_list ap)
+                 const char* file, int line, const char *fmt, va_list ap)
 {
   fprintf(stderr, "%s:%d", file, line);
   if (prefix && *prefix) fprintf(stderr, ": %s", prefix);
@@ -57,7 +57,7 @@ void test_vlogf_(test_t *t, const char *prefix, const char* expr,
 }
 
 void test_errorf_(test_t *t, const char* expr,
-                         const char* file, int line, const char *fmt, ...) {
+                  const char* file, int line, const char *fmt, ...) {
   ++t->errors;
   va_list ap;
   va_start(ap, fmt);
@@ -66,7 +66,7 @@ void test_errorf_(test_t *t, const char* expr,
 }
 
 bool test_check_(test_t *t, bool expr, const char *sexpr,
-                        const char *file, int line, const char* fmt, ...) {
+                 const char *file, int line, const char* fmt, ...) {
   if (!expr) {
     ++t->errors;
     va_list ap;
@@ -78,7 +78,7 @@ bool test_check_(test_t *t, bool expr, const char *sexpr,
 }
 
 void test_logf_(test_t *t, const char *prefix, const char* expr,
-                       const char* file, int line, const char *fmt, ...) {
+                const char* file, int line, const char *fmt, ...) {
   va_list ap;
   va_start(ap, fmt);
   test_vlogf_(t, prefix, expr, file, line, fmt, ap);
@@ -95,35 +95,39 @@ void assert_fail_(const char* expr, const char* file, int line, const
char *fmt,
 }
 
 /* Unconditional assert (does not depend on NDEBUG) for tests. */
-#define TEST_ASSERT(expr) \
+#define TEST_ASSERT(expr)                                               \
   ((expr) ?  (void)0 : assert_fail_(#expr, __FILE__, __LINE__, NULL))
 
 /* Unconditional assert with printf-style message (does not depend on NDEBUG) for tests.
*/
-#define TEST_ASSERTF(expr, ...) \
+#define TEST_ASSERTF(expr, ...)                                         \
   ((expr) ?  (void)0 : assert_fail_(#expr, __FILE__, __LINE__, __VA_ARGS__))
 
 /* Like TEST_ASSERT but includes  errno string for err */
 /* TODO aconway 2017-02-16: not thread safe, replace with safe strerror_r or similar */
-#define TEST_ASSERT_ERRNO(expr, err) \
+#define TEST_ASSERT_ERRNO(expr, err)            \
   TEST_ASSERTF((expr), "%s", strerror(err))
 
 
 /* Print a message but don't mark the test as having an error */
-#define TEST_LOGF(TEST, ...) \
+#define TEST_LOGF(TEST, ...)                                            \
   test_logf_((TEST), "info", NULL, __FILE__, __LINE__, __VA_ARGS__)
 
 /* Print an error with printf-style message, increment TEST->errors */
-#define TEST_ERRORF(TEST, ...) \
+#define TEST_ERRORF(TEST, ...)                                  \
   test_errorf_((TEST), NULL, __FILE__, __LINE__, __VA_ARGS__)
 
-/* If EXPR is false, print and record an error for t  */
-#define TEST_CHECKF(TEST, EXPR, ...) \
+/* If EXPR is false, print and record an error for t including #EXPR  */
+#define TEST_CHECKF(TEST, EXPR, ...)                                    \
   test_check_((TEST), (EXPR), #EXPR, __FILE__, __LINE__, __VA_ARGS__)
 
 /* If EXPR is false, print and record an error for t including EXPR  */
-#define TEST_CHECK(TEST, EXPR) \
+#define TEST_CHECK(TEST, EXPR)                                  \
   test_check_((TEST), (EXPR), #EXPR, __FILE__, __LINE__, "")
 
+/* If EXPR is false, print and record an error for t NOT including #EXPR  */
+#define TEST_CHECKNF(TEST, EXPR, ...)                                   \
+  test_check_((TEST), (EXPR), NULL, __FILE__, __LINE__, __VA_ARGS__)
+
 bool test_etype_equal_(test_t *t, pn_event_type_t want, pn_event_type_t got, const char *file,
int line) {
   return test_check_(t, want == got, NULL, file, line, "want %s got %s",
                      pn_event_type_name(want),
@@ -153,18 +157,18 @@ bool test_etypes_equal_(test_t *t, const pn_event_type_t* want, size_t
want_len,
   return want_len == got_len;
 }
 
-#define TEST_STR_EQUAL(TEST, WANT, GOT) \
+#define TEST_STR_EQUAL(TEST, WANT, GOT)                                 \
   test_check_((TEST), !strcmp((WANT), (GOT)), NULL, __FILE__, __LINE__, "want '%s', got '%s'",
(WANT), (GOT))
 
 
-#define TEST_STR_IN(TEST, WANT, GOT) \
+#define TEST_STR_IN(TEST, WANT, GOT)                                    \
   test_check_((TEST), strstr((GOT), (WANT)), NULL, __FILE__, __LINE__, "'%s' not in '%s'",
(WANT), (GOT))
 
-#define TEST_ETYPE_EQUAL(TEST, WANT, GOT) \
+#define TEST_ETYPE_EQUAL(TEST, WANT, GOT)                       \
   test_etype_equal_((TEST), (WANT), (GOT), __FILE__, __LINE__)
 
 /* Compare arrays of pn_event_type_t */
-#define TEST_ETYPES_EQUAL(TEST, WANT, WLEN, GOT, GLEN)                       \
+#define TEST_ETYPES_EQUAL(TEST, WANT, WLEN, GOT, GLEN)                  \
   test_etypes_equal_((TEST), (WANT), (WLEN), (GOT), (GLEN), __FILE__, __LINE__)
 
 pn_event_t *test_event_type_(test_t *t, pn_event_type_t want, pn_event_t *got, const char
*file, int line) {
@@ -182,35 +186,47 @@ pn_event_t *test_event_type_(test_t *t, pn_event_type_t want, pn_event_t
*got, c
   return got;
 }
 
-#define TEST_EVENT_TYPE(TEST, WANT, GOT) \
+#define TEST_EVENT_TYPE(TEST, WANT, GOT)                        \
   test_event_type_((TEST), (WANT), (GOT), __FILE__, __LINE__)
 
+#define TEST_COND_EMPTY(TEST, C)                                        \
+  TEST_CHECKNF((TEST), (!(C) || !pn_condition_is_set(C)), "Unexpected condition - %s:%s",
\
+              pn_condition_get_name(C), pn_condition_get_description(C))
+
+#define TEST_COND_DESC(TEST, WANT, C)                                   \
+  (TEST_CHECKNF(t, pn_condition_is_set((C)), "No condition, expected :%s", (WANT)) ? \
+   TEST_STR_IN(t, (WANT), pn_condition_get_description(C)) : 0);
+
+#define TEST_COND_NAME(TEST, WANT, C)                                   \
+  (TEST_CHECKNF(t, pn_condition_is_set((C)), "No condition, expected %s:", (WANT)) ? \
+   TEST_STR_EQUAL(t, (WANT), pn_condition_get_name(C)) : 0);
+
 /* T is name of a test_t variable, EXPR is the test expression (which should update T)
    FAILED is incremented if the test has errors
 */
-#define RUN_TEST(FAILED, T, EXPR) do {                          \
-    fprintf(stderr, "TEST: %s\n", #EXPR);                                \
-    fflush(stdout);                                             \
-    test_t T = { #EXPR, 0 };                                    \
-    (EXPR);                                                     \
-    if (T.errors) {                                             \
-      fprintf(stderr, "FAIL: %s (%d errors)\n", #EXPR, T.errors);        \
-      ++(FAILED);                                               \
-    }                                                           \
+#define RUN_TEST(FAILED, T, EXPR) do {                                  \
+    fprintf(stderr, "TEST: %s\n", #EXPR);                               \
+    fflush(stdout);                                                     \
+    test_t T = { #EXPR, 0 };                                            \
+    (EXPR);                                                             \
+    if (T.errors) {                                                     \
+      fprintf(stderr, "FAIL: %s (%d errors)\n", #EXPR, T.errors);       \
+      ++(FAILED);                                                       \
+    }                                                                   \
   } while(0)
 
 /* Like RUN_TEST but only if one of the argv strings is found in the test EXPR */
-#define RUN_ARGV_TEST(FAILED, T, EXPR) do {                             \
-    if (argc == 1) {                                                    \
-      RUN_TEST(FAILED, T, EXPR);                                        \
-    } else {                                                            \
-      for (int i = 1; i < argc; ++i) {                                  \
-        if (strstr(#EXPR, argv[i])) {                                   \
-          RUN_TEST(FAILED, T, EXPR);                                    \
-          break;                                                        \
-        }                                                               \
-      }                                                                 \
-    }                                                                   \
+#define RUN_ARGV_TEST(FAILED, T, EXPR) do {     \
+    if (argc == 1) {                            \
+      RUN_TEST(FAILED, T, EXPR);                \
+    } else {                                    \
+      for (int i = 1; i < argc; ++i) {          \
+        if (strstr(#EXPR, argv[i])) {           \
+          RUN_TEST(FAILED, T, EXPR);            \
+          break;                                \
+        }                                       \
+      }                                         \
+    }                                           \
   } while(0)
 
 /* Some very simple platform-secifics to acquire an unused socket */


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message