2 This file is part of GNUnet.
3 Copyright (C) 2004, 2005, 2006, 2008, 2009 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * @file fs/test_fs_file_information.c
21 * @brief simple testcase for file_information operations
22 * @author Christian Grothoff
25 * - test that metatdata, etc. are all correct (for example,
26 * there is a known bug with dirname never being set that is
28 * - need to iterate over file-information structure
29 * - other API functions may not yet be tested (such as
30 * filedata-from-callback)
33 #include "gnunet_util_lib.h"
34 #include "gnunet_fs_service.h"
38 * File-size we use for testing.
40 #define FILESIZE (1024 * 1024 * 2)
43 * How long should our test-content live?
45 #define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
49 mycleaner (void *cls, struct GNUNET_FS_FileInformation *fi, uint64_t length,
50 struct GNUNET_CONTAINER_MetaData *meta, struct GNUNET_FS_Uri **uri,
51 struct GNUNET_FS_BlockOptions *bo, int *do_index, void **client_info)
58 run (void *cls, char *const *args, const char *cfgfile,
59 const struct GNUNET_CONFIGURATION_Handle *cfg)
61 const char *keywords[] = {
68 struct GNUNET_CONTAINER_MetaData *meta;
69 struct GNUNET_FS_Uri *kuri;
70 struct GNUNET_FS_FileInformation *fi1;
71 struct GNUNET_FS_FileInformation *fi2;
72 struct GNUNET_FS_FileInformation *fidir;
73 struct GNUNET_FS_Handle *fs;
75 struct GNUNET_FS_BlockOptions bo;
77 fs = GNUNET_FS_start (cfg, "test-fs-file-information", NULL, NULL,
78 GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
79 fn1 = GNUNET_DISK_mktemp ("gnunet-file_information-test-dst");
80 buf = GNUNET_malloc (FILESIZE);
81 for (i = 0; i < FILESIZE; i++)
82 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
83 GNUNET_assert (FILESIZE ==
84 GNUNET_DISK_fn_write (fn1, buf, FILESIZE,
85 GNUNET_DISK_PERM_USER_READ |
86 GNUNET_DISK_PERM_USER_WRITE));
89 fn2 = GNUNET_DISK_mktemp ("gnunet-file_information-test-dst");
90 buf = GNUNET_malloc (FILESIZE);
91 for (i = 0; i < FILESIZE; i++)
92 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
93 GNUNET_assert (FILESIZE ==
94 GNUNET_DISK_fn_write (fn2, buf, FILESIZE,
95 GNUNET_DISK_PERM_USER_READ |
96 GNUNET_DISK_PERM_USER_WRITE));
99 meta = GNUNET_CONTAINER_meta_data_create ();
100 kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords);
101 bo.content_priority = 42;
102 bo.anonymity_level = 1;
103 bo.replication_level = 0;
104 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
106 GNUNET_FS_file_information_create_from_file (fs,
107 "file_information-context1",
108 fn1, kuri, meta, GNUNET_YES,
110 GNUNET_assert (fi1 != NULL);
112 GNUNET_FS_file_information_create_from_file (fs,
113 "file_information-context2",
114 fn2, kuri, meta, GNUNET_YES,
116 GNUNET_assert (fi2 != NULL);
118 GNUNET_FS_file_information_create_empty_directory (fs,
119 "file_information-context-dir",
120 kuri, meta, &bo, NULL);
121 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1));
122 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2));
123 GNUNET_FS_uri_destroy (kuri);
124 GNUNET_CONTAINER_meta_data_destroy (meta);
125 GNUNET_assert (NULL != fidir);
126 /* FIXME: test more of API! */
127 GNUNET_FS_file_information_destroy (fidir, &mycleaner, NULL);
128 GNUNET_DISK_directory_remove (fn1);
129 GNUNET_DISK_directory_remove (fn2);
130 GNUNET_free_non_null (fn1);
131 GNUNET_free_non_null (fn2);
137 main (int argc, char *argv[])
139 char *const argvx[] = {
140 "test-fs-file_information",
142 "test_fs_file_information_data.conf",
145 struct GNUNET_GETOPT_CommandLineOption options[] = {
146 GNUNET_GETOPT_OPTION_END
149 GNUNET_log_setup ("test_fs_file_information",
152 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx,
153 "test-fs-file_information", "nohelp", options, &run,
158 /* end of test_fs_file_information.c */