#include <time.h>

#include "test_term.c"
#include "test_namespace.c"
#include "test_codec_nt.c"
#include "test_codec_ttl.c"
#include "test_store.c"
#include "test_graph.c"

#define TEST_STORE_PATH TMPDIR "/lsup_test_mdb"

int main(int argc, char **argv) {

    // Set env variable to test path.
    putenv ("LSUP_MDB_STORE_PATH=" TEST_STORE_PATH);
    // Clear out database from previous test.
    rm_r (TEST_STORE_PATH);

    clock_t start, end;
    double wallclock;

    start = clock();

    int rc = LSUP_init();
    if (rc != LSUP_OK) return rc;

    if (
        term_tests() ||
        namespace_tests() ||
        store_tests() ||
        graph_tests() ||
        codec_nt_tests() ||
        codec_ttl_tests() ||
        0
    ) {
        log_error ("Test failed.");
        rc = -1;
    } else {
        log_info ("");
        log_info ("********************");
        log_info ("* ALL TESTS PASSED *");
        log_info ("********************");
        rc = 0;
    }

    end = clock();
    wallclock = (end - start) * 1000 / CLOCKS_PER_SEC;

    log_info ("");
    log_info ("Run %d tests in %lu ms.", tests_run, (size_t) wallclock);

    return rc;
}