summaryrefslogtreecommitdiff
path: root/src/gnsrecord/test_gnsrecord_serialization.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gnsrecord/test_gnsrecord_serialization.c')
-rw-r--r--src/gnsrecord/test_gnsrecord_serialization.c159
1 files changed, 79 insertions, 80 deletions
diff --git a/src/gnsrecord/test_gnsrecord_serialization.c b/src/gnsrecord/test_gnsrecord_serialization.c
index f2ee1a479..34dcff5cb 100644
--- a/src/gnsrecord/test_gnsrecord_serialization.c
+++ b/src/gnsrecord/test_gnsrecord_serialization.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 * @file gnsrecord/test_gnsrecord_serialization.c 21 * @file gnsrecord/test_gnsrecord_serialization.c
22 * @brief testcase for gnsrecord_serialization.c 22 * @brief testcase for gnsrecord_serialization.c
@@ -26,16 +26,16 @@
26#include "gnunet_gnsrecord_lib.h" 26#include "gnunet_gnsrecord_lib.h"
27#include "gnunet_dnsparser_lib.h" 27#include "gnunet_dnsparser_lib.h"
28 28
29#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) 29#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 100)
30 30
31static int res; 31static int res;
32 32
33 33
34static void 34static void
35run (void *cls, 35run(void *cls,
36 char *const *args, 36 char *const *args,
37 const char *cfgfile, 37 const char *cfgfile,
38 const struct GNUNET_CONFIGURATION_Handle *cfg) 38 const struct GNUNET_CONFIGURATION_Handle *cfg)
39{ 39{
40 size_t len; 40 size_t len;
41 int c; 41 int c;
@@ -44,112 +44,111 @@ run (void *cls,
44 size_t data_len; 44 size_t data_len;
45 struct GNUNET_GNSRECORD_Data src[rd_count]; 45 struct GNUNET_GNSRECORD_Data src[rd_count];
46 46
47 memset(src, '\0', rd_count * sizeof (struct GNUNET_GNSRECORD_Data)); 47 memset(src, '\0', rd_count * sizeof(struct GNUNET_GNSRECORD_Data));
48 48
49 data_len = 0; 49 data_len = 0;
50 for (c = 0; c < rd_count; c++) 50 for (c = 0; c < rd_count; c++)
51 { 51 {
52 src[c].record_type = GNUNET_DNSPARSER_TYPE_TXT; 52 src[c].record_type = GNUNET_DNSPARSER_TYPE_TXT;
53 src[c].data_size = data_len; 53 src[c].data_size = data_len;
54 src[c].data = GNUNET_malloc (data_len); 54 src[c].data = GNUNET_malloc(data_len);
55 55
56 /* Setting data to data_len * record_type */ 56 /* Setting data to data_len * record_type */
57 memset ((char *) src[c].data, 'a', data_len); 57 memset((char *)src[c].data, 'a', data_len);
58 data_len += 10; 58 data_len += 10;
59 } 59 }
60 res = 0; 60 res = 0;
61 61
62 len = GNUNET_GNSRECORD_records_get_size (rd_count, src); 62 len = GNUNET_GNSRECORD_records_get_size(rd_count, src);
63 char rd_ser[len]; 63 char rd_ser[len];
64 GNUNET_assert (len == 64 GNUNET_assert(len ==
65 GNUNET_GNSRECORD_records_serialize (rd_count, 65 GNUNET_GNSRECORD_records_serialize(rd_count,
66 src, 66 src,
67 len, 67 len,
68 rd_ser)); 68 rd_ser));
69 69
70 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 70 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
71 "Serialized data len: %u\n", 71 "Serialized data len: %u\n",
72 (unsigned int) len); 72 (unsigned int)len);
73 73
74 GNUNET_assert (rd_ser != NULL); 74 GNUNET_assert(rd_ser != NULL);
75 { 75 {
76 struct GNUNET_GNSRECORD_Data dst[rd_count]; 76 struct GNUNET_GNSRECORD_Data dst[rd_count];
77 GNUNET_assert (GNUNET_OK == 77 GNUNET_assert(GNUNET_OK ==
78 GNUNET_GNSRECORD_records_deserialize (len, 78 GNUNET_GNSRECORD_records_deserialize(len,
79 rd_ser, 79 rd_ser,
80 rd_count, 80 rd_count,
81 dst)); 81 dst));
82 82
83 GNUNET_assert (dst != NULL); 83 GNUNET_assert(dst != NULL);
84 84
85 for (c = 0; c < rd_count; c++) 85 for (c = 0; c < rd_count; c++)
86 {
87 if (src[c].data_size != dst[c].data_size)
88 {
89 GNUNET_break (0);
90 res = 1;
91 }
92 if (src[c].expiration_time != dst[c].expiration_time)
93 {
94 GNUNET_break (0);
95 res = 1;
96 }
97 if (src[c].flags != dst[c].flags)
98 {
99 GNUNET_break (0);
100 res = 1;
101 }
102 if (src[c].record_type != dst[c].record_type)
103 { 86 {
104 GNUNET_break (0); 87 if (src[c].data_size != dst[c].data_size)
105 res = 1; 88 {
106 } 89 GNUNET_break(0);
107 90 res = 1;
108 { 91 }
109 size_t data_size = src[c].data_size; 92 if (src[c].expiration_time != dst[c].expiration_time)
110 char data[data_size]; 93 {
94 GNUNET_break(0);
95 res = 1;
96 }
97 if (src[c].flags != dst[c].flags)
98 {
99 GNUNET_break(0);
100 res = 1;
101 }
102 if (src[c].record_type != dst[c].record_type)
103 {
104 GNUNET_break(0);
105 res = 1;
106 }
111 107
112 memset (data, 'a', data_size);
113 if (0 != memcmp (data, dst[c].data, data_size))
114 {
115 GNUNET_break (0);
116 res = 1;
117 }
118 if (0 != memcmp (data, src[c].data, data_size))
119 {
120 GNUNET_break (0);
121 res = 1;
122 }
123 if (0 != memcmp (src[c].data, dst[c].data, src[c].data_size))
124 { 108 {
125 GNUNET_break (0); 109 size_t data_size = src[c].data_size;
126 res = 1; 110 char data[data_size];
111
112 memset(data, 'a', data_size);
113 if (0 != memcmp(data, dst[c].data, data_size))
114 {
115 GNUNET_break(0);
116 res = 1;
117 }
118 if (0 != memcmp(data, src[c].data, data_size))
119 {
120 GNUNET_break(0);
121 res = 1;
122 }
123 if (0 != memcmp(src[c].data, dst[c].data, src[c].data_size))
124 {
125 GNUNET_break(0);
126 res = 1;
127 }
127 } 128 }
128 } 129 }
129 } 130 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Element [%i]: EQUAL\n", c);
130 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Element [%i]: EQUAL\n", c);
131 } 131 }
132 132
133 for (c = 0; c < rd_count; c++) 133 for (c = 0; c < rd_count; c++)
134 { 134 {
135 GNUNET_free ((void *)src[c].data); 135 GNUNET_free((void *)src[c].data);
136 } 136 }
137} 137}
138 138
139 139
140int 140int
141main (int argcx, char *argvx[]) 141main(int argcx, char *argvx[])
142{ 142{
143 static char *const argv[] = { "test_gnsrecord_serialization", 143 static char *const argv[] = { "test_gnsrecord_serialization",
144 NULL 144 NULL };
145 };
146 static struct GNUNET_GETOPT_CommandLineOption options[] = { 145 static struct GNUNET_GETOPT_CommandLineOption options[] = {
147 GNUNET_GETOPT_OPTION_END 146 GNUNET_GETOPT_OPTION_END
148 }; 147 };
149 148
150 res = 1; 149 res = 1;
151 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, "test_namestore_record_serialization", 150 GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) - 1, argv, "test_namestore_record_serialization",
152 "nohelp", options, &run, &res); 151 "nohelp", options, &run, &res);
153 return res; 152 return res;
154} 153}
155 154