Mercurial > gnulib
annotate tests/test-safe-alloc.c @ 40196:e63f5d3edab5
relocatable-prog: Update documentation.
* doc/relocatable-maint.texi (Supporting Relocation): Update to match
the recent changes.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sun, 24 Feb 2019 01:49:15 +0100 |
parents | b06060465f09 |
children |
rev | line source |
---|---|
11174
59bd6cfe1edd
Tests for module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff
changeset
|
1 /* |
59bd6cfe1edd
Tests for module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff
changeset
|
2 * Test the safe-alloc macros |
59bd6cfe1edd
Tests for module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff
changeset
|
3 * |
40057
b06060465f09
maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents:
19484
diff
changeset
|
4 * Copyright (C) 2009-2019 Free Software Foundation, Inc. |
11174
59bd6cfe1edd
Tests for module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff
changeset
|
5 * |
59bd6cfe1edd
Tests for module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff
changeset
|
6 * This library is free software; you can redistribute it and/or |
59bd6cfe1edd
Tests for module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff
changeset
|
7 * modify it under the terms of the GNU Lesser General Public |
59bd6cfe1edd
Tests for module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff
changeset
|
8 * License as published by the Free Software Foundation; either |
18132
66d8c6c5aa71
safe-alloc-tests: fix typo in license header
Dmitry Smirnov <onlyjob@member.fsf.org>
parents:
17848
diff
changeset
|
9 * version 2.1 of the License, or (at your option) any later version. |
11174
59bd6cfe1edd
Tests for module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff
changeset
|
10 * |
59bd6cfe1edd
Tests for module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff
changeset
|
11 * This library is distributed in the hope that it will be useful, |
59bd6cfe1edd
Tests for module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff
changeset
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
59bd6cfe1edd
Tests for module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff
changeset
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
59bd6cfe1edd
Tests for module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff
changeset
|
14 * Lesser General Public License for more details. |
59bd6cfe1edd
Tests for module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff
changeset
|
15 * |
59bd6cfe1edd
Tests for module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff
changeset
|
16 * You should have received a copy of the GNU Lesser General Public |
19190 | 17 * License along with this library; if not, see <https://www.gnu.org/licenses/>. |
11174
59bd6cfe1edd
Tests for module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff
changeset
|
18 * |
59bd6cfe1edd
Tests for module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff
changeset
|
19 * Author: David Lutterkort <lutter@redhat.com> |
59bd6cfe1edd
Tests for module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff
changeset
|
20 */ |
59bd6cfe1edd
Tests for module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff
changeset
|
21 |
59bd6cfe1edd
Tests for module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff
changeset
|
22 #include <config.h> |
59bd6cfe1edd
Tests for module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff
changeset
|
23 |
11204
55b4123a6159
Cosmetic tweaks in the safe-alloc module.
Bruno Haible <bruno@clisp.org>
parents:
11174
diff
changeset
|
24 #include "safe-alloc.h" |
11174
59bd6cfe1edd
Tests for module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff
changeset
|
25 |
12496
a48d3d749ca5
Refactor common macros used in tests.
Bruno Haible <bruno@clisp.org>
parents:
12421
diff
changeset
|
26 #include "macros.h" |
11174
59bd6cfe1edd
Tests for module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff
changeset
|
27 |
11204
55b4123a6159
Cosmetic tweaks in the safe-alloc module.
Bruno Haible <bruno@clisp.org>
parents:
11174
diff
changeset
|
28 int |
55b4123a6159
Cosmetic tweaks in the safe-alloc module.
Bruno Haible <bruno@clisp.org>
parents:
11174
diff
changeset
|
29 main () |
11174
59bd6cfe1edd
Tests for module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff
changeset
|
30 { |
11204
55b4123a6159
Cosmetic tweaks in the safe-alloc module.
Bruno Haible <bruno@clisp.org>
parents:
11174
diff
changeset
|
31 struct tst |
55b4123a6159
Cosmetic tweaks in the safe-alloc module.
Bruno Haible <bruno@clisp.org>
parents:
11174
diff
changeset
|
32 { |
11174
59bd6cfe1edd
Tests for module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff
changeset
|
33 int a; |
59bd6cfe1edd
Tests for module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff
changeset
|
34 int b; |
59bd6cfe1edd
Tests for module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff
changeset
|
35 }; |
59bd6cfe1edd
Tests for module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff
changeset
|
36 |
59bd6cfe1edd
Tests for module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff
changeset
|
37 struct tst *p = NULL; |
59bd6cfe1edd
Tests for module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff
changeset
|
38 int r; |
59bd6cfe1edd
Tests for module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff
changeset
|
39 |
11204
55b4123a6159
Cosmetic tweaks in the safe-alloc module.
Bruno Haible <bruno@clisp.org>
parents:
11174
diff
changeset
|
40 r = ALLOC (p); |
55b4123a6159
Cosmetic tweaks in the safe-alloc module.
Bruno Haible <bruno@clisp.org>
parents:
11174
diff
changeset
|
41 ASSERT (r >= 0); |
11174
59bd6cfe1edd
Tests for module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff
changeset
|
42 |
11204
55b4123a6159
Cosmetic tweaks in the safe-alloc module.
Bruno Haible <bruno@clisp.org>
parents:
11174
diff
changeset
|
43 ASSERT (p->a == 0 && p->b == 0); |
11174
59bd6cfe1edd
Tests for module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff
changeset
|
44 |
59bd6cfe1edd
Tests for module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff
changeset
|
45 p->a = p->b = 42; |
11204
55b4123a6159
Cosmetic tweaks in the safe-alloc module.
Bruno Haible <bruno@clisp.org>
parents:
11174
diff
changeset
|
46 r = REALLOC_N (p, 5); |
11174
59bd6cfe1edd
Tests for module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff
changeset
|
47 |
11204
55b4123a6159
Cosmetic tweaks in the safe-alloc module.
Bruno Haible <bruno@clisp.org>
parents:
11174
diff
changeset
|
48 ASSERT (p[0].a == 42 && p[0].b == 42); |
11174
59bd6cfe1edd
Tests for module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff
changeset
|
49 |
11204
55b4123a6159
Cosmetic tweaks in the safe-alloc module.
Bruno Haible <bruno@clisp.org>
parents:
11174
diff
changeset
|
50 FREE (p); |
55b4123a6159
Cosmetic tweaks in the safe-alloc module.
Bruno Haible <bruno@clisp.org>
parents:
11174
diff
changeset
|
51 ASSERT (p == NULL); |
55b4123a6159
Cosmetic tweaks in the safe-alloc module.
Bruno Haible <bruno@clisp.org>
parents:
11174
diff
changeset
|
52 |
55b4123a6159
Cosmetic tweaks in the safe-alloc module.
Bruno Haible <bruno@clisp.org>
parents:
11174
diff
changeset
|
53 return 0; |
11174
59bd6cfe1edd
Tests for module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff
changeset
|
54 } |