File: util.h

package info (click to toggle)
interface99 1.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 324 kB
  • sloc: ansic: 951; sh: 48; makefile: 6
file content (34 lines) | stat: -rw-r--r-- 2,390 bytes parent folder | download | duplicates (2)
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
#ifndef INTERFACE99_TESTS_UTIL_H
#define INTERFACE99_TESTS_UTIL_H

#define ENSURE_EXPR_TYPE(expr, type)                                                               \
    do {                                                                                           \
        type x = (expr);                                                                           \
        (void)x;                                                                                   \
    } while (0)

#define ENSURE_VTABLE_FIELD_TYPE(vtable_type, field, type)                                         \
    do {                                                                                           \
        ENSURE_FIELD_TYPE(vtable_type, field, type);                                               \
        ENSURE_FIELD_TYPE(struct vtable_type, field, type);                                        \
    } while (0)
#define ENSURE_FIELD_TYPE(outer_type, field, type) ENSURE_EXPR_TYPE(((outer_type){0}).field, type)

#define ENSURE_DYN_OBJ_TYPE(iface)                                                                 \
    do {                                                                                           \
        ENSURE_FIELD_TYPE(iface, self, void *);                                                    \
        ENSURE_FIELD_TYPE(iface, vptr, const iface##VTable *);                                     \
                                                                                                   \
        ENSURE_FIELD_TYPE(struct iface, self, void *);                                             \
        ENSURE_FIELD_TYPE(struct iface, vptr, const iface##VTable *);                              \
    } while (0)

#define ENSURE_DYN_OBJ(implementer, iface)                                                         \
    do {                                                                                           \
        implementer x = {0};                                                                       \
        iface x_dyn = DYN(implementer, iface, &x);                                                 \
        assert(x_dyn.self == &x);                                                                  \
        assert(x_dyn.vptr == &VTABLE(implementer, iface));                                         \
    } while (0)

#endif // INTERFACE99_TESTS_UTIL_H