1#include "test/jemalloc_test.h"
2
3TEST_BEGIN(test_same_size)
4{
5	void *p;
6	size_t sz, tsz;
7
8	p = mallocx(42, 0);
9	assert_ptr_not_null(p, "Unexpected mallocx() error");
10	sz = sallocx(p, 0);
11
12	tsz = xallocx(p, sz, 0, 0);
13	assert_zu_eq(tsz, sz, "Unexpected size change: %zu --> %zu", sz, tsz);
14
15	dallocx(p, 0);
16}
17TEST_END
18
19TEST_BEGIN(test_extra_no_move)
20{
21	void *p;
22	size_t sz, tsz;
23
24	p = mallocx(42, 0);
25	assert_ptr_not_null(p, "Unexpected mallocx() error");
26	sz = sallocx(p, 0);
27
28	tsz = xallocx(p, sz, sz-42, 0);
29	assert_zu_eq(tsz, sz, "Unexpected size change: %zu --> %zu", sz, tsz);
30
31	dallocx(p, 0);
32}
33TEST_END
34
35TEST_BEGIN(test_no_move_fail)
36{
37	void *p;
38	size_t sz, tsz;
39
40	p = mallocx(42, 0);
41	assert_ptr_not_null(p, "Unexpected mallocx() error");
42	sz = sallocx(p, 0);
43
44	tsz = xallocx(p, sz + 5, 0, 0);
45	assert_zu_eq(tsz, sz, "Unexpected size change: %zu --> %zu", sz, tsz);
46
47	dallocx(p, 0);
48}
49TEST_END
50
51int
52main(void)
53{
54
55	return (test(
56	    test_same_size,
57	    test_extra_no_move,
58	    test_no_move_fail));
59}
60