2
* Copyright (C) 2010 Red Hat, Inc.
4
* This work is provided "as is"; redistribution and modification
5
* in whole or in part, in any medium, physical or electronic is
6
* permitted without restriction.
8
* This work is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
* In no event shall the authors or contributors be liable for any
13
* direct, indirect, incidental, special, exemplary, or consequential
14
* damages (including, but not limited to, procurement of substitute
15
* goods or services; loss of use, data, or profits; or business
16
* interruption) however caused and on any theory of liability, whether
17
* in contract, strict liability, or tort (including negligence or
18
* otherwise) arising in any way out of the use of this software, even
19
* if advised of the possibility of such damage.
28
gsize a = G_MAXSIZE / 10 + 10;
33
#define CHECK_PASS(P) p = (P); g_assert (p == NULL);
34
#define CHECK_FAIL(P) p = (P); g_assert (p != NULL);
36
CHECK_PASS (g_try_malloc_n (a, a));
37
CHECK_PASS (g_try_malloc_n (a, b));
38
CHECK_PASS (g_try_malloc_n (b, a));
39
CHECK_FAIL (g_try_malloc_n (b, b));
41
CHECK_PASS (g_try_malloc0_n (a, a));
42
CHECK_PASS (g_try_malloc0_n (a, b));
43
CHECK_PASS (g_try_malloc0_n (b, a));
44
CHECK_FAIL (g_try_malloc0_n (b, b));
47
CHECK_PASS (g_try_realloc_n (q, a, a));
48
CHECK_PASS (g_try_realloc_n (q, a, b));
49
CHECK_PASS (g_try_realloc_n (q, b, a));
50
CHECK_FAIL (g_try_realloc_n (q, b, b));
53
CHECK_PASS (g_try_new (X, a));
54
CHECK_FAIL (g_try_new (X, b));
56
CHECK_PASS (g_try_new0 (X, a));
57
CHECK_FAIL (g_try_new0 (X, b));
60
CHECK_PASS (g_try_renew (X, q, a));
61
CHECK_FAIL (g_try_renew (X, q, b));
67
#define CHECK_FAIL(P) if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) { p = (P); exit (0); } g_test_trap_assert_failed();
68
#define CHECK_PASS(P) if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) { p = (P); exit (0); } g_test_trap_assert_passed();
70
CHECK_FAIL (g_malloc_n (a, a));
71
CHECK_FAIL (g_malloc_n (a, b));
72
CHECK_FAIL (g_malloc_n (b, a));
73
CHECK_PASS (g_malloc_n (b, b));
75
CHECK_FAIL (g_malloc0_n (a, a));
76
CHECK_FAIL (g_malloc0_n (a, b));
77
CHECK_FAIL (g_malloc0_n (b, a));
78
CHECK_PASS (g_malloc0_n (b, b));
81
CHECK_FAIL (g_realloc_n (q, a, a));
82
CHECK_FAIL (g_realloc_n (q, a, b));
83
CHECK_FAIL (g_realloc_n (q, b, a));
84
CHECK_PASS (g_realloc_n (q, b, b));
87
CHECK_FAIL (g_new (X, a));
88
CHECK_PASS (g_new (X, b));
90
CHECK_FAIL (g_new0 (X, a));
91
CHECK_PASS (g_new0 (X, b));
94
CHECK_FAIL (g_renew (X, q, a));
95
CHECK_PASS (g_renew (X, q, b));
103
g_test_init (&argc, &argv, NULL);
105
g_test_add_func ("/mem/overflow", mem_overflow);