aboutsummaryrefslogtreecommitdiff
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.c124
1 files changed, 64 insertions, 60 deletions
diff --git a/src/gnsrecord/test_gnsrecord_serialization.c b/src/gnsrecord/test_gnsrecord_serialization.c
index 3edd2bc48..03a4d8b03 100644
--- a/src/gnsrecord/test_gnsrecord_serialization.c
+++ b/src/gnsrecord/test_gnsrecord_serialization.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2013 GNUnet e.V. 3 Copyright (C) 2013 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software: you can redistribute it and/or modify it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
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 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 General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20/** 18/**
21 * @file gnsrecord/test_gnsrecord_serialization.c 19 * @file gnsrecord/test_gnsrecord_serialization.c
@@ -24,6 +22,7 @@
24#include "platform.h" 22#include "platform.h"
25#include "gnunet_util_lib.h" 23#include "gnunet_util_lib.h"
26#include "gnunet_gnsrecord_lib.h" 24#include "gnunet_gnsrecord_lib.h"
25#include "gnunet_dnsparser_lib.h"
27 26
28#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) 27#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100)
29 28
@@ -31,7 +30,9 @@ static int res;
31 30
32 31
33static void 32static void
34run (void *cls, char *const *args, const char *cfgfile, 33run (void *cls,
34 char *const *args,
35 const char *cfgfile,
35 const struct GNUNET_CONFIGURATION_Handle *cfg) 36 const struct GNUNET_CONFIGURATION_Handle *cfg)
36{ 37{
37 size_t len; 38 size_t len;
@@ -46,7 +47,7 @@ run (void *cls, char *const *args, const char *cfgfile,
46 data_len = 0; 47 data_len = 0;
47 for (c = 0; c < rd_count; c++) 48 for (c = 0; c < rd_count; c++)
48 { 49 {
49 src[c].record_type = c+1; 50 src[c].record_type = GNUNET_DNSPARSER_TYPE_TXT;
50 src[c].data_size = data_len; 51 src[c].data_size = data_len;
51 src[c].data = GNUNET_malloc (data_len); 52 src[c].data = GNUNET_malloc (data_len);
52 53
@@ -69,58 +70,61 @@ run (void *cls, char *const *args, const char *cfgfile,
69 (unsigned int) len); 70 (unsigned int) len);
70 71
71 GNUNET_assert (rd_ser != NULL); 72 GNUNET_assert (rd_ser != NULL);
72
73 struct GNUNET_GNSRECORD_Data dst[rd_count];
74 GNUNET_assert (GNUNET_OK ==
75 GNUNET_GNSRECORD_records_deserialize (len,
76 rd_ser,
77 rd_count,
78 dst));
79
80 GNUNET_assert (dst != NULL);
81
82 for (c = 0; c < rd_count; c++)
83 { 73 {
84 if (src[c].data_size != dst[c].data_size) 74 struct GNUNET_GNSRECORD_Data dst[rd_count];
85 { 75 GNUNET_assert (GNUNET_OK ==
86 GNUNET_break (0); 76 GNUNET_GNSRECORD_records_deserialize (len,
87 res = 1; 77 rd_ser,
88 } 78 rd_count,
89 if (src[c].expiration_time != dst[c].expiration_time) 79 dst));
90 {
91 GNUNET_break (0);
92 res = 1;
93 }
94 if (src[c].flags != dst[c].flags)
95 {
96 GNUNET_break (0);
97 res = 1;
98 }
99 if (src[c].record_type != dst[c].record_type)
100 {
101 GNUNET_break (0);
102 res = 1;
103 }
104 80
105 size_t data_size = src[c].data_size; 81 GNUNET_assert (dst != NULL);
106 char data[data_size]; 82
107 memset (data, 'a', data_size); 83 for (c = 0; c < rd_count; c++)
108 if (0 != memcmp (data, dst[c].data, data_size))
109 {
110 GNUNET_break (0);
111 res = 1;
112 }
113 if (0 != memcmp (data, src[c].data, data_size))
114 {
115 GNUNET_break (0);
116 res = 1;
117 }
118 if (0 != memcmp (src[c].data, dst[c].data, src[c].data_size))
119 { 84 {
120 GNUNET_break (0); 85 if (src[c].data_size != dst[c].data_size)
121 res = 1; 86 {
87 GNUNET_break (0);
88 res = 1;
89 }
90 if (src[c].expiration_time != dst[c].expiration_time)
91 {
92 GNUNET_break (0);
93 res = 1;
94 }
95 if (src[c].flags != dst[c].flags)
96 {
97 GNUNET_break (0);
98 res = 1;
99 }
100 if (src[c].record_type != dst[c].record_type)
101 {
102 GNUNET_break (0);
103 res = 1;
104 }
105
106 {
107 size_t data_size = src[c].data_size;
108 char data[data_size];
109
110 memset (data, 'a', data_size);
111 if (0 != memcmp (data, dst[c].data, data_size))
112 {
113 GNUNET_break (0);
114 res = 1;
115 }
116 if (0 != memcmp (data, src[c].data, data_size))
117 {
118 GNUNET_break (0);
119 res = 1;
120 }
121 if (0 != memcmp (src[c].data, dst[c].data, src[c].data_size))
122 {
123 GNUNET_break (0);
124 res = 1;
125 }
126 }
122 } 127 }
123
124 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Element [%i]: EQUAL\n", c); 128 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Element [%i]: EQUAL\n", c);
125 } 129 }
126 130