eo2: tests: extract mgs checks into eo_error_msgs.c|h
authorJérémy Zurcher <jeremy@asynk.ch>
Wed, 8 Jan 2014 13:10:39 +0000 (14:10 +0100)
committerTom Hacohen <tom@stosb.com>
Thu, 10 Apr 2014 03:20:20 +0000 (04:20 +0100)
src/Makefile_Eo.am
src/tests/eo/suite/eo_error_msgs.c [new file with mode: 0644]
src/tests/eo/suite/eo_error_msgs.h [new file with mode: 0644]
src/tests/eo/suite/eo_test_class_errors.c

index 17d44b9..0d210be 100644 (file)
@@ -93,6 +93,8 @@ tests/eo/suite/eo_test_class_simple.c \
 tests/eo/suite/eo_test_class_simple.h \
 tests/eo/suite/eo_suite.c \
 tests/eo/suite/eo_suite.h \
+tests/eo/suite/eo_error_msgs.h \
+tests/eo/suite/eo_error_msgs.c \
 tests/eo/suite/eo_test_class_errors.c \
 tests/eo/suite/eo_test_general.c \
 tests/eo/suite/eo_test_value.c \
diff --git a/src/tests/eo/suite/eo_error_msgs.c b/src/tests/eo/suite/eo_error_msgs.c
new file mode 100644 (file)
index 0000000..ae5b5d0
--- /dev/null
@@ -0,0 +1,53 @@
+#include "eo_error_msgs.h"
+
+void
+eo_test_print_cb(const Eina_Log_Domain *d, Eina_Log_Level level, const char *file, const char *fnc, int line, const char *fmt, void *data, va_list args EINA_UNUSED)
+{
+   struct log_ctx *myctx = data;
+
+   if (level > _EINA_LOG_MAX)
+      return;
+
+   ck_assert_int_eq(level, myctx->expected_level);
+   if (myctx->msg)
+      ck_assert_str_eq(myctx->msg, fmt);
+   ck_assert_str_eq(myctx->fnc, fnc);
+   myctx->did = EINA_TRUE;
+
+#ifdef SHOW_LOG
+   eina_log_print_cb_stderr(d, level, file, fnc, line, fmt, NULL, args);
+#else
+   (void)d;
+   (void)file;
+   (void)line;
+#endif
+}
+
+void
+eo_test_safety_print_cb(const Eina_Log_Domain *d, Eina_Log_Level level, const char *file, const char *fnc, int line, const char *fmt, void *data, va_list args EINA_UNUSED)
+{
+   struct log_ctx *myctx = data;
+   va_list cp_args;
+   const char *str;
+
+   if (level > _EINA_LOG_MAX)
+     return;
+
+   va_copy(cp_args, args);
+   str = va_arg(cp_args, const char *);
+   va_end(cp_args);
+
+   ck_assert_int_eq(level, myctx->expected_level);
+   ck_assert_str_eq(fmt, "%s");
+   ck_assert_str_eq(myctx->msg, str);
+   ck_assert_str_eq(myctx->fnc, fnc);
+   myctx->did = EINA_TRUE;
+
+#ifdef SHOW_LOG
+   eina_log_print_cb_stderr(d, level, file, fnc, line, fmt, NULL, args);
+#else
+   (void)d;
+   (void)file;
+   (void)line;
+#endif
+}
diff --git a/src/tests/eo/suite/eo_error_msgs.h b/src/tests/eo/suite/eo_error_msgs.h
new file mode 100644 (file)
index 0000000..c3690fd
--- /dev/null
@@ -0,0 +1,30 @@
+#ifndef _EO_ERROR_MSGS_H
+#define _EO_ERROR_MSGS_H
+
+#include "Eo.h"
+#include "eo_suite.h"
+
+/* The Max level to consider when working with the print cb. */
+#define _EINA_LOG_MAX 2
+/* #define SHOW_LOG 1 */
+
+struct log_ctx {
+   const char *msg;
+   const char *fnc;
+   Eina_Bool did;
+   int expected_level;
+};
+
+void
+eo_test_print_cb(const Eina_Log_Domain *d, Eina_Log_Level level, const char *file, const char *fnc, int line, const char *fmt, void *data, va_list args EINA_UNUSED);
+
+void
+eo_test_safety_print_cb(const Eina_Log_Domain *d, Eina_Log_Level level, const char *file, const char *fnc, int line, const char *fmt, void *data, va_list args EINA_UNUSED);
+
+#define TEST_EO_ERROR(fn, _msg)                  \
+  ctx.msg = _msg;                                \
+  ctx.fnc = fn;                                  \
+  ctx.did = EINA_FALSE;                          \
+  ctx.expected_level = EINA_LOG_LEVEL_ERR
+
+#endif /* _EO_ERROR_MSGS_H */
index abc839e..24a07f4 100644 (file)
@@ -6,82 +6,15 @@
 
 #include "Eo.h"
 #include "eo_suite.h"
