aboutsummaryrefslogtreecommitdiff
path: root/src/util/test_common_allocation.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/test_common_allocation.c')
-rw-r--r--src/util/test_common_allocation.c118
1 files changed, 59 insertions, 59 deletions
diff --git a/src/util/test_common_allocation.c b/src/util/test_common_allocation.c
index fcc453d6b..e67360044 100644
--- a/src/util/test_common_allocation.c
+++ b/src/util/test_common_allocation.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file util/test_common_allocation.c 22 * @file util/test_common_allocation.c
@@ -27,7 +27,7 @@
27 27
28 28
29static int 29static int
30check () 30check()
31{ 31{
32#define MAX_TESTVAL 1024 32#define MAX_TESTVAL 1024
33 char *ptrs[MAX_TESTVAL]; 33 char *ptrs[MAX_TESTVAL];
@@ -41,112 +41,112 @@ check ()
41 /* GNUNET_malloc/GNUNET_free test */ 41 /* GNUNET_malloc/GNUNET_free test */
42 k = 352; /* random start value */ 42 k = 352; /* random start value */
43 for (i = 1; i < MAX_TESTVAL; i++) 43 for (i = 1; i < MAX_TESTVAL; i++)
44 { 44 {
45 ptrs[i] = GNUNET_malloc (i); 45 ptrs[i] = GNUNET_malloc(i);
46 for (j = 0; j < i; j++) 46 for (j = 0; j < i; j++)
47 ptrs[i][j] = k++; 47 ptrs[i][j] = k++;
48 } 48 }
49 49
50 for (i = MAX_TESTVAL - 1; i >= 1; i--) 50 for (i = MAX_TESTVAL - 1; i >= 1; i--)
51 { 51 {
52 for (j = i - 1; j >= 0; j--) 52 for (j = i - 1; j >= 0; j--)
53 if (ptrs[i][j] != (char) --k) 53 if (ptrs[i][j] != (char)--k)
54 return 1; 54 return 1;
55 GNUNET_free (ptrs[i]); 55 GNUNET_free(ptrs[i]);
56 } 56 }
57 57
58 /* GNUNET_free_non_null test */ 58 /* GNUNET_free_non_null test */
59 GNUNET_free_non_null (NULL); 59 GNUNET_free_non_null(NULL);
60 GNUNET_free_non_null (GNUNET_malloc (4)); 60 GNUNET_free_non_null(GNUNET_malloc(4));
61 61
62 /* GNUNET_strdup tests */ 62 /* GNUNET_strdup tests */
63 ptrs[0] = GNUNET_strdup ("bar"); 63 ptrs[0] = GNUNET_strdup("bar");
64 if (0 != strcmp (ptrs[0], "bar")) 64 if (0 != strcmp(ptrs[0], "bar"))
65 return 3; 65 return 3;
66 /* now realloc */ 66 /* now realloc */
67 ptrs[0] = GNUNET_realloc (ptrs[0], 12); 67 ptrs[0] = GNUNET_realloc(ptrs[0], 12);
68 strcpy (ptrs[0], "Hello World"); 68 strcpy(ptrs[0], "Hello World");
69 69
70 GNUNET_free (ptrs[0]); 70 GNUNET_free(ptrs[0]);
71 GNUNET_asprintf (&ptrs[0], "%s %s", "Hello", "World"); 71 GNUNET_asprintf(&ptrs[0], "%s %s", "Hello", "World");
72 GNUNET_assert (strlen (ptrs[0]) == 11); 72 GNUNET_assert(strlen(ptrs[0]) == 11);
73 GNUNET_free (ptrs[0]); 73 GNUNET_free(ptrs[0]);
74 74
75 /* GNUNET_array_grow tests */ 75 /* GNUNET_array_grow tests */
76 ptrs[0] = NULL; 76 ptrs[0] = NULL;
77 ui = 0; 77 ui = 0;
78 GNUNET_array_grow (ptrs[0], ui, 42); 78 GNUNET_array_grow(ptrs[0], ui, 42);
79 if (ui != 42) 79 if (ui != 42)
80 return 4; 80 return 4;
81 GNUNET_array_grow (ptrs[0], ui, 22); 81 GNUNET_array_grow(ptrs[0], ui, 22);
82 if (ui != 22) 82 if (ui != 22)
83 return 5; 83 return 5;
84 for (j = 0; j < 22; j++) 84 for (j = 0; j < 22; j++)
85 ptrs[0][j] = j; 85 ptrs[0][j] = j;
86 GNUNET_array_grow (ptrs[0], ui, 32); 86 GNUNET_array_grow(ptrs[0], ui, 32);
87 for (j = 0; j < 22; j++) 87 for (j = 0; j < 22; j++)
88 if (ptrs[0][j] != j) 88 if (ptrs[0][j] != j)
89 return 6; 89 return 6;
90 for (j = 22; j < 32; j++) 90 for (j = 22; j < 32; j++)
91 if (ptrs[0][j] != 0) 91 if (ptrs[0][j] != 0)
92 return 7; 92 return 7;
93 GNUNET_array_grow (ptrs[0], ui, 0); 93 GNUNET_array_grow(ptrs[0], ui, 0);
94 if (i != 0) 94 if (i != 0)
95 return 8; 95 return 8;
96 if (ptrs[0] != NULL) 96 if (ptrs[0] != NULL)
97 return 9; 97 return 9;
98 98
99 /* GNUNET_new_array_2d tests */ 99 /* GNUNET_new_array_2d tests */
100 a2 = GNUNET_new_array_2d (17, 22, unsigned int); 100 a2 = GNUNET_new_array_2d(17, 22, unsigned int);
101 for (i = 0; i < 17; i++) 101 for (i = 0; i < 17; i++)
102 {
103 for (j = 0; j < 22; j++)
104 { 102 {
105 if (0 != a2[i][j]) 103 for (j = 0; j < 22; j++)
106 { 104 {
107 GNUNET_free (a2); 105 if (0 != a2[i][j])
108 return 10; 106 {
109 } 107 GNUNET_free(a2);
110 a2[i][j] = i * 100 + j; 108 return 10;
109 }
110 a2[i][j] = i * 100 + j;
111 }
111 } 112 }
112 } 113 GNUNET_free(a2);
113 GNUNET_free (a2);
114 114
115 /* GNUNET_new_array_3d tests */ 115 /* GNUNET_new_array_3d tests */
116 a3 = GNUNET_new_array_3d (2, 3, 4, char); 116 a3 = GNUNET_new_array_3d(2, 3, 4, char);
117 for (i = 0; i < 2; i++) 117 for (i = 0; i < 2; i++)
118 {
119 for (j = 0; j < 3; j++)
120 { 118 {
121 for (k = 0; k < 4; k++) 119 for (j = 0; j < 3; j++)
122 {
123 if (0 != a3[i][j][k])
124 { 120 {
125 GNUNET_free (a3); 121 for (k = 0; k < 4; k++)
126 return 11; 122 {
123 if (0 != a3[i][j][k])
124 {
125 GNUNET_free(a3);
126 return 11;
127 }
128 a3[i][j][k] = i * 100 + j * 10 + k;
129 }
127 } 130 }
128 a3[i][j][k] = i * 100 + j * 10 + k;
129 }
130 } 131 }
131 } 132 GNUNET_free(a3);
132 GNUNET_free (a3);
133 return 0; 133 return 0;
134} 134}
135 135
136 136
137int 137int
138main (int argc, char *argv[]) 138main(int argc, char *argv[])
139{ 139{
140 int ret; 140 int ret;
141 141
142 GNUNET_log_setup ("test-common-allocation", 142 GNUNET_log_setup("test-common-allocation",
143 "WARNING", 143 "WARNING",
144 NULL); 144 NULL);
145 ret = check (); 145 ret = check();
146 if (ret != 0) 146 if (ret != 0)
147 fprintf (stderr, 147 fprintf(stderr,
148 "ERROR %d.\n", 148 "ERROR %d.\n",
149 ret); 149 ret);
150 return ret; 150 return ret;
151} 151}
152 152