Eobj: Enforce some interface restrictions.

SVN revision: 70330
This commit is contained in:
Tom Hacohen 2012-04-19 11:30:10 +00:00
parent 5d72c686c7
commit bfe38419bd
2 changed files with 70 additions and 4 deletions

View File

@ -685,7 +685,7 @@ eobj_class_new(const Eobj_Class_Description *desc, const Eobj_Class *parent, ...
{ \
if (!x) \
{ \
ERR("%s must not be NULL! Aborting.", #x); \
ERR("'%s' must not be False! Aborting.", #x); \
return NULL; \
} \
} \
@ -694,6 +694,16 @@ eobj_class_new(const Eobj_Class_Description *desc, const Eobj_Class *parent, ...
_CLS_NEW_CHECK(desc);
_CLS_NEW_CHECK(desc->name);
/* Check restrictions on Interface types. */
if (desc->type == EOBJ_CLASS_TYPE_INTERFACE)
{
_CLS_NEW_CHECK(!desc->constructor);
_CLS_NEW_CHECK(!desc->destructor);
_CLS_NEW_CHECK(!desc->class_constructor);
_CLS_NEW_CHECK(!desc->class_destructor);
_CLS_NEW_CHECK(!desc->data_size);
}
klass = calloc(1, sizeof(Eobj_Class));
klass->parent = parent;

View File

@ -1,6 +1,4 @@
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "config.h"
#include <stdio.h>
@ -238,9 +236,67 @@ START_TEST(eobj_inconsistent_mro)
}
END_TEST
static void _stub_constructor(Eobj *obj __UNUSED__, void *data __UNUSED__) {}
static void _stub_class_constructor(Eobj_Class *klass __UNUSED__) {}
START_TEST(eobj_bad_interface)
{
eobj_init();
const Eobj_Class *klass;
static Eobj_Class_Description class_desc = {
"Interface",
EOBJ_CLASS_TYPE_INTERFACE,
EOBJ_CLASS_DESCRIPTION_OPS(NULL, NULL, 0),
NULL,
10,
NULL,
NULL,
NULL,
NULL
};
klass = eobj_class_new(&class_desc, NULL, NULL);
fail_if(klass);
class_desc.data_size = 0;
class_desc.constructor = _stub_constructor;
klass = eobj_class_new(&class_desc, NULL, NULL);
fail_if(klass);
class_desc.constructor = NULL;
class_desc.destructor = _stub_constructor;
klass = eobj_class_new(&class_desc, NULL, NULL);
fail_if(klass);
class_desc.destructor = NULL;
class_desc.class_constructor = _stub_class_constructor;
klass = eobj_class_new(&class_desc, NULL, NULL);
fail_if(klass);
class_desc.class_constructor = NULL;
class_desc.class_destructor = _stub_class_constructor;
klass = eobj_class_new(&class_desc, NULL, NULL);
fail_if(klass);
class_desc.class_destructor = NULL;
klass = eobj_class_new(&class_desc, NULL, NULL);
fail_if(!klass);
eobj_shutdown();
}
END_TEST
void eobj_test_class_errors(TCase *tc)
{
tcase_add_test(tc, eobj_incomplete_desc);
tcase_add_test(tc, eobj_inherit_errors);
tcase_add_test(tc, eobj_inconsistent_mro);
tcase_add_test(tc, eobj_bad_interface);
}