#include #include #include "test.h" #include "store_mdb.h" #include "assets.h" static char *path = "/tmp/testdb"; static void rmdb() { char data_path[32], lock_path[32]; sprintf(data_path, "%s/data.mdb", path); sprintf(lock_path, "%s/lock.mdb", path); printf("Removing %s\n", data_path); remove(data_path); printf("Removing %s\n", lock_path); remove(lock_path); remove(path); } /** @brief Test triple store. */ static int test_triple_store() { rmdb(); EXPECT_PASS(LSUP_store_setup(&path)); LSUP_MDBStore *store; store = LSUP_store_new(path, NULL); // triple store. ASSERT(store != NULL, "Error initializing store!"); LSUP_Triple *trp = create_triples(); LSUP_SerTerm sterms[NUM_TRP][3]; LSUP_SerTriple ser_trp[NUM_TRP]; for (int i = 0; i < NUM_TRP; i++) { ser_trp[i].s = sterms[i]; ser_trp[i].p = sterms[i] + 1; ser_trp[i].o = sterms[i] + 2; for (int j = 0; j < 3; j++) { LSUP_term_serialize( LSUP_triple_term_by_pos(trp + i, j), LSUP_ser_triple_term_by_pos(ser_trp + i, j)); } } EXPECT_PASS(LSUP_store_add(store, NULL, ser_trp, NUM_TRP)); for (int i = 0; i < NUM_TRP; i++) { LSUP_buffer_done(ser_trp[i].s); LSUP_buffer_done(ser_trp[i].p); LSUP_buffer_done(ser_trp[i].o); } LSUP_store_free(store); free_triples(trp); return 0; } /** @brief Test quad store. * * Insert the same triple set twice with different contexts. */ static int test_quad_store() { rmdb(); EXPECT_PASS(LSUP_store_setup(&path)); LSUP_MDBStore *store; store = LSUP_store_new(path, NULL); // triple store. ASSERT(store != NULL, "Error initializing store!"); LSUP_Triple *trp = create_triples(); LSUP_SerTerm sterms[NUM_TRP][3]; LSUP_SerTriple ser_trp[NUM_TRP]; for (int i = 0; i < NUM_TRP; i++) { ser_trp[i].s = sterms[i]; ser_trp[i].p = sterms[i] + 1; ser_trp[i].o = sterms[i] + 2; for (int j = 0; j < 3; j++) { LSUP_term_serialize( LSUP_triple_term_by_pos(trp + i, j), LSUP_ser_triple_term_by_pos(ser_trp + i, j)); } } LSUP_Term *ctx1 = LSUP_uri_new("urn:c:1"); LSUP_SerTerm sc1_s; LSUP_term_serialize(ctx1, &sc1_s); EXPECT_PASS(LSUP_store_add(store, &sc1_s, ser_trp, NUM_TRP)); LSUP_Term *ctx2 = LSUP_uri_new("urn:c:2"); LSUP_SerTerm sc2_s; LSUP_term_serialize(ctx2, &sc2_s); EXPECT_PASS(LSUP_store_add(store, &sc2_s, ser_trp, NUM_TRP)); for (int i = 0; i < NUM_TRP; i++) { LSUP_buffer_done(ser_trp[i].s); LSUP_buffer_done(ser_trp[i].p); LSUP_buffer_done(ser_trp[i].o); } LSUP_store_free(store); free_triples(trp); return 0; } int store_mdb_test() { RUN(test_triple_store); RUN(test_quad_store); return 0; }