2 This file is part of GNUnet.
3 (C) 2004, 2005, 2006, 2008, 2009 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 3, 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 fs/test_fs_file_information.c
23 * @brief simple testcase for file_information operations
24 * @author Christian Grothoff
27 * - test that metatdata, etc. are all correct (for example,
28 * there is a known bug with dirname never being set that is
30 * - need to iterate over file-information structure
31 * - other API functions may not yet be tested (such as
32 * filedata-from-callback)
36 #include "gnunet_util_lib.h"
37 #include "gnunet_fs_service.h"
39 #define VERBOSE GNUNET_NO
42 * File-size we use for testing.
44 #define FILESIZE (1024 * 1024 * 2)
47 * How long should our test-content live?
49 #define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
54 struct GNUNET_FS_FileInformation *fi,
56 struct GNUNET_CONTAINER_MetaData *meta,
57 struct GNUNET_FS_Uri **uri,
58 struct GNUNET_FS_BlockOptions *bo,
70 const struct GNUNET_CONFIGURATION_Handle *cfg)
72 const char *keywords[] = {
79 struct GNUNET_CONTAINER_MetaData *meta;
80 struct GNUNET_FS_Uri *kuri;
81 struct GNUNET_FS_FileInformation *fi1;
82 struct GNUNET_FS_FileInformation *fi2;
83 struct GNUNET_FS_FileInformation *fidir;
84 struct GNUNET_FS_Handle *fs;
86 struct GNUNET_FS_BlockOptions bo;
88 fs = GNUNET_FS_start (cfg, "test-fs-file-information", NULL, NULL,
90 GNUNET_FS_OPTIONS_END);
91 fn1 = GNUNET_DISK_mktemp ("gnunet-file_information-test-dst");
92 buf = GNUNET_malloc (FILESIZE);
93 for (i = 0; i < FILESIZE; i++)
94 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
95 GNUNET_assert (FILESIZE ==
96 GNUNET_DISK_fn_write (fn1,
99 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE));
102 fn2 = GNUNET_DISK_mktemp ("gnunet-file_information-test-dst");
103 buf = GNUNET_malloc (FILESIZE);
104 for (i = 0; i < FILESIZE; i++)
105 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
106 GNUNET_assert (FILESIZE ==
107 GNUNET_DISK_fn_write (fn2,
110 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE));
113 meta = GNUNET_CONTAINER_meta_data_create ();
114 kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords);
115 bo.content_priority = 42;
116 bo.anonymity_level = 1;
117 bo.replication_level = 0;
118 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
119 fi1 = GNUNET_FS_file_information_create_from_file (fs,
120 "file_information-context1",
126 GNUNET_assert (fi1 != NULL);
127 fi2 = GNUNET_FS_file_information_create_from_file (fs,
128 "file_information-context2",
134 GNUNET_assert (fi2 != NULL);
135 fidir = GNUNET_FS_file_information_create_empty_directory (fs,
136 "file_information-context-dir",
140 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1));
141 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2));
142 GNUNET_FS_uri_destroy (kuri);
143 GNUNET_CONTAINER_meta_data_destroy (meta);
144 GNUNET_assert (NULL != fidir);
145 /* FIXME: test more of API! */
146 GNUNET_FS_file_information_destroy (fidir,
149 GNUNET_DISK_directory_remove (fn1);
150 GNUNET_DISK_directory_remove (fn2);
151 GNUNET_free_non_null (fn1);
152 GNUNET_free_non_null (fn2);
160 struct GNUNET_CONTAINER_MetaData *m;
161 struct GNUNET_CONTAINER_MetaData *d;
162 struct EXTRACTOR_PluginList *ex;
163 unsigned char *thumb;
167 ex = EXTRACTOR_plugin_add_config (NULL, "thumbnailgtk", EXTRACTOR_OPTION_DEFAULT_POLICY);
171 "Test incomplete, have no GTK thumbnail extractor available.\n");
172 return 0; /* can not test, no thumbnailer */
174 ex = EXTRACTOR_plugin_add_config (ex, "mime", EXTRACTOR_OPTION_DEFAULT_POLICY);
175 m = GNUNET_CONTAINER_meta_data_create ();
176 if (3 != GNUNET_FS_meta_data_extract_from_file (m,
177 "test_fs_file_information_meta_data_image.jpg",
181 EXTRACTOR_plugin_remove_all (ex);
182 GNUNET_CONTAINER_meta_data_destroy (m);
185 EXTRACTOR_plugin_remove_all (ex);
186 d = GNUNET_CONTAINER_meta_data_duplicate (m);
187 GNUNET_CONTAINER_meta_data_destroy (m);
189 size = GNUNET_CONTAINER_meta_data_get_thumbnail (d, &thumb);
193 GNUNET_CONTAINER_meta_data_destroy (d);
197 GNUNET_CONTAINER_meta_data_add_publication_date (d);
198 date = GNUNET_CONTAINER_meta_data_get_by_type (d,
199 EXTRACTOR_METATYPE_PUBLICATION_DATE);
203 GNUNET_CONTAINER_meta_data_destroy (d);
207 GNUNET_CONTAINER_meta_data_destroy (d);
214 main (int argc, char *argv[])
216 char *const argvx[] = {
217 "test-fs-file_information",
219 "test_fs_file_information_data.conf",
225 struct GNUNET_GETOPT_CommandLineOption options[] = {
226 GNUNET_GETOPT_OPTION_END
229 GNUNET_log_setup ("test_fs_file_information",
236 if (0 != testThumbnail ())
238 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
239 argvx, "test-fs-file_information",
240 "nohelp", options, &run, NULL);
244 /* end of test_fs_file_information.c */