[go: up one dir, main page]

File: alloc.cc

package info (click to toggle)
criterion 2.3.3git1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 3,832 kB
  • sloc: ansic: 17,852; cpp: 795; python: 72; sh: 27; makefile: 23
file content (38 lines) | stat: -rw-r--r-- 732 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
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);
}