[tracker/roi-png-fix: 1/14] tests/libtracker-extract: Unit test to read regions in the XMP metadata
- From: Mikael Ottela <mottela src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/roi-png-fix: 1/14] tests/libtracker-extract: Unit test to read regions in the XMP metadata
- Date: Fri, 9 Sep 2011 14:17:56 +0000 (UTC)
commit 59b2ad7b49138669cc15c407e3541a5fb69bf310
Author: Ivan Frade <ivan frade gmail com>
Date: Mon Jul 25 18:39:52 2011 +0300
tests/libtracker-extract: Unit test to read regions in the XMP metadata
tests/libtracker-extract/Makefile.am | 2 +-
tests/libtracker-extract/areas-with-contacts.xmp | 53 +++++++++
tests/libtracker-extract/areas.xmp | 31 +++++
tests/libtracker-extract/tracker-test-xmp.c | 130 +++++++++++++++++++++-
4 files changed, 212 insertions(+), 4 deletions(-)
---
diff --git a/tests/libtracker-extract/Makefile.am b/tests/libtracker-extract/Makefile.am
index 8e78e50..7986025 100644
--- a/tests/libtracker-extract/Makefile.am
+++ b/tests/libtracker-extract/Makefile.am
@@ -30,4 +30,4 @@ tracker_test_utils_SOURCES = tracker-test-utils.c
tracker_test_xmp_SOURCES = tracker-test-xmp.c
-EXTRA_DIST = encoding-detect.bin
+EXTRA_DIST = encoding-detect.bin areas.xmp areas-with-contacts.xmp
diff --git a/tests/libtracker-extract/areas-with-contacts.xmp b/tests/libtracker-extract/areas-with-contacts.xmp
new file mode 100644
index 0000000..5479630
--- /dev/null
+++ b/tests/libtracker-extract/areas-with-contacts.xmp
@@ -0,0 +1,53 @@
+<x:xmpmeta xmlns:x='adobe:ns:meta/' x:xmptk='Image::ExifTool 8.60'>
+<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
+ <rdf:Description rdf:about=''
+ xmlns:mwg-rs='http://www.metadataworkinggroup.com/schemas/regions/'
+ xmlns:rdfs='http://www.w3.org/2000/01/rdf-schema#'
+ xmlns:stArea='http://ns.adobe.com/xap/1.0/sType/Area#'
+ xmlns:stDim='http://ns.adobe.com/xap/1.0/sType/Dimensions#'
+ xmlns:nco='http://www.semanticdesktop.org/ontologies/2007/03/22/nco#'
+ xmlns:xmpRights='http://ns.adobe.com/xap/1.0/rights/'>
+ <mwg-rs:Regions rdf:parseType='Resource'>
+ <mwg-rs:AppliedToDimensions rdf:parseType='Resource'>
+ <stDim:h>2848</stDim:h>
+ <stDim:unit>pixel</stDim:unit>
+ <stDim:w>4288</stDim:w>
+ </mwg-rs:AppliedToDimensions>
+ <mwg-rs:RegionList>
+ <rdf:Bag>
+ <rdf:li rdf:parseType='Resource'>
+ <mwg-rs:Area rdf:parseType='Resource'>
+ <stArea:h>0.17</stArea:h>
+ <stArea:unit>normalized</stArea:unit>
+ <stArea:w>0.15</stArea:w>
+ <stArea:x>0.3</stArea:x>
+ <stArea:y>0.4</stArea:y>
+ </mwg-rs:Area>
+ <mwg-rs:Extensions rdf:parseType='Resource'>
+ <nco:PersonContact>urn:uuid:1</nco:PersonContact>
+ </mwg-rs:Extensions>
+ <mwg-rs:Name>Albert Einstein</mwg-rs:Name>
+ <mwg-rs:Type>Face</mwg-rs:Type>
+ <rdfs:seeAlso rdf:resource='dc:subject'/>
+ </rdf:li>
+ <rdf:li rdf:parseType='Resource'>
+ <mwg-rs:Area rdf:parseType='Resource'>
+ <stArea:h>0.15</stArea:h>
+ <stArea:unit>normalized</stArea:unit>
+ <stArea:w>0.17</stArea:w>
+ <stArea:x>0.4</stArea:x>
+ <stArea:y>0.3</stArea:y>
+ </mwg-rs:Area>
+ <mwg-rs:Extensions rdf:parseType='Resource'>
+ <nco:PersonContact>urn:uuid:2</nco:PersonContact>
+ </mwg-rs:Extensions>
+ <mwg-rs:Name>Dilbert</mwg-rs:Name>
+ <mwg-rs:Type>Face</mwg-rs:Type>
+ <rdfs:seeAlso rdf:resource='dc:subject'/>
+ </rdf:li>
+ </rdf:Bag>
+ </mwg-rs:RegionList>
+ </mwg-rs:Regions>
+ </rdf:Description>
+</rdf:RDF>
+</x:xmpmeta>
diff --git a/tests/libtracker-extract/areas.xmp b/tests/libtracker-extract/areas.xmp
new file mode 100644
index 0000000..1a102cb
--- /dev/null
+++ b/tests/libtracker-extract/areas.xmp
@@ -0,0 +1,31 @@
+<x:xmpmeta
+ xmlns:x="adobe:ns:meta/"
+ xmlns:exif="http://ns.adobe.com/exif/1.0/"
+ xmlns:stDim="http://ns.adobe.com/xap/1.0/sType/Dimensions#"
+ xmlns:stArea="http://ns.adobe.com/xap/1.0/sType/Area#"
+ xmlns:mwg-rs="http://www.metadataworkinggroup.com/schemas/regions/">
+ <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
+ <rdf:Description rdf:about="">
+ <mwg-rs:Regions rdf:parseType="Resource">
+ <mwg-rs:AppliedToDimensions stDim:w="4288" stDim:h="2848" stDim:unit="pixel"/>
+ <mwg-rs:RegionList>
+ <rdf:Bag>
+ <rdf:li rdf:parseType="Resource">
+ <mwg-rs:Area stArea:x="0.5" stArea:y="0.5" stArea:w="0.06"
+ stArea:h="0.09" stArea:unit="normalized"/>
+ <mwg-rs:Type>Face</mwg-rs:Type>
+ <mwg-rs:Name>John Doe</mwg-rs:Name>
+ </rdf:li>
+ <rdf:li rdf:parseType="Resource">
+ <mwg-rs:Area stArea:x="0.51" stArea:y="0.51" stArea:w="0.01"
+ stArea:h="0.09" stArea:unit="normalized"/>
+ <mwg-rs:Type>Pet</mwg-rs:Type>
+ <mwg-rs:Name>Fido</mwg-rs:Name>
+ <mwg-rs:Description>Fido looks happy!</mwg-rs:Description>
+ </rdf:li>
+ </rdf:Bag>
+ </mwg-rs:RegionList>
+ </mwg-rs:Regions>
+ </rdf:Description>
+ </rdf:RDF>
+</x:xmpmeta>
diff --git a/tests/libtracker-extract/tracker-test-xmp.c b/tests/libtracker-extract/tracker-test-xmp.c
index b5db24e..8e1e0ff 100644
--- a/tests/libtracker-extract/tracker-test-xmp.c
+++ b/tests/libtracker-extract/tracker-test-xmp.c
@@ -88,6 +88,7 @@
" </rdf:Description>" \
" </rdf:RDF></x:xmpmeta> "
+
typedef struct {
const gchar *exif_value;
const gchar *nepomuk_translation;
@@ -255,7 +256,7 @@ test_xmp_metering_mode (void)
static void
test_xmp_orientation (void)
{
- gint i;
+ guint i;
for (i = 0; i < G_N_ELEMENTS (ORIENTATIONS); i++) {
TrackerXmpData *data;
@@ -336,6 +337,124 @@ test_xmp_apply_location (void)
g_assert_cmpint (tracker_sparql_builder_get_length (metadata), >=, 3);
}
+
+/*
+ * 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;
+ /* Print the sparql */
+ 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");
+
+ /* To add few more metadata */
+ //data->title = g_strdup ("test");
+
+ tracker_xmp_apply (preupdate, metadata, 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)
+{
+ TrackerXmpData *data;
+ TrackerXmpRegion *region;
+
+ GFile *f;
+ gchar *contents;
+ gsize size;
+
+ f = g_file_new_for_path ("./areas.xmp");
+ g_assert(g_file_load_contents (f, NULL, &contents, &size, NULL, NULL));
+ g_object_unref (f);
+
+ data = tracker_xmp_new (contents, size, "test://file");
+
+ g_assert_cmpint (2, ==, g_list_length (data->regions));
+
+ /* Regions are stacked while parsing.*/
+ region = g_list_nth_data (data->regions, 0);
+ g_assert_cmpstr (region->x, ==, "0.51");
+ g_assert_cmpstr (region->y, ==, "0.51");
+ g_assert_cmpstr (region->width, ==, "0.01");
+ g_assert_cmpstr (region->height, ==, "0.09");
+ g_assert_cmpstr (region->type, ==, "Pet");
+ g_assert_cmpstr (region->title, ==, "Fido");
+ g_assert_cmpstr (region->description, ==, "Fido looks happy!");
+
+ region = g_list_nth_data (data->regions, 1);
+ g_assert_cmpstr (region->x, ==, "0.5");
+ g_assert_cmpstr (region->y, ==, "0.5");
+ g_assert_cmpstr (region->width, ==, "0.06");
+ g_assert_cmpstr (region->height, ==, "0.09");
+ g_assert_cmpstr (region->type, ==, "Face");
+ g_assert_cmpstr (region->title, ==, "John Doe");
+
+ debug_print_sparql (data);
+
+ tracker_xmp_free (data);
+}
+
+static void
+test_xmp_regions_quill (void)
+{
+ TrackerXmpData *data;
+ TrackerXmpRegion *region;
+
+ GFile *f;
+ gchar *contents;
+ gsize size;
+
+ f = g_file_new_for_path ("./areas-with-contacts.xmp");
+ g_assert(g_file_load_contents (f, NULL, &contents, &size, NULL, NULL));
+ g_object_unref (f);
+
+ data = tracker_xmp_new (contents, size, "test://file");
+
+ g_assert_cmpint (2, ==, g_list_length (data->regions));
+
+ region = g_list_nth_data (data->regions, 0);
+ g_assert_cmpstr (region->x, ==, "0.4");
+ g_assert_cmpstr (region->y, ==, "0.3");
+ g_assert_cmpstr (region->width, ==, "0.17");
+ g_assert_cmpstr (region->height, ==, "0.15");
+ g_assert_cmpstr (region->type, ==, "Face");
+ g_assert_cmpstr (region->title, ==, "Dilbert");
+ g_assert_cmpstr (region->link_class, ==, "nco:PersonContact");
+ g_assert_cmpstr (region->link_uri, ==, "urn:uuid:2");
+
+ region = g_list_nth_data (data->regions, 1);
+ g_assert_cmpstr (region->x, ==, "0.3");
+ g_assert_cmpstr (region->y, ==, "0.4");
+ g_assert_cmpstr (region->width, ==, "0.15");
+ g_assert_cmpstr (region->height, ==, "0.17");
+ g_assert_cmpstr (region->type, ==, "Face");
+ g_assert_cmpstr (region->title, ==, "Albert Einstein");
+ 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);
+}
+
int
main (int argc,
char **argv)
@@ -349,9 +468,10 @@ main (int argc,
g_test_message ("Testing XMP");
#ifdef HAVE_EXEMPI
+
g_test_add_func ("/libtracker-extract/tracker-xmp/parsing_xmp",
test_parsing_xmp);
-
+/*
g_test_add_func ("/libtracker-extract/tracker-xmp/metering-mode",
test_xmp_metering_mode);
@@ -360,9 +480,13 @@ main (int argc,
g_test_add_func ("/libtracker-extract/tracker-xmp/sparql_translation",
test_xmp_apply);
+*/
+ g_test_add_func ("/libtracker-extract/tracker-xmp/xmp_regions",
+ test_xmp_regions);
+ g_test_add_func ("/libtracker-extract/tracker-xmp/xmp_regions_2",
+ test_xmp_regions_quill);
#endif
-
g_test_add_func ("/libtracker-extract/tracker-xmp/sparql_translation_location",
test_xmp_apply_location);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]