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
|
#include "criterion/criterion.h"
#include "criterion/alloc.h"
struct Obj {
int foo;
long bar;
Obj() {}
Obj(int foo, long bar) : foo(foo), bar(bar) {}
};
Test(alloc, object) {
Obj *o = criterion::new_obj<Obj>(42, 314);
cr_assert(not(zero(ptr, o)));
cr_assert(eq(int, o->foo, 42));
cr_assert(eq(long, o->bar, 314));
criterion::delete_obj(o);
}
Test(alloc, array) {
Obj *o = criterion::new_arr<Obj>(3);
cr_assert(not(zero(ptr, o)));
new (&o[0])Obj(1, 2);
new (&o[1])Obj(2, 4);
new (&o[2])Obj(3, 6);
for (int i = 0; i < 3; ++i) {
cr_assert(eq(int, o[i].foo, i + 1));
cr_assert(eq(long, o[i].bar, 2 * (i + 1)));
}
criterion::delete_arr(o);
}
|