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_EXTRA_LOGGING
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)
53 mycleaner (void *cls, struct GNUNET_FS_FileInformation *fi, uint64_t length,
54 struct GNUNET_CONTAINER_MetaData *meta, struct GNUNET_FS_Uri **uri,
55 struct GNUNET_FS_BlockOptions *bo, int *do_index, void **client_info)
62 run (void *cls, char *const *args, const char *cfgfile,
63 const struct GNUNET_CONFIGURATION_Handle *cfg)
65 const char *keywords[] = {
72 struct GNUNET_CONTAINER_MetaData *meta;
73 struct GNUNET_FS_Uri *kuri;
74 struct GNUNET_FS_FileInformation *fi1;
75 struct GNUNET_FS_FileInformation *fi2;
76 struct GNUNET_FS_FileInformation *fidir;
77 struct GNUNET_FS_Handle *fs;
79 struct GNUNET_FS_BlockOptions bo;
81 fs = GNUNET_FS_start (cfg, "test-fs-file-information", NULL, NULL,
82 GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
83 fn1 = GNUNET_DISK_mktemp ("gnunet-file_information-test-dst");
84 buf = GNUNET_malloc (FILESIZE);
85 for (i = 0; i < FILESIZE; i++)
86 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
87 GNUNET_assert (FILESIZE ==
88 GNUNET_DISK_fn_write (fn1, buf, FILESIZE,
89 GNUNET_DISK_PERM_USER_READ |
90 GNUNET_DISK_PERM_USER_WRITE));
93 fn2 = GNUNET_DISK_mktemp ("gnunet-file_information-test-dst");
94 buf = GNUNET_malloc (FILESIZE);
95 for (i = 0; i < FILESIZE; i++)
96 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
97 GNUNET_assert (FILESIZE ==
98 GNUNET_DISK_fn_write (fn2, buf, FILESIZE,
99 GNUNET_DISK_PERM_USER_READ |
100 GNUNET_DISK_PERM_USER_WRITE));
103 meta = GNUNET_CONTAINER_meta_data_create ();
104 kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords);
105 bo.content_priority = 42;
106 bo.anonymity_level = 1;
107 bo.replication_level = 0;
108 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
110 GNUNET_FS_file_information_create_from_file (fs,
111 "file_information-context1",
112 fn1, kuri, meta, GNUNET_YES,
114 GNUNET_assert (fi1 != NULL);
116 GNUNET_FS_file_information_create_from_file (fs,
117 "file_information-context2",
118 fn2, kuri, meta, GNUNET_YES,
120 GNUNET_assert (fi2 != NULL);
122 GNUNET_FS_file_information_create_empty_directory (fs,
123 "file_information-context-dir",
125 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1));
126 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2));
127 GNUNET_FS_uri_destroy (kuri);
128 GNUNET_CONTAINER_meta_data_destroy (meta);
129 GNUNET_assert (NULL != fidir);
130 /* FIXME: test more of API! */
131 GNUNET_FS_file_information_destroy (fidir, &mycleaner, NULL);
132 GNUNET_DISK_directory_remove (fn1);
133 GNUNET_DISK_directory_remove (fn2);
134 GNUNET_free_non_null (fn1);
135 GNUNET_free_non_null (fn2);
143 struct GNUNET_CONTAINER_MetaData *m;
144 struct GNUNET_CONTAINER_MetaData *d;
145 struct EXTRACTOR_PluginList *ex;
146 unsigned char *thumb;
150 ex = EXTRACTOR_plugin_add_config (NULL, "thumbnailgtk",
151 EXTRACTOR_OPTION_DEFAULT_POLICY);
155 "Test incomplete, have no GTK thumbnail extractor available.\n");
156 return 0; /* can not test, no thumbnailer */
158 ex = EXTRACTOR_plugin_add_config (ex, "mime",
159 EXTRACTOR_OPTION_DEFAULT_POLICY);
160 m = GNUNET_CONTAINER_meta_data_create ();
162 GNUNET_FS_meta_data_extract_from_file (m,
163 "test_fs_file_information_meta_data_image.jpg",
167 EXTRACTOR_plugin_remove_all (ex);
168 GNUNET_CONTAINER_meta_data_destroy (m);
171 EXTRACTOR_plugin_remove_all (ex);
172 d = GNUNET_CONTAINER_meta_data_duplicate (m);
173 GNUNET_CONTAINER_meta_data_destroy (m);
175 size = GNUNET_CONTAINER_meta_data_get_thumbnail (d, &thumb);
179 GNUNET_CONTAINER_meta_data_destroy (d);
183 GNUNET_CONTAINER_meta_data_add_publication_date (d);
185 GNUNET_CONTAINER_meta_data_get_by_type (d,
186 EXTRACTOR_METATYPE_PUBLICATION_DATE);
190 GNUNET_CONTAINER_meta_data_destroy (d);
194 GNUNET_CONTAINER_meta_data_destroy (d);
201 main (int argc, char *argv[])
203 char *const argvx[] = {
204 "test-fs-file_information",
206 "test_fs_file_information_data.conf",
212 struct GNUNET_GETOPT_CommandLineOption options[] = {
213 GNUNET_GETOPT_OPTION_END
216 GNUNET_log_setup ("test_fs_file_information",
223 if (0 != testThumbnail ())
225 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx,
226 "test-fs-file_information", "nohelp", options, &run,
231 /* end of test_fs_file_information.c */