1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
/* Copyright 2018. Martin Uecker.
* All rights reserved. Use of this source code is governed by
* a BSD-style license which can be found in the LICENSE file.
*
* Authors:
* 2018 Martin Uecker <martin.uecker@med.uni-goettingen.de>
*/
#include "misc/types.h"
#include "utest.h"
typedef struct superclass_s { TYPEID* TYPEID; } superclass;
struct class1 {
INTERFACE(superclass);
};
DEF_TYPEID(class1);
static bool test_cast_down_pos(void)
{
bool ok = true;
PTR_ALLOC(struct class1, cp);
SET_TYPEID(class1, cp);
struct superclass_s* sp = CAST_UP(cp);
if (cp != CAST_MAYBE(class1, sp))
ok = false;
PTR_FREE(cp);
return ok;
}
UT_REGISTER_TEST(test_cast_down_pos);
struct class2 {
INTERFACE(superclass);
};
DEF_TYPEID(class2);
static bool test_cast_down_neg(void)
{
bool ok = true;
PTR_ALLOC(struct class2, cp);
SET_TYPEID(class2, cp);
struct superclass_s* sp = CAST_UP(cp);
if (NULL != CAST_MAYBE(class1, sp))
ok = false;
PTR_FREE(cp);
return ok;
}
UT_REGISTER_TEST(test_cast_down_neg);
|