2015-09-19 18:08:37 +02:00
|
|
|
#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);
|
2016-09-05 21:32:57 +02:00
|
|
|
|
2015-09-19 18:08:37 +02:00
|
|
|
cr_assert_not_null(o);
|
|
|
|
|
|
|
|
cr_assert_eq(o->foo, 42);
|
|
|
|
cr_assert_eq(o->bar, 314);
|
|
|
|
|
|
|
|
criterion::delete_obj(o);
|
|
|
|
}
|
|
|
|
|
|
|
|
Test(alloc, array) {
|
|
|
|
Obj *o = criterion::new_arr<Obj>(3);
|
2016-09-05 21:32:57 +02:00
|
|
|
|
2015-09-19 18:08:37 +02:00
|
|
|
cr_assert_not_null(o);
|
|
|
|
|
2016-09-05 21:32:57 +02:00
|
|
|
new (&o[0])Obj(1, 2);
|
|
|
|
new (&o[1])Obj(2, 4);
|
|
|
|
new (&o[2])Obj(3, 6);
|
2015-09-19 18:08:37 +02:00
|
|
|
|
|
|
|
for (int i = 0; i < 3; ++i) {
|
|
|
|
cr_assert_eq(o[i].foo, i + 1);
|
|
|
|
cr_assert_eq(o[i].bar, 2 * (i + 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
criterion::delete_arr(o);
|
|
|
|
}
|