]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-alloc-util.c
udev-builtin-blkid: Use _cleanup_blkid_free_probe_ to free probe (#6108)
[thirdparty/systemd.git] / src / test / test-alloc-util.c
1 /***
2 This file is part of systemd.
3
4 Copyright 2010 Lennart Poettering
5
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
10
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
18 ***/
19
20 #include "alloc-util.h"
21 #include "macro.h"
22 #include "util.h"
23
24 static void test_alloca(void) {
25 static const uint8_t zero[997] = { };
26 char *t;
27
28 t = alloca_align(17, 512);
29 assert_se(!((uintptr_t)t & 0xff));
30 memzero(t, 17);
31
32 t = alloca0_align(997, 1024);
33 assert_se(!((uintptr_t)t & 0x1ff));
34 assert_se(!memcmp(t, zero, 997));
35 }
36
37 static void test_memdup_multiply(void) {
38 int org[] = {1, 2, 3};
39 int *dup;
40
41 dup = (int*)memdup_multiply(org, sizeof(int), 3);
42
43 assert_se(dup);
44 assert_se(dup[0] == 1);
45 assert_se(dup[1] == 2);
46 assert_se(dup[2] == 3);
47 free(dup);
48 }
49
50 int main(int argc, char *argv[]) {
51 test_alloca();
52 test_memdup_multiply();
53
54 return 0;
55 }