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.
17 * @file fs/test_fs_file_information.c
18 * @brief simple testcase for file_information operations
19 * @author Christian Grothoff
22 * - test that metatdata, etc. are all correct (for example,
23 * there is a known bug with dirname never being set that is
25 * - need to iterate over file-information structure
26 * - other API functions may not yet be tested (such as
27 * filedata-from-callback)
30 #include "gnunet_util_lib.h"
31 #include "gnunet_fs_service.h"
35 * File-size we use for testing.
37 #define FILESIZE (1024 * 1024 * 2)
40 * How long should our test-content live?
42 #define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
46 mycleaner (void *cls, struct GNUNET_FS_FileInformation *fi, uint64_t length,
47 struct GNUNET_CONTAINER_MetaData *meta, struct GNUNET_FS_Uri **uri,
48 struct GNUNET_FS_BlockOptions *bo, int *do_index, void **client_info)
55 run (void *cls, char *const *args, const char *cfgfile,
56 const struct GNUNET_CONFIGURATION_Handle *cfg)
58 const char *keywords[] = {
65 struct GNUNET_CONTAINER_MetaData *meta;
66 struct GNUNET_FS_Uri *kuri;
67 struct GNUNET_FS_FileInformation *fi1;
68 struct GNUNET_FS_FileInformation *fi2;
69 struct GNUNET_FS_FileInformation *fidir;
70 struct GNUNET_FS_Handle *fs;
72 struct GNUNET_FS_BlockOptions bo;
74 fs = GNUNET_FS_start (cfg, "test-fs-file-information", NULL, NULL,
75 GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
76 fn1 = GNUNET_DISK_mktemp ("gnunet-file_information-test-dst");
77 buf = GNUNET_malloc (FILESIZE);
78 for (i = 0; i < FILESIZE; i++)
79 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
80 GNUNET_assert (FILESIZE ==
81 GNUNET_DISK_fn_write (fn1, buf, FILESIZE,
82 GNUNET_DISK_PERM_USER_READ |
83 GNUNET_DISK_PERM_USER_WRITE));
86 fn2 = GNUNET_DISK_mktemp ("gnunet-file_information-test-dst");
87 buf = GNUNET_malloc (FILESIZE);
88 for (i = 0; i < FILESIZE; i++)
89 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
90 GNUNET_assert (FILESIZE ==
91 GNUNET_DISK_fn_write (fn2, buf, FILESIZE,
92 GNUNET_DISK_PERM_USER_READ |
93 GNUNET_DISK_PERM_USER_WRITE));
96 meta = GNUNET_CONTAINER_meta_data_create ();
97 kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords);
98 bo.content_priority = 42;
99 bo.anonymity_level = 1;
100 bo.replication_level = 0;
101 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
103 GNUNET_FS_file_information_create_from_file (fs,
104 "file_information-context1",
105 fn1, kuri, meta, GNUNET_YES,
107 GNUNET_assert (fi1 != NULL);
109 GNUNET_FS_file_information_create_from_file (fs,
110 "file_information-context2",
111 fn2, kuri, meta, GNUNET_YES,
113 GNUNET_assert (fi2 != NULL);
115 GNUNET_FS_file_information_create_empty_directory (fs,
116 "file_information-context-dir",
117 kuri, meta, &bo, NULL);
118 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1));
119 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2));
120 GNUNET_FS_uri_destroy (kuri);
121 GNUNET_CONTAINER_meta_data_destroy (meta);
122 GNUNET_assert (NULL != fidir);
123 /* FIXME: test more of API! */
124 GNUNET_FS_file_information_destroy (fidir, &mycleaner, NULL);
125 GNUNET_DISK_directory_remove (fn1);
126 GNUNET_DISK_directory_remove (fn2);
127 GNUNET_free_non_null (fn1);
128 GNUNET_free_non_null (fn2);
134 main (int argc, char *argv[])
136 char *const argvx[] = {
137 "test-fs-file_information",
139 "test_fs_file_information_data.conf",
142 struct GNUNET_GETOPT_CommandLineOption options[] = {
143 GNUNET_GETOPT_OPTION_END
146 GNUNET_log_setup ("test_fs_file_information",
149 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx,
150 "test-fs-file_information", "nohelp", options, &run,
155 /* end of test_fs_file_information.c */