#include #include "volksdata/store_mdb.h" #include "test.h" #define MDBSTORE_ID "file:///tmp/testdb" /** @brief Test context switching. */ static int test_ctx_switch() { const VOLK_StoreInt *sif = VOLK_store_int (VOLK_STORE_MDB); VOLK_Store *store = VOLK_store_new (VOLK_STORE_MDB, MDBSTORE_ID, 0, true); 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; VOLK_BufferTriple **tdata = malloc (num_trp * sizeof (*tdata)); VOLK_Triple *trp = VOLK_triple_new ( VOLK_iriref_new ("urn:s:1"), VOLK_iriref_new ("urn:p:1"), NULL); char *o_str = malloc (8 * sizeof (*o_str)); if (UNLIKELY (!o_str)) return VOLK_MEM_ERR; for (unsigned int i = 0; i < num_trp; i++) { sprintf (o_str, "%.7d", i); if (trp->o) VOLK_term_free (trp->o); trp->o = VOLK_literal_new (o_str, NULL); tdata[i] = VOLK_triple_serialize (trp); } VOLK_triple_free (trp); free (o_str); LOG_DEBUG ("Created %lu triples.", num_trp); VOLK_Term *c1 = VOLK_iriref_new ("urn:c:1"), *c2 = VOLK_iriref_new ("urn:c:2"); VOLK_Buffer *sc1 = VOLK_term_serialize (c1), *sc2 = VOLK_term_serialize (c2); VOLK_term_free (c1); VOLK_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++) VOLK_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); VOLK_buffer_free (sc1); VOLK_buffer_free (sc2); VOLK_store_free (store); return 0; } int store_mdb_tests() { RUN (test_ctx_switch); return 0; }