Eobj: Added more function override tests.
[profile/ivi/eobj.git] / examples / function_overrides / inherit2.c
1 #include "Eobj.h"
2 #include "simple.h"
3
4 #include "inherit.h"
5 #include "inherit2.h"
6
7 #include "config.h"
8
9 #include "../eunit_tests.h"
10
11 EAPI Eobj_Op INHERIT2_BASE_ID = 0;
12
13 static Eobj_Class *_my_class = NULL;
14
15 static void
16 _a_set(Eobj *obj, void *class_data __UNUSED__, va_list *list)
17 {
18    int a;
19    a = va_arg(*list, int);
20    printf("%s %d\n", eobj_class_name_get(_my_class), a);
21    eobj_do(obj, SIMPLE_A_PRINT());
22    eobj_super_do(obj, SIMPLE_A_SET(a + 1));
23 }
24
25 static void
26 _print(Eobj *obj, void *class_data __UNUSED__, va_list *list __UNUSED__)
27 {
28    printf("Hey\n");
29    fail_if(eobj_super_do(obj, INHERIT2_PRINT()));
30 }
31
32 static void
33 _print2(Eobj *obj __UNUSED__, void *class_data __UNUSED__, va_list *list __UNUSED__)
34 {
35    printf("Hey2\n");
36 }
37
38 static void
39 _class_constructor(Eobj_Class *klass)
40 {
41    const Eobj_Op_Func_Description func_desc[] = {
42         EOBJ_OP_FUNC_DESCRIPTION(SIMPLE_ID(SIMPLE_SUB_ID_A_SET), _a_set),
43         EOBJ_OP_FUNC_DESCRIPTION(INHERIT2_ID(INHERIT2_SUB_ID_PRINT), _print),
44         EOBJ_OP_FUNC_DESCRIPTION(INHERIT2_ID(INHERIT2_SUB_ID_PRINT2), _print2),
45         EOBJ_OP_FUNC_DESCRIPTION_SENTINEL
46    };
47
48    eobj_class_funcs_set(klass, func_desc);
49 }
50
51 const Eobj_Class *
52 inherit2_class_get(void)
53 {
54    if (_my_class) return _my_class;
55
56    static const Eobj_Op_Description op_desc[] = {
57         EOBJ_OP_DESCRIPTION(INHERIT2_SUB_ID_PRINT, "", "Print hey"),
58         EOBJ_OP_DESCRIPTION(INHERIT2_SUB_ID_PRINT2, "", "Print hey2"),
59         EOBJ_OP_DESCRIPTION_SENTINEL
60    };
61
62    static const Eobj_Class_Description class_desc = {
63         "Inherit2",
64         EOBJ_CLASS_TYPE_REGULAR,
65         EOBJ_CLASS_DESCRIPTION_OPS(&INHERIT2_BASE_ID, op_desc, INHERIT2_SUB_ID_LAST),
66         NULL,
67         0,
68         NULL,
69         NULL,
70         _class_constructor,
71         NULL
72    };
73
74    return _my_class = eobj_class_new(&class_desc, INHERIT_CLASS, NULL);
75 }