Eobj: Modified the mixin test to test the mixin mro.

SVN revision: 70320
This commit is contained in:
Tom Hacohen 2012-04-19 08:52:11 +00:00
parent ae800b358e
commit 7713059d6d
8 changed files with 113 additions and 18 deletions

View File

@ -3,6 +3,7 @@ LIST(APPEND MIXIN_CC_SOURCES
simple.c simple.c
mixin.c mixin.c
mixin2.c mixin2.c
mixin3.c
) )
include_directories( include_directories(

View File

@ -2,6 +2,8 @@
#include "simple.h" #include "simple.h"
#include "mixin.h" #include "mixin.h"
#include "../eunit_tests.h"
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
@ -13,8 +15,9 @@ main(int argc, char *argv[])
eobj_do(obj, SIMPLE_A_SET(1), SIMPLE_B_SET(2)); eobj_do(obj, SIMPLE_A_SET(1), SIMPLE_B_SET(2));
int a, b; int a, b, sum = 0;
eobj_do(obj, SIMPLE_A_GET(&a), SIMPLE_B_GET(&b), MIXIN_ADD_AND_PRINT(5)); eobj_do(obj, SIMPLE_A_GET(&a), SIMPLE_B_GET(&b), MIXIN_AB_SUM_GET(&sum));
fail_if(sum != a + b + 2); /* 2 for the two mixins... */
eobj_unref(obj); eobj_unref(obj);
eobj_shutdown(); eobj_shutdown();

View File

@ -9,12 +9,14 @@ EAPI Eobj_Op MIXIN_BASE_ID = 0;
static const Eobj_Class *_my_class = NULL; static const Eobj_Class *_my_class = NULL;
static void static void
_add_and_print_set(Eobj *obj, void *class_data __UNUSED__, va_list *list) _ab_sum_get(Eobj *obj, void *class_data __UNUSED__, va_list *list)
{ {
int a, b, x; int a, b;
eobj_do(obj, SIMPLE_A_GET(&a), SIMPLE_B_GET(&b)); eobj_do(obj, SIMPLE_A_GET(&a), SIMPLE_B_GET(&b));
x = va_arg(*list, const int); int *sum = va_arg(*list, int *);
printf("%s %d\n", __func__, a + b + x); if (sum)
*sum = a + b;
printf("%s %s\n", eobj_class_name_get(_my_class), __func__);
} }
static void static void
@ -33,7 +35,7 @@ static void
_class_constructor(Eobj_Class *klass) _class_constructor(Eobj_Class *klass)
{ {
const Eobj_Op_Func_Description func_desc[] = { const Eobj_Op_Func_Description func_desc[] = {
EOBJ_OP_FUNC(MIXIN_ID(MIXIN_SUB_ID_ADD_AND_SET), _add_and_print_set), EOBJ_OP_FUNC(MIXIN_ID(MIXIN_SUB_ID_AB_SUM_GET), _ab_sum_get),
EOBJ_OP_FUNC_SENTINEL EOBJ_OP_FUNC_SENTINEL
}; };
@ -46,7 +48,7 @@ mixin_class_get(void)
if (_my_class) return _my_class; if (_my_class) return _my_class;
static const Eobj_Op_Description op_desc[] = { static const Eobj_Op_Description op_desc[] = {
EOBJ_OP_DESCRIPTION(MIXIN_SUB_ID_ADD_AND_SET, "i", "Add A + B + param and print it"), EOBJ_OP_DESCRIPTION(MIXIN_SUB_ID_AB_SUM_GET, "i", "Get the sum of a and b."),
EOBJ_OP_DESCRIPTION_SENTINEL EOBJ_OP_DESCRIPTION_SENTINEL
}; };

View File

@ -6,13 +6,13 @@
extern EAPI Eobj_Op MIXIN_BASE_ID; extern EAPI Eobj_Op MIXIN_BASE_ID;
enum { enum {
MIXIN_SUB_ID_ADD_AND_SET, MIXIN_SUB_ID_AB_SUM_GET,
MIXIN_SUB_ID_LAST MIXIN_SUB_ID_LAST
}; };
#define MIXIN_ID(sub_id) (MIXIN_BASE_ID + sub_id) #define MIXIN_ID(sub_id) (MIXIN_BASE_ID + sub_id)
#define MIXIN_ADD_AND_PRINT(x) MIXIN_ID(MIXIN_SUB_ID_ADD_AND_SET), EOBJ_TYPECHECK(int, x) #define MIXIN_AB_SUM_GET(sum) MIXIN_ID(MIXIN_SUB_ID_AB_SUM_GET), EOBJ_TYPECHECK(int *, sum)
#define MIXIN_CLASS mixin_class_get() #define MIXIN_CLASS mixin_class_get()
const Eobj_Class *mixin_class_get(void) EINA_CONST; const Eobj_Class *mixin_class_get(void) EINA_CONST;

View File

@ -5,16 +5,24 @@
#include "config.h" #include "config.h"
#include "../eunit_tests.h"
static const Eobj_Class *_my_class = NULL; static const Eobj_Class *_my_class = NULL;
static void static void
_add_and_print_set(Eobj *obj, void *class_data __UNUSED__, va_list *list) _ab_sum_get(Eobj *obj, void *class_data __UNUSED__, va_list *list)
{ {
int a, b, x; int *sum = va_arg(*list, int *);
eobj_do(obj, SIMPLE_A_GET(&a), SIMPLE_B_GET(&b)); printf("%s %s\n", eobj_class_name_get(_my_class), __func__);
x = va_arg(*list, const int); eobj_do_super(obj, MIXIN_AB_SUM_GET(sum));
printf("%s %d\n", eobj_class_name_get(eobj_class_get(obj)), a + b + x);
eobj_do_super(obj, MIXIN_ADD_AND_PRINT(x)); ++*sum;
{
int _a, _b;
eobj_do(obj, SIMPLE_A_GET(&_a), SIMPLE_B_GET(&_b));
fail_if(*sum != _a + _b + 1);
}
} }
static void static void
@ -33,7 +41,7 @@ static void
_class_constructor(Eobj_Class *klass) _class_constructor(Eobj_Class *klass)
{ {
const Eobj_Op_Func_Description func_desc[] = { const Eobj_Op_Func_Description func_desc[] = {
EOBJ_OP_FUNC(MIXIN_ID(MIXIN_SUB_ID_ADD_AND_SET), _add_and_print_set), EOBJ_OP_FUNC(MIXIN_ID(MIXIN_SUB_ID_AB_SUM_GET), _ab_sum_get),
EOBJ_OP_FUNC_SENTINEL EOBJ_OP_FUNC_SENTINEL
}; };

View File

@ -0,0 +1,71 @@
#include "Eobj.h"
#include "mixin.h"
#include "mixin3.h"
#include "simple.h"
#include "config.h"
#include "../eunit_tests.h"
static const Eobj_Class *_my_class = NULL;
static void
_ab_sum_get(Eobj *obj, void *class_data __UNUSED__, va_list *list)
{
int *sum = va_arg(*list, int *);
printf("%s %s\n", eobj_class_name_get(_my_class), __func__);
eobj_do_super(obj, MIXIN_AB_SUM_GET(sum));
++*sum;
{
int _a, _b;
eobj_do(obj, SIMPLE_A_GET(&_a), SIMPLE_B_GET(&_b));
fail_if(*sum != _a + _b + 2);
}
}
static void
_constructor(Eobj *obj, void *class_data __UNUSED__)
{
eobj_constructor_super(obj);
}
static void
_destructor(Eobj *obj, void *class_data __UNUSED__)
{
eobj_destructor_super(obj);
}
static void
_class_constructor(Eobj_Class *klass)
{
const Eobj_Op_Func_Description func_desc[] = {
EOBJ_OP_FUNC(MIXIN_ID(MIXIN_SUB_ID_AB_SUM_GET), _ab_sum_get),
EOBJ_OP_FUNC_SENTINEL
};
eobj_class_funcs_set(klass, func_desc);
}
const Eobj_Class *
mixin3_class_get(void)
{
if (_my_class) return _my_class;
static const Eobj_Class_Description class_desc = {
"Mixin3",
EOBJ_CLASS_TYPE_MIXIN,
EOBJ_CLASS_DESCRIPTION_OPS(NULL, NULL, 0),
NULL,
0,
_constructor,
_destructor,
_class_constructor,
NULL
};
_my_class = eobj_class_new(&class_desc, MIXIN_CLASS, NULL);
return _my_class;
}

View File

@ -0,0 +1,9 @@
#ifndef MIXIN3_H
#define MIXIN3_H
#include "Eobj.h"
#define MIXIN3_CLASS mixin3_class_get()
const Eobj_Class *mixin3_class_get(void) EINA_CONST;
#endif

View File

@ -1,6 +1,7 @@
#include "Eobj.h" #include "Eobj.h"
#include "mixin.h" #include "mixin.h"
#include "mixin2.h" #include "mixin2.h"
#include "mixin3.h"
#include "simple.h" #include "simple.h"
#include "config.h" #include "config.h"
@ -77,5 +78,5 @@ simple_class_get(void)
NULL NULL
}; };
return _my_class = eobj_class_new(&class_desc, EOBJ_BASE_CLASS, MIXIN2_CLASS, NULL); return _my_class = eobj_class_new(&class_desc, EOBJ_BASE_CLASS, MIXIN3_CLASS, MIXIN2_CLASS, NULL);
} }