2 This file is part of GNUnet.
3 (C) 2003, 2004, 2006, 2009, 2010 Christian Grothoff (and other contributing authors)
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 2, or (at your
8 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 General Public License for more details.
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.
22 * @file util/test_container_meta_data.c
23 * @brief Test for container_meta_data.c
24 * @author Christian Grothoff
28 #include "gnunet_common.h"
29 #include "gnunet_container_lib.h"
31 #define ABORT(m) { fprintf(stderr, "Error at %s:%d\n", __FILE__, __LINE__); if (m != NULL) GNUNET_CONTAINER_meta_data_destroy(m); return 1; }
36 struct GNUNET_CONTAINER_MetaData *m;
42 m = GNUNET_CONTAINER_meta_data_create ();
44 GNUNET_CONTAINER_meta_data_insert (m,
46 EXTRACTOR_METATYPE_TITLE,
47 EXTRACTOR_METAFORMAT_UTF8,
50 strlen("TestTitle")+1))
53 GNUNET_CONTAINER_meta_data_insert (m,
55 EXTRACTOR_METATYPE_AUTHOR_NAME,
56 EXTRACTOR_METAFORMAT_UTF8,
59 strlen ("TestTitle")+1))
61 if (GNUNET_OK == GNUNET_CONTAINER_meta_data_insert (m,
63 EXTRACTOR_METATYPE_TITLE,
64 EXTRACTOR_METAFORMAT_UTF8,
67 strlen ("TestTitle")+1)) /* dup! */
69 if (GNUNET_OK == GNUNET_CONTAINER_meta_data_insert (m,
71 EXTRACTOR_METATYPE_AUTHOR_NAME,
72 EXTRACTOR_METAFORMAT_UTF8,
75 strlen ("TestTitle")+1)) /* dup! */
77 if (2 != GNUNET_CONTAINER_meta_data_iterate (m, NULL, NULL))
80 GNUNET_CONTAINER_meta_data_delete (m,
81 EXTRACTOR_METATYPE_AUTHOR_NAME,
83 strlen("TestTitle")+1))
85 if (GNUNET_OK == GNUNET_CONTAINER_meta_data_delete (m,
86 EXTRACTOR_METATYPE_AUTHOR_NAME,
88 strlen ("TestTitle")+1)) /* already gone */
90 if (1 != GNUNET_CONTAINER_meta_data_iterate (m, NULL, NULL))
93 GNUNET_CONTAINER_meta_data_delete (m,
94 EXTRACTOR_METATYPE_TITLE,
96 strlen ("TestTitle")+1))
98 if (GNUNET_OK == GNUNET_CONTAINER_meta_data_delete (m,
99 EXTRACTOR_METATYPE_TITLE,
101 strlen ("TestTitle")+1)) /* already gone */
103 if (0 != GNUNET_CONTAINER_meta_data_iterate (m, NULL, NULL))
105 for (j = 0; j < i; j++)
107 GNUNET_snprintf (val,
110 "A teststring that should compress well.", j);
112 GNUNET_CONTAINER_meta_data_insert (m,
114 EXTRACTOR_METATYPE_UNKNOWN,
115 EXTRACTOR_METAFORMAT_UTF8,
121 if (i != GNUNET_CONTAINER_meta_data_iterate (m, NULL, NULL))
125 GNUNET_CONTAINER_meta_data_get_serialized_size (m);
127 if (size != GNUNET_CONTAINER_meta_data_serialize (m,
129 GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL))
131 GNUNET_free_non_null (sval);
134 GNUNET_CONTAINER_meta_data_destroy (m);
135 m = GNUNET_CONTAINER_meta_data_deserialize (sval, size);
139 for (j = 0; j < i; j++)
141 GNUNET_snprintf (val,
142 sizeof(val), "%s.%d",
143 "A teststring that should compress well.", j);
145 GNUNET_CONTAINER_meta_data_delete (m,
146 EXTRACTOR_METATYPE_UNKNOWN,
153 if (0 != GNUNET_CONTAINER_meta_data_iterate (m, NULL, NULL))
155 GNUNET_CONTAINER_meta_data_destroy (m);
162 struct GNUNET_CONTAINER_MetaData *meta;
166 unsigned long long size;
168 meta = GNUNET_CONTAINER_meta_data_create ();
169 for (q = 0; q <= i; q++)
171 GNUNET_snprintf (txt, 128, "%u -- %u\n", i, q);
172 GNUNET_CONTAINER_meta_data_insert (meta,
174 q % EXTRACTOR_metatype_get_max(),
175 EXTRACTOR_METAFORMAT_UTF8,
181 GNUNET_CONTAINER_meta_data_get_serialized_size (meta);
182 data = GNUNET_malloc (size * 4);
183 if (size != GNUNET_CONTAINER_meta_data_serialize (meta,
185 GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL))
190 GNUNET_CONTAINER_meta_data_destroy (meta);
198 struct GNUNET_CONTAINER_MetaData *m;
202 m = GNUNET_CONTAINER_meta_data_create ();
204 GNUNET_CONTAINER_meta_data_insert (m,
206 EXTRACTOR_METATYPE_UNKNOWN,
207 EXTRACTOR_METAFORMAT_UTF8,
213 GNUNET_CONTAINER_meta_data_insert (m,
215 EXTRACTOR_METATYPE_FILENAME,
216 EXTRACTOR_METAFORMAT_UTF8,
219 strlen ("lib-link.m4")+1))
222 size = GNUNET_CONTAINER_meta_data_serialize (m, &val, (size_t) -1,
223 GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL);
224 GNUNET_CONTAINER_meta_data_destroy (m);
225 m = GNUNET_CONTAINER_meta_data_deserialize (val, size);
229 GNUNET_CONTAINER_meta_data_destroy (m);
237 struct GNUNET_CONTAINER_MetaData *m;
238 struct GNUNET_CONTAINER_MetaData *d;
239 struct EXTRACTOR_PluginList *ex;
240 unsigned char *thumb;
244 ex = EXTRACTOR_plugin_add_config (NULL, "thumbnailgtk", EXTRACTOR_OPTION_DEFAULT_POLICY);
248 "Test incomplete, have no GTK thumbnail extractor available.\n");
249 return 0; /* can not test, no thumbnailer */
251 ex = EXTRACTOR_plugin_add_config (ex, "mime", EXTRACTOR_OPTION_DEFAULT_POLICY);
252 m = GNUNET_CONTAINER_meta_data_create ();
253 if (3 != GNUNET_CONTAINER_meta_data_extract_from_file (m,
254 "test_container_meta_data_image.jpg",
258 EXTRACTOR_plugin_remove_all (ex);
259 GNUNET_CONTAINER_meta_data_destroy (m);
262 EXTRACTOR_plugin_remove_all (ex);
263 d = GNUNET_CONTAINER_meta_data_duplicate (m);
264 GNUNET_CONTAINER_meta_data_destroy (m);
265 size = GNUNET_CONTAINER_meta_data_get_thumbnail (d, &thumb);
269 GNUNET_CONTAINER_meta_data_destroy (d);
273 GNUNET_CONTAINER_meta_data_add_publication_date (d);
274 date = GNUNET_CONTAINER_meta_data_get_by_type (d,
275 EXTRACTOR_METATYPE_PUBLICATION_DATE);
279 GNUNET_CONTAINER_meta_data_destroy (d);
283 GNUNET_CONTAINER_meta_data_destroy (d);
289 main (int argc, char *argv[])
291 int failureCount = 0;
294 GNUNET_log_setup ("test-container-meta-data", "WARNING", NULL);
295 for (i = 0; i < 255; i++)
296 failureCount += testMeta (i);
297 for (i = 1; i < 255; i++)
298 failureCount += testMetaMore (i);
299 failureCount += testMetaLink ();
300 failureCount += testThumbnail ();
302 if (failureCount != 0)
307 /* end of test_container_meta_data.c */