diff --git a/legacy/eobj/examples/composite_objects/main.c b/legacy/eobj/examples/composite_objects/main.c index ce61260952..531bfe50a7 100644 --- a/legacy/eobj/examples/composite_objects/main.c +++ b/legacy/eobj/examples/composite_objects/main.c @@ -2,6 +2,8 @@ #include "simple.h" #include "comp.h" +#include "../eunit_tests.h" + static int cb_called = EINA_FALSE; static Eina_Bool @@ -29,18 +31,11 @@ main(int argc, char *argv[]) int a; eobj_do(obj, SIMPLE_A_SET(1)); - if (!cb_called) - { - printf("Error! %d\n", __LINE__); - return 1; - } + fail_if(!cb_called); eobj_do(obj, SIMPLE_A_GET(&a)); - if (a != 1) - { - printf("Error! %d\n", __LINE__); - return 1; - } + fail_if(a != 1); + eobj_unref(obj); eobj_shutdown(); diff --git a/legacy/eobj/examples/constructors/main.c b/legacy/eobj/examples/constructors/main.c index a684d01031..70a9ecb6ff 100644 --- a/legacy/eobj/examples/constructors/main.c +++ b/legacy/eobj/examples/constructors/main.c @@ -5,6 +5,8 @@ #include "simple4.h" #include "mixin.h" +#include "../eunit_tests.h" + int my_init_count = 0; int @@ -17,11 +19,7 @@ main(int argc, char *argv[]) Eobj *obj = eobj_add(SIMPLE_CLASS, NULL); - if (my_init_count != 2) - { - printf("Error! my_init_count == %d\n", my_init_count); - ret = 1; - } + fail_if(my_init_count != 2); eobj_do(obj, SIMPLE_A_SET(1), SIMPLE_B_SET(2)); @@ -30,42 +28,22 @@ main(int argc, char *argv[]) eobj_unref(obj); - if (my_init_count != 0) - { - printf("Error! my_init_count == %d\n", my_init_count); - ret = 1; - } + fail_if(my_init_count != 0); obj = eobj_add(SIMPLE2_CLASS, NULL); - if (obj) - { - printf("Error! obj is supposed to be NULL.\n"); - ret = 1; - } + fail_if(obj); obj = eobj_add(SIMPLE3_CLASS, NULL); - if (obj) - { - printf("Error! obj is supposed to be NULL.\n"); - ret = 1; - } + fail_if(obj); my_init_count = 0; obj = eobj_add(SIMPLE4_CLASS, NULL); - if (my_init_count != 2) - { - printf("Error! my_init_count == %d\n", my_init_count); - ret = 1; - } + fail_if(my_init_count != 2); eobj_unref(obj); - if (my_init_count != 0) - { - printf("Error! my_init_count == %d\n", my_init_count); - ret = 1; - } + fail_if(my_init_count != 0); eobj_shutdown(); return ret; diff --git a/legacy/eobj/examples/eunit_tests.h b/legacy/eobj/examples/eunit_tests.h new file mode 100644 index 0000000000..000d18c015 --- /dev/null +++ b/legacy/eobj/examples/eunit_tests.h @@ -0,0 +1,17 @@ +#ifndef _EUNIT_TESTS_H +#define _EUNIT_TESTS_H + +#define _EUNIT_EXIT_CODE 1 + +#define fail_if(x) \ + do { \ + if (x) \ + { \ + fprintf(stderr, "%s:%d - Failure '%s' is TRUE.", \ + __FILE__, __LINE__, # x); \ + exit(_EUNIT_EXIT_CODE); \ + } \ + } while (0) + +#endif + diff --git a/legacy/eobj/examples/function_overrides/main.c b/legacy/eobj/examples/function_overrides/main.c index 9715a9b2a1..b026a576ce 100644 --- a/legacy/eobj/examples/function_overrides/main.c +++ b/legacy/eobj/examples/function_overrides/main.c @@ -4,6 +4,8 @@ #include "inherit2.h" #include "inherit3.h" +#include "../eunit_tests.h" + int main(int argc, char *argv[]) { @@ -15,20 +17,15 @@ main(int argc, char *argv[]) eobj_do(obj, SIMPLE_A_SET(1)); Simple_Public_Data *pd = eobj_data_get(obj, SIMPLE_CLASS); - if (pd->a != 2) - { - return 1; - } + fail_if(pd->a != 2); + eobj_unref(obj); obj = eobj_add(INHERIT3_CLASS, NULL); eobj_do(obj, SIMPLE_A_SET(1)); pd = eobj_data_get(obj, SIMPLE_CLASS); - if (pd->a != 3) - { - return 1; - } + fail_if(pd->a != 3); eobj_unref(obj); diff --git a/legacy/eobj/examples/signals/main.c b/legacy/eobj/examples/signals/main.c index 867e1ce354..ce9dbdb135 100644 --- a/legacy/eobj/examples/signals/main.c +++ b/legacy/eobj/examples/signals/main.c @@ -1,6 +1,10 @@ #include "Eobj.h" #include "simple.h" +#include "../eunit_tests.h" + +static int cb_count = 0; + static Eina_Bool _a_changed_cb(void *data, Eobj *obj, const Eobj_Event_Description *desc, void *event_info) { @@ -10,6 +14,8 @@ _a_changed_cb(void *data, Eobj *obj, const Eobj_Event_Description *desc, void *e int new_a = *((int *) event_info); printf("%s event_info:'%d' data:'%s'\n", __func__, new_a, (const char *) data); + cb_count++; + /* Fix data is NULL, stop. */ return !!data; } @@ -33,6 +39,8 @@ main(int argc, char *argv[]) eobj_do(obj, SIMPLE_A_SET(1)); + fail_if(cb_count != 3); + eobj_event_callback_del_full(obj, SIG_A_CHANGED, _a_changed_cb, NULL); eobj_unref(obj);