cannam@226
|
1 /*
|
cannam@226
|
2 Copyright 2011-2016 David Robillard <http://drobilla.net>
|
cannam@226
|
3
|
cannam@226
|
4 Permission to use, copy, modify, and/or distribute this software for any
|
cannam@226
|
5 purpose with or without fee is hereby granted, provided that the above
|
cannam@226
|
6 copyright notice and this permission notice appear in all copies.
|
cannam@226
|
7
|
cannam@226
|
8 THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
cannam@226
|
9 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
cannam@226
|
10 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
cannam@226
|
11 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
cannam@226
|
12 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
cannam@226
|
13 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
cannam@226
|
14 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
cannam@226
|
15 */
|
cannam@226
|
16
|
cannam@226
|
17 #include <stdarg.h>
|
cannam@226
|
18 #include <stdio.h>
|
cannam@226
|
19 #include <stdlib.h>
|
cannam@226
|
20 #include <string.h>
|
cannam@226
|
21
|
cannam@226
|
22 #include "sord/sord.h"
|
cannam@226
|
23
|
cannam@226
|
24 static const int DIGITS = 3;
|
cannam@226
|
25 static const unsigned n_objects_per = 2;
|
cannam@226
|
26
|
cannam@226
|
27 static int n_expected_errors = 0;
|
cannam@226
|
28
|
cannam@226
|
29 typedef struct {
|
cannam@226
|
30 SordQuad query;
|
cannam@226
|
31 int expected_num_results;
|
cannam@226
|
32 } QueryTest;
|
cannam@226
|
33
|
cannam@226
|
34 #define USTR(s) ((const uint8_t*)(s))
|
cannam@226
|
35
|
cannam@226
|
36 static SordNode*
|
cannam@226
|
37 uri(SordWorld* world, int num)
|
cannam@226
|
38 {
|
cannam@226
|
39 if (num == 0)
|
cannam@226
|
40 return 0;
|
cannam@226
|
41
|
cannam@226
|
42 char str[] = "eg:000";
|
cannam@226
|
43 char* uri_num = str + 3; // First `0'
|
cannam@226
|
44 snprintf(uri_num, DIGITS + 1, "%0*d", DIGITS, num);
|
cannam@226
|
45 return sord_new_uri(world, (const uint8_t*)str);
|
cannam@226
|
46 }
|
cannam@226
|
47
|
cannam@226
|
48 static int
|
cannam@226
|
49 test_fail(const char* fmt, ...)
|
cannam@226
|
50 {
|
cannam@226
|
51 va_list args;
|
cannam@226
|
52 va_start(args, fmt);
|
cannam@226
|
53 fprintf(stderr, "error: ");
|
cannam@226
|
54 vfprintf(stderr, fmt, args);
|
cannam@226
|
55 va_end(args);
|
cannam@226
|
56 return 1;
|
cannam@226
|
57 }
|
cannam@226
|
58
|
cannam@226
|
59 static int
|
cannam@226
|
60 generate(SordWorld* world,
|
cannam@226
|
61 SordModel* sord,
|
cannam@226
|
62 size_t n_quads,
|
cannam@226
|
63 SordNode* graph)
|
cannam@226
|
64 {
|
cannam@226
|
65 fprintf(stderr, "Generating %zu (S P *) quads with %u objects each\n",
|
cannam@226
|
66 n_quads, n_objects_per);
|
cannam@226
|
67
|
cannam@226
|
68 for (size_t i = 0; i < n_quads; ++i) {
|
cannam@226
|
69 int num = (i * n_objects_per) + 1;
|
cannam@226
|
70
|
cannam@226
|
71 SordNode* ids[2 + n_objects_per];
|
cannam@226
|
72 for (unsigned j = 0; j < 2 + n_objects_per; ++j) {
|
cannam@226
|
73 ids[j] = uri(world, num++);
|
cannam@226
|
74 }
|
cannam@226
|
75
|
cannam@226
|
76 for (unsigned j = 0; j < n_objects_per; ++j) {
|
cannam@226
|
77 SordQuad tup = { ids[0], ids[1], ids[2 + j], graph };
|
cannam@226
|
78 if (!sord_add(sord, tup)) {
|
cannam@226
|
79 return test_fail("Fail: Failed to add quad\n");
|
cannam@226
|
80 }
|
cannam@226
|
81 }
|
cannam@226
|
82
|
cannam@226
|
83 for (unsigned j = 0; j < 2 + n_objects_per; ++j) {
|
cannam@226
|
84 sord_node_free(world, ids[j]);
|
cannam@226
|
85 }
|
cannam@226
|
86 }
|
cannam@226
|
87
|
cannam@226
|
88 // Add some literals
|
cannam@226
|
89
|
cannam@226
|
90 // (98 4 "hello") and (98 4 "hello"^^<5>)
|
cannam@226
|
91 SordQuad tup = { 0, 0, 0, 0 };
|
cannam@226
|
92 tup[0] = uri(world, 98);
|
cannam@226
|
93 tup[1] = uri(world, 4);
|
cannam@226
|
94 tup[2] = sord_new_literal(world, 0, USTR("hello"), NULL);
|
cannam@226
|
95 tup[3] = graph;
|
cannam@226
|
96 sord_add(sord, tup);
|
cannam@226
|
97 sord_node_free(world, (SordNode*)tup[2]);
|
cannam@226
|
98 tup[2] = sord_new_literal(world, uri(world, 5), USTR("hello"), NULL);
|
cannam@226
|
99 if (!sord_add(sord, tup)) {
|
cannam@226
|
100 return test_fail("Failed to add typed literal\n");
|
cannam@226
|
101 }
|
cannam@226
|
102
|
cannam@226
|
103 // (96 4 "hello"^^<4>) and (96 4 "hello"^^<5>)
|
cannam@226
|
104 tup[0] = uri(world, 96);
|
cannam@226
|
105 tup[1] = uri(world, 4);
|
cannam@226
|
106 tup[2] = sord_new_literal(world, uri(world, 4), USTR("hello"), NULL);
|
cannam@226
|
107 tup[3] = graph;
|
cannam@226
|
108 sord_add(sord, tup);
|
cannam@226
|
109 sord_node_free(world, (SordNode*)tup[2]);
|
cannam@226
|
110 tup[2] = sord_new_literal(world, uri(world, 5), USTR("hello"), NULL);
|
cannam@226
|
111 if (!sord_add(sord, tup)) {
|
cannam@226
|
112 return test_fail("Failed to add typed literal\n");
|
cannam@226
|
113 }
|
cannam@226
|
114
|
cannam@226
|
115 // (94 5 "hello") and (94 5 "hello"@en-gb)
|
cannam@226
|
116 tup[0] = uri(world, 94);
|
cannam@226
|
117 tup[1] = uri(world, 5);
|
cannam@226
|
118 tup[2] = sord_new_literal(world, 0, USTR("hello"), NULL);
|
cannam@226
|
119 tup[3] = graph;
|
cannam@226
|
120 sord_add(sord, tup);
|
cannam@226
|
121 sord_node_free(world, (SordNode*)tup[2]);
|
cannam@226
|
122 tup[2] = sord_new_literal(world, NULL, USTR("hello"), "en-gb");
|
cannam@226
|
123 if (!sord_add(sord, tup)) {
|
cannam@226
|
124 return test_fail("Failed to add literal with language\n");
|
cannam@226
|
125 }
|
cannam@226
|
126
|
cannam@226
|
127 // (92 6 "hello"@en-us) and (92 5 "hello"@en-gb)
|
cannam@226
|
128 tup[0] = uri(world, 92);
|
cannam@226
|
129 tup[1] = uri(world, 6);
|
cannam@226
|
130 tup[2] = sord_new_literal(world, 0, USTR("hello"), "en-us");
|
cannam@226
|
131 tup[3] = graph;
|
cannam@226
|
132 sord_add(sord, tup);
|
cannam@226
|
133 sord_node_free(world, (SordNode*)tup[2]);
|
cannam@226
|
134 tup[2] = sord_new_literal(world, NULL, USTR("hello"), "en-gb");
|
cannam@226
|
135 if (!sord_add(sord, tup)) {
|
cannam@226
|
136 return test_fail("Failed to add literal with language\n");
|
cannam@226
|
137 }
|
cannam@226
|
138
|
cannam@226
|
139 sord_node_free(world, (SordNode*)tup[0]);
|
cannam@226
|
140 sord_node_free(world, (SordNode*)tup[2]);
|
cannam@226
|
141 tup[0] = uri(world, 14);
|
cannam@226
|
142 tup[2] = sord_new_literal(world, 0, USTR("bonjour"), "fr");
|
cannam@226
|
143 sord_add(sord, tup);
|
cannam@226
|
144 sord_node_free(world, (SordNode*)tup[2]);
|
cannam@226
|
145 tup[2] = sord_new_literal(world, 0, USTR("salut"), "fr");
|
cannam@226
|
146 sord_add(sord, tup);
|
cannam@226
|
147
|
cannam@226
|
148 // Attempt to add some duplicates
|
cannam@226
|
149 if (sord_add(sord, tup)) {
|
cannam@226
|
150 return test_fail("Fail: Successfully added duplicate quad\n");
|
cannam@226
|
151 }
|
cannam@226
|
152 if (sord_add(sord, tup)) {
|
cannam@226
|
153 return test_fail("Fail: Successfully added duplicate quad\n");
|
cannam@226
|
154 }
|
cannam@226
|
155
|
cannam@226
|
156 // Add a blank node subject
|
cannam@226
|
157 sord_node_free(world, (SordNode*)tup[0]);
|
cannam@226
|
158 tup[0] = sord_new_blank(world, USTR("ablank"));
|
cannam@226
|
159 sord_add(sord, tup);
|
cannam@226
|
160
|
cannam@226
|
161 sord_node_free(world, (SordNode*)tup[1]);
|
cannam@226
|
162 sord_node_free(world, (SordNode*)tup[2]);
|
cannam@226
|
163 tup[1] = uri(world, 6);
|
cannam@226
|
164 tup[2] = uri(world, 7);
|
cannam@226
|
165 sord_add(sord, tup);
|
cannam@226
|
166 sord_node_free(world, (SordNode*)tup[0]);
|
cannam@226
|
167 sord_node_free(world, (SordNode*)tup[1]);
|
cannam@226
|
168 sord_node_free(world, (SordNode*)tup[2]);
|
cannam@226
|
169
|
cannam@226
|
170 return EXIT_SUCCESS;
|
cannam@226
|
171 }
|
cannam@226
|
172
|
cannam@226
|
173 #define TUP_FMT "(%6s %6s %6s)"
|
cannam@226
|
174 #define TUP_FMT_ARGS(t) \
|
cannam@226
|
175 ((t)[0] ? sord_node_get_string((t)[0]) : USTR("*")), \
|
cannam@226
|
176 ((t)[1] ? sord_node_get_string((t)[1]) : USTR("*")), \
|
cannam@226
|
177 ((t)[2] ? sord_node_get_string((t)[2]) : USTR("*"))
|
cannam@226
|
178
|
cannam@226
|
179 static int
|
cannam@226
|
180 test_read(SordWorld* world, SordModel* sord, SordNode* g,
|
cannam@226
|
181 const size_t n_quads)
|
cannam@226
|
182 {
|
cannam@226
|
183 int ret = EXIT_SUCCESS;
|
cannam@226
|
184
|
cannam@226
|
185 SordQuad id;
|
cannam@226
|
186
|
cannam@226
|
187 SordIter* iter = sord_begin(sord);
|
cannam@226
|
188 if (sord_iter_get_model(iter) != sord) {
|
cannam@226
|
189 return test_fail("Fail: Iterator has incorrect sord pointer\n");
|
cannam@226
|
190 }
|
cannam@226
|
191
|
cannam@226
|
192 for (; !sord_iter_end(iter); sord_iter_next(iter))
|
cannam@226
|
193 sord_iter_get(iter, id);
|
cannam@226
|
194
|
cannam@226
|
195 // Attempt to increment past end
|
cannam@226
|
196 if (!sord_iter_next(iter)) {
|
cannam@226
|
197 return test_fail("Fail: Successfully incremented past end\n");
|
cannam@226
|
198 }
|
cannam@226
|
199
|
cannam@226
|
200 sord_iter_free(iter);
|
cannam@226
|
201
|
cannam@226
|
202 const uint8_t* s = USTR("hello");
|
cannam@226
|
203 SordNode* plain_hello = sord_new_literal(world, 0, s, NULL);
|
cannam@226
|
204 SordNode* type4_hello = sord_new_literal(world, uri(world, 4), s, NULL);
|
cannam@226
|
205 SordNode* type5_hello = sord_new_literal(world, uri(world, 5), s, NULL);
|
cannam@226
|
206 SordNode* gb_hello = sord_new_literal(world, NULL, s, "en-gb");
|
cannam@226
|
207 SordNode* us_hello = sord_new_literal(world, NULL, s, "en-us");
|
cannam@226
|
208
|
cannam@226
|
209 #define NUM_PATTERNS 18
|
cannam@226
|
210
|
cannam@226
|
211 QueryTest patterns[NUM_PATTERNS] = {
|
cannam@226
|
212 { { 0, 0, 0 }, (int)(n_quads * n_objects_per) + 12 },
|
cannam@226
|
213 { { uri(world, 1), 0, 0 }, 2 },
|
cannam@226
|
214 { { uri(world, 9), uri(world, 9), uri(world, 9) }, 0 },
|
cannam@226
|
215 { { uri(world, 1), uri(world, 2), uri(world, 4) }, 1 },
|
cannam@226
|
216 { { uri(world, 3), uri(world, 4), uri(world, 0) }, 2 },
|
cannam@226
|
217 { { uri(world, 0), uri(world, 2), uri(world, 4) }, 1 },
|
cannam@226
|
218 { { uri(world, 0), uri(world, 0), uri(world, 4) }, 1 },
|
cannam@226
|
219 { { uri(world, 1), uri(world, 0), uri(world, 0) }, 2 },
|
cannam@226
|
220 { { uri(world, 1), uri(world, 0), uri(world, 4) }, 1 },
|
cannam@226
|
221 { { uri(world, 0), uri(world, 2), uri(world, 0) }, 2 },
|
cannam@226
|
222 { { uri(world, 98), uri(world, 4), plain_hello }, 1 },
|
cannam@226
|
223 { { uri(world, 98), uri(world, 4), type5_hello }, 1 },
|
cannam@226
|
224 { { uri(world, 96), uri(world, 4), type4_hello }, 1 },
|
cannam@226
|
225 { { uri(world, 96), uri(world, 4), type5_hello }, 1 },
|
cannam@226
|
226 { { uri(world, 94), uri(world, 5), plain_hello }, 1 },
|
cannam@226
|
227 { { uri(world, 94), uri(world, 5), gb_hello }, 1 },
|
cannam@226
|
228 { { uri(world, 92), uri(world, 6), gb_hello }, 1 },
|
cannam@226
|
229 { { uri(world, 92), uri(world, 6), us_hello }, 1 } };
|
cannam@226
|
230
|
cannam@226
|
231 SordQuad match = { uri(world, 1), uri(world, 2), uri(world, 4), g };
|
cannam@226
|
232 if (!sord_contains(sord, match)) {
|
cannam@226
|
233 return test_fail("Fail: No match for " TUP_FMT "\n",
|
cannam@226
|
234 TUP_FMT_ARGS(match));
|
cannam@226
|
235 }
|
cannam@226
|
236
|
cannam@226
|
237 SordQuad nomatch = { uri(world, 1), uri(world, 2), uri(world, 9), g };
|
cannam@226
|
238 if (sord_contains(sord, nomatch)) {
|
cannam@226
|
239 return test_fail("Fail: False match for " TUP_FMT "\n",
|
cannam@226
|
240 TUP_FMT_ARGS(nomatch));
|
cannam@226
|
241 }
|
cannam@226
|
242
|
cannam@226
|
243 if (sord_get(sord, NULL, NULL, uri(world, 3), g)) {
|
cannam@226
|
244 return test_fail("Fail: Get *,*,3 succeeded\n");
|
cannam@226
|
245 } else if (!sord_node_equals(
|
cannam@226
|
246 sord_get(sord, uri(world, 1), uri(world, 2), NULL, g),
|
cannam@226
|
247 uri(world, 3))) {
|
cannam@226
|
248 return test_fail("Fail: Get 1,2,* != 3\n");
|
cannam@226
|
249 } else if (!sord_node_equals(
|
cannam@226
|
250 sord_get(sord, uri(world, 1), NULL, uri(world, 3), g),
|
cannam@226
|
251 uri(world, 2))) {
|
cannam@226
|
252 return test_fail("Fail: Get 1,*,3 != 2\n");
|
cannam@226
|
253 } else if (!sord_node_equals(
|
cannam@226
|
254 sord_get(sord, NULL, uri(world, 2), uri(world, 3), g),
|
cannam@226
|
255 uri(world, 1))) {
|
cannam@226
|
256 return test_fail("Fail: Get *,2,3 != 1\n");
|
cannam@226
|
257 }
|
cannam@226
|
258
|
cannam@226
|
259 for (unsigned i = 0; i < NUM_PATTERNS; ++i) {
|
cannam@226
|
260 QueryTest test = patterns[i];
|
cannam@226
|
261 SordQuad pat = { test.query[0], test.query[1], test.query[2], g };
|
cannam@226
|
262 fprintf(stderr, "Query " TUP_FMT "... ", TUP_FMT_ARGS(pat));
|
cannam@226
|
263
|
cannam@226
|
264 iter = sord_find(sord, pat);
|
cannam@226
|
265 int num_results = 0;
|
cannam@226
|
266 for (; !sord_iter_end(iter); sord_iter_next(iter)) {
|
cannam@226
|
267 sord_iter_get(iter, id);
|
cannam@226
|
268 ++num_results;
|
cannam@226
|
269 if (!sord_quad_match(pat, id)) {
|
cannam@226
|
270 sord_iter_free(iter);
|
cannam@226
|
271 return test_fail(
|
cannam@226
|
272 "Fail: Query result " TUP_FMT " does not match pattern\n",
|
cannam@226
|
273 TUP_FMT_ARGS(id));
|
cannam@226
|
274 }
|
cannam@226
|
275 }
|
cannam@226
|
276 sord_iter_free(iter);
|
cannam@226
|
277 if (num_results != test.expected_num_results) {
|
cannam@226
|
278 return test_fail("Fail: Expected %d results, got %d\n",
|
cannam@226
|
279 test.expected_num_results, num_results);
|
cannam@226
|
280 }
|
cannam@226
|
281 fprintf(stderr, "OK (%u matches)\n", test.expected_num_results);
|
cannam@226
|
282 }
|
cannam@226
|
283
|
cannam@226
|
284 // Query blank node subject
|
cannam@226
|
285 SordQuad pat = { sord_new_blank(world, USTR("ablank")), 0, 0 };
|
cannam@226
|
286 if (!pat[0]) {
|
cannam@226
|
287 return test_fail("Blank node subject lost\n");
|
cannam@226
|
288 }
|
cannam@226
|
289 fprintf(stderr, "Query " TUP_FMT "... ", TUP_FMT_ARGS(pat));
|
cannam@226
|
290 iter = sord_find(sord, pat);
|
cannam@226
|
291 int num_results = 0;
|
cannam@226
|
292 for (; !sord_iter_end(iter); sord_iter_next(iter)) {
|
cannam@226
|
293 sord_iter_get(iter, id);
|
cannam@226
|
294 ++num_results;
|
cannam@226
|
295 if (!sord_quad_match(pat, id)) {
|
cannam@226
|
296 sord_iter_free(iter);
|
cannam@226
|
297 return test_fail(
|
cannam@226
|
298 "Fail: Query result " TUP_FMT " does not match pattern\n",
|
cannam@226
|
299 TUP_FMT_ARGS(id));
|
cannam@226
|
300 }
|
cannam@226
|
301 }
|
cannam@226
|
302 fprintf(stderr, "OK\n");
|
cannam@226
|
303 sord_node_free(world, (SordNode*)pat[0]);
|
cannam@226
|
304 sord_iter_free(iter);
|
cannam@226
|
305 if (num_results != 2) {
|
cannam@226
|
306 return test_fail("Blank node subject query failed\n");
|
cannam@226
|
307 }
|
cannam@226
|
308
|
cannam@226
|
309 // Test nested queries
|
cannam@226
|
310 fprintf(stderr, "Nested Queries... ");
|
cannam@226
|
311 const SordNode* last_subject = 0;
|
cannam@226
|
312 iter = sord_search(sord, NULL, NULL, NULL, NULL);
|
cannam@226
|
313 for (; !sord_iter_end(iter); sord_iter_next(iter)) {
|
cannam@226
|
314 sord_iter_get(iter, id);
|
cannam@226
|
315 if (id[0] == last_subject)
|
cannam@226
|
316 continue;
|
cannam@226
|
317
|
cannam@226
|
318 SordQuad subpat = { id[0], 0, 0 };
|
cannam@226
|
319 SordIter* subiter = sord_find(sord, subpat);
|
cannam@226
|
320 uint64_t num_sub_results = 0;
|
cannam@226
|
321 if (sord_iter_get_node(subiter, SORD_SUBJECT) != id[0]) {
|
cannam@226
|
322 return test_fail("Fail: Incorrect initial submatch\n");
|
cannam@226
|
323 }
|
cannam@226
|
324 for (; !sord_iter_end(subiter); sord_iter_next(subiter)) {
|
cannam@226
|
325 SordQuad subid;
|
cannam@226
|
326 sord_iter_get(subiter, subid);
|
cannam@226
|
327 if (!sord_quad_match(subpat, subid)) {
|
cannam@226
|
328 sord_iter_free(iter);
|
cannam@226
|
329 sord_iter_free(subiter);
|
cannam@226
|
330 return test_fail(
|
cannam@226
|
331 "Fail: Nested query result does not match pattern\n");
|
cannam@226
|
332 }
|
cannam@226
|
333 ++num_sub_results;
|
cannam@226
|
334 }
|
cannam@226
|
335 sord_iter_free(subiter);
|
cannam@226
|
336 if (num_sub_results != n_objects_per) {
|
cannam@226
|
337 return test_fail(
|
cannam@226
|
338 "Fail: Nested query " TUP_FMT " failed"
|
cannam@226
|
339 " (%d results, expected %d)\n",
|
cannam@226
|
340 TUP_FMT_ARGS(subpat), num_sub_results, n_objects_per);
|
cannam@226
|
341 }
|
cannam@226
|
342
|
cannam@226
|
343 uint64_t count = sord_count(sord, id[0], 0, 0, 0);
|
cannam@226
|
344 if (count != num_sub_results) {
|
cannam@226
|
345 return test_fail("Fail: Query " TUP_FMT " sord_count() %d"
|
cannam@226
|
346 "does not match result count %d\n",
|
cannam@226
|
347 TUP_FMT_ARGS(subpat), count, num_sub_results);
|
cannam@226
|
348 }
|
cannam@226
|
349
|
cannam@226
|
350 last_subject = id[0];
|
cannam@226
|
351 }
|
cannam@226
|
352 fprintf(stderr, "OK\n\n");
|
cannam@226
|
353 sord_iter_free(iter);
|
cannam@226
|
354
|
cannam@226
|
355 return ret;
|
cannam@226
|
356 }
|
cannam@226
|
357
|
cannam@226
|
358 static SerdStatus
|
cannam@226
|
359 unexpected_error(void* handle, const SerdError* error)
|
cannam@226
|
360 {
|
cannam@226
|
361 fprintf(stderr, "unexpected error: ");
|
cannam@226
|
362 vfprintf(stderr, error->fmt, *error->args);
|
cannam@226
|
363 return SERD_SUCCESS;
|
cannam@226
|
364 }
|
cannam@226
|
365
|
cannam@226
|
366 static SerdStatus
|
cannam@226
|
367 expected_error(void* handle, const SerdError* error)
|
cannam@226
|
368 {
|
cannam@226
|
369 fprintf(stderr, "expected error: ");
|
cannam@226
|
370 vfprintf(stderr, error->fmt, *error->args);
|
cannam@226
|
371 ++n_expected_errors;
|
cannam@226
|
372 return SERD_SUCCESS;
|
cannam@226
|
373 }
|
cannam@226
|
374
|
cannam@226
|
375 static int
|
cannam@226
|
376 finished(SordWorld* world, SordModel* sord, int status)
|
cannam@226
|
377 {
|
cannam@226
|
378 sord_free(sord);
|
cannam@226
|
379 sord_world_free(world);
|
cannam@226
|
380 return status;
|
cannam@226
|
381 }
|
cannam@226
|
382
|
cannam@226
|
383 int
|
cannam@226
|
384 main(int argc, char** argv)
|
cannam@226
|
385 {
|
cannam@226
|
386 static const size_t n_quads = 300;
|
cannam@226
|
387
|
cannam@226
|
388 sord_free(NULL); // Shouldn't crash
|
cannam@226
|
389
|
cannam@226
|
390 SordWorld* world = sord_world_new();
|
cannam@226
|
391
|
cannam@226
|
392
|
cannam@226
|
393 // Attempt to create invalid URI
|
cannam@226
|
394 fprintf(stderr, "expected ");
|
cannam@226
|
395 SordNode* bad_uri = sord_new_uri(world, USTR("noscheme"));
|
cannam@226
|
396 if (bad_uri) {
|
cannam@226
|
397 return test_fail("Successfully created invalid URI \"noscheme\"\n");
|
cannam@226
|
398 }
|
cannam@226
|
399 sord_node_free(world, bad_uri);
|
cannam@226
|
400
|
cannam@226
|
401 sord_world_set_error_sink(world, expected_error, NULL);
|
cannam@226
|
402
|
cannam@226
|
403 // Attempt to create invalid CURIE
|
cannam@226
|
404 SerdNode base = serd_node_from_string(SERD_URI, USTR("http://example.org/"));
|
cannam@226
|
405 SerdEnv* env = serd_env_new(&base);
|
cannam@226
|
406 SerdNode sbadns = serd_node_from_string(SERD_CURIE, USTR("badns:"));
|
cannam@226
|
407 SordNode* badns = sord_node_from_serd_node(world, env, &sbadns, NULL, NULL);
|
cannam@226
|
408 if (badns) {
|
cannam@226
|
409 return test_fail("Successfully created CURIE with bad namespace\n");
|
cannam@226
|
410 }
|
cannam@226
|
411 sord_node_free(world, badns);
|
cannam@226
|
412 serd_env_free(env);
|
cannam@226
|
413
|
cannam@226
|
414 // Attempt to create node from garbage
|
cannam@226
|
415 SerdNode junk = SERD_NODE_NULL;
|
cannam@226
|
416 junk.type = (SerdType)1234;
|
cannam@226
|
417 if (sord_node_from_serd_node(world, env, &junk, NULL, NULL)) {
|
cannam@226
|
418 return test_fail("Successfully created node from garbage serd node\n");
|
cannam@226
|
419 }
|
cannam@226
|
420
|
cannam@226
|
421 // Attempt to create NULL node
|
cannam@226
|
422 SordNode* nil_node = sord_node_from_serd_node(
|
cannam@226
|
423 world, NULL, &SERD_NODE_NULL, NULL, NULL);
|
cannam@226
|
424 if (nil_node) {
|
cannam@226
|
425 return test_fail("Successfully created NULL node\n");
|
cannam@226
|
426 }
|
cannam@226
|
427 sord_node_free(world, nil_node);
|
cannam@226
|
428
|
cannam@226
|
429 // Attempt to double-free a node
|
cannam@226
|
430 SordNode* garbage = sord_new_uri(world, USTR("urn:garbage"));
|
cannam@226
|
431 sord_node_free(world, garbage);
|
cannam@226
|
432 sord_world_set_error_sink(world, expected_error, NULL);
|
cannam@226
|
433 sord_node_free(world, garbage);
|
cannam@226
|
434 sord_world_set_error_sink(world, unexpected_error, NULL);
|
cannam@226
|
435 if (n_expected_errors != 2) {
|
cannam@226
|
436 return test_fail("Successfully freed node twice\n");
|
cannam@226
|
437 }
|
cannam@226
|
438
|
cannam@226
|
439 sord_world_set_error_sink(world, unexpected_error, NULL);
|
cannam@226
|
440
|
cannam@226
|
441 // Check node flags are set properly
|
cannam@226
|
442 SordNode* with_newline = sord_new_literal(world, NULL, USTR("a\nb"), NULL);
|
cannam@226
|
443 if (!(sord_node_get_flags(with_newline) & SERD_HAS_NEWLINE)) {
|
cannam@226
|
444 return test_fail("Newline flag not set\n");
|
cannam@226
|
445 }
|
cannam@226
|
446 SordNode* with_quote = sord_new_literal(world, NULL, USTR("a\"b"), NULL);
|
cannam@226
|
447 if (!(sord_node_get_flags(with_quote) & SERD_HAS_QUOTE)) {
|
cannam@226
|
448 return test_fail("Quote flag not set\n");
|
cannam@226
|
449 }
|
cannam@226
|
450
|
cannam@226
|
451 // Create with minimal indexing
|
cannam@226
|
452 SordModel* sord = sord_new(world, SORD_SPO, false);
|
cannam@226
|
453 generate(world, sord, n_quads, NULL);
|
cannam@226
|
454
|
cannam@226
|
455 if (test_read(world, sord, NULL, n_quads)) {
|
cannam@226
|
456 sord_free(sord);
|
cannam@226
|
457 sord_world_free(world);
|
cannam@226
|
458 return EXIT_FAILURE;
|
cannam@226
|
459 }
|
cannam@226
|
460
|
cannam@226
|
461 // Check adding tuples with NULL fields fails
|
cannam@226
|
462 sord_world_set_error_sink(world, expected_error, NULL);
|
cannam@226
|
463 const size_t initial_num_quads = sord_num_quads(sord);
|
cannam@226
|
464 SordQuad tup = { 0, 0, 0, 0};
|
cannam@226
|
465 if (sord_add(sord, tup)) {
|
cannam@226
|
466 return test_fail("Added NULL tuple\n");
|
cannam@226
|
467 }
|
cannam@226
|
468 tup[0] = uri(world, 1);
|
cannam@226
|
469 if (sord_add(sord, tup)) {
|
cannam@226
|
470 return test_fail("Added tuple with NULL P and O\n");
|
cannam@226
|
471 }
|
cannam@226
|
472 tup[1] = uri(world, 2);
|
cannam@226
|
473 if (sord_add(sord, tup)) {
|
cannam@226
|
474 return test_fail("Added tuple with NULL O\n");
|
cannam@226
|
475 }
|
cannam@226
|
476
|
cannam@226
|
477 if (sord_num_quads(sord) != initial_num_quads) {
|
cannam@226
|
478 return test_fail("Num quads %zu != %zu\n",
|
cannam@226
|
479 sord_num_quads(sord), initial_num_quads);
|
cannam@226
|
480 }
|
cannam@226
|
481
|
cannam@226
|
482 // Check adding tuples with an active iterator fails
|
cannam@226
|
483 SordIter* iter = sord_begin(sord);
|
cannam@226
|
484 tup[2] = uri(world, 3);
|
cannam@226
|
485 if (sord_add(sord, tup)) {
|
cannam@226
|
486 return test_fail("Added tuple with active iterator\n");
|
cannam@226
|
487 }
|
cannam@226
|
488
|
cannam@226
|
489 // Check removing tuples with several active iterator fails
|
cannam@226
|
490 SordIter* iter2 = sord_begin(sord);
|
cannam@226
|
491 if (!sord_erase(sord, iter)) {
|
cannam@226
|
492 return test_fail("Erased tuple with several active iterators\n");
|
cannam@226
|
493 }
|
cannam@226
|
494 n_expected_errors = 0;
|
cannam@226
|
495 sord_remove(sord, tup);
|
cannam@226
|
496 if (n_expected_errors != 1) {
|
cannam@226
|
497 return test_fail("Removed tuple with several active iterators\n");
|
cannam@226
|
498 }
|
cannam@226
|
499 sord_iter_free(iter);
|
cannam@226
|
500 sord_iter_free(iter2);
|
cannam@226
|
501
|
cannam@226
|
502 sord_world_set_error_sink(world, unexpected_error, NULL);
|
cannam@226
|
503
|
cannam@226
|
504 // Check interning merges equivalent values
|
cannam@226
|
505 SordNode* uri_id = sord_new_uri(world, USTR("http://example.org"));
|
cannam@226
|
506 SordNode* blank_id = sord_new_blank(world, USTR("testblank"));
|
cannam@226
|
507 SordNode* lit_id = sord_new_literal(world, uri_id, USTR("hello"), NULL);
|
cannam@226
|
508 if (sord_node_get_type(uri_id) != SORD_URI) {
|
cannam@226
|
509 return test_fail("URI node has incorrect type\n");
|
cannam@226
|
510 } else if (sord_node_get_type(blank_id) != SORD_BLANK) {
|
cannam@226
|
511 return test_fail("Blank node has incorrect type\n");
|
cannam@226
|
512 } else if (sord_node_get_type(lit_id) != SORD_LITERAL) {
|
cannam@226
|
513 return test_fail("Literal node has incorrect type\n");
|
cannam@226
|
514 }
|
cannam@226
|
515
|
cannam@226
|
516 const size_t initial_num_nodes = sord_num_nodes(world);
|
cannam@226
|
517
|
cannam@226
|
518 SordNode* uri_id2 = sord_new_uri(world, USTR("http://example.org"));
|
cannam@226
|
519 SordNode* blank_id2 = sord_new_blank(world, USTR("testblank"));
|
cannam@226
|
520 SordNode* lit_id2 = sord_new_literal(world, uri_id, USTR("hello"), NULL);
|
cannam@226
|
521 if (uri_id2 != uri_id || !sord_node_equals(uri_id2, uri_id)) {
|
cannam@226
|
522 fprintf(stderr, "Fail: URI interning failed (duplicates)\n");
|
cannam@226
|
523 return finished(world, sord, EXIT_FAILURE);
|
cannam@226
|
524 } else if (blank_id2 != blank_id
|
cannam@226
|
525 || !sord_node_equals(blank_id2, blank_id)) {
|
cannam@226
|
526 fprintf(stderr, "Fail: Blank node interning failed (duplicates)\n");
|
cannam@226
|
527 return finished(world, sord, EXIT_FAILURE);
|
cannam@226
|
528 } else if (lit_id2 != lit_id || !sord_node_equals(lit_id2, lit_id)) {
|
cannam@226
|
529 fprintf(stderr, "Fail: Literal interning failed (duplicates)\n");
|
cannam@226
|
530 return finished(world, sord, EXIT_FAILURE);
|
cannam@226
|
531 }
|
cannam@226
|
532
|
cannam@226
|
533 if (sord_num_nodes(world) != initial_num_nodes) {
|
cannam@226
|
534 return test_fail("Num nodes %zu != %zu\n",
|
cannam@226
|
535 sord_num_nodes(world), initial_num_nodes);
|
cannam@226
|
536 }
|
cannam@226
|
537
|
cannam@226
|
538 const uint8_t ni_hao[] = { 0xE4, 0xBD, 0xA0, 0xE5, 0xA5, 0xBD };
|
cannam@226
|
539 SordNode* chello = sord_new_literal(world, NULL, ni_hao, "cmn");
|
cannam@226
|
540
|
cannam@226
|
541 // Test literal length
|
cannam@226
|
542 size_t n_bytes;
|
cannam@226
|
543 size_t n_chars;
|
cannam@226
|
544 const uint8_t* str = sord_node_get_string_counted(lit_id2, &n_bytes);
|
cannam@226
|
545 if (strcmp((const char*)str, "hello")) {
|
cannam@226
|
546 return test_fail("Literal node corrupt\n");
|
cannam@226
|
547 } else if (n_bytes != strlen("hello")) {
|
cannam@226
|
548 return test_fail("ASCII literal byte count incorrect\n");
|
cannam@226
|
549 }
|
cannam@226
|
550
|
cannam@226
|
551 str = sord_node_get_string_measured(lit_id2, &n_bytes, &n_chars);
|
cannam@226
|
552 if (n_bytes != strlen("hello") || n_chars != strlen("hello")) {
|
cannam@226
|
553 return test_fail("ASCII literal measured length incorrect\n");
|
cannam@226
|
554 }
|
cannam@226
|
555
|
cannam@226
|
556 str = sord_node_get_string_measured(chello, &n_bytes, &n_chars);
|
cannam@226
|
557 if (n_bytes != 6) {
|
cannam@226
|
558 return test_fail("Multi-byte literal byte count incorrect\n");
|
cannam@226
|
559 } else if (n_chars != 2) {
|
cannam@226
|
560 return test_fail("Multi-byte literal character count incorrect\n");
|
cannam@226
|
561 }
|
cannam@226
|
562
|
cannam@226
|
563 // Check interning doesn't clash non-equivalent values
|
cannam@226
|
564 SordNode* uri_id3 = sord_new_uri(world, USTR("http://example.orgX"));
|
cannam@226
|
565 SordNode* blank_id3 = sord_new_blank(world, USTR("testblankX"));
|
cannam@226
|
566 SordNode* lit_id3 = sord_new_literal(world, uri_id, USTR("helloX"), NULL);
|
cannam@226
|
567 if (uri_id3 == uri_id || sord_node_equals(uri_id3, uri_id)) {
|
cannam@226
|
568 fprintf(stderr, "Fail: URI interning failed (clash)\n");
|
cannam@226
|
569 return finished(world, sord, EXIT_FAILURE);
|
cannam@226
|
570 } else if (blank_id3 == blank_id || sord_node_equals(blank_id3, blank_id)) {
|
cannam@226
|
571 fprintf(stderr, "Fail: Blank node interning failed (clash)\n");
|
cannam@226
|
572 return finished(world, sord, EXIT_FAILURE);
|
cannam@226
|
573 } else if (lit_id3 == lit_id || sord_node_equals(lit_id3, lit_id)) {
|
cannam@226
|
574 fprintf(stderr, "Fail: Literal interning failed (clash)\n");
|
cannam@226
|
575 return finished(world, sord, EXIT_FAILURE);
|
cannam@226
|
576 }
|
cannam@226
|
577
|
cannam@226
|
578 // Check literal interning
|
cannam@226
|
579 SordNode* lit4 = sord_new_literal(world, NULL, USTR("hello"), NULL);
|
cannam@226
|
580 SordNode* lit5 = sord_new_literal(world, uri_id2, USTR("hello"), NULL);
|
cannam@226
|
581 SordNode* lit6 = sord_new_literal(world, NULL, USTR("hello"), "en-ca");
|
cannam@226
|
582 if (lit4 == lit5 || sord_node_equals(lit4, lit5)
|
cannam@226
|
583 || lit4 == lit6 || sord_node_equals(lit4, lit6)
|
cannam@226
|
584 || lit5 == lit6 || sord_node_equals(lit5, lit6)) {
|
cannam@226
|
585 fprintf(stderr, "Fail: Literal interning failed (type/lang clash)\n");
|
cannam@226
|
586 return finished(world, sord, EXIT_FAILURE);
|
cannam@226
|
587 }
|
cannam@226
|
588
|
cannam@226
|
589 // Check relative URI construction
|
cannam@226
|
590 SordNode* reluri = sord_new_relative_uri(
|
cannam@226
|
591 world, USTR("a/b"), USTR("http://example.org/"));
|
cannam@226
|
592 if (strcmp((const char*)sord_node_get_string(reluri),
|
cannam@226
|
593 "http://example.org/a/b")) {
|
cannam@226
|
594 fprintf(stderr, "Fail: Bad relative URI constructed: <%s>\n",
|
cannam@226
|
595 sord_node_get_string(reluri));
|
cannam@226
|
596 return finished(world, sord, EXIT_FAILURE);
|
cannam@226
|
597 }
|
cannam@226
|
598 SordNode* reluri2 = sord_new_relative_uri(
|
cannam@226
|
599 world, USTR("http://drobilla.net/"), USTR("http://example.org/"));
|
cannam@226
|
600 if (strcmp((const char*)sord_node_get_string(reluri2),
|
cannam@226
|
601 "http://drobilla.net/")) {
|
cannam@226
|
602 fprintf(stderr, "Fail: Bad relative URI constructed: <%s>\n",
|
cannam@226
|
603 sord_node_get_string(reluri));
|
cannam@226
|
604 return finished(world, sord, EXIT_FAILURE);
|
cannam@226
|
605 }
|
cannam@226
|
606
|
cannam@226
|
607 // Check comparison with NULL
|
cannam@226
|
608 sord_node_free(world, uri_id);
|
cannam@226
|
609 sord_node_free(world, blank_id);
|
cannam@226
|
610 sord_node_free(world, lit_id);
|
cannam@226
|
611 sord_node_free(world, uri_id2);
|
cannam@226
|
612 sord_node_free(world, blank_id2);
|
cannam@226
|
613 sord_node_free(world, lit_id2);
|
cannam@226
|
614 sord_node_free(world, uri_id3);
|
cannam@226
|
615 sord_node_free(world, blank_id3);
|
cannam@226
|
616 sord_node_free(world, lit_id3);
|
cannam@226
|
617 sord_free(sord);
|
cannam@226
|
618
|
cannam@226
|
619 static const char* const index_names[6] = {
|
cannam@226
|
620 "spo", "sop", "ops", "osp", "pso", "pos"
|
cannam@226
|
621 };
|
cannam@226
|
622
|
cannam@226
|
623 for (int i = 0; i < 6; ++i) {
|
cannam@226
|
624 sord = sord_new(world, (1 << i), false);
|
cannam@226
|
625 printf("Testing Index `%s'\n", index_names[i]);
|
cannam@226
|
626 generate(world, sord, n_quads, 0);
|
cannam@226
|
627 if (test_read(world, sord, 0, n_quads))
|
cannam@226
|
628 return finished(world, sord, EXIT_FAILURE);
|
cannam@226
|
629 sord_free(sord);
|
cannam@226
|
630 }
|
cannam@226
|
631
|
cannam@226
|
632 static const char* const graph_index_names[6] = {
|
cannam@226
|
633 "gspo", "gsop", "gops", "gosp", "gpso", "gpos"
|
cannam@226
|
634 };
|
cannam@226
|
635
|
cannam@226
|
636 for (int i = 0; i < 6; ++i) {
|
cannam@226
|
637 sord = sord_new(world, (1 << i), true);
|
cannam@226
|
638 printf("Testing Index `%s'\n", graph_index_names[i]);
|
cannam@226
|
639 SordNode* graph = uri(world, 42);
|
cannam@226
|
640 generate(world, sord, n_quads, graph);
|
cannam@226
|
641 if (test_read(world, sord, graph, n_quads))
|
cannam@226
|
642 return finished(world, sord, EXIT_FAILURE);
|
cannam@226
|
643 sord_free(sord);
|
cannam@226
|
644 }
|
cannam@226
|
645
|
cannam@226
|
646 // Test removing
|
cannam@226
|
647 sord = sord_new(world, SORD_SPO, true);
|
cannam@226
|
648 tup[0] = uri(world, 1);
|
cannam@226
|
649 tup[1] = uri(world, 2);
|
cannam@226
|
650 tup[2] = sord_new_literal(world, 0, USTR("hello"), NULL);
|
cannam@226
|
651 tup[3] = 0;
|
cannam@226
|
652 sord_add(sord, tup);
|
cannam@226
|
653 if (!sord_ask(sord, tup[0], tup[1], tup[2], tup[3])) {
|
cannam@226
|
654 fprintf(stderr, "Failed to add tuple\n");
|
cannam@226
|
655 return finished(world, sord, EXIT_FAILURE);
|
cannam@226
|
656 }
|
cannam@226
|
657 sord_node_free(world, (SordNode*)tup[2]);
|
cannam@226
|
658 tup[2] = sord_new_literal(world, 0, USTR("hi"), NULL);
|
cannam@226
|
659 sord_add(sord, tup);
|
cannam@226
|
660 sord_remove(sord, tup);
|
cannam@226
|
661 if (sord_num_quads(sord) != 1) {
|
cannam@226
|
662 fprintf(stderr, "Remove failed (%zu quads, expected 1)\n",
|
cannam@226
|
663 sord_num_quads(sord));
|
cannam@226
|
664 return finished(world, sord, EXIT_FAILURE);
|
cannam@226
|
665 }
|
cannam@226
|
666
|
cannam@226
|
667 iter = sord_find(sord, tup);
|
cannam@226
|
668 if (!sord_iter_end(iter)) {
|
cannam@226
|
669 fprintf(stderr, "Found removed tuple\n");
|
cannam@226
|
670 return finished(world, sord, EXIT_FAILURE);
|
cannam@226
|
671 }
|
cannam@226
|
672 sord_iter_free(iter);
|
cannam@226
|
673
|
cannam@226
|
674 // Test double remove (silent success)
|
cannam@226
|
675 sord_remove(sord, tup);
|
cannam@226
|
676
|
cannam@226
|
677 // Load a couple graphs
|
cannam@226
|
678 SordNode* graph42 = uri(world, 42);
|
cannam@226
|
679 SordNode* graph43 = uri(world, 43);
|
cannam@226
|
680 generate(world, sord, 1, graph42);
|
cannam@226
|
681 generate(world, sord, 1, graph43);
|
cannam@226
|
682
|
cannam@226
|
683 // Remove one graph via iterator
|
cannam@226
|
684 SerdStatus st;
|
cannam@226
|
685 iter = sord_search(sord, NULL, NULL, NULL, graph43);
|
cannam@226
|
686 while (!sord_iter_end(iter)) {
|
cannam@226
|
687 if ((st = sord_erase(sord, iter))) {
|
cannam@226
|
688 fprintf(stderr, "Remove by iterator failed (%s)\n",
|
cannam@226
|
689 serd_strerror(st));
|
cannam@226
|
690 return finished(world, sord, EXIT_FAILURE);
|
cannam@226
|
691 }
|
cannam@226
|
692 }
|
cannam@226
|
693 sord_iter_free(iter);
|
cannam@226
|
694
|
cannam@226
|
695 // Erase the first tuple (an element in the default graph)
|
cannam@226
|
696 iter = sord_begin(sord);
|
cannam@226
|
697 if (sord_erase(sord, iter)) {
|
cannam@226
|
698 return test_fail("Failed to erase begin iterator on non-empty model\n");
|
cannam@226
|
699 }
|
cannam@226
|
700 sord_iter_free(iter);
|
cannam@226
|
701
|
cannam@226
|
702 // Ensure only the other graph is left
|
cannam@226
|
703 SordQuad quad;
|
cannam@226
|
704 SordQuad pat = { 0, 0, 0, graph42 };
|
cannam@226
|
705 for (iter = sord_begin(sord); !sord_iter_end(iter); sord_iter_next(iter)) {
|
cannam@226
|
706 sord_iter_get(iter, quad);
|
cannam@226
|
707 if (!sord_quad_match(quad, pat)) {
|
cannam@226
|
708 fprintf(stderr, "Graph removal via iteration failed\n");
|
cannam@226
|
709 return finished(world, sord, EXIT_FAILURE);
|
cannam@226
|
710 }
|
cannam@226
|
711 }
|
cannam@226
|
712 sord_iter_free(iter);
|
cannam@226
|
713
|
cannam@226
|
714 // Load file into two separate graphs
|
cannam@226
|
715 sord_free(sord);
|
cannam@226
|
716 sord = sord_new(world, SORD_SPO, true);
|
cannam@226
|
717 env = serd_env_new(&base);
|
cannam@226
|
718 SordNode* graph1 = sord_new_uri(world, USTR("http://example.org/graph1"));
|
cannam@226
|
719 SordNode* graph2 = sord_new_uri(world, USTR("http://example.org/graph2"));
|
cannam@226
|
720 SerdReader* reader = sord_new_reader(sord, env, SERD_TURTLE, graph1);
|
cannam@226
|
721 if ((st = serd_reader_read_string(reader, USTR("<s> <p> <o> .")))) {
|
cannam@226
|
722 fprintf(stderr, "Failed to read string (%s)\n", serd_strerror(st));
|
cannam@226
|
723 return finished(world, sord, EXIT_FAILURE);
|
cannam@226
|
724 }
|
cannam@226
|
725 serd_reader_free(reader);
|
cannam@226
|
726 reader = sord_new_reader(sord, env, SERD_TURTLE, graph2);
|
cannam@226
|
727 if ((st = serd_reader_read_string(reader, USTR("<s> <p> <o> .")))) {
|
cannam@226
|
728 fprintf(stderr, "Failed to re-read string (%s)\n", serd_strerror(st));
|
cannam@226
|
729 return finished(world, sord, EXIT_FAILURE);
|
cannam@226
|
730 }
|
cannam@226
|
731 serd_reader_free(reader);
|
cannam@226
|
732 serd_env_free(env);
|
cannam@226
|
733
|
cannam@226
|
734 // Ensure we only see triple once
|
cannam@226
|
735 size_t n_triples = 0;
|
cannam@226
|
736 for (iter = sord_begin(sord); !sord_iter_end(iter); sord_iter_next(iter)) {
|
cannam@226
|
737 fprintf(stderr, "%s %s %s %s\n",
|
cannam@226
|
738 sord_node_get_string(sord_iter_get_node(iter, SORD_SUBJECT)),
|
cannam@226
|
739 sord_node_get_string(sord_iter_get_node(iter, SORD_PREDICATE)),
|
cannam@226
|
740 sord_node_get_string(sord_iter_get_node(iter, SORD_OBJECT)),
|
cannam@226
|
741 sord_node_get_string(sord_iter_get_node(iter, SORD_GRAPH)));
|
cannam@226
|
742
|
cannam@226
|
743 ++n_triples;
|
cannam@226
|
744 }
|
cannam@226
|
745 sord_iter_free(iter);
|
cannam@226
|
746 if (n_triples != 1) {
|
cannam@226
|
747 fprintf(stderr, "Found duplicate triple\n");
|
cannam@226
|
748 return finished(world, sord, EXIT_FAILURE);
|
cannam@226
|
749 }
|
cannam@226
|
750
|
cannam@226
|
751 // Test SPO iteration on an SOP indexed store
|
cannam@226
|
752 sord_free(sord);
|
cannam@226
|
753 sord = sord_new(world, SORD_SOP, false);
|
cannam@226
|
754 generate(world, sord, 1, graph42);
|
cannam@226
|
755 for (iter = sord_begin(sord); !sord_iter_end(iter); sord_iter_next(iter)) {
|
cannam@226
|
756 ++n_triples;
|
cannam@226
|
757 }
|
cannam@226
|
758 sord_iter_free(iter);
|
cannam@226
|
759
|
cannam@226
|
760 return finished(world, sord, EXIT_SUCCESS);
|
cannam@226
|
761 }
|