diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-10-16 20:14:02 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-10-16 20:14:02 +0000 |
commit | 3d670727232e79b7e49a1df7ba9260db4e5798a0 (patch) | |
tree | 093f7b5aec28134dc6c5fe34cd2d8bfb1e1445ad /src/gnsrecord/test_gnsrecord_serialization.c | |
parent | 2de26776993a5e591e487321a5dc1d62b86d9cd4 (diff) | |
download | gnunet-3d670727232e79b7e49a1df7ba9260db4e5798a0.tar.gz gnunet-3d670727232e79b7e49a1df7ba9260db4e5798a0.zip |
-moving namestore_common functions to gnsrecord library
Diffstat (limited to 'src/gnsrecord/test_gnsrecord_serialization.c')
-rw-r--r-- | src/gnsrecord/test_gnsrecord_serialization.c | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/src/gnsrecord/test_gnsrecord_serialization.c b/src/gnsrecord/test_gnsrecord_serialization.c new file mode 100644 index 000000000..de6a7ba1d --- /dev/null +++ b/src/gnsrecord/test_gnsrecord_serialization.c | |||
@@ -0,0 +1,140 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2013 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | 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 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
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 | |||
28 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) | ||
29 | |||
30 | static int res; | ||
31 | |||
32 | |||
33 | static void | ||
34 | run (void *cls, char *const *args, const char *cfgfile, | ||
35 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
36 | { | ||
37 | size_t len; | ||
38 | int c; | ||
39 | |||
40 | int rd_count = 3; | ||
41 | size_t data_len; | ||
42 | struct GNUNET_NAMESTORE_RecordData src[rd_count]; | ||
43 | |||
44 | memset(src, '\0', rd_count * sizeof (struct GNUNET_NAMESTORE_RecordData)); | ||
45 | |||
46 | data_len = 0; | ||
47 | for (c = 0; c < rd_count; c++) | ||
48 | { | ||
49 | src[c].record_type = c+1; | ||
50 | src[c].data_size = data_len; | ||
51 | src[c].data = GNUNET_malloc (data_len); | ||
52 | |||
53 | /* Setting data to data_len * record_type */ | ||
54 | memset ((char *) src[c].data, 'a', data_len); | ||
55 | data_len += 10; | ||
56 | } | ||
57 | res = 0; | ||
58 | |||
59 | len = GNUNET_NAMESTORE_records_get_size(rd_count, src); | ||
60 | char rd_ser[len]; | ||
61 | GNUNET_assert (len == GNUNET_NAMESTORE_records_serialize(rd_count, src, len, rd_ser)); | ||
62 | |||
63 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Serialized data len: %u\n",len); | ||
64 | |||
65 | GNUNET_assert (rd_ser != NULL); | ||
66 | |||
67 | struct GNUNET_NAMESTORE_RecordData dst[rd_count]; | ||
68 | GNUNET_assert (GNUNET_OK == GNUNET_NAMESTORE_records_deserialize (len, rd_ser, rd_count, dst)); | ||
69 | |||
70 | GNUNET_assert (dst != NULL); | ||
71 | |||
72 | for (c = 0; c < rd_count; c++) | ||
73 | { | ||
74 | if (src[c].data_size != dst[c].data_size) | ||
75 | { | ||
76 | GNUNET_break (0); | ||
77 | res = 1; | ||
78 | } | ||
79 | if (src[c].expiration_time != dst[c].expiration_time) | ||
80 | { | ||
81 | GNUNET_break (0); | ||
82 | res = 1; | ||
83 | } | ||
84 | if (src[c].flags != dst[c].flags) | ||
85 | { | ||
86 | GNUNET_break (0); | ||
87 | res = 1; | ||
88 | } | ||
89 | if (src[c].record_type != dst[c].record_type) | ||
90 | { | ||
91 | GNUNET_break (0); | ||
92 | res = 1; | ||
93 | } | ||
94 | |||
95 | size_t data_size = src[c].data_size; | ||
96 | char data[data_size]; | ||
97 | memset (data, 'a', data_size); | ||
98 | if (0 != memcmp (data, dst[c].data, data_size)) | ||
99 | { | ||
100 | GNUNET_break (0); | ||
101 | res = 1; | ||
102 | } | ||
103 | if (0 != memcmp (data, src[c].data, data_size)) | ||
104 | { | ||
105 | GNUNET_break (0); | ||
106 | res = 1; | ||
107 | } | ||
108 | if (0 != memcmp (src[c].data, dst[c].data, src[c].data_size)) | ||
109 | { | ||
110 | GNUNET_break (0); | ||
111 | res = 1; | ||
112 | } | ||
113 | |||
114 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Element [%i]: EQUAL\n", c); | ||
115 | } | ||
116 | |||
117 | for (c = 0; c < rd_count; c++) | ||
118 | { | ||
119 | GNUNET_free ((void *)src[c].data); | ||
120 | } | ||
121 | } | ||
122 | |||
123 | |||
124 | int | ||
125 | main (int argcx, char *argvx[]) | ||
126 | { | ||
127 | static char *const argv[] = { "test_gnsrecord_serialization", | ||
128 | NULL | ||
129 | }; | ||
130 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
131 | GNUNET_GETOPT_OPTION_END | ||
132 | }; | ||
133 | |||
134 | res = 1; | ||
135 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, "test_namestore_record_serialization", | ||
136 | "nohelp", options, &run, &res); | ||
137 | return res; | ||
138 | } | ||
139 | |||
140 | /* end of test_gnsrecord_serialization.c */ | ||