summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Hacohen <tom@stosb.com>2015-04-17 14:31:19 +0100
committerTom Hacohen <tom@stosb.com>2015-05-06 17:56:05 +0100
commit6cb22bae35a8e621e0857fc2738657ff068478f8 (patch)
treeb6a9d95a7907803517ab3883fd51546464e3facc /src
parent875bc1514604dca87f19270694bcede4b2434dc2 (diff)
Eo: Add eo_do_part.
This is a convenience macro to be used by the common pattern of getting a part and then immediately calling functions on it. For example, without this macro, you'd have to write code like: Eo *part; eo_do(obj, part = efl_part_name_get("partname")); eo_do(part, a_set(7)); while using the helper function trims it to: eo_do_part(obj, efl_part_name_get("partname"), a_set(7)); @feature
Diffstat (limited to 'src')
-rw-r--r--src/lib/eo/Eo.h7
-rw-r--r--src/tests/eo/suite/eo_test_class_simple.c10
-rw-r--r--src/tests/eo/suite/eo_test_class_simple.h1
-rw-r--r--src/tests/eo/suite/eo_test_general.c34
4 files changed, 52 insertions, 0 deletions
diff --git a/src/lib/eo/Eo.h b/src/lib/eo/Eo.h
index c1ff090869..0825f90531 100644
--- a/src/lib/eo/Eo.h
+++ b/src/lib/eo/Eo.h
@@ -605,6 +605,13 @@ EAPI Eo * _eo_add_end(void);
605 605
606#define eo_do_super_ret(eoid, clsid, ret_tmp, func) _eo_do_common_ret(eoid, clsid, EINA_TRUE, ret_tmp, func) 606#define eo_do_super_ret(eoid, clsid, ret_tmp, func) _eo_do_common_ret(eoid, clsid, EINA_TRUE, ret_tmp, func)
607 607
608#define eo_do_part(eoid, part_func, ...) \
609 do { \
610 Eo *__eo_part = eoid; \
611 eo_do(eoid, __eo_part = part_func); \
612 eo_do(__eo_part, __VA_ARGS__); \
613 } while (0)
614
608/*****************************************************************************/ 615/*****************************************************************************/
609 616
610/** 617/**
diff --git a/src/tests/eo/suite/eo_test_class_simple.c b/src/tests/eo/suite/eo_test_class_simple.c
index cbefee7d1d..4bc3904acb 100644
--- a/src/tests/eo/suite/eo_test_class_simple.c
+++ b/src/tests/eo/suite/eo_test_class_simple.c
@@ -45,6 +45,15 @@ _class_hi_print(Eo_Class *klass, void *data EINA_UNUSED)
45 return EINA_TRUE; 45 return EINA_TRUE;
46} 46}
47 47
48EO_FUNC_BODYV(simple_part_get, Eo *, NULL, EO_FUNC_CALL(name), const char *name);
49
50static Eo *
51_part_get(Eo *obj, void *class_data EINA_UNUSED, const char *name EINA_UNUSED)
52{
53 /* A normal part get will do something saner, we just create objects. */
54 return eo_add(SIMPLE_CLASS, obj);
55}
56
48EO_VOID_FUNC_BODYV(simple_recursive, EO_FUNC_CALL(n), int n); 57EO_VOID_FUNC_BODYV(simple_recursive, EO_FUNC_CALL(n), int n);
49 58
50static void 59static void
@@ -83,6 +92,7 @@ static Eo_Op_Description op_descs[] = {
83 EO_OP_FUNC(simple_a_print, _a_print, "Print property a"), 92 EO_OP_FUNC(simple_a_print, _a_print, "Print property a"),
84 EO_OP_CLASS_FUNC(simple_class_hi_print, _class_hi_print, "Print property a"), 93 EO_OP_CLASS_FUNC(simple_class_hi_print, _class_hi_print, "Print property a"),
85 EO_OP_FUNC(simple_recursive, _recursive, "Recursive function"), 94 EO_OP_FUNC(simple_recursive, _recursive, "Recursive function"),
95 EO_OP_FUNC(simple_part_get, _part_get, "Part getter"),
86 EO_OP_FUNC(simple_pure_virtual, NULL, "Pure Virtual function"), 96 EO_OP_FUNC(simple_pure_virtual, NULL, "Pure Virtual function"),
87 EO_OP_SENTINEL 97 EO_OP_SENTINEL
88}; 98};
diff --git a/src/tests/eo/suite/eo_test_class_simple.h b/src/tests/eo/suite/eo_test_class_simple.h
index 7d774b761f..2fce591372 100644
--- a/src/tests/eo/suite/eo_test_class_simple.h
+++ b/src/tests/eo/suite/eo_test_class_simple.h
@@ -13,6 +13,7 @@ EAPI Eina_Bool simple_class_hi_print(void);
13EAPI void simple_recursive(int n); 13EAPI void simple_recursive(int n);
14EAPI void simple_pure_virtual(void); 14EAPI void simple_pure_virtual(void);
15EAPI void simple_no_implementation(void); 15EAPI void simple_no_implementation(void);
16EAPI Eo *simple_part_get(const char *name);
16 17
17extern const Eo_Event_Description _EV_A_CHANGED; 18extern const Eo_Event_Description _EV_A_CHANGED;
18#define EV_A_CHANGED (&(_EV_A_CHANGED)) 19#define EV_A_CHANGED (&(_EV_A_CHANGED))
diff --git a/src/tests/eo/suite/eo_test_general.c b/src/tests/eo/suite/eo_test_general.c
index 684a05c94d..b0dc77a3e9 100644
--- a/src/tests/eo/suite/eo_test_general.c
+++ b/src/tests/eo/suite/eo_test_general.c
@@ -939,6 +939,39 @@ START_TEST(eo_add_failures)
939} 939}
940END_TEST 940END_TEST
941 941
942START_TEST(eo_parts)
943{
944 int a = 0;
945
946 eo_init();
947
948 Eo *obj = eo_add(SIMPLE_CLASS, NULL);
949
950 eo_do(obj, simple_a_set(3), a = simple_a_get());
951 ck_assert_int_eq(a, 3);
952
953 eo_do_part(obj, simple_part_get("test"),
954 simple_a_set(7),
955 a = simple_a_get()
956 );
957 ck_assert_int_eq(a, 7);
958
959 eo_do(obj, simple_a_set(3), a = simple_a_get());
960 ck_assert_int_eq(a, 3);
961
962 /* Faking a call, just asserting NULL as the part to check default values. */
963 eo_do_part(obj, NULL,
964 simple_a_set(7),
965 a = simple_a_get()
966 );
967 ck_assert_int_eq(a, 0);
968
969 eo_del(obj);
970
971 eo_shutdown();
972}
973END_TEST
974
942void eo_test_general(TCase *tc) 975void eo_test_general(TCase *tc)
943{ 976{
944 tcase_add_test(tc, eo_simple); 977 tcase_add_test(tc, eo_simple);
@@ -956,4 +989,5 @@ void eo_test_general(TCase *tc)
956 tcase_add_test(tc, eo_add_do_and_custom); 989 tcase_add_test(tc, eo_add_do_and_custom);
957 tcase_add_test(tc, eo_pointers_indirection); 990 tcase_add_test(tc, eo_pointers_indirection);
958 tcase_add_test(tc, eo_add_failures); 991 tcase_add_test(tc, eo_add_failures);
992 tcase_add_test(tc, eo_parts);
959} 993}