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
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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, 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)
35 #include "gnunet_util_lib.h"
36 #include "gnunet_fs_service.h"
40 * File-size we use for testing.
42 #define FILESIZE (1024 * 1024 * 2)
45 * How long should our test-content live?
47 #define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
51 mycleaner (void *cls, struct GNUNET_FS_FileInformation *fi, uint64_t length,
52 struct GNUNET_CONTAINER_MetaData *meta, struct GNUNET_FS_Uri **uri,
53 struct GNUNET_FS_BlockOptions *bo, int *do_index, void **client_info)
60 run (void *cls, char *const *args, const char *cfgfile,
61 const struct GNUNET_CONFIGURATION_Handle *cfg)
63 const char *keywords[] = {
70 struct GNUNET_CONTAINER_MetaData *meta;
71 struct GNUNET_FS_Uri *kuri;
72 struct GNUNET_FS_FileInformation *fi1;
73 struct GNUNET_FS_FileInformation *fi2;
74 struct GNUNET_FS_FileInformation *fidir;
75 struct GNUNET_FS_Handle *fs;
77 struct GNUNET_FS_BlockOptions bo;
79 fs = GNUNET_FS_start (cfg, "test-fs-file-information", NULL, NULL,
80 GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
81 fn1 = GNUNET_DISK_mktemp ("gnunet-file_information-test-dst");
82 buf = GNUNET_malloc (FILESIZE);
83 for (i = 0; i < FILESIZE; i++)
84 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
85 GNUNET_assert (FILESIZE ==
86 GNUNET_DISK_fn_write (fn1, buf, FILESIZE,
87 GNUNET_DISK_PERM_USER_READ |
88 GNUNET_DISK_PERM_USER_WRITE));
91 fn2 = 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 (fn2, buf, FILESIZE,
97 GNUNET_DISK_PERM_USER_READ |
98 GNUNET_DISK_PERM_USER_WRITE));
101 meta = GNUNET_CONTAINER_meta_data_create ();
102 kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords);
103 bo.content_priority = 42;
104 bo.anonymity_level = 1;
105 bo.replication_level = 0;
106 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
108 GNUNET_FS_file_information_create_from_file (fs,
109 "file_information-context1",
110 fn1, kuri, meta, GNUNET_YES,
112 GNUNET_assert (fi1 != NULL);
114 GNUNET_FS_file_information_create_from_file (fs,
115 "file_information-context2",
116 fn2, kuri, meta, GNUNET_YES,
118 GNUNET_assert (fi2 != NULL);
120 GNUNET_FS_file_information_create_empty_directory (fs,
121 "file_information-context-dir",
122 kuri, meta, &bo, NULL);
123 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1));
124 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2));
125 GNUNET_FS_uri_destroy (kuri);
126 GNUNET_CONTAINER_meta_data_destroy (meta);
127 GNUNET_assert (NULL != fidir);
128 /* FIXME: test more of API! */
129 GNUNET_FS_file_information_destroy (fidir, &mycleaner, NULL);
130 GNUNET_DISK_directory_remove (fn1);
131 GNUNET_DISK_directory_remove (fn2);
132 GNUNET_free_non_null (fn1);
133 GNUNET_free_non_null (fn2);
139 main (int argc, char *argv[])
141 char *const argvx[] = {
142 "test-fs-file_information",
144 "test_fs_file_information_data.conf",
147 struct GNUNET_GETOPT_CommandLineOption options[] = {
148 GNUNET_GETOPT_OPTION_END
151 GNUNET_log_setup ("test_fs_file_information",
154 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx,
155 "test-fs-file_information", "nohelp", options, &run,
160 /* end of test_fs_file_information.c */