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.
16 * @file gnsrecord/test_gnsrecord_serialization.c
17 * @brief testcase for gnsrecord_serialization.c
20 #include "gnunet_util_lib.h"
21 #include "gnunet_gnsrecord_lib.h"
22 #include "gnunet_dnsparser_lib.h"
24 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100)
33 const struct GNUNET_CONFIGURATION_Handle *cfg)
40 struct GNUNET_GNSRECORD_Data src[rd_count];
42 memset(src, '\0', rd_count * sizeof (struct GNUNET_GNSRECORD_Data));
45 for (c = 0; c < rd_count; c++)
47 src[c].record_type = GNUNET_DNSPARSER_TYPE_TXT;
48 src[c].data_size = data_len;
49 src[c].data = GNUNET_malloc (data_len);
51 /* Setting data to data_len * record_type */
52 memset ((char *) src[c].data, 'a', data_len);
57 len = GNUNET_GNSRECORD_records_get_size (rd_count, src);
60 GNUNET_GNSRECORD_records_serialize (rd_count,
65 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
66 "Serialized data len: %u\n",
69 GNUNET_assert (rd_ser != NULL);
71 struct GNUNET_GNSRECORD_Data dst[rd_count];
72 GNUNET_assert (GNUNET_OK ==
73 GNUNET_GNSRECORD_records_deserialize (len,
78 GNUNET_assert (dst != NULL);
80 for (c = 0; c < rd_count; c++)
82 if (src[c].data_size != dst[c].data_size)
87 if (src[c].expiration_time != dst[c].expiration_time)
92 if (src[c].flags != dst[c].flags)
97 if (src[c].record_type != dst[c].record_type)
104 size_t data_size = src[c].data_size;
105 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))
125 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Element [%i]: EQUAL\n", c);
128 for (c = 0; c < rd_count; c++)
130 GNUNET_free ((void *)src[c].data);
136 main (int argcx, char *argvx[])
138 static char *const argv[] = { "test_gnsrecord_serialization",
141 static struct GNUNET_GETOPT_CommandLineOption options[] = {
142 GNUNET_GETOPT_OPTION_END
146 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, "test_namestore_record_serialization",
147 "nohelp", options, &run, &res);
151 /* end of test_gnsrecord_serialization.c */