summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSam Thursfield <ssssam@gmail.com>2016-03-27 00:15:33 +0000
committerSam Thursfield <sam@afuera.me.uk>2016-07-14 13:20:48 +0100
commit8cc026da8cdebba4d5b17ed23841ec59d79f60e3 (patch)
treeeb5af6ba2150d6dcd86a70582ab736c9eb48b3ce /tests
parent032e2a7ed874bacce4ca5f0dd9ddbad6ab8f5f81 (diff)
downloadtracker-8cc026da8cdebba4d5b17ed23841ec59d79f60e3.tar.gz
Use TrackerResource instead of TrackerSparqlBuilder in all extractorswip/sam/resource-rebase-6
For a long time, all the Tracker extractors have manually constructed a SPARQL update command using TrackerSparqlBuilder to represent their output. This commit changes all of them to use the TrackerResource class instead, which makes the code a lot more concise and readable. This introduces some API breaks in the internal libtracker-extract library. This has been a private library since Tracker 0.16 or earlier, so it's fine. If the extractors only output SPARQL then they are only useful to people who are using a SPARQL store. Now we can output a serialization format like Turtle as well. This will hopefully make the extract modules useful outside of Tracker itself. I've tried to preserve the behaviour of the extractors as much as possible, but there are two things that are now handled differently: * nao:Tag resources are given a fixed URI based on the tag label, such as <urn:tag:My_Tag>. Previously they were inserted as blank nodes, so tracker-store would give them unique IDs like <urn:uuid:1234...> * All extractors created nco:Contact resources for content publishers, but previously some would assign fixed URIs based on the name <urn:contact:James%20Joyce>, while others would insert them as blank nodes so they would be assigned unique IDs like <urn:uuid:1234...>. Now, all extractors create nco:Contact resources with fixed URIs based on the content creator's name. https://bugzilla.gnome.org/show_bug.cgi?id=767472
Diffstat (limited to 'tests')
-rw-r--r--tests/libtracker-extract/tracker-extract-info-test.c13
-rw-r--r--tests/libtracker-extract/tracker-test-xmp.c107
2 files changed, 22 insertions, 98 deletions
diff --git a/tests/libtracker-extract/tracker-extract-info-test.c b/tests/libtracker-extract/tracker-extract-info-test.c
index d8b3b182e..d189d44c3 100644
--- a/tests/libtracker-extract/tracker-extract-info-test.c
+++ b/tests/libtracker-extract/tracker-extract-info-test.c
@@ -29,21 +29,12 @@ test_extract_info_setters (void)
file = g_file_new_for_path ("./imaginary-file-2");
- info = tracker_extract_info_new (file, "imaginary/mime", "test-graph", "test-urn");
+ info = tracker_extract_info_new (file, "imaginary/mime");
info_ref = tracker_extract_info_ref (info);
g_assert (g_file_equal (file, tracker_extract_info_get_file (info)));
g_assert_cmpstr (tracker_extract_info_get_mimetype (info), ==, "imaginary/mime");
- g_assert_cmpstr (tracker_extract_info_get_graph (info), ==, "test-graph");
- g_assert_cmpstr (tracker_extract_info_get_urn (info), ==, "test-urn");
- g_assert (tracker_extract_info_get_preupdate_builder (info));
- g_assert (tracker_extract_info_get_postupdate_builder (info));
- g_assert (tracker_extract_info_get_metadata_builder (info));
-
- g_assert (!tracker_extract_info_get_where_clause (info));
- tracker_extract_info_set_where_clause (info, "where stuff");
- g_assert_cmpstr (tracker_extract_info_get_where_clause (info), ==, "where stuff");
tracker_extract_info_unref (info_ref);
tracker_extract_info_unref (info);
@@ -59,7 +50,7 @@ test_extract_info_empty_objects (void)
file = g_file_new_for_path ("./imaginary-file");
- info = tracker_extract_info_new (file, "imaginary/mime", "test-graph", "test-urn");
+ info = tracker_extract_info_new (file, "imaginary/mime");
info_ref = tracker_extract_info_ref (info);
tracker_extract_info_unref (info_ref);
diff --git a/tests/libtracker-extract/tracker-test-xmp.c b/tests/libtracker-extract/tracker-test-xmp.c
index 0936e2ccd..0cf7afcc2 100644
--- a/tests/libtracker-extract/tracker-test-xmp.c
+++ b/tests/libtracker-extract/tracker-test-xmp.c
@@ -284,108 +284,53 @@ test_xmp_orientation (void)
static void
test_xmp_apply (void)
{
- TrackerSparqlBuilder *metadata, *preupdate;
- GString *where;
+ TrackerResource *resource;
+ TrackerResource *artist;
TrackerXmpData *data;
- const gchar *graph = NULL;
- metadata = tracker_sparql_builder_new_update ();
- preupdate = tracker_sparql_builder_new_update ();
- where = g_string_new ("");
+ resource = tracker_resource_new ("urn:uuid:test");
data = tracker_xmp_new (EXAMPLE_XMP, strlen (EXAMPLE_XMP), "urn:uuid:test");
g_assert (data != NULL);
- tracker_sparql_builder_insert_open (metadata, NULL);
- tracker_sparql_builder_subject_iri (metadata, "urn:uuid:test");
+ g_assert (tracker_xmp_apply_to_resource (resource, data));
- g_assert (tracker_xmp_apply (preupdate, metadata, graph, where, "urn:uuid:test", data));
+ /* We just check a few of the properties at random. */
+ g_assert_cmpstr (tracker_resource_get_first_string (resource, "nie:description"), ==,
+ "Description of the content");
- tracker_sparql_builder_insert_close (metadata);
+ artist = tracker_resource_get_first_relation (resource, "nco:contributor");
+ g_assert_cmpstr (tracker_resource_get_first_string(artist, "nco:fullname"), ==,
+ "Artist in exif");
- /* This is the only way to check the sparql is kinda correct */
-
- /* Disabled this for 0.8.5. It was reporting 41 not 50, this
- * test is not credible and I can't see how it can be trusted
- * as a method for making sure the query is correct.
- *
- * -mr
- */
-
- /* g_assert_cmpint (tracker_sparql_builder_get_length (metadata), ==, 50); */
- g_string_free (where, TRUE);
- g_object_unref (metadata);
- g_object_unref (preupdate);
-
- tracker_xmp_free (data);
+ tracker_xmp_free (data);
}
static void
test_xmp_apply_location (void)
{
TrackerXmpData data = { 0, };
- TrackerSparqlBuilder *metadata, *preupdate;
- GString *where;
- const gchar *graph = NULL;
+ TrackerResource *resource, *location, *address;
data.address = g_strdup ("Itamerenkatu 11-13");
data.city = g_strdup ("Helsinki");
data.state = g_strdup ("N/A");
data.country = g_strdup ("Findland");
- metadata = tracker_sparql_builder_new_update ();
- preupdate = tracker_sparql_builder_new_update ();
- where = g_string_new ("");
-
- tracker_sparql_builder_insert_open (metadata, NULL);
- tracker_sparql_builder_subject_iri (metadata, "urn:uuid:test");
-
- g_assert (tracker_xmp_apply (preupdate, metadata, graph, where, "urn:uuid:test", &data));
-
- tracker_sparql_builder_insert_close (metadata);
+ resource = tracker_resource_new ("urn:uuid:test");
- /* This is the only way to check the sparql is kinda correct */
+ g_assert (tracker_xmp_apply_to_resource (resource, &data));
- /* The builder just contains this:
- <urn:uuid:test> slo:location [ a slo:GeoLocation ;
- slo:postalAddress <urn:uuid:c50c4305-c617-4188-b3d3-42ba2291d0de>] .
- } */
+ location = tracker_resource_get_first_relation (resource, "slo:location");
+ address = tracker_resource_get_first_relation (location, "slo:postalAddress");
- g_assert_cmpint (tracker_sparql_builder_get_length (metadata), >=, 3);
+ g_assert_cmpstr (tracker_resource_get_first_string (address, "nco:streetAddress"), ==, data.address);
+ g_assert_cmpstr (tracker_resource_get_first_string (address, "nco:region"), ==, data.state);
+ g_assert_cmpstr (tracker_resource_get_first_string (address, "nco:locality"), ==, data.city);
+ g_assert_cmpstr (tracker_resource_get_first_string (address, "nco:country"), ==, data.country);
}
-/*
- * The generated sparql cannot be validated automatically.
- * Debug function to print it in the terminal.
- */
-static void
-debug_print_sparql (TrackerXmpData *data)
-{
- /* To print the sparql */
- TrackerSparqlBuilder *metadata, *preupdate;
- GString *where;
- const gchar *graph = NULL;
-
- metadata = tracker_sparql_builder_new_update ();
- preupdate = tracker_sparql_builder_new_update ();
- where = g_string_new ("");
-
- tracker_sparql_builder_insert_open (metadata, NULL);
- tracker_sparql_builder_subject_iri (metadata, "urn:uuid:test");
-
- tracker_xmp_apply (preupdate, metadata, graph, where, "urn:uuid:test", data);
-
- tracker_sparql_builder_insert_close (metadata);
-
- g_print ("%s\n", tracker_sparql_builder_get_result (preupdate));
- g_print ("%s\n", tracker_sparql_builder_get_result (metadata));
-
- g_object_unref (metadata);
- g_object_unref (preupdate);
- g_string_free (where, TRUE);
-}
-
static void
test_xmp_regions (void)
{
@@ -426,10 +371,6 @@ test_xmp_regions (void)
g_assert_cmpstr (region->type, ==, "Face");
g_assert_cmpstr (region->title, ==, "John Doe");
- if (0) {
- debug_print_sparql (data);
- }
-
tracker_xmp_free (data);
}
@@ -476,8 +417,6 @@ test_xmp_regions_quill (void)
g_assert_cmpstr (region->link_class, ==, "nco:PersonContact");
g_assert_cmpstr (region->link_uri, ==, "urn:uuid:1");
- //debug_print_sparql (data);
-
tracker_xmp_free (data);
}
@@ -521,8 +460,6 @@ test_xmp_regions_ns_prefix (void)
g_assert_cmpstr (region->type, ==, "Face");
g_assert_cmpstr (region->title, ==, "Average Joe");
- //debug_print_sparql (data);
-
tracker_xmp_free (data);
}
@@ -557,8 +494,6 @@ test_xmp_regions_nb282393 ()
g_assert_cmpstr (region->height, ==, "0.440000");
g_assert_cmpstr (region->title, ==, " ");
- //debug_print_sparql (data);
-
tracker_xmp_free (data);
}
@@ -596,8 +531,6 @@ test_xmp_regions_nb282393_2 ()
g_assert_cmpstr (region->link_class, ==, "nco:PersonContact");
g_assert_cmpstr (region->link_uri, ==, "urn:uuid:840a3c05-6cc6-48a1-bb56-fc50fae3345a");
- //debug_print_sparql (data);
-
tracker_xmp_free (data);
}