aboutsummaryrefslogtreecommitdiff
path: root/src/fs/test_fs_file_information.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/test_fs_file_information.c')
-rw-r--r--src/fs/test_fs_file_information.c124
1 files changed, 62 insertions, 62 deletions
diff --git a/src/fs/test_fs_file_information.c b/src/fs/test_fs_file_information.c
index 06682043a..1f008997f 100644
--- a/src/fs/test_fs_file_information.c
+++ b/src/fs/test_fs_file_information.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file fs/test_fs_file_information.c 22 * @file fs/test_fs_file_information.c
@@ -44,21 +44,21 @@
44/** 44/**
45 * How long should our test-content live? 45 * How long should our test-content live?
46 */ 46 */
47#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) 47#define LIFETIME GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 15)
48 48
49 49
50static int 50static int
51mycleaner (void *cls, struct GNUNET_FS_FileInformation *fi, uint64_t length, 51mycleaner(void *cls, struct GNUNET_FS_FileInformation *fi, uint64_t length,
52 struct GNUNET_CONTAINER_MetaData *meta, struct GNUNET_FS_Uri **uri, 52 struct GNUNET_CONTAINER_MetaData *meta, struct GNUNET_FS_Uri **uri,
53 struct GNUNET_FS_BlockOptions *bo, int *do_index, void **client_info) 53 struct GNUNET_FS_BlockOptions *bo, int *do_index, void **client_info)
54{ 54{
55 return GNUNET_OK; 55 return GNUNET_OK;
56} 56}
57 57
58 58
59static void 59static void
60run (void *cls, char *const *args, const char *cfgfile, 60run(void *cls, char *const *args, const char *cfgfile,
61 const struct GNUNET_CONFIGURATION_Handle *cfg) 61 const struct GNUNET_CONFIGURATION_Handle *cfg)
62{ 62{
63 const char *keywords[] = { 63 const char *keywords[] = {
64 "down_foo", 64 "down_foo",
@@ -76,67 +76,67 @@ run (void *cls, char *const *args, const char *cfgfile,
76 size_t i; 76 size_t i;
77 struct GNUNET_FS_BlockOptions bo; 77 struct GNUNET_FS_BlockOptions bo;
78 78
79 fs = GNUNET_FS_start (cfg, "test-fs-file-information", NULL, NULL, 79 fs = GNUNET_FS_start(cfg, "test-fs-file-information", NULL, NULL,
80 GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); 80 GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
81 fn1 = GNUNET_DISK_mktemp ("gnunet-file_information-test-dst"); 81 fn1 = GNUNET_DISK_mktemp("gnunet-file_information-test-dst");
82 buf = GNUNET_malloc (FILESIZE); 82 buf = GNUNET_malloc(FILESIZE);
83 for (i = 0; i < FILESIZE; i++) 83 for (i = 0; i < FILESIZE; i++)
84 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); 84 buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256);
85 GNUNET_assert (FILESIZE == 85 GNUNET_assert(FILESIZE ==
86 GNUNET_DISK_fn_write (fn1, buf, FILESIZE, 86 GNUNET_DISK_fn_write(fn1, buf, FILESIZE,
87 GNUNET_DISK_PERM_USER_READ | 87 GNUNET_DISK_PERM_USER_READ |
88 GNUNET_DISK_PERM_USER_WRITE)); 88 GNUNET_DISK_PERM_USER_WRITE));
89 GNUNET_free (buf); 89 GNUNET_free(buf);
90 90
91 fn2 = GNUNET_DISK_mktemp ("gnunet-file_information-test-dst"); 91 fn2 = GNUNET_DISK_mktemp("gnunet-file_information-test-dst");
92 buf = GNUNET_malloc (FILESIZE); 92 buf = GNUNET_malloc(FILESIZE);
93 for (i = 0; i < FILESIZE; i++) 93 for (i = 0; i < FILESIZE; i++)
94 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); 94 buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256);
95 GNUNET_assert (FILESIZE == 95 GNUNET_assert(FILESIZE ==
96 GNUNET_DISK_fn_write (fn2, buf, FILESIZE, 96 GNUNET_DISK_fn_write(fn2, buf, FILESIZE,
97 GNUNET_DISK_PERM_USER_READ | 97 GNUNET_DISK_PERM_USER_READ |
98 GNUNET_DISK_PERM_USER_WRITE)); 98 GNUNET_DISK_PERM_USER_WRITE));
99 GNUNET_free (buf); 99 GNUNET_free(buf);
100 100
101 meta = GNUNET_CONTAINER_meta_data_create (); 101 meta = GNUNET_CONTAINER_meta_data_create();
102 kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords); 102 kuri = GNUNET_FS_uri_ksk_create_from_args(2, keywords);
103 bo.content_priority = 42; 103 bo.content_priority = 42;
104 bo.anonymity_level = 1; 104 bo.anonymity_level = 1;
105 bo.replication_level = 0; 105 bo.replication_level = 0;
106 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); 106 bo.expiration_time = GNUNET_TIME_relative_to_absolute(LIFETIME);
107 fi1 = 107 fi1 =
108 GNUNET_FS_file_information_create_from_file (fs, 108 GNUNET_FS_file_information_create_from_file(fs,
109 "file_information-context1", 109 "file_information-context1",
110 fn1, kuri, meta, GNUNET_YES, 110 fn1, kuri, meta, GNUNET_YES,
111 &bo); 111 &bo);
112 GNUNET_assert (fi1 != NULL); 112 GNUNET_assert(fi1 != NULL);
113 fi2 = 113 fi2 =
114 GNUNET_FS_file_information_create_from_file (fs, 114 GNUNET_FS_file_information_create_from_file(fs,
115 "file_information-context2", 115 "file_information-context2",
116 fn2, kuri, meta, GNUNET_YES, 116 fn2, kuri, meta, GNUNET_YES,
117 &bo); 117 &bo);
118 GNUNET_assert (fi2 != NULL); 118 GNUNET_assert(fi2 != NULL);
119 fidir = 119 fidir =
120 GNUNET_FS_file_information_create_empty_directory (fs, 120 GNUNET_FS_file_information_create_empty_directory(fs,
121 "file_information-context-dir", 121 "file_information-context-dir",
122 kuri, meta, &bo, NULL); 122 kuri, meta, &bo, NULL);
123 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1)); 123 GNUNET_assert(GNUNET_OK == GNUNET_FS_file_information_add(fidir, fi1));
124 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2)); 124 GNUNET_assert(GNUNET_OK == GNUNET_FS_file_information_add(fidir, fi2));
125 GNUNET_FS_uri_destroy (kuri); 125 GNUNET_FS_uri_destroy(kuri);
126 GNUNET_CONTAINER_meta_data_destroy (meta); 126 GNUNET_CONTAINER_meta_data_destroy(meta);
127 GNUNET_assert (NULL != fidir); 127 GNUNET_assert(NULL != fidir);
128 /* FIXME: test more of API! */ 128 /* FIXME: test more of API! */
129 GNUNET_FS_file_information_destroy (fidir, &mycleaner, NULL); 129 GNUNET_FS_file_information_destroy(fidir, &mycleaner, NULL);
130 GNUNET_DISK_directory_remove (fn1); 130 GNUNET_DISK_directory_remove(fn1);
131 GNUNET_DISK_directory_remove (fn2); 131 GNUNET_DISK_directory_remove(fn2);
132 GNUNET_free_non_null (fn1); 132 GNUNET_free_non_null(fn1);
133 GNUNET_free_non_null (fn2); 133 GNUNET_free_non_null(fn2);
134 GNUNET_FS_stop (fs); 134 GNUNET_FS_stop(fs);
135} 135}
136 136
137 137
138int 138int
139main (int argc, char *argv[]) 139main(int argc, char *argv[])
140{ 140{
141 char *const argvx[] = { 141 char *const argvx[] = {
142 "test-fs-file_information", 142 "test-fs-file_information",
@@ -148,12 +148,12 @@ main (int argc, char *argv[])
148 GNUNET_GETOPT_OPTION_END 148 GNUNET_GETOPT_OPTION_END
149 }; 149 };
150 150
151 GNUNET_log_setup ("test_fs_file_information", 151 GNUNET_log_setup("test_fs_file_information",
152 "WARNING", 152 "WARNING",
153 NULL); 153 NULL);
154 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx, 154 GNUNET_PROGRAM_run((sizeof(argvx) / sizeof(char *)) - 1, argvx,
155 "test-fs-file_information", "nohelp", options, &run, 155 "test-fs-file_information", "nohelp", options, &run,
156 NULL); 156 NULL);
157 return 0; 157 return 0;
158} 158}
159 159