2 This file is part of GNUnet.
3 (C) 2001, 2002, 2003, 2005, 2006 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file util/test_common_allocation.c
23 * @brief testcase for common_allocation.c
26 #include "gnunet_common.h"
31 #define MAX_TESTVAL 1024
32 char *ptrs[MAX_TESTVAL];
38 /* GNUNET_malloc/GNUNET_free test */
39 k = 352; /* random start value */
40 for (i = 1; i < MAX_TESTVAL; i++)
42 ptrs[i] = GNUNET_malloc (i);
43 for (j = 0; j < i; j++)
47 for (i = MAX_TESTVAL - 1; i >= 1; i--)
49 for (j = i - 1; j >= 0; j--)
50 if (ptrs[i][j] != (char) --k)
52 GNUNET_free (ptrs[i]);
55 /* GNUNET_free_non_null test */
56 GNUNET_free_non_null (NULL);
57 GNUNET_free_non_null (GNUNET_malloc (4));
59 /* GNUNET_strdup tests */
60 ptrs[0] = GNUNET_strdup ("bar");
61 if (0 != strcmp (ptrs[0], "bar"))
64 ptrs[0] = GNUNET_realloc (ptrs[0], 12);
65 strcpy (ptrs[0], "Hello World");
67 GNUNET_free (ptrs[0]);
68 GNUNET_asprintf (&ptrs[0], "%s %s", "Hello", "World");
69 GNUNET_assert (strlen (ptrs[0]) == 11);
70 GNUNET_free (ptrs[0]);
72 /* GNUNET_array_grow tests */
75 GNUNET_array_grow (ptrs[0], ui, 42);
78 GNUNET_array_grow (ptrs[0], ui, 22);
81 for (j = 0; j < 22; j++)
83 GNUNET_array_grow (ptrs[0], ui, 32);
84 for (j = 0; j < 22; j++)
87 for (j = 22; j < 32; j++)
90 GNUNET_array_grow (ptrs[0], ui, 0);
101 main (int argc, char *argv[])
105 GNUNET_log_setup ("test-common-allocation", "WARNING", NULL);
108 fprintf (stderr, "ERROR %d.\n", ret);
112 /* end of test_common_allocation.c */