Commit d10a9683 authored by Philipp Schafft's avatar Philipp Schafft

Feature: Added tests for REFOBJECT_GET_TYPENAME() and REFOBJECT_IS_VALID()

parent c0ff8611
......@@ -38,16 +38,23 @@
*/
#ifdef HAVE_TYPE_ATTRIBUTE_TRANSPARENT_UNION
#define REFOBJECT_NULL ((refobject_t)(refobject_base_t*)NULL)
#define REFOBJECT_GET_BASE(x) (((refobject_t)(x)).refobject_base)
#define REFOBJECT_IS_NULL(x) (((refobject_t)(x)).refobject_base == NULL)
#define REFOBJECT_TO_TYPE(x,y) ((y)(((refobject_t)(x)).refobject_base))
#else
#define REFOBJECT_NULL NULL
#define REFOBJECT_GET_BASE(x) ((refobject_base_t)(x))
#define REFOBJECT_IS_NULL(x) ((x) == NULL)
#define REFOBJECT_TO_TYPE(x,y) ((y)(x))
#endif
#define REFOBJECT_FROM_TYPE(x) ((refobject_t)(refobject_base_t*)(x))
#define REFOBJECT_GET_TYPE(x) (REFOBJECT_GET_BASE((x)) == NULL ? NULL : REFOBJECT_GET_BASE((x))->type)
#define REFOBJECT_GET_TYPENAME(x) (REFOBJECT_GET_TYPE((x)) == NULL ? NULL : REFOBJECT_GET_TYPE((x))->type_name)
#define REFOBJECT_IS_VALID(x,type) (!REFOBJECT_IS_NULL((x)) && REFOBJECT_GET_TYPE((x)) == &(refobject_type__ ## type))
#define REFOBJECT_CONTROL_VERSION 0
#define REFOBJECT_FORWARD_TYPE(type) extern const refobject_type_t refobject_type__ ## type;
#define REFOBJECT_DEFINE_TYPE(type, extra) const refobject_type_t refobject_type__ ## type = { \
......
......@@ -39,6 +39,44 @@ static void test_create_ref_unref(void)
ctest_test("un-referenced (2 of 2)", refobject_unref(a) == 0);
}
static void test_typename(void)
{
refobject_base_t *a;
const char *typename;
a = refobject_new__new(refobject_base_t, NULL, NULL, REFOBJECT_NULL);
ctest_test("refobject created", !REFOBJECT_IS_NULL(a));
typename = REFOBJECT_GET_TYPENAME(a);
ctest_test("got typename", typename != NULL);
ctest_test("typename matches", strcmp(typename, "refobject_base_t") == 0);
ctest_test("un-referenced", refobject_unref(a) == 0);
}
static void test_valid(void)
{
refobject_base_t *a;
typedef struct {
refobject_base_t __base;
} ctest_test_type_t;
REFOBJECT_DEFINE_PRIVATE_TYPE(ctest_test_type_t,
REFOBJECT_DEFINE_TYPE_FREE(NULL)
);
ctest_test("NULL is not valid", !REFOBJECT_IS_VALID(REFOBJECT_NULL, refobject_base_t));
a = refobject_new__new(refobject_base_t, NULL, NULL, REFOBJECT_NULL);
ctest_test("refobject created", !REFOBJECT_IS_NULL(a));
ctest_test("is valid", REFOBJECT_IS_VALID(a, refobject_base_t));
ctest_test("is valid as diffrent type", !REFOBJECT_IS_VALID(a, ctest_test_type_t));
ctest_test("un-referenced", refobject_unref(a) == 0);
}
static void test_sizes(void)
{
refobject_t a;
......@@ -202,6 +240,9 @@ int main (void)
test_create_ref_unref();
test_typename();
test_valid();
test_sizes();
test_name();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment