1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- #include <unistd.h>
- #include "test.h"
- #include "store_mdb.h"
- #define MDBSTORE_ID "file:///tmp/testdb"
- /** @brief Test context switching.
- */
- static int test_ctx_switch()
- {
- const LSUP_StoreInt *sif = LSUP_store_int (LSUP_STORE_MDB);
- sif->setup_fn (MDBSTORE_ID, true);
- LSUP_Store *store = LSUP_store_new (LSUP_STORE_MDB, MDBSTORE_ID, 0);
- ASSERT (store != NULL, "Error initializing store!");
- // Create enough triples to test a multi-page copy of triple data.
- // Add small buffer (4) to create a 3rd page.
- size_t num_trp = (getpagesize() * 2 / TRP_KLEN) + 4;
- LSUP_BufferTriple **tdata = malloc (num_trp * sizeof (*tdata));
- LSUP_Triple *trp = LSUP_triple_new (
- LSUP_iriref_new ("urn:s:1", NULL),
- LSUP_iriref_new ("urn:p:1", NULL),
- NULL);
- char *o_str = malloc (8 * sizeof (*o_str));
- if (UNLIKELY (!o_str)) return LSUP_MEM_ERR;
- for (unsigned int i = 0; i < num_trp; i++) {
- sprintf (o_str, "%.7d", i);
- if (trp->o) LSUP_term_free (trp->o);
- trp->o = LSUP_literal_new (o_str, NULL);
- tdata[i] = LSUP_triple_serialize (trp);
- }
- LSUP_triple_free (trp);
- free (o_str);
- LOG_DEBUG ("Created %lu triples.", num_trp);
- LSUP_Term
- *c1 = LSUP_iriref_new ("urn:c:1", NULL),
- *c2 = LSUP_iriref_new ("urn:c:2", NULL);
- LSUP_Buffer
- *sc1 = LSUP_term_serialize (c1),
- *sc2 = LSUP_term_serialize (c2);
- LSUP_term_free (c1);
- LSUP_term_free (c2);
- void *it = sif->add_init_fn (store->data, sc1, NULL);
- for (size_t i = 0; i < num_trp; i++)
- sif->add_iter_fn (it, tdata[i]);
- sif->add_done_fn (it);
- for (size_t i = 0; i < num_trp; i++)
- LSUP_btriple_free (tdata[i]);
- free (tdata);
- size_t check_ct;
- ASSERT (
- it = sif->lookup_fn (
- store->data, NULL, NULL, NULL, sc1, NULL, &check_ct
- ), "Error looking up triples!");
- EXPECT_INT_EQ (check_ct, num_trp);
- sif->lu_free_fn (it);
- RCCK (sif->update_ctx_fn (store->data, sc1, sc2, NULL));
- ASSERT (
- it = sif->lookup_fn (
- store->data, NULL, NULL, NULL, sc2, NULL, &check_ct
- ), "Error looking up triples!");
- EXPECT_INT_EQ (check_ct, num_trp);
- sif->lu_free_fn (it);
- LSUP_buffer_free (sc1);
- LSUP_buffer_free (sc2);
- LSUP_store_free (store);
- return 0;
- }
- int store_mdb_tests()
- {
- RUN (test_ctx_switch);
- return 0;
- }
|