void TestFindDocument(CuTest* tc) { db_connection* conn; bson *b, *finder; bson** found_documents; char* json; conn = alloc_test_conn(); b = make_sample_bson(); json = str_replace_j( "{'string': 'value'}"); finder = bson_from_json_str( json ); free( json ); db_document_insert( conn, b ); found_documents = db_document_find( conn, finder ); CuAssertIntEquals( tc, 1, sizeof( found_documents ) / sizeof( bson* ) ); bson_destroy( b ); free( b ); db_connection_destroy( conn ); free( conn ); delete_db(); }
void TestEstablishConnection(CuTest* tc) { db_connection* conn = alloc_test_conn(); CuAssertTrue( tc, conn->new ); CuAssertIntEquals( tc, 0, db_current_size( conn ) ); db_connection_destroy( conn ); free( conn ); delete_db(); }
CuSuite* db_test_suite(void) { CuSuite* suite = CuSuiteNew(); delete_db(); SUITE_ADD_TEST(suite, TestEstablishConnection); SUITE_ADD_TEST(suite, TestInsertDocument); // SUITE_ADD_TEST(suite, TestFindDocument); return suite; }
void TestInsertDocument(CuTest* tc) { db_connection* conn; bson* b; size_t i; conn = alloc_test_conn(); b = make_sample_bson(); for( i = 1; i < 11; ++i ) { db_document_insert( conn, b ); CuAssertIntEquals( tc, i, db_current_size( conn ) ); CuAssertIntEquals( tc, bson_size(b) * i, conn->free_p ); } bson_destroy( b ); free( b ); db_connection_destroy( conn ); free( conn ); delete_db(); }
static void test_ontology_change (void) { gchar *ontology_file; GFile *file2; gchar *prefix, *build_prefix; gchar *ontology_dir; guint i; GError *error = NULL; gchar *test_schemas[5] = { NULL, NULL, NULL, NULL, NULL }; delete_db (TRUE); prefix = g_build_path (G_DIR_SEPARATOR_S, TOP_SRCDIR, "tests", "libtracker-data", NULL); build_prefix = g_build_path (G_DIR_SEPARATOR_S, TOP_BUILDDIR, "tests", "libtracker-data", NULL); test_schemas[0] = g_build_path (G_DIR_SEPARATOR_S, prefix, "ontologies", "20-dc", NULL); test_schemas[1] = g_build_path (G_DIR_SEPARATOR_S, prefix, "ontologies", "31-nao", NULL); test_schemas[2] = g_build_path (G_DIR_SEPARATOR_S, prefix, "ontologies", "90-tracker", NULL); test_schemas[3] = g_build_path (G_DIR_SEPARATOR_S, build_prefix, "change", "ontologies", "99-example", NULL); ontology_file = g_build_path (G_DIR_SEPARATOR_S, build_prefix, "change", "ontologies", "99-example.ontology", NULL); file2 = g_file_new_for_path (ontology_file); g_file_delete (file2, NULL, NULL); ontology_dir = g_build_path (G_DIR_SEPARATOR_S, build_prefix, "change", "ontologies", NULL); g_mkdir_with_parents (ontology_dir, 0777); g_free (ontology_dir); for (i = 0; changes[i].ontology; i++) { GFile *file1; gchar *queries = NULL; gchar *source = g_build_path (G_DIR_SEPARATOR_S, prefix, "change", "source", changes[i].ontology, NULL); gchar *update = g_build_path (G_DIR_SEPARATOR_S, prefix, "change", "updates", changes[i].update, NULL); gchar *from, *to; file1 = g_file_new_for_path (source); from = g_file_get_path (file1); to = g_file_get_path (file2); g_debug ("copy %s to %s", from, to); g_free (from); g_free (to); g_file_copy (file1, file2, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &error); g_assert_no_error (error); g_chmod (ontology_file, 0666); tracker_data_manager_init (0, (const gchar **) test_schemas, NULL, FALSE, FALSE, 100, 100, NULL, NULL, NULL, &error); g_assert_no_error (error); if (g_file_get_contents (update, &queries, NULL, NULL)) { gchar *query = strtok (queries, "\n"); while (query) { tracker_data_update_sparql (query, &error); g_assert_no_error (error); query = strtok (NULL, "\n"); } g_free (queries); } g_free (update); g_free (source); g_object_unref (file1); if (changes[i].test_name) { gchar *query_filename; gchar *results_filename; gchar *test_prefix; test_prefix = g_build_filename (prefix, changes[i].test_name, NULL); query_filename = g_strconcat (test_prefix, ".rq", NULL); results_filename = g_strconcat (test_prefix, ".out", NULL); query_helper (query_filename, results_filename); g_free (test_prefix); g_free (query_filename); g_free (results_filename); } tracker_data_manager_shutdown (); } delete_db (FALSE); tracker_data_manager_init (0, (const gchar **) test_schemas, NULL, TRUE, FALSE, 100, 100, NULL, NULL, NULL, &error); g_assert_no_error (error); for (i = 0; change_tests[i].test_name != NULL; i++) { gchar *query_filename; gchar *results_filename; gchar *test_prefix; test_prefix = g_build_filename (prefix, change_tests[i].test_name, NULL); query_filename = g_strconcat (test_prefix, ".rq", NULL); results_filename = g_strconcat (test_prefix, ".out", NULL); query_helper (query_filename, results_filename); g_free (test_prefix); g_free (query_filename); g_free (results_filename); } tracker_data_manager_shutdown (); g_file_delete (file2, NULL, NULL); g_object_unref (file2); g_free (test_schemas[0]); g_free (test_schemas[1]); g_free (test_schemas[2]); g_free (build_prefix); g_free (prefix); }