From 2fb5a5461097808791b17da04aa8ca74c0e2bc7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Wed, 8 Jan 2014 14:48:36 +0100 Subject: [PATCH] eo2: add tests for method call error msgs --- src/Makefile_Eo.am | 1 + src/tests/eo/suite/eo_suite.c | 1 + src/tests/eo/suite/eo_suite.h | 1 + src/tests/eo/suite/eo_test_call_errors.c | 73 +++++++++++++++++++++++ src/tests/eo/suite/eo_test_class_simple.c | 3 + src/tests/eo/suite/eo_test_class_simple.h | 2 + 6 files changed, 81 insertions(+) create mode 100644 src/tests/eo/suite/eo_test_call_errors.c diff --git a/src/Makefile_Eo.am b/src/Makefile_Eo.am index 0d210be5e6..9b1cb117c2 100644 --- a/src/Makefile_Eo.am +++ b/src/Makefile_Eo.am @@ -96,6 +96,7 @@ 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_call_errors.c \ tests/eo/suite/eo_test_general.c \ tests/eo/suite/eo_test_value.c \ tests/eo/suite/eo_test_init.c diff --git a/src/tests/eo/suite/eo_suite.c b/src/tests/eo/suite/eo_suite.c index 9d040d32cc..db303cfebb 100644 --- a/src/tests/eo/suite/eo_suite.c +++ b/src/tests/eo/suite/eo_suite.c @@ -20,6 +20,7 @@ static const Eo_Test_Case etc[] = { { "Eo init", eo_test_init }, { "Eo general", eo_test_general }, { "Eo class errors", eo_test_class_errors }, + { "Eo call errors", eo_test_call_errors }, { "Eo eina value", eo_test_value }, { NULL, NULL } }; diff --git a/src/tests/eo/suite/eo_suite.h b/src/tests/eo/suite/eo_suite.h index c26db968be..4a3c3b0f21 100644 --- a/src/tests/eo/suite/eo_suite.h +++ b/src/tests/eo/suite/eo_suite.h @@ -6,6 +6,7 @@ void eo_test_init(TCase *tc); void eo_test_general(TCase *tc); void eo_test_class_errors(TCase *tc); +void eo_test_call_errors(TCase *tc); void eo_test_value(TCase *tc); #endif /* _EO_SUITE_H */ diff --git a/src/tests/eo/suite/eo_test_call_errors.c b/src/tests/eo/suite/eo_test_call_errors.c new file mode 100644 index 0000000000..76a60ffc53 --- /dev/null +++ b/src/tests/eo/suite/eo_test_call_errors.c @@ -0,0 +1,73 @@ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include + +#include "Eo.h" +#include "eo_suite.h" +#include "eo_error_msgs.h" +#include "eo_test_class_simple.h" + +static struct log_ctx ctx; + +START_TEST(eo_pure_virtual_fct_call) +{ + eo_init(); + eina_log_print_cb_set(eo_test_print_cb, &ctx); + + Eo *obj = eo2_add(SIMPLE_CLASS, NULL); + fail_if(!obj); + + TEST_EO_ERROR("_eo2_call_resolve", "in %s:%d: you called a pure virtual func '%s' (%d)."); + eo2_do(obj, simple_pure_virtual()); + fail_unless(ctx.did); + + eo_unref(obj); + eina_log_print_cb_set(eina_log_print_cb_stderr, NULL); + eo_shutdown(); +} +END_TEST + +START_TEST(eo_api_not_implemented_call) +{ + eo_init(); + eina_log_print_cb_set(eo_test_print_cb, &ctx); + + Eo *obj = eo2_add(SIMPLE_CLASS, NULL); + fail_if(!obj); + + TEST_EO_ERROR("_eo2_api_op_id_get", "in %s:%d: unable to resolve %s api func %p."); + eo2_do(obj, simple_no_implementation()); + fail_unless(ctx.did); + + eo_unref(obj); + eina_log_print_cb_set(eina_log_print_cb_stderr, NULL); + eo_shutdown(); +} +END_TEST + +START_TEST(eo_op_not_found_in_super) +{ + eo_init(); + eina_log_print_cb_set(eo_test_print_cb, &ctx); + + Eo *obj = eo2_add(SIMPLE_CLASS, NULL); + fail_if(!obj); + + TEST_EO_ERROR("_eo2_call_resolve", "in %s:%d: func '%s' (%d) could not be resolved for class '%s' for super of '%s'."); + eo2_do_super(obj, SIMPLE_CLASS, simple_a_set(10)); + fail_unless(ctx.did); + + eo_unref(obj); + eina_log_print_cb_set(eina_log_print_cb_stderr, NULL); + eo_shutdown(); +} +END_TEST + +void eo_test_call_errors(TCase *tc) +{ + tcase_add_test(tc, eo_pure_virtual_fct_call); + tcase_add_test(tc, eo_api_not_implemented_call); + tcase_add_test(tc, eo_op_not_found_in_super); +} diff --git a/src/tests/eo/suite/eo_test_class_simple.c b/src/tests/eo/suite/eo_test_class_simple.c index d6fc49d233..89cd14e073 100644 --- a/src/tests/eo/suite/eo_test_class_simple.c +++ b/src/tests/eo/suite/eo_test_class_simple.c @@ -73,6 +73,8 @@ EO2_VOID_FUNC_BODYV(simple_a_set, EO2_FUNC_CALL(a), int a); EO2_FUNC_BODY(simple_a_get, int, 0); EO2_FUNC_BODY(simple_a_print, Eina_Bool, EINA_FALSE); EO2_FUNC_BODY(simple_class_hi_print, Eina_Bool, EINA_FALSE); +EO2_VOID_FUNC_BODY(simple_pure_virtual); +EO2_VOID_FUNC_BODY(simple_no_implementation); static Eo2_Op_Description op_descs[] = { EO2_OP_FUNC_OVERRIDE(eo2_dbg_info_get, _dbg_info_get), @@ -81,6 +83,7 @@ static Eo2_Op_Description op_descs[] = { EO2_OP_FUNC(simple_a_print, _a_print, "Print property a"), EO2_OP_CLASS_FUNC(simple_class_hi_print, _class_hi_print, "Print property a"), EO2_OP_FUNC(simple_recursive, _recursive, "Recursive function"), + EO2_OP_FUNC(simple_pure_virtual, NULL, "Pure Virtual function"), EO2_OP_SENTINEL }; diff --git a/src/tests/eo/suite/eo_test_class_simple.h b/src/tests/eo/suite/eo_test_class_simple.h index 03bbebdf43..7d774b761f 100644 --- a/src/tests/eo/suite/eo_test_class_simple.h +++ b/src/tests/eo/suite/eo_test_class_simple.h @@ -11,6 +11,8 @@ EAPI int simple_a_get(void); EAPI Eina_Bool simple_a_print(void); EAPI Eina_Bool simple_class_hi_print(void); EAPI void simple_recursive(int n); +EAPI void simple_pure_virtual(void); +EAPI void simple_no_implementation(void); extern const Eo_Event_Description _EV_A_CHANGED; #define EV_A_CHANGED (&(_EV_A_CHANGED))