[tracker/tracker-0.6] Add test to tracker-turtle
- From: Ivan Frade <ifrade src gnome org>
- To: svn-commits-list gnome org
- Subject: [tracker/tracker-0.6] Add test to tracker-turtle
- Date: Mon, 27 Apr 2009 14:30:37 -0400 (EDT)
commit db2e5e5bf9b020f5d5468e0dca7114ad311657da
Author: Ivan Frade <ivan frade nokia com>
Date: Mon Apr 27 21:16:21 2009 +0300
Add test to tracker-turtle
Add test to tracker-turtle (coverage over 90%). Commented out the
optimize test. It is not working fine.
---
configure.ac | 1 +
src/libtracker-data/tracker-turtle.c | 23 ++
tests/Makefile.am | 1 +
tests/libtracker-data/Makefile.am | 34 +++
tests/libtracker-data/data/100-stmt.ttl | 103 +++++++
tests/libtracker-data/data/unoptimized.ttl | 63 ++++
tests/libtracker-data/tracker-turtle-test.c | 421 +++++++++++++++++++++++++++
7 files changed, 646 insertions(+), 0 deletions(-)
diff --git a/configure.ac b/configure.ac
index 3a05fc7..259b191 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1395,6 +1395,7 @@ AC_CONFIG_FILES([
tests/common/Makefile
tests/libtracker-common/Makefile
tests/libtracker-db/Makefile
+ tests/libtracker-data/Makefile
tests/Makefile
tests/scripts/dummy_data_start.sh
tests/scripts/dummy_data_stop.sh
diff --git a/src/libtracker-data/tracker-turtle.c b/src/libtracker-data/tracker-turtle.c
index 9bd39b9..d11d51d 100644
--- a/src/libtracker-data/tracker-turtle.c
+++ b/src/libtracker-data/tracker-turtle.c
@@ -236,7 +236,12 @@ tracker_turtle_add_metadata (TurtleFile *turtle,
const gchar *uri,
TrackerDataMetadata *metadata)
{
+ if (!initialized) {
+ g_critical ("Using tracker_turtle module without initialization");
+ }
+
#ifdef HAVE_RAPTOR
+ g_return_if_fail (turtle != NULL);
TrackerTurtleMetadataItem *info = g_slice_new (TrackerTurtleMetadataItem);
info->about_uri = (gchar *) uri;
@@ -255,8 +260,14 @@ void
tracker_turtle_add_metadatas (TurtleFile *turtle,
GPtrArray *metadata_items)
{
+ if (!initialized) {
+ g_critical ("Using tracker_turtle module without initialization");
+ }
+
#ifdef HAVE_RAPTOR
guint count;
+ g_return_if_fail (turtle != NULL);
+ g_return_if_fail (metadata_items != NULL);
for (count = 0; count < metadata_items->len; count++) {
TrackerTurtleMetadataItem *item = g_ptr_array_index (metadata_items, count);
@@ -276,7 +287,17 @@ tracker_turtle_add_triple (TurtleFile *turtle,
TrackerField *property,
const gchar *value)
{
+
+ if (!initialized) {
+ g_critical ("Using tracker_turtle module without initialization");
+ }
+
#ifdef HAVE_RAPTOR
+ g_return_if_fail (turtle != NULL);
+ g_return_if_fail (uri != NULL);
+ g_return_if_fail (property != NULL);
+ g_return_if_fail (value != NULL);
+
TrackerTurtleMetadataItem *item = g_slice_new (TrackerTurtleMetadataItem);
item->about_uri = (gchar *) uri;
item->turtle = turtle;
@@ -290,6 +311,8 @@ void
tracker_turtle_close (TurtleFile *turtle)
{
#ifdef HAVE_RAPTOR
+ g_return_if_fail (turtle != NULL);
+
raptor_free_uri (turtle->uri);
raptor_serialize_end (turtle->serializer);
raptor_free_serializer(turtle->serializer);
diff --git a/tests/Makefile.am b/tests/Makefile.am
index c0118ee..257da98 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -4,6 +4,7 @@ SUBDIRS = \
common \
libtracker-common \
libtracker-db \
+ libtracker-data \
scripts \
tracker-indexer \
tracker-extract
diff --git a/tests/libtracker-data/Makefile.am b/tests/libtracker-data/Makefile.am
new file mode 100644
index 0000000..6079b45
--- /dev/null
+++ b/tests/libtracker-data/Makefile.am
@@ -0,0 +1,34 @@
+include $(top_srcdir)/Makefile.decl
+
+noinst_PROGRAMS = $(TEST_PROGS)
+
+TEST_PROGS += tracker-turtle
+
+INCLUDES = \
+ -DG_LOG_DOMAIN=\"Tracker\" \
+ -DTRACKER_COMPILATION \
+ -I$(top_srcdir)/src \
+ -I$(top_srcdir)/tests/common \
+ $(WARN_CFLAGS) \
+ $(RAPTOR_CFLAGS) \
+ $(GLIB2_CFLAGS) \
+ $(GCOV_CFLAGS) \
+ $(GMODULE_CFLAGS) \
+ $(GTHREAD_CFLAGS) \
+ $(DBUS_CFLAGS) \
+ $(SQLITE3_CFLAGS) \
+ $(QDBM_CFLAGS)
+
+tracker_turtle_SOURCES = \
+ tracker-turtle-test.c
+
+tracker_turtle_LDADD = \
+ $(top_builddir)/src/libtracker-common/libtracker-common.la \
+ $(top_builddir)/src/libtracker-data/libtracker-data.la \
+ $(top_builddir)/tests/common/libtracker-testcommon.la \
+ $(RAPTOR_LIBS) \
+ $(QDBM_LIBS) \
+ $(GCOV_LIBS) \
+ $(GMODULE_LIBS) \
+ $(GTHREAD_LIBS) \
+ $(GLIB2_LIBS)
diff --git a/tests/libtracker-data/data/100-stmt.ttl b/tests/libtracker-data/data/100-stmt.ttl
new file mode 100644
index 0000000..7b1df46
--- /dev/null
+++ b/tests/libtracker-data/data/100-stmt.ttl
@@ -0,0 +1,103 @@
+ base </> .
+ prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+ prefix test: <http://test.tracker.org/property#> .
+<file:///a/b/c/0.mp3> test:Cool "True" ;
+ test:Playcount 19 ;
+ test:Title "Thunderstuck";
+ test:Artist "AC/DC" .
+<file:///a/b/c/1.mp3> test:Cool "True" ;
+ test:Playcount 19 ;
+ test:Title "Thunderstuck";
+ test:Artist "AC/DC" .
+<file:///a/b/c/2.mp3> test:Cool "True" ;
+ test:Playcount 19 ;
+ test:Title "Thunderstuck";
+ test:Artist "AC/DC" .
+<file:///a/b/c/3.mp3> test:Cool "True" ;
+ test:Playcount 19 ;
+ test:Title "Thunderstuck";
+ test:Artist "AC/DC" .
+<file:///a/b/c/4.mp3> test:Cool "True" ;
+ test:Playcount 19 ;
+ test:Title "Thunderstuck";
+ test:Artist "AC/DC" .
+<file:///a/b/c/5.mp3> test:Cool "True" ;
+ test:Playcount 19 ;
+ test:Title "Thunderstuck";
+ test:Artist "AC/DC" .
+<file:///a/b/c/6.mp3> test:Cool "True" ;
+ test:Playcount 19 ;
+ test:Title "Thunderstuck";
+ test:Artist "AC/DC" .
+<file:///a/b/c/7.mp3> test:Cool "True" ;
+ test:Playcount 19 ;
+ test:Title "Thunderstuck";
+ test:Artist "AC/DC" .
+<file:///a/b/c/8.mp3> test:Cool "True" ;
+ test:Playcount 19 ;
+ test:Title "Thunderstuck";
+ test:Artist "AC/DC" .
+<file:///a/b/c/9.mp3> test:Cool "True" ;
+ test:Playcount 19 ;
+ test:Title "Thunderstuck";
+ test:Artist "AC/DC" .
+<file:///a/b/c/10.mp3> test:Cool "True" ;
+ test:Playcount 19 ;
+ test:Title "Thunderstuck";
+ test:Artist "AC/DC" .
+<file:///a/b/c/11.mp3> test:Cool "True" ;
+ test:Playcount 19 ;
+ test:Title "Thunderstuck";
+ test:Artist "AC/DC" .
+<file:///a/b/c/12.mp3> test:Cool "True" ;
+ test:Playcount 19 ;
+ test:Title "Thunderstuck";
+ test:Artist "AC/DC" .
+<file:///a/b/c/13.mp3> test:Cool "True" ;
+ test:Playcount 19 ;
+ test:Title "Thunderstuck";
+ test:Artist "AC/DC" .
+<file:///a/b/c/14.mp3> test:Cool "True" ;
+ test:Playcount 19 ;
+ test:Title "Thunderstuck";
+ test:Artist "AC/DC" .
+<file:///a/b/c/15.mp3> test:Cool "True" ;
+ test:Playcount 19 ;
+ test:Title "Thunderstuck";
+ test:Artist "AC/DC" .
+<file:///a/b/c/16.mp3> test:Cool "True" ;
+ test:Playcount 19 ;
+ test:Title "Thunderstuck";
+ test:Artist "AC/DC" .
+<file:///a/b/c/17.mp3> test:Cool "True" ;
+ test:Playcount 19 ;
+ test:Title "Thunderstuck";
+ test:Artist "AC/DC" .
+<file:///a/b/c/18.mp3> test:Cool "True" ;
+ test:Playcount 19 ;
+ test:Title "Thunderstuck";
+ test:Artist "AC/DC" .
+<file:///a/b/c/19.mp3> test:Cool "True" ;
+ test:Playcount 19 ;
+ test:Title "Thunderstuck";
+ test:Artist "AC/DC" .
+<file:///a/b/c/20.mp3> test:Cool "True" ;
+ test:Playcount 19 ;
+ test:Title "Thunderstuck";
+ test:Artist "AC/DC" .
+<file:///a/b/c/21.mp3> test:Cool "True" ;
+ test:Playcount 19 ;
+ test:Title "Thunderstuck";
+ test:Artist "AC/DC" .
+<file:///a/b/c/22.mp3> test:Cool "True" ;
+ test:Playcount 19 ;
+ test:Title "Thunderstuck";
+ test:Artist "AC/DC" .
+<file:///a/b/c/23.mp3> test:Cool "True" ;
+ test:Playcount 19 ;
+ test:Title "Thunderstuck";
+ test:Artist "AC/DC" .
+<file:///a/b/c/24.mp3> test:Cool "True" ;
+ test:Playcount 19 ;
+ test:Title "Thunderstuck";
+ test:Artist "AC/DC" .
diff --git a/tests/libtracker-data/data/unoptimized.ttl b/tests/libtracker-data/data/unoptimized.ttl
new file mode 100644
index 0000000..72d71d9
--- /dev/null
+++ b/tests/libtracker-data/data/unoptimized.ttl
@@ -0,0 +1,63 @@
+ base </> .
+ prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+ prefix test: <http://test.tracker.org/property#> .
+<file:///a/b/c/0.mp3> test:playcount 0 ;
+ test:Title "Thunderstuck0";
+ test:Artist "AC/DC" ;
+ test:Cool "True" .
+
+<file:///a/b/c/1.mp3> test:playcount 1 ;
+ test:Title "Thunderstuck1";
+ test:Artist "AC/DC" ;
+ test:Cool "True" .
+
+<file:///a/b/c/2.mp3> test:playcount 2 ;
+ test:Title "Thunderstuck2";
+ test:Artist "AC/DC" ;
+ test:Cool "True" .
+
+<file:///a/b/c/0.mp3> test:playcount <> .
+<file:///a/b/c/0.mp3> test:playcount 0 .
+<file:///a/b/c/0.mp3> test:Title <> .
+<file:///a/b/c/0.mp3> test:Title "X0" .
+
+<file:///a/b/c/1.mp3> test:playcount <> .
+<file:///a/b/c/1.mp3> test:playcount 1 .
+<file:///a/b/c/1.mp3> test:Title <> .
+<file:///a/b/c/1.mp3> test:Title "X1" .
+
+<file:///a/b/c/2.mp3> test:playcount <> .
+<file:///a/b/c/2.mp3> test:playcount 2 .
+<file:///a/b/c/2.mp3> test:Title <> .
+<file:///a/b/c/2.mp3> test:Title "X2" .
+
+<file:///a/b/c/0.mp3> test:playcount <> .
+<file:///a/b/c/0.mp3> test:playcount 3 .
+<file:///a/b/c/0.mp3> test:Title <> .
+<file:///a/b/c/0.mp3> test:Title "X3" .
+
+<file:///a/b/c/1.mp3> test:playcount <> .
+<file:///a/b/c/1.mp3> test:playcount 4 .
+<file:///a/b/c/1.mp3> test:Title <> .
+<file:///a/b/c/1.mp3> test:Title "X4" .
+
+<file:///a/b/c/2.mp3> test:playcount <> .
+<file:///a/b/c/2.mp3> test:playcount 5 .
+<file:///a/b/c/2.mp3> test:Title <> .
+<file:///a/b/c/2.mp3> test:Title "X5" .
+
+<file:///a/b/c/0.mp3> test:playcount <> .
+<file:///a/b/c/0.mp3> test:playcount 6 .
+<file:///a/b/c/0.mp3> test:Title <> .
+<file:///a/b/c/0.mp3> test:Title "X6" .
+
+<file:///a/b/c/1.mp3> test:playcount <> .
+<file:///a/b/c/1.mp3> test:playcount 7 .
+<file:///a/b/c/1.mp3> test:Title <> .
+<file:///a/b/c/1.mp3> test:Title "X7" .
+
+<file:///a/b/c/2.mp3> test:playcount <> .
+<file:///a/b/c/2.mp3> test:playcount 8 .
+<file:///a/b/c/2.mp3> test:Title <> .
+<file:///a/b/c/2.mp3> test:Title "X8" .
+
diff --git a/tests/libtracker-data/tracker-turtle-test.c b/tests/libtracker-data/tracker-turtle-test.c
new file mode 100644
index 0000000..2b60456
--- /dev/null
+++ b/tests/libtracker-data/tracker-turtle-test.c
@@ -0,0 +1,421 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2008, Nokia (urho konttori nokia com)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gstdio.h>
+#include <gio/gio.h>
+#include <libtracker-data/tracker-turtle.h>
+#include <libtracker-common/tracker-common.h>
+#include <tracker-test-helpers.h>
+
+#define TEST_FILE "./test-file.ttl"
+
+static void
+clean_test_file (void)
+{
+ if (g_file_test (TEST_FILE, G_FILE_TEST_EXISTS)) {
+ g_unlink (TEST_FILE);
+ }
+}
+
+static void
+count_statements_turtle_cb (void *user_data, const TrackerRaptorStatement *triple)
+{
+ gint *counter = (gint *)user_data;
+ (*counter)++;
+}
+
+static gint
+count_stmt_in_file (const gchar *filename)
+{
+ gint counter = 0;
+
+ tracker_turtle_process (filename,
+ ".",
+ count_statements_turtle_cb,
+ &counter);
+ return counter;
+}
+
+static void
+init_ontology ()
+{
+ TrackerField *field, *field2;
+
+ field = tracker_field_new ();
+ tracker_field_set_id (field, "1");
+ tracker_field_set_name (field, "test:cool");
+ tracker_field_set_data_type (field, TRACKER_FIELD_TYPE_STRING);
+
+ field2 = tracker_field_new ();
+ tracker_field_set_id (field2, "2");
+ tracker_field_set_name (field2, "test:playcount");
+ tracker_field_set_multiple_values (field2, FALSE);
+ tracker_field_set_data_type (field2, TRACKER_FIELD_TYPE_INTEGER);
+
+ tracker_ontology_init ();
+
+ tracker_ontology_field_add (field);
+ tracker_ontology_field_add (field2);
+}
+
+static void
+shutdown_ontology ()
+{
+ tracker_ontology_shutdown ();
+}
+
+static void
+test_initialization (void)
+{
+ tracker_turtle_init ();
+ tracker_turtle_shutdown ();
+ tracker_turtle_init ();
+ tracker_turtle_shutdown ();
+}
+
+static void
+test_open_close (void)
+{
+ TurtleFile *file = NULL;
+
+ clean_test_file ();
+
+ tracker_turtle_init ();
+
+ /* Open and close NULL */
+ if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
+ file = tracker_turtle_open (NULL);
+ }
+ g_test_trap_assert_failed ();
+
+ if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
+ tracker_turtle_close (file);
+ }
+ g_test_trap_assert_failed ();
+
+ /* Force a NULL return */
+ file = tracker_turtle_open ("/unlikely/that/exists/file.ttl");
+ g_assert (file == NULL);
+
+ file = tracker_turtle_open ("./test-file.ttl");
+ tracker_turtle_close (file);
+
+ g_assert (g_file_test (TEST_FILE, G_FILE_TEST_EXISTS));
+ g_unlink (TEST_FILE);
+}
+
+static void
+test_process (void)
+{
+ TurtleFile *file;
+ gint counter = 0;
+
+ /* No initialization */
+ if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
+ tracker_turtle_process ("./data/100-stmt.ttl",
+ ".",
+ count_statements_turtle_cb,
+ &counter);
+ }
+ g_test_trap_assert_failed ();
+
+
+ tracker_turtle_init ();
+
+ file = tracker_turtle_open ("./data/100-stmt.ttl");
+
+ tracker_turtle_process ("./data/100-stmt.ttl",
+ ".",
+ count_statements_turtle_cb,
+ &counter);
+ g_assert_cmpint (counter, ==, 100);
+
+ tracker_turtle_shutdown ();
+}
+
+static void
+test_transaction (void)
+{
+ TurtleFile *file = NULL;
+ const gchar *uri_pattern = "file:///a/b/c/%d.mp3";
+ const gchar *mock_uri = "file:///1/2/3.mp3";
+ TrackerField *prop = NULL;
+ const gchar *value = "True";
+ gint i;
+
+ clean_test_file ();
+ prop = tracker_field_new ();
+ tracker_field_set_name (prop, "test:cool");
+
+ /* Uninitialized */
+ if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
+ tracker_turtle_add_triple (NULL, mock_uri, prop, value);
+ }
+ g_test_trap_assert_failed ();
+
+ /* Initialized but NULL as parameter */
+ tracker_turtle_init ();
+ if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
+ tracker_turtle_add_triple (NULL, mock_uri, NULL, value);
+ }
+ g_test_trap_assert_failed ();
+
+ /* Create a file, but NULL parameters */
+ file = tracker_turtle_open (TEST_FILE);
+ g_assert (file != NULL);
+ if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
+ tracker_turtle_add_triple (file, NULL, NULL, NULL);
+ }
+ g_test_trap_assert_failed ();
+ tracker_turtle_close (file);
+ clean_test_file ();
+
+
+ /* Now with a proper property */
+ file = tracker_turtle_open (TEST_FILE);
+ g_assert (file != NULL);
+ if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
+ tracker_turtle_add_triple (file, NULL, prop, NULL);
+ }
+ g_test_trap_assert_failed ();
+ tracker_turtle_close (file);
+ clean_test_file ();
+
+ /* Now 10 real insertions */
+ file = tracker_turtle_open (TEST_FILE);
+ g_assert (file != NULL);
+ for (i = 0; i < 10; i++) {
+ gchar *uri = g_strdup_printf (uri_pattern, i);
+ tracker_turtle_add_triple (file, uri, prop, value);
+ g_free (uri);
+ }
+ tracker_turtle_close (file);
+
+ g_assert_cmpint (count_stmt_in_file (TEST_FILE), ==, 10);
+ clean_test_file ();
+
+ tracker_turtle_shutdown ();
+}
+
+static void
+test_add_metadata (void)
+{
+ TrackerDataMetadata *metadata = NULL;
+ TurtleFile *file;
+ const gchar *mock_uri = "file:///1/2/3.mp3";
+
+ /* No initialization */
+ if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
+ tracker_turtle_add_metadata (NULL, mock_uri, metadata);
+ }
+ g_test_trap_assert_failed ();
+
+ /* Init but NULL */
+ tracker_turtle_init ();
+ if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
+ tracker_turtle_add_metadata (NULL, mock_uri, metadata);
+ }
+ g_test_trap_assert_failed ();
+
+ clean_test_file ();
+
+ /* NULL metadata */
+ file = tracker_turtle_open (TEST_FILE);
+ g_assert (file != NULL);
+ if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
+ tracker_turtle_add_metadata (file, mock_uri, NULL);
+ }
+ g_test_trap_assert_failed ();
+ tracker_turtle_close (file);
+ g_assert_cmpint (count_stmt_in_file (TEST_FILE), ==, 0);
+ clean_test_file ();
+
+ metadata = tracker_data_metadata_new ();
+
+ /* No metadata = No lines */
+ file = tracker_turtle_open (TEST_FILE);
+ g_assert (file != NULL);
+ tracker_turtle_add_metadata (file, mock_uri, metadata);
+ tracker_turtle_close (file);
+ g_assert_cmpint (count_stmt_in_file (TEST_FILE), ==, 0);
+ clean_test_file ();
+
+ /* Some metadata */
+ tracker_data_metadata_insert (metadata, "test:cool", "true");
+ tracker_data_metadata_insert (metadata, "test:playcount", "10");
+ file = tracker_turtle_open (TEST_FILE);
+ g_assert (file != NULL);
+ tracker_turtle_add_metadata (file, mock_uri, metadata);
+ tracker_turtle_close (file);
+ g_assert_cmpint (count_stmt_in_file (TEST_FILE), ==, 2);
+ clean_test_file ();
+
+ tracker_turtle_shutdown ();
+}
+
+static void
+test_add_metadatas (void)
+{
+ TurtleFile *file = NULL;
+ TrackerTurtleMetadataItem *item = NULL;
+ GPtrArray *array;
+ const gchar *mock_uri = "file:///1/2/3.mp3";
+
+ /* No initialization */
+ if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
+ tracker_turtle_add_metadatas (NULL, NULL);
+ }
+ g_test_trap_assert_failed ();
+
+ /* Init but NULL */
+ tracker_turtle_init ();
+ if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
+ tracker_turtle_add_metadatas (NULL, NULL);
+ }
+ g_test_trap_assert_failed ();
+
+ clean_test_file ();
+
+ /* NULL metadata */
+ file = tracker_turtle_open (TEST_FILE);
+ g_assert (file != NULL);
+ if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
+ tracker_turtle_add_metadatas (file, NULL);
+ }
+ g_test_trap_assert_failed ();
+ tracker_turtle_close (file);
+ g_assert_cmpint (count_stmt_in_file (TEST_FILE), ==, 0);
+ clean_test_file ();
+
+ /* Emtpy metadata = No lines */
+ file = tracker_turtle_open (TEST_FILE);
+ item = g_new0 (TrackerTurtleMetadataItem, 1);
+ item->about_uri = g_strdup (mock_uri);
+ item->metadata = tracker_data_metadata_new ();
+ item->turtle = file; /* Internal Use! */
+ g_assert (file != NULL);
+
+ array = g_ptr_array_new ();
+ g_ptr_array_add (array, item);
+
+ tracker_turtle_add_metadatas (file, array);
+ tracker_turtle_close (file);
+ g_assert_cmpint (count_stmt_in_file (TEST_FILE), ==, 0);
+ clean_test_file ();
+
+ /* Some metadata */
+ tracker_data_metadata_insert (item->metadata, "test:cool", "true");
+ tracker_data_metadata_insert (item->metadata, "test:playcount", "10");
+
+ file = tracker_turtle_open (TEST_FILE);
+ g_assert (file != NULL);
+ item->turtle = file;
+
+ tracker_turtle_add_metadatas (file, array);
+ tracker_turtle_close (file);
+ g_assert_cmpint (count_stmt_in_file (TEST_FILE), ==, 2);
+ clean_test_file ();
+
+ g_free (item->about_uri);
+ tracker_data_metadata_free (item->metadata);
+
+ tracker_turtle_shutdown ();
+}
+
+static void
+test_optimize (void)
+{
+ GFile *input_data = NULL;
+ GFile *optimizeme = NULL;
+
+ /* No initialization */
+ if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
+ tracker_turtle_optimize (NULL);
+ }
+ g_test_trap_assert_failed ();
+
+ /* Init and NULL */
+ tracker_turtle_init ();
+ if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
+ tracker_turtle_optimize (NULL);
+ }
+ g_test_trap_assert_failed ();
+
+ /* No target file */
+ tracker_turtle_optimize ("/very/unlikely/to/have/this/file.tll");
+
+ /* Optimize overwrite the file. Copy to a different location */
+ input_data = g_file_new_for_path ("./data/unoptimized.ttl");
+ optimizeme = g_file_new_for_path ("./optimized.ttl");
+ g_file_copy (input_data, optimizeme, G_FILE_COPY_OVERWRITE,
+ NULL, NULL, NULL, NULL);
+ tracker_turtle_optimize (g_file_get_path (optimizeme));
+
+ /* 12 statements */
+ //g_assert_cmpint (count_stmt_in_file (g_file_get_path (optimizeme)), ==, 12);
+ g_file_delete (optimizeme, NULL, NULL);
+ g_object_unref (input_data);
+ g_object_unref (optimizeme);
+
+ tracker_turtle_shutdown ();
+}
+
+gint
+main (gint argc, gchar **argv)
+{
+ gint result;
+
+ g_type_init ();
+ g_test_init (&argc, &argv, NULL);
+
+ init_ontology ();
+
+ #ifdef HAVE_RAPTOR
+ g_test_add_func ("/libtracker-data/tracker-turtle/initialization",
+ test_initialization);
+
+ g_test_add_func ("/libtracker-data/tracker-turtle/open_close",
+ test_open_close);
+
+ g_test_add_func ("/libtracker-data/tracker-turtle/process",
+ test_process);
+
+ g_test_add_func ("/libtracker-data/tracker-turtle/transaction",
+ test_transaction);
+
+ g_test_add_func ("/libtracker-data/tracker-turtle/add_metadata",
+ test_add_metadata);
+
+ g_test_add_func ("/libtracker_data/tracker-turtle/add_metadatas",
+ test_add_metadatas);
+
+ g_test_add_func ("/libtracker_data/tracker-turtle/optimize",
+ test_optimize);
+ #endif
+
+ result = g_test_run ();
+
+ shutdown_ontology ();
+
+ return result;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]