summaryrefslogtreecommitdiff
path: root/src/tests/eo
diff options
context:
space:
mode:
authorMarcel Hollerbach <mail@marcel-hollerbach.de>2019-02-05 15:40:41 +0100
committerMarcel Hollerbach <mail@marcel-hollerbach.de>2019-02-07 14:43:25 +0100
commit0f32bb90476703f81fd08800eda0a0d89321f80f (patch)
tree97f71bd6fedc72e0609e0e807527de0da4a54072 /src/tests/eo
parent0709bdea6f94149b6b319461edd27b7a0035552d (diff)
eo: here comes reflection API
this adds support in eo to generate a reflection API. To get the actaul reflection to the klass, the API efl_class_reflection_table_set needs to be called, the table in the end can be generated by eolian. Reflection API is inherited by the extended class. This means, if you have two reflection tables, first, the most upperst is called, then the next lower one is called. For now this API accepts NULL setter or getter, and will ignore them silently when they are called. fix T7681 Differential Revision: https://phab.enlightenment.org/D7879
Diffstat (limited to 'src/tests/eo')
-rw-r--r--src/tests/eo/suite/eo_suite.c1
-rw-r--r--src/tests/eo/suite/eo_suite.h1
-rw-r--r--src/tests/eo/suite/eo_test_class_simple.c28
-rw-r--r--src/tests/eo/suite/eo_test_reflection.c66
-rw-r--r--src/tests/eo/suite/meson.build3
5 files changed, 96 insertions, 3 deletions
diff --git a/src/tests/eo/suite/eo_suite.c b/src/tests/eo/suite/eo_suite.c
index 57b7c613f3..fe8e419e0f 100644
--- a/src/tests/eo/suite/eo_suite.c
+++ b/src/tests/eo/suite/eo_suite.c
@@ -20,6 +20,7 @@ static const Efl_Test_Case etc[] = {
20 { "Eo threaded eo calls", eo_test_threaded_calls }, 20 { "Eo threaded eo calls", eo_test_threaded_calls },
21 { "Eo event calls", eo_test_event}, 21 { "Eo event calls", eo_test_event},
22 { "Eo lifecycle", eo_test_lifecycle}, 22 { "Eo lifecycle", eo_test_lifecycle},
23 { "Eo Reflection", eo_test_reflection},
23 { NULL, NULL } 24 { NULL, NULL }
24}; 25};
25 26
diff --git a/src/tests/eo/suite/eo_suite.h b/src/tests/eo/suite/eo_suite.h
index 700325c465..84da2054f8 100644
--- a/src/tests/eo/suite/eo_suite.h
+++ b/src/tests/eo/suite/eo_suite.h
@@ -12,4 +12,5 @@ void eo_test_value(TCase *tc);
12void eo_test_threaded_calls(TCase *tc); 12void eo_test_threaded_calls(TCase *tc);
13void eo_test_event(TCase *tc); 13void eo_test_event(TCase *tc);
14void eo_test_lifecycle(TCase *tc); 14void eo_test_lifecycle(TCase *tc);
15void eo_test_reflection(TCase *tc);
15#endif /* _EO_SUITE_H */ 16#endif /* _EO_SUITE_H */
diff --git a/src/tests/eo/suite/eo_test_class_simple.c b/src/tests/eo/suite/eo_test_class_simple.c
index dfba73f669..8d82b1eb11 100644
--- a/src/tests/eo/suite/eo_test_class_simple.c
+++ b/src/tests/eo/suite/eo_test_class_simple.c
@@ -23,6 +23,16 @@ _a_set(Eo *obj EINA_UNUSED, void *class_data, int a)
23 efl_event_callback_legacy_call(obj, EV_A_CHANGED, &pd->a); 23 efl_event_callback_legacy_call(obj, EV_A_CHANGED, &pd->a);
24} 24}
25 25
26static void
27_a_set_reflect(Eo *obj, Eina_Value value)
28{
29 int a;
30
31 eina_value_int_convert(&value, &a);
32 simple_a_set(obj, a);
33 eina_value_flush(&value);
34}
35
26static int 36static int
27_a_get(Eo *obj EINA_UNUSED, void *class_data) 37_a_get(Eo *obj EINA_UNUSED, void *class_data)
28{ 38{
@@ -31,6 +41,14 @@ _a_get(Eo *obj EINA_UNUSED, void *class_data)
31 return pd->a; 41 return pd->a;
32} 42}
33 43
44static Eina_Value
45_a_get_reflect(Eo *obj)
46{
47 int a = simple_a_get(obj);
48
49 return eina_value_int_init(a);
50}
51
34static Eina_Bool 52static Eina_Bool
35_a_print(Eo *obj EINA_UNUSED, void *class_data) 53_a_print(Eo *obj EINA_UNUSED, void *class_data)
36{ 54{
@@ -103,8 +121,14 @@ _class_initializer(Efl_Class *klass)
103 EFL_OPS_DEFINE(cops, 121 EFL_OPS_DEFINE(cops,
104 EFL_OBJECT_OP_FUNC(simple_class_hi_print, _class_hi_print), 122 EFL_OBJECT_OP_FUNC(simple_class_hi_print, _class_hi_print),
105 ); 123 );
106 124 static const Efl_Object_Property_Reflection reflection_table[] = {
107 return efl_class_functions_set(klass, &ops, &cops, NULL); 125 {"simple_a", _a_set_reflect, _a_get_reflect},
126 };
127 static const Efl_Object_Property_Reflection_Ops ref_ops = {
128 reflection_table, EINA_C_ARRAY_LENGTH(reflection_table)
129 };
130
131 return efl_class_functions_set(klass, &ops, &cops, &ref_ops);
108} 132}
109 133
110static const Efl_Class_Description class_desc = { 134static const Efl_Class_Description class_desc = {
diff --git a/src/tests/eo/suite/eo_test_reflection.c b/src/tests/eo/suite/eo_test_reflection.c
new file mode 100644
index 0000000000..ae1e11b214
--- /dev/null
+++ b/src/tests/eo/suite/eo_test_reflection.c
@@ -0,0 +1,66 @@
1#ifdef HAVE_CONFIG_H
2# include "config.h"
3#endif
4
5#include <stdio.h>
6
7#include <Eo.h>
8
9#include "eo_suite.h"
10#include "eo_test_class_simple.h"
11
12
13EFL_START_TEST(eo_test_reflection_invalid)
14{
15 Eina_Value numb_val = eina_value_int_init(1337);
16 Eo *simple = efl_new(SIMPLE_CLASS);
17
18 simple_a_set(simple, 22);
19 efl_property_reflection_set(simple, "simple_a_asdf", numb_val);
20 fail_if(efl_property_reflection_get(simple, "simple_a_invalid").type != EINA_VALUE_EMPTY.type);
21}
22EFL_END_TEST
23
24EFL_START_TEST(eo_test_reflection_inherited)
25{
26 const int numb = 42;
27 int number_ref;
28 Eina_Value numb_val = eina_value_int_init(numb);
29 Eo *simple = efl_new(SIMPLE3_CLASS);
30
31 simple_a_set(simple, 22);
32 efl_property_reflection_set(simple, "simple_a", numb_val);
33 ck_assert_int_eq(simple_a_get(simple), numb);
34
35 simple_a_set(simple, 22);
36 Eina_Value res = efl_property_reflection_get(simple, "simple_a");
37 eina_value_int_convert(&res, &number_ref);
38 ck_assert_int_eq(number_ref, 22);
39
40}
41EFL_END_TEST
42
43EFL_START_TEST(eo_test_reflection_simple)
44{
45 const int numb = 42;
46 int number_ref;
47 Eina_Value numb_val = eina_value_int_init(numb);
48 Eo *simple = efl_new(SIMPLE_CLASS);
49
50 simple_a_set(simple, 22);
51 efl_property_reflection_set(simple, "simple_a", numb_val);
52 ck_assert_int_eq(simple_a_get(simple), numb);
53
54 simple_a_set(simple, 22);
55 Eina_Value res = efl_property_reflection_get(simple, "simple_a");
56 eina_value_int_convert(&res, &number_ref);
57 ck_assert_int_eq(number_ref, 22);
58}
59EFL_END_TEST
60
61void eo_test_reflection(TCase *tc)
62{
63 tcase_add_test(tc, eo_test_reflection_simple);
64 tcase_add_test(tc, eo_test_reflection_inherited);
65 tcase_add_test(tc, eo_test_reflection_invalid);
66}
diff --git a/src/tests/eo/suite/meson.build b/src/tests/eo/suite/meson.build
index 6e7f4ba6f7..39f73787e7 100644
--- a/src/tests/eo/suite/meson.build
+++ b/src/tests/eo/suite/meson.build
@@ -17,7 +17,8 @@ eo_suite_src = [
17 'eo_test_event.c', 17 'eo_test_event.c',
18 'eo_test_threaded_calls.c', 18 'eo_test_threaded_calls.c',
19 'eo_test_init.c', 19 'eo_test_init.c',
20 'eo_test_lifecycle.c' 20 'eo_test_lifecycle.c',
21 'eo_test_reflection.c'
21] 22]
22 23
23eo_suite = executable('eo_suite', 24eo_suite = executable('eo_suite',