From d0b9ac0738414abfc66a0284163bb0f10eab2e69 Mon Sep 17 00:00:00 2001 From: tasn Date: Thu, 12 Apr 2012 11:20:19 +0000 Subject: [PATCH] Eobj: Improved testing a bit. git-svn-id: http://svn.enlightenment.org/svn/e/trunk/PROTO/eobj@70135 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- tests/CMakeLists.txt | 1 + tests/class_simple.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++ tests/class_simple.h | 30 ++++++++++++++++++++++ tests/eobj_test_general.c | 17 +++++++++++-- tests/eobj_test_init.c | 2 ++ 5 files changed, 111 insertions(+), 2 deletions(-) create mode 100644 tests/class_simple.c create mode 100644 tests/class_simple.h diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6080f07..ad920d6 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -4,6 +4,7 @@ if (CHECK_ENABLED) eobj_suite.c eobj_test_init.c eobj_test_general.c + class_simple.c ) add_executable(eobj_suite ${EOBJ_SUITE_CC_SOURCES}) diff --git a/tests/class_simple.c b/tests/class_simple.c new file mode 100644 index 0000000..2bbf052 --- /dev/null +++ b/tests/class_simple.c @@ -0,0 +1,63 @@ +#include "Eobj.h" +#include "class_simple.h" + +EAPI Eobj_Op SIMPLE_BASE_ID = 0; + +static Eobj_Class *_my_class = NULL; + +static void +_a_set(Eobj *obj, Eobj_Op op, va_list *list) +{ + Simple_Public_Data *pd = eobj_data_get(obj, _my_class); + (void) op; + int a; + a = va_arg(*list, int); + printf("%s %d\n", eobj_class_name_get(_my_class), a); + pd->a = a; +} + +static void +_a_print(Eobj *obj, Eobj_Op op, va_list *list) +{ + Simple_Public_Data *pd = eobj_data_get(obj, _my_class); + (void) op; + (void) list; + printf("Print %s %d\n", eobj_class_name_get(_my_class), pd->a); +} + +static void +_class_constructor(Eobj_Class *klass) +{ + const Eobj_Op_Func_Description func_desc[] = { + EOBJ_OP_FUNC_DESCRIPTION(SIMPLE_ID(SIMPLE_SUB_ID_A_SET), _a_set), + EOBJ_OP_FUNC_DESCRIPTION(SIMPLE_ID(SIMPLE_SUB_ID_A_PRINT), _a_print), + EOBJ_OP_FUNC_DESCRIPTION_SENTINEL + }; + + eobj_class_funcs_set(klass, func_desc); +} + +const Eobj_Class * +simple_class_get(void) +{ + if (_my_class) return _my_class; + + static const Eobj_Op_Description op_desc[] = { + EOBJ_OP_DESCRIPTION(SIMPLE_SUB_ID_A_SET, "i", "Set property A"), + EOBJ_OP_DESCRIPTION_SENTINEL + }; + + static const Eobj_Class_Description class_desc = { + "Simple", + EOBJ_CLASS_TYPE_REGULAR, + EOBJ_CLASS_DESCRIPTION_OPS(&SIMPLE_BASE_ID, op_desc, SIMPLE_SUB_ID_LAST), + NULL, + sizeof(Simple_Public_Data), + NULL, + NULL, + _class_constructor, + NULL + }; + + return _my_class = eobj_class_new(&class_desc, EOBJ_CLASS_BASE, NULL); +} diff --git a/tests/class_simple.h b/tests/class_simple.h new file mode 100644 index 0000000..c6b4611 --- /dev/null +++ b/tests/class_simple.h @@ -0,0 +1,30 @@ +#ifndef SIMPLE_H +#define SIMPLE_H + +#include "Eobj.h" + +extern EAPI Eobj_Op SIMPLE_BASE_ID; + +enum { + SIMPLE_SUB_ID_A_SET, + SIMPLE_SUB_ID_A_PRINT, + SIMPLE_SUB_ID_LAST +}; + +typedef struct +{ + int a; +} Simple_Public_Data; + +#define SIMPLE_ID(sub_id) (SIMPLE_BASE_ID + sub_id) + +#define SIMPLE_A_SET(a) SIMPLE_ID(SIMPLE_SUB_ID_A_SET), EOBJ_TYPECHECK(int, a) +#define SIMPLE_A_PRINT() SIMPLE_ID(SIMPLE_SUB_ID_A_PRINT) + +extern const Eobj_Event_Description _SIG_A_CHANGED; +#define SIG_A_CHANGED (&(_SIG_A_CHANGED)) + +#define SIMPLE_CLASS simple_class_get() +const Eobj_Class *simple_class_get(void) EINA_CONST; + +#endif diff --git a/tests/eobj_test_general.c b/tests/eobj_test_general.c index 8e55c61..418e184 100644 --- a/tests/eobj_test_general.c +++ b/tests/eobj_test_general.c @@ -7,12 +7,25 @@ #include "eobj_suite.h" #include "Eobj.h" -START_TEST(eobj_simple) +#include "class_simple.h" + +START_TEST(eobj_op_errors) { + eobj_init(); + Eobj *obj = eobj_add(SIMPLE_CLASS, NULL); + + /* Out of bounds op for a legal class. */ + fail_if(eobj_do(obj, 0x00010111)); + + /* Ilegal class. */ + fail_if(eobj_do(obj, 0x0F010111)); + + eobj_unref(obj); + eobj_shutdown(); } END_TEST void eobj_test_general(TCase *tc) { - tcase_add_test(tc, eobj_simple); + tcase_add_test(tc, eobj_op_errors); } diff --git a/tests/eobj_test_init.c b/tests/eobj_test_init.c index 52b8883..e6f3307 100644 --- a/tests/eobj_test_init.c +++ b/tests/eobj_test_init.c @@ -10,6 +10,8 @@ START_TEST(eobj_simple) { fail_if(!eobj_init()); /* one init by test suite */ + fail_if(eobj_init() != 1); + fail_if(eobj_shutdown() != 1); fail_if(!eobj_shutdown()); } END_TEST -- 2.7.4