diff options
Diffstat (limited to 'src/gnsrecord/test_gnsrecord_serialization.c')
-rw-r--r-- | src/gnsrecord/test_gnsrecord_serialization.c | 157 |
1 files changed, 0 insertions, 157 deletions
diff --git a/src/gnsrecord/test_gnsrecord_serialization.c b/src/gnsrecord/test_gnsrecord_serialization.c deleted file mode 100644 index d268cb7f3..000000000 --- a/src/gnsrecord/test_gnsrecord_serialization.c +++ /dev/null | |||
@@ -1,157 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2013 GNUnet e.V. | ||
4 | |||
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. | ||
9 | |||
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. | ||
14 | |||
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/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | /** | ||
21 | * @file gnsrecord/test_gnsrecord_serialization.c | ||
22 | * @brief testcase for gnsrecord_serialization.c | ||
23 | */ | ||
24 | #include "platform.h" | ||
25 | #include "gnunet_util_lib.h" | ||
26 | #include "gnunet_gnsrecord_lib.h" | ||
27 | #include "gnunet_dnsparser_lib.h" | ||
28 | |||
29 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) | ||
30 | |||
31 | static int res; | ||
32 | |||
33 | |||
34 | static void | ||
35 | run (void *cls, | ||
36 | char *const *args, | ||
37 | const char *cfgfile, | ||
38 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
39 | { | ||
40 | size_t len; | ||
41 | int c; | ||
42 | |||
43 | int rd_count = 3; | ||
44 | size_t data_len; | ||
45 | struct GNUNET_GNSRECORD_Data src[rd_count]; | ||
46 | |||
47 | memset (src, '\0', rd_count * sizeof(struct GNUNET_GNSRECORD_Data)); | ||
48 | |||
49 | data_len = 0; | ||
50 | for (c = 0; c < rd_count; c++) | ||
51 | { | ||
52 | src[c].record_type = GNUNET_DNSPARSER_TYPE_TXT; | ||
53 | src[c].data_size = data_len; | ||
54 | src[c].data = GNUNET_malloc (data_len); | ||
55 | |||
56 | /* Setting data to data_len * record_type */ | ||
57 | memset ((char *) src[c].data, 'a', data_len); | ||
58 | data_len += 10; | ||
59 | } | ||
60 | res = 0; | ||
61 | |||
62 | len = GNUNET_GNSRECORD_records_get_size (rd_count, src); | ||
63 | char rd_ser[len]; | ||
64 | GNUNET_assert (len == | ||
65 | GNUNET_GNSRECORD_records_serialize (rd_count, | ||
66 | src, | ||
67 | len, | ||
68 | rd_ser)); | ||
69 | |||
70 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
71 | "Serialized data len: %u\n", | ||
72 | (unsigned int) len); | ||
73 | |||
74 | GNUNET_assert (rd_ser != NULL); | ||
75 | { | ||
76 | struct GNUNET_GNSRECORD_Data dst[rd_count]; | ||
77 | GNUNET_assert (GNUNET_OK == | ||
78 | GNUNET_GNSRECORD_records_deserialize (len, | ||
79 | rd_ser, | ||
80 | rd_count, | ||
81 | dst)); | ||
82 | |||
83 | GNUNET_assert (dst != NULL); | ||
84 | |||
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 | { | ||
104 | GNUNET_break (0); | ||
105 | res = 1; | ||
106 | } | ||
107 | |||
108 | { | ||
109 | size_t data_size = src[c].data_size; | ||
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 | } | ||
128 | } | ||
129 | } | ||
130 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Element [%i]: EQUAL\n", c); | ||
131 | } | ||
132 | |||
133 | for (c = 0; c < rd_count; c++) | ||
134 | { | ||
135 | GNUNET_free_nz ((void *) src[c].data); | ||
136 | } | ||
137 | } | ||
138 | |||
139 | |||
140 | int | ||
141 | main (int argcx, char *argvx[]) | ||
142 | { | ||
143 | static char *const argv[] = { "test_gnsrecord_serialization", | ||
144 | NULL }; | ||
145 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
146 | GNUNET_GETOPT_OPTION_END | ||
147 | }; | ||
148 | |||
149 | res = 1; | ||
150 | GNUNET_PROGRAM_run ((sizeof(argv) / sizeof(char *)) - 1, argv, | ||
151 | "test_namestore_record_serialization", | ||
152 | "nohelp", options, &run, &res); | ||
153 | return res; | ||
154 | } | ||
155 | |||
156 | |||
157 | /* end of test_gnsrecord_serialization.c */ | ||