diff options
Diffstat (limited to 'src/fs/test_fs_file_information.c')
-rw-r--r-- | src/fs/test_fs_file_information.c | 163 |
1 files changed, 0 insertions, 163 deletions
diff --git a/src/fs/test_fs_file_information.c b/src/fs/test_fs_file_information.c deleted file mode 100644 index 22013db27..000000000 --- a/src/fs/test_fs_file_information.c +++ /dev/null | |||
@@ -1,163 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2004, 2005, 2006, 2008, 2009 GNUnet e.V. | ||
4 | |||
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. | ||
9 | |||
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. | ||
14 | |||
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/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file fs/test_fs_file_information.c | ||
23 | * @brief simple testcase for file_information operations | ||
24 | * @author Christian Grothoff | ||
25 | * | ||
26 | * TODO: | ||
27 | * - test that metadata, etc. are all correct (for example, | ||
28 | * there is a known bug with dirname never being set that is | ||
29 | * not detected!) | ||
30 | * - need to iterate over file-information structure | ||
31 | * - other API functions may not yet be tested (such as | ||
32 | * filedata-from-callback) | ||
33 | */ | ||
34 | #include "platform.h" | ||
35 | #include "gnunet_util_lib.h" | ||
36 | #include "gnunet_fs_service.h" | ||
37 | |||
38 | |||
39 | /** | ||
40 | * File-size we use for testing. | ||
41 | */ | ||
42 | #define FILESIZE (1024 * 1024 * 2) | ||
43 | |||
44 | /** | ||
45 | * How long should our test-content live? | ||
46 | */ | ||
47 | #define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) | ||
48 | |||
49 | |||
50 | static int | ||
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) | ||
54 | { | ||
55 | return GNUNET_OK; | ||
56 | } | ||
57 | |||
58 | |||
59 | static void | ||
60 | run (void *cls, char *const *args, const char *cfgfile, | ||
61 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
62 | { | ||
63 | const char *keywords[] = { | ||
64 | "down_foo", | ||
65 | "down_bar", | ||
66 | }; | ||
67 | char *fn1; | ||
68 | char *fn2; | ||
69 | char *buf; | ||
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; | ||
76 | size_t i; | ||
77 | struct GNUNET_FS_BlockOptions bo; | ||
78 | |||
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 | (void) GNUNET_DISK_directory_remove (fn1); | ||
86 | GNUNET_assert (GNUNET_OK == | ||
87 | GNUNET_DISK_fn_write (fn1, buf, FILESIZE, | ||
88 | GNUNET_DISK_PERM_USER_READ | ||
89 | | GNUNET_DISK_PERM_USER_WRITE)); | ||
90 | GNUNET_free (buf); | ||
91 | |||
92 | fn2 = GNUNET_DISK_mktemp ("gnunet-file_information-test-dst"); | ||
93 | buf = GNUNET_malloc (FILESIZE); | ||
94 | for (i = 0; i < FILESIZE; i++) | ||
95 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); | ||
96 | (void) GNUNET_DISK_directory_remove (fn2); | ||
97 | GNUNET_assert (GNUNET_OK == | ||
98 | GNUNET_DISK_fn_write (fn2, buf, FILESIZE, | ||
99 | GNUNET_DISK_PERM_USER_READ | ||
100 | | GNUNET_DISK_PERM_USER_WRITE)); | ||
101 | GNUNET_free (buf); | ||
102 | |||
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); | ||
109 | fi1 = | ||
110 | GNUNET_FS_file_information_create_from_file (fs, | ||
111 | "file_information-context1", | ||
112 | fn1, kuri, meta, GNUNET_YES, | ||
113 | &bo); | ||
114 | GNUNET_assert (fi1 != NULL); | ||
115 | fi2 = | ||
116 | GNUNET_FS_file_information_create_from_file (fs, | ||
117 | "file_information-context2", | ||
118 | fn2, kuri, meta, GNUNET_YES, | ||
119 | &bo); | ||
120 | GNUNET_assert (fi2 != NULL); | ||
121 | fidir = | ||
122 | GNUNET_FS_file_information_create_empty_directory (fs, | ||
123 | "file_information-context-dir", | ||
124 | kuri, meta, &bo, NULL); | ||
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 (fn1); | ||
135 | GNUNET_free (fn2); | ||
136 | GNUNET_FS_stop (fs); | ||
137 | } | ||
138 | |||
139 | |||
140 | int | ||
141 | main (int argc, char *argv[]) | ||
142 | { | ||
143 | char *const argvx[] = { | ||
144 | "test-fs-file_information", | ||
145 | "-c", | ||
146 | "test_fs_file_information_data.conf", | ||
147 | NULL | ||
148 | }; | ||
149 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
150 | GNUNET_GETOPT_OPTION_END | ||
151 | }; | ||
152 | |||
153 | GNUNET_log_setup ("test_fs_file_information", | ||
154 | "WARNING", | ||
155 | NULL); | ||
156 | GNUNET_PROGRAM_run ((sizeof(argvx) / sizeof(char *)) - 1, argvx, | ||
157 | "test-fs-file_information", "nohelp", options, &run, | ||
158 | NULL); | ||
159 | return 0; | ||
160 | } | ||
161 | |||
162 | |||
163 | /* end of test_fs_file_information.c */ | ||