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 it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
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/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
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"
27 #include "gnunet_dnsparser_lib.h"
29 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100)
38 const struct GNUNET_CONFIGURATION_Handle *cfg)
45 struct GNUNET_GNSRECORD_Data src[rd_count];
47 memset (src, '\0', rd_count * sizeof(struct GNUNET_GNSRECORD_Data));
50 for (c = 0; c < rd_count; c++)
52 src[c].record_type = GNUNET_DNSPARSER_TYPE_TXT;
53 src[c].data_size = data_len;
54 src[c].data = GNUNET_malloc (data_len);
56 /* Setting data to data_len * record_type */
57 memset ((char *) src[c].data, 'a', data_len);
62 len = GNUNET_GNSRECORD_records_get_size (rd_count, src);
65 GNUNET_GNSRECORD_records_serialize (rd_count,
70 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
71 "Serialized data len: %u\n",
74 GNUNET_assert (rd_ser != NULL);
76 struct GNUNET_GNSRECORD_Data dst[rd_count];
77 GNUNET_assert (GNUNET_OK ==
78 GNUNET_GNSRECORD_records_deserialize (len,
83 GNUNET_assert (dst != NULL);
85 for (c = 0; c < rd_count; c++)
87 if (src[c].data_size != dst[c].data_size)
92 if (src[c].expiration_time != dst[c].expiration_time)
97 if (src[c].flags != dst[c].flags)
102 if (src[c].record_type != dst[c].record_type)
109 size_t data_size = src[c].data_size;
110 char data[data_size];
112 memset (data, 'a', data_size);
113 if (0 != memcmp (data, dst[c].data, data_size))
118 if (0 != memcmp (data, src[c].data, data_size))
123 if (0 != memcmp (src[c].data, dst[c].data, src[c].data_size))
130 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Element [%i]: EQUAL\n", c);
133 for (c = 0; c < rd_count; c++)
135 GNUNET_free_nz ((void *) src[c].data);
141 main (int argcx, char *argvx[])
143 static char *const argv[] = { "test_gnsrecord_serialization",
145 static struct GNUNET_GETOPT_CommandLineOption options[] = {
146 GNUNET_GETOPT_OPTION_END
150 GNUNET_PROGRAM_run ((sizeof(argv) / sizeof(char *)) - 1, argv,
151 "test_namestore_record_serialization",
152 "nohelp", options, &run, &res);
157 /* end of test_gnsrecord_serialization.c */