2 This file is part of GNUnet.
3 Copyright (C) 2013 GNUnet e.V.
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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
21 * @file gnsrecord/test_gnsrecord_serialization.c
22 * @brief testcase for gnsrecord_serialization.c
25 #include "gnunet_util_lib.h"
26 #include "gnunet_gnsrecord_lib.h"
28 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100)
34 run (void *cls, char *const *args, const char *cfgfile,
35 const struct GNUNET_CONFIGURATION_Handle *cfg)
42 struct GNUNET_GNSRECORD_Data src[rd_count];
44 memset(src, '\0', rd_count * sizeof (struct GNUNET_GNSRECORD_Data));
47 for (c = 0; c < rd_count; c++)
49 src[c].record_type = c+1;
50 src[c].data_size = data_len;
51 src[c].data = GNUNET_malloc (data_len);
53 /* Setting data to data_len * record_type */
54 memset ((char *) src[c].data, 'a', data_len);
59 len = GNUNET_GNSRECORD_records_get_size (rd_count, src);
62 GNUNET_GNSRECORD_records_serialize (rd_count,
67 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
68 "Serialized data len: %u\n",
71 GNUNET_assert (rd_ser != NULL);
73 struct GNUNET_GNSRECORD_Data dst[rd_count];
74 GNUNET_assert (GNUNET_OK ==
75 GNUNET_GNSRECORD_records_deserialize (len,
80 GNUNET_assert (dst != NULL);
82 for (c = 0; c < rd_count; c++)
84 if (src[c].data_size != dst[c].data_size)
89 if (src[c].expiration_time != dst[c].expiration_time)
94 if (src[c].flags != dst[c].flags)
99 if (src[c].record_type != dst[c].record_type)
105 size_t data_size = src[c].data_size;
106 char data[data_size];
107 memset (data, 'a', data_size);
108 if (0 != memcmp (data, dst[c].data, data_size))
113 if (0 != memcmp (data, src[c].data, data_size))
118 if (0 != memcmp (src[c].data, dst[c].data, src[c].data_size))
124 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Element [%i]: EQUAL\n", c);
127 for (c = 0; c < rd_count; c++)
129 GNUNET_free ((void *)src[c].data);
135 main (int argcx, char *argvx[])
137 static char *const argv[] = { "test_gnsrecord_serialization",
140 static struct GNUNET_GETOPT_CommandLineOption options[] = {
141 GNUNET_GETOPT_OPTION_END
145 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, "test_namestore_record_serialization",
146 "nohelp", options, &run, &res);
150 /* end of test_gnsrecord_serialization.c */