diff options
Diffstat (limited to 'src/fs/test_fs_directory.c')
-rw-r--r-- | src/fs/test_fs_directory.c | 170 |
1 files changed, 86 insertions, 84 deletions
diff --git a/src/fs/test_fs_directory.c b/src/fs/test_fs_directory.c index 936c3bed4..37d74613a 100644 --- a/src/fs/test_fs_directory.c +++ b/src/fs/test_fs_directory.c | |||
@@ -30,9 +30,11 @@ | |||
30 | #include "gnunet_fs_service.h" | 30 | #include "gnunet_fs_service.h" |
31 | #include "fs_api.h" | 31 | #include "fs_api.h" |
32 | 32 | ||
33 | #define ABORT() { fprintf(stderr, "Error at %s:%d\n", __FILE__, __LINE__); return 1; } | 33 | #define ABORT() { fprintf (stderr, "Error at %s:%d\n", __FILE__, __LINE__); \ |
34 | return 1; } | ||
34 | 35 | ||
35 | struct PCLS { | 36 | struct PCLS |
37 | { | ||
36 | struct GNUNET_FS_Uri **uri; | 38 | struct GNUNET_FS_Uri **uri; |
37 | struct GNUNET_CONTAINER_MetaData **md; | 39 | struct GNUNET_CONTAINER_MetaData **md; |
38 | unsigned int pos; | 40 | unsigned int pos; |
@@ -40,9 +42,9 @@ struct PCLS { | |||
40 | }; | 42 | }; |
41 | 43 | ||
42 | static void | 44 | static void |
43 | processor(void *cls, const char *filename, const struct GNUNET_FS_Uri *uri, | 45 | processor (void *cls, const char *filename, const struct GNUNET_FS_Uri *uri, |
44 | const struct GNUNET_CONTAINER_MetaData *md, size_t length, | 46 | const struct GNUNET_CONTAINER_MetaData *md, size_t length, |
45 | const void *data) | 47 | const void *data) |
46 | { | 48 | { |
47 | struct PCLS *p = cls; | 49 | struct PCLS *p = cls; |
48 | int i; | 50 | int i; |
@@ -50,19 +52,19 @@ processor(void *cls, const char *filename, const struct GNUNET_FS_Uri *uri, | |||
50 | if (NULL == uri) | 52 | if (NULL == uri) |
51 | return; /* ignore directory's meta data */ | 53 | return; /* ignore directory's meta data */ |
52 | for (i = 0; i < p->max; i++) | 54 | for (i = 0; i < p->max; i++) |
55 | { | ||
56 | if (GNUNET_CONTAINER_meta_data_test_equal (p->md[i], md) && | ||
57 | GNUNET_FS_uri_test_equal (p->uri[i], uri)) | ||
53 | { | 58 | { |
54 | if (GNUNET_CONTAINER_meta_data_test_equal(p->md[i], md) && | 59 | p->pos++; |
55 | GNUNET_FS_uri_test_equal(p->uri[i], uri)) | 60 | return; |
56 | { | ||
57 | p->pos++; | ||
58 | return; | ||
59 | } | ||
60 | } | 61 | } |
61 | fprintf(stderr, "Error at %s:%d\n", __FILE__, __LINE__); | 62 | } |
63 | fprintf (stderr, "Error at %s:%d\n", __FILE__, __LINE__); | ||
62 | } | 64 | } |
63 | 65 | ||
64 | static int | 66 | static int |
65 | testDirectory(unsigned int i) | 67 | testDirectory (unsigned int i) |
66 | { | 68 | { |
67 | struct GNUNET_FS_DirectoryBuilder *db; | 69 | struct GNUNET_FS_DirectoryBuilder *db; |
68 | char *data; | 70 | char *data; |
@@ -81,99 +83,99 @@ testDirectory(unsigned int i) | |||
81 | const char *s; | 83 | const char *s; |
82 | 84 | ||
83 | cls.max = i; | 85 | cls.max = i; |
84 | uris = GNUNET_malloc(sizeof(struct GNUNET_FS_Uri *) * i); | 86 | uris = GNUNET_malloc (sizeof(struct GNUNET_FS_Uri *) * i); |
85 | mds = GNUNET_malloc(sizeof(struct GNUNET_CONTAINER_MetaData *) * i); | 87 | mds = GNUNET_malloc (sizeof(struct GNUNET_CONTAINER_MetaData *) * i); |
86 | meta = GNUNET_CONTAINER_meta_data_create(); | 88 | meta = GNUNET_CONTAINER_meta_data_create (); |
87 | GNUNET_CONTAINER_meta_data_insert(meta, "<test>", EXTRACTOR_METATYPE_TITLE, | 89 | GNUNET_CONTAINER_meta_data_insert (meta, "<test>", EXTRACTOR_METATYPE_TITLE, |
88 | EXTRACTOR_METAFORMAT_UTF8, "text/plain", | 90 | EXTRACTOR_METAFORMAT_UTF8, "text/plain", |
89 | "A title", strlen("A title") + 1); | 91 | "A title", strlen ("A title") + 1); |
90 | GNUNET_CONTAINER_meta_data_insert(meta, "<test>", | 92 | GNUNET_CONTAINER_meta_data_insert (meta, "<test>", |
91 | EXTRACTOR_METATYPE_AUTHOR_NAME, | 93 | EXTRACTOR_METATYPE_AUTHOR_NAME, |
92 | EXTRACTOR_METAFORMAT_UTF8, "text/plain", | 94 | EXTRACTOR_METAFORMAT_UTF8, "text/plain", |
93 | "An author", strlen("An author") + 1); | 95 | "An author", strlen ("An author") + 1); |
94 | for (p = 0; p < i; p++) | 96 | for (p = 0; p < i; p++) |
97 | { | ||
98 | mds[p] = GNUNET_CONTAINER_meta_data_create (); | ||
99 | for (q = 0; q <= p; q++) | ||
95 | { | 100 | { |
96 | mds[p] = GNUNET_CONTAINER_meta_data_create(); | 101 | GNUNET_snprintf (txt, sizeof(txt), "%u -- %u\n", p, q); |
97 | for (q = 0; q <= p; q++) | 102 | GNUNET_CONTAINER_meta_data_insert (mds[p], "<test>", |
98 | { | ||
99 | GNUNET_snprintf(txt, sizeof(txt), "%u -- %u\n", p, q); | ||
100 | GNUNET_CONTAINER_meta_data_insert(mds[p], "<test>", | ||
101 | #if HAVE_EXTRACTOR_H && HAVE_LIBEXTRACTOR | 103 | #if HAVE_EXTRACTOR_H && HAVE_LIBEXTRACTOR |
102 | q % EXTRACTOR_metatype_get_max(), | 104 | q % EXTRACTOR_metatype_get_max (), |
103 | #else | 105 | #else |
104 | q % 128, | 106 | q % 128, |
105 | #endif | 107 | #endif |
106 | EXTRACTOR_METAFORMAT_UTF8, | 108 | EXTRACTOR_METAFORMAT_UTF8, |
107 | "text/plain", txt, strlen(txt) + 1); | 109 | "text/plain", txt, strlen (txt) + 1); |
108 | } | ||
109 | GNUNET_snprintf(uri, sizeof(uri), | ||
110 | "gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.%u", | ||
111 | p); | ||
112 | emsg = NULL; | ||
113 | uris[p] = GNUNET_FS_uri_parse(uri, &emsg); | ||
114 | if (uris[p] == NULL) | ||
115 | { | ||
116 | GNUNET_CONTAINER_meta_data_destroy(mds[p]); | ||
117 | while (--p > 0) | ||
118 | { | ||
119 | GNUNET_CONTAINER_meta_data_destroy(mds[p]); | ||
120 | GNUNET_FS_uri_destroy(uris[p]); | ||
121 | } | ||
122 | GNUNET_free(mds); | ||
123 | GNUNET_free(uris); | ||
124 | GNUNET_free(emsg); | ||
125 | GNUNET_CONTAINER_meta_data_destroy(meta); | ||
126 | ABORT(); /* error in testcase */ | ||
127 | } | ||
128 | GNUNET_assert(emsg == NULL); | ||
129 | } | 110 | } |
130 | start = GNUNET_TIME_absolute_get(); | 111 | GNUNET_snprintf (uri, sizeof(uri), |
131 | db = GNUNET_FS_directory_builder_create(meta); | 112 | "gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.%u", |
132 | for (p = 0; p < i; p++) | 113 | p); |
133 | GNUNET_FS_directory_builder_add(db, uris[p], mds[p], NULL); | 114 | emsg = NULL; |
134 | GNUNET_FS_directory_builder_finish(db, &dlen, (void **)&data); | 115 | uris[p] = GNUNET_FS_uri_parse (uri, &emsg); |
135 | s = GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_duration | 116 | if (uris[p] == NULL) |
136 | (start), | ||
137 | GNUNET_YES); | ||
138 | fprintf(stdout, | ||
139 | "Creating directory with %u entires and total size %llu took %s\n", | ||
140 | i, (unsigned long long)dlen, s); | ||
141 | if (i < 100) | ||
142 | { | 117 | { |
143 | cls.pos = 0; | 118 | GNUNET_CONTAINER_meta_data_destroy (mds[p]); |
144 | cls.uri = uris; | 119 | while (--p > 0) |
145 | cls.md = mds; | 120 | { |
146 | GNUNET_FS_directory_list_contents(dlen, data, 0, &processor, &cls); | 121 | GNUNET_CONTAINER_meta_data_destroy (mds[p]); |
147 | GNUNET_assert(cls.pos == i); | 122 | GNUNET_FS_uri_destroy (uris[p]); |
123 | } | ||
124 | GNUNET_free (mds); | ||
125 | GNUNET_free (uris); | ||
126 | GNUNET_free (emsg); | ||
127 | GNUNET_CONTAINER_meta_data_destroy (meta); | ||
128 | ABORT (); /* error in testcase */ | ||
148 | } | 129 | } |
149 | GNUNET_free(data); | 130 | GNUNET_assert (emsg == NULL); |
150 | GNUNET_CONTAINER_meta_data_destroy(meta); | 131 | } |
132 | start = GNUNET_TIME_absolute_get (); | ||
133 | db = GNUNET_FS_directory_builder_create (meta); | ||
151 | for (p = 0; p < i; p++) | 134 | for (p = 0; p < i; p++) |
152 | { | 135 | GNUNET_FS_directory_builder_add (db, uris[p], mds[p], NULL); |
153 | GNUNET_CONTAINER_meta_data_destroy(mds[p]); | 136 | GNUNET_FS_directory_builder_finish (db, &dlen, (void **) &data); |
154 | GNUNET_FS_uri_destroy(uris[p]); | 137 | s = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration |
155 | } | 138 | (start), |
156 | GNUNET_free(uris); | 139 | GNUNET_YES); |
157 | GNUNET_free(mds); | 140 | fprintf (stdout, |
141 | "Creating directory with %u entires and total size %llu took %s\n", | ||
142 | i, (unsigned long long) dlen, s); | ||
143 | if (i < 100) | ||
144 | { | ||
145 | cls.pos = 0; | ||
146 | cls.uri = uris; | ||
147 | cls.md = mds; | ||
148 | GNUNET_FS_directory_list_contents (dlen, data, 0, &processor, &cls); | ||
149 | GNUNET_assert (cls.pos == i); | ||
150 | } | ||
151 | GNUNET_free (data); | ||
152 | GNUNET_CONTAINER_meta_data_destroy (meta); | ||
153 | for (p = 0; p < i; p++) | ||
154 | { | ||
155 | GNUNET_CONTAINER_meta_data_destroy (mds[p]); | ||
156 | GNUNET_FS_uri_destroy (uris[p]); | ||
157 | } | ||
158 | GNUNET_free (uris); | ||
159 | GNUNET_free (mds); | ||
158 | return ret; | 160 | return ret; |
159 | } | 161 | } |
160 | 162 | ||
161 | 163 | ||
162 | int | 164 | int |
163 | main(int argc, char *argv[]) | 165 | main (int argc, char *argv[]) |
164 | { | 166 | { |
165 | int failureCount = 0; | 167 | int failureCount = 0; |
166 | int i; | 168 | int i; |
167 | 169 | ||
168 | GNUNET_log_setup("test_fs_directory", | 170 | GNUNET_log_setup ("test_fs_directory", |
169 | #if VERBOSE | 171 | #if VERBOSE |
170 | "DEBUG", | 172 | "DEBUG", |
171 | #else | 173 | #else |
172 | "WARNING", | 174 | "WARNING", |
173 | #endif | 175 | #endif |
174 | NULL); | 176 | NULL); |
175 | for (i = 17; i < 1000; i *= 2) | 177 | for (i = 17; i < 1000; i *= 2) |
176 | failureCount += testDirectory(i); | 178 | failureCount += testDirectory (i); |
177 | if (failureCount != 0) | 179 | if (failureCount != 0) |
178 | return 1; | 180 | return 1; |
179 | return 0; | 181 | return 0; |