diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2014-01-08 14:10:39 +0100 |
---|---|---|
committer | Tom Hacohen <tom@stosb.com> | 2014-04-10 04:20:20 +0100 |
commit | d23b9ffd236e68a08d9d7c2a119f0a3da2a4b116 (patch) | |
tree | 70d2d9a6140fa00c069b81d7cfb23c2b1b30f203 /src/tests/eo | |
parent | a0d761cfa9bd182449b2c4cf483c07e71821f1cb (diff) | |
download | efl-d23b9ffd236e68a08d9d7c2a119f0a3da2a4b116.tar.gz |
eo2: tests: extract mgs checks into eo_error_msgs.c|h
Diffstat (limited to 'src/tests/eo')
-rw-r--r-- | src/tests/eo/suite/eo_error_msgs.c | 53 | ||||
-rw-r--r-- | src/tests/eo/suite/eo_error_msgs.h | 30 | ||||
-rw-r--r-- | src/tests/eo/suite/eo_test_class_errors.c | 83 |
3 files changed, 91 insertions, 75 deletions
diff --git a/src/tests/eo/suite/eo_error_msgs.c b/src/tests/eo/suite/eo_error_msgs.c new file mode 100644 index 0000000000..ae5b5d0ddc --- /dev/null +++ b/src/tests/eo/suite/eo_error_msgs.c @@ -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 index 0000000000..c3690fd345 --- /dev/null +++ b/src/tests/eo/suite/eo_error_msgs.h @@ -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 */ diff --git a/src/tests/eo/suite/eo_test_class_errors.c b/src/tests/eo/suite/eo_test_class_errors.c index abc839eacd..24a07f47e9 100644 --- a/src/tests/eo/suite/eo_test_class_errors.c +++ b/src/tests/eo/suite/eo_test_class_errors.c @@ -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; |