+#include "eo_error_msgs.h"
 #include "eo_test_class_simple.h"
 
-/* The Max level to consider when working with the print cb. */
-#define _EINA_LOG_MAX 2
-
-struct log_ctx {
-   const char *msg;
-   const char *fnc;
-   Eina_Bool did;
-   int expected_level;
-};
-
 static struct log_ctx ctx;
 
-static void
-_eo_test_print_cb(const Eina_Log_Domain *d, Eina_Log_Level level, const char *file, const char *fnc, int line, const char *fmt, void *data, va_list args EINA_UNUSED)
-{
-   struct log_ctx *myctx = data;
-
-   if (level > _EINA_LOG_MAX)
-      return;
-
-   ck_assert_int_eq(level, myctx->expected_level);
-   if (myctx->msg)
-      ck_assert_str_eq(myctx->msg, fmt);
-   ck_assert_str_eq(myctx->fnc, fnc);
-   myctx->did = EINA_TRUE;
-
-#ifdef SHOW_LOG
-   eina_log_print_cb_stderr(d, level, file, fnc, line, fmt, NULL, args);
-#else
-   (void)d;
-   (void)file;
-   (void)line;
-#endif
-}
-
-static void
-_eo_test_safety_print_cb(const Eina_Log_Domain *d, Eina_Log_Level level, const char *file, const char *fnc, int line, const char *fmt, void *data, va_list args EINA_UNUSED)
-{
-   struct log_ctx *myctx = data;
-   va_list cp_args;
-   const char *str;
-
-   if (level > _EINA_LOG_MAX)
-      return;
-
-   va_copy(cp_args, args);
-   str = va_arg(cp_args, const char *);
-   va_end(cp_args);
-
-   ck_assert_int_eq(level, myctx->expected_level);
-   ck_assert_str_eq(fmt, "%s");
-   ck_assert_str_eq(myctx->msg, str);
-   ck_assert_str_eq(myctx->fnc, fnc);
-   myctx->did = EINA_TRUE;
-
-#ifdef SHOW_LOG
-   eina_log_print_cb_stderr(d, level, file, fnc, line, fmt, NULL, args);
-#else
-   (void)d;
-   (void)file;
-   (void)line;
-#endif
-}
-
-#define TEST_EO_ERROR(fn, _msg)                  \
-  ctx.msg = _msg;                                \
-  ctx.fnc = fn;                                  \
-  ctx.did = EINA_FALSE;                          \
-  ctx.expected_level = EINA_LOG_LEVEL_ERR
-
 START_TEST(eo_inherit_errors)
 {
    eo_init();
-   eina_log_print_cb_set(_eo_test_print_cb, &ctx);
+   eina_log_print_cb_set(eo_test_print_cb, &ctx);
 
    const Eo_Class *klass;
    const Eo_Class *klass_mixin;
@@ -148,7 +81,7 @@ END_TEST
 START_TEST(eo_inconsistent_mro)
 {
    eo_init();
-   eina_log_print_cb_set(_eo_test_print_cb, &ctx);
+   eina_log_print_cb_set(eo_test_print_cb, &ctx);
 
    const Eo_Class *klass;
    const Eo_Class *klass_mixin;
@@ -230,7 +163,7 @@ static void _stub_class_constructor(Eo_Class *klass EINA_UNUSED) {}
 START_TEST(eo_bad_interface)
 {
    eo_init();
-   eina_log_print_cb_set(_eo_test_safety_print_cb, &ctx);
+   eina_log_print_cb_set(eo_test_safety_print_cb, &ctx);
 
    const Eo_Class *klass;
 
@@ -279,7 +212,7 @@ void null_fct (void) {}
 START_TEST(eo_null_api)
 {
    eo_init();
-   eina_log_print_cb_set(_eo_test_print_cb, &ctx);
+   eina_log_print_cb_set(eo_test_print_cb, &ctx);
 
    const Eo_Class *klass;
 
@@ -312,7 +245,7 @@ END_TEST
 START_TEST(eo_wrong_override)
 {
    eo_init();
-   eina_log_print_cb_set(_eo_test_print_cb, &ctx);
+   eina_log_print_cb_set(eo_test_print_cb, &ctx);
 
    const Eo_Class *klass;
 
@@ -345,7 +278,7 @@ END_TEST
 START_TEST(eo_api_redefined)
 {
    eo_init();
-   eina_log_print_cb_set(_eo_test_print_cb, &ctx);
+   eina_log_print_cb_set(eo_test_print_cb, &ctx);
 
    const Eo_Class *klass;
 
@@ -379,7 +312,7 @@ END_TEST
 START_TEST(eo_dich_func_override)
 {
    eo_init();
-   eina_log_print_cb_set(_eo_test_print_cb, &ctx);
+   eina_log_print_cb_set(eo_test_print_cb, &ctx);
 
    const Eo_Class *klass;