123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313 |
- #include "test.h"
- #include "store_mdb.h"
- #include "assets.h"
- static char *path = "/tmp/testdb";
- static int test_triple_store()
- {
- EXPECT_PASS (LSUP_mdbstore_setup (path, true));
- LSUP_MDBStore *store = LSUP_mdbstore_new (path, NULL);
- ASSERT (store != NULL, "Error initializing store!");
- LSUP_Triple *trp = create_triples();
- LSUP_SerTriple ser_trp[NUM_TRP];
- for (int i = 0; i < NUM_TRP; i++) {
- LSUP_striple_init (ser_trp + i, BUF_DUMMY, BUF_DUMMY, BUF_DUMMY);
- LSUP_triple_serialize (trp + i, ser_trp + i);
- }
-
- size_t ins;
- EXPECT_PASS (LSUP_mdbstore_add (store, NULL, ser_trp, NUM_TRP, &ins));
- EXPECT_INT_EQ (ins, 8);
- EXPECT_INT_EQ (LSUP_mdbstore_size (store), 8);
-
- LSUP_SerTriple lut[12] = {
- {NULL, NULL, NULL},
- {ser_trp[0].s, NULL, NULL},
- {ser_trp[2].s, NULL, NULL},
- {NULL, ser_trp[0].p, NULL},
- {NULL, ser_trp[0].s, NULL},
- {NULL, NULL, ser_trp[6].o},
- {ser_trp[4].s, ser_trp[4].p, NULL},
- {NULL, ser_trp[7].p, ser_trp[7].o},
- {ser_trp[5].s, NULL, ser_trp[5].o},
- {ser_trp[5].s, NULL, ser_trp[5].o},
- {ser_trp[4].s, ser_trp[4].p, ser_trp[4].o},
- {ser_trp[4].s, ser_trp[4].p, ser_trp[6].o},
- };
- LSUP_Buffer *luc[12] = {
- NULL,
- NULL,
- ser_trp[2].s,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- ser_trp[2].s,
- NULL,
- NULL,
- };
- size_t results[12] = {
- 8,
- 5, 1, 1, 0, 1,
- 2, 1, 2, 2,
- 1, 0,
- };
- for (int i = 0; i < 12; i++) {
- size_t ct;
- TRACE ("Testing triple lookup #%d.\n", i);
- LSUP_MDBIterator *it = LSUP_mdbstore_lookup(
- store, lut + i, luc[i], &ct);
- EXPECT_INT_EQ (ct, results[i]);
- LSUP_mdbiter_free (it);
- }
- for (int i = 0; i < NUM_TRP; i++) {
- LSUP_buffer_free (ser_trp[i].s);
- LSUP_buffer_free (ser_trp[i].p);
- LSUP_buffer_free (ser_trp[i].o);
- }
- LSUP_mdbstore_free (store);
- free_triples (trp);
- return 0;
- }
- static int test_quad_store()
- {
- EXPECT_PASS (LSUP_mdbstore_setup (path, true));
- LSUP_Term *ctx1 = LSUP_uri_new ("urn:c:1");
- LSUP_Buffer *sc1 = LSUP_buffer_new_from_term (ctx1);
- LSUP_MDBStore *store = LSUP_mdbstore_new (path, sc1);
- ASSERT (store != NULL, "Error initializing store!");
- LSUP_Triple *trp = create_triples();
- LSUP_SerTriple ser_trp[NUM_TRP];
- for (int i = 0; i < NUM_TRP; i++) {
- LSUP_striple_init (ser_trp + i, BUF_DUMMY, BUF_DUMMY, BUF_DUMMY);
- LSUP_triple_serialize (trp + i, ser_trp + i);
- }
-
- size_t ct;
- EXPECT_PASS (LSUP_mdbstore_add (store, NULL, ser_trp, 6, &ct));
- EXPECT_INT_EQ (ct, 6);
- LSUP_Term *ctx2 = LSUP_uri_new ("urn:c:2");
- LSUP_Buffer *sc2 = LSUP_buffer_new_from_term (ctx2);
-
- EXPECT_PASS (LSUP_mdbstore_add (store, sc2, ser_trp + 4, 6, &ct));
- EXPECT_INT_EQ (ct, 4);
-
- EXPECT_INT_EQ (LSUP_mdbstore_size (store), 10);
-
- LSUP_Term *ctx3 = LSUP_uri_new ("urn:c:3");
- LSUP_Buffer *sc3 = LSUP_buffer_new_from_term (ctx3);
-
- LSUP_SerTriple lut[41] = {
-
- {NULL, NULL, NULL},
- {ser_trp[0].s, NULL, NULL},
- {NULL, ser_trp[0].p, NULL},
- {NULL, ser_trp[0].s, NULL},
- {NULL, NULL, ser_trp[6].o},
- {ser_trp[4].s, ser_trp[4].p, NULL},
- {NULL, ser_trp[7].p, ser_trp[7].o},
- {ser_trp[5].s, NULL, ser_trp[5].o},
- {ser_trp[4].s, ser_trp[4].p, ser_trp[4].o},
- {ser_trp[2].s, ser_trp[4].p, ser_trp[5].o},
-
- {NULL, NULL, NULL},
- {ser_trp[0].s, NULL, NULL},
- {ser_trp[2].s, NULL, NULL},
- {NULL, ser_trp[0].p, NULL},
- {NULL, ser_trp[6].p, NULL},
- {NULL, NULL, ser_trp[6].o},
- {ser_trp[4].s, ser_trp[4].p, NULL},
- {NULL, ser_trp[7].p, ser_trp[7].o},
- {ser_trp[5].s, NULL, ser_trp[5].o},
- {ser_trp[4].s, ser_trp[4].p, ser_trp[4].o},
- {ser_trp[6].s, ser_trp[6].p, ser_trp[6].o},
-
- {NULL, NULL, NULL},
- {ser_trp[0].s, NULL, NULL},
- {NULL, ser_trp[0].p, NULL},
- {NULL, ser_trp[0].s, NULL},
- {NULL, NULL, ser_trp[6].o},
- {ser_trp[4].s, ser_trp[4].p, NULL},
- {NULL, ser_trp[7].p, ser_trp[7].o},
- {ser_trp[5].s, NULL, ser_trp[5].o},
- {ser_trp[4].s, ser_trp[4].p, ser_trp[4].o},
- {ser_trp[6].s, ser_trp[6].p, ser_trp[6].o},
-
- {NULL, NULL, NULL},
- {ser_trp[0].s, NULL, NULL},
- {NULL, ser_trp[0].p, NULL},
- {NULL, ser_trp[0].s, NULL},
- {NULL, NULL, ser_trp[6].o},
- {ser_trp[4].s, ser_trp[4].p, NULL},
- {NULL, ser_trp[7].p, ser_trp[7].o},
- {ser_trp[5].s, NULL, ser_trp[5].o},
- {ser_trp[4].s, ser_trp[4].p, ser_trp[4].o},
- {ser_trp[6].s, ser_trp[6].p, ser_trp[6].o},
- };
- LSUP_Buffer *luc[41] = {
-
- NULL,
- NULL, NULL, NULL, NULL,
- NULL, NULL, NULL,
- NULL, NULL,
-
- sc1,
- sc1, sc1, sc1, sc1, sc1,
- sc1, sc1, sc1,
- sc1, sc1,
-
- sc2,
- sc2, sc2, sc2, sc2,
- sc2, sc2, sc2,
- sc2, sc2,
-
- sc3,
- sc3, sc3, sc3, sc3,
- sc3, sc3, sc3,
- sc3, sc3,
- };
- size_t results[41] = {
-
- 8,
- 5, 1, 0, 1,
- 2, 1, 2,
- 1, 0,
-
- 6,
- 4, 1, 1, 0, 0,
- 1, 0, 1,
- 1, 0,
-
- 4,
- 3, 0, 0, 1,
- 2, 1, 2,
- 1, 1,
-
- 0,
- 0, 0, 0, 0,
- 0, 0, 0,
- 0, 0,
- };
- for (int i = 0; i < 41; i++) {
- size_t ct;
- printf ("Testing triple lookup #%d: {", i);
- if (lut[i].s) LSUP_buffer_print (lut[i].s);
- else printf ("NULL");
- printf (", ");
- if (lut[i].p) LSUP_buffer_print (lut[i].p);
- else printf ("NULL");
- printf (", ");
- if (lut[i].o) LSUP_buffer_print (lut[i].o);
- else printf ("NULL");
- printf (", ");
- if (luc[i]) LSUP_buffer_print (luc[i]);
- else printf ("NULL");
- printf ("}\n");
- LSUP_MDBIterator *it = LSUP_mdbstore_lookup(
- store, lut + i, luc[i], &ct);
- ASSERT (it != NULL, "Lookup error!");
- EXPECT_INT_EQ (ct, results[i]);
- LSUP_mdbiter_free (it);
- }
- for (int i = 0; i < NUM_TRP; i++) {
- LSUP_buffer_free (ser_trp[i].s);
- LSUP_buffer_free (ser_trp[i].p);
- LSUP_buffer_free (ser_trp[i].o);
- }
- LSUP_term_free (ctx1);
- LSUP_term_free (ctx2);
- LSUP_term_free (ctx3);
- LSUP_buffer_free (sc1);
- LSUP_buffer_free (sc2);
- LSUP_buffer_free (sc3);
- free_triples (trp);
- LSUP_mdbstore_free (store);
- return 0;
- }
- int store_mdb_test()
- {
- RUN (test_triple_store);
- RUN (test_quad_store);
- return 0;
- }
|