tracker-0.16.2/tests/libtracker-extract/tracker-test-xmp.c

No issues found

  1 /*
  2  * Copyright (C) 2010, Nokia <ivan.frade@nokia.com>
  3  *
  4  * This library is free software; you can redistribute it and/or
  5  * modify it under the terms of the GNU General Public
  6  * License as published by the Free Software Foundation; either
  7  * version 2 of the License, or (at your option) any later version.
  8  *
  9  * This library is distributed in the hope that it will be useful,
 10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 12  * General Public License for more details.
 13  *
 14  * You should have received a copy of the GNU General Public
 15  * License along with this library; if not, write to the
 16  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 17  * Boston, MA  02110-1301, USA.
 18  */
 19 
 20 #include "config.h"
 21 
 22 #include <glib-object.h>
 23 
 24 #include <libtracker-extract/tracker-extract.h>
 25 
 26 #define BROKEN_XMP "This is not even XML"
 27 #define EXAMPLE_XMP	  \
 28 "   <x:xmpmeta   " \
 29 "      xmlns:x=\'adobe:ns:meta/\'" \
 30 "      xmlns:dc=\"http://purl.org/dc/elements/1.1/\"" \
 31 "      xmlns:xmp=\"http://ns.adobe.com/xap/1.0/\"" \
 32 "      xmlns:exif=\"http://ns.adobe.com/exif/1.0/\"" \
 33 "      xmlns:tiff=\"http://ns.adobe.com/tiff/1.0/\">" \
 34 "     <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">" \
 35 "        <rdf:Description rdf:about=\"\">" \
 36 "         <dc:format>application/pdf</dc:format>" \
 37 "         <dc:title>Title of the content</dc:title>" \
 38 "         <dc:rights>CC share alike</dc:rights> " \
 39 "         <dc:description>Description of the content</dc:description>" \
 40 "         <dc:date>2010-03-18T15:17:04Z</dc:date>" \
 41 "         <dc:keywords>test, data, xmp</dc:keywords>" \
 42 "         <dc:subject>Subject of the content</dc:subject>" \
 43 "         <dc:publisher>A honest developer</dc:publisher>" \
 44 "         <dc:contributor>A honest contributor</dc:contributor>" \
 45 "         <dc:type>PhysicalObject</dc:type>" \
 46 "         <dc:identifier>12345</dc:identifier>" \
 47 "         <dc:source>My dirty mind</dc:source>" \
 48 "         <dc:language>Spanglish</dc:language>" \
 49 "         <dc:relation>Single</dc:relation>" \
 50 "         <dc:coverage>Pretty high after this test</dc:coverage>" \
 51 "         <dc:creator>The ultimate creator</dc:creator>" \
 52 "         <exif:Title>Title in exif</exif:Title>" \
 53 "         <exif:DateTimeOriginal>2010-03-18T15:17:04Z</exif:DateTimeOriginal>" \
 54 "         <exif:Artist>Artist in exif</exif:Artist>" \
 55 "         <exif:Make>Make in exif</exif:Make>" \
 56 "         <exif:Model>Model in exif</exif:Model>" \
 57 "         <exif:Flash>0</exif:Flash>" \
 58 "         <exif:MeteringMode>3</exif:MeteringMode>" \
 59 "         <exif:ExposureTime>1000</exif:ExposureTime>" \
 60 "         <exif:FNumber>12</exif:FNumber>" \
 61 "         <exif:FocalLength>50</exif:FocalLength>" \
 62 "         <exif:ISOSpeedRatings>400</exif:ISOSpeedRatings>" \
 63 "         <exif:WhiteBalance>1</exif:WhiteBalance>" \
 64 "         <exif:Copyright>Copyright in exif</exif:Copyright>" \
 65 "         <tiff:Orientation>1</tiff:Orientation>" \
 66 "         <xmp:CreateDate>2002-08-15T17:10:04Z</xmp:CreateDate>" \
 67 "        </rdf:Description> " \
 68 "     </rdf:RDF> " \
 69 "   </x:xmpmeta>"
 70 
 71 #define METERING_MODE_XMP \
 72 "   <x:xmpmeta   " \
 73 "      xmlns:x=\'adobe:ns:meta/\'" \
 74 "      xmlns:exif=\"http://ns.adobe.com/exif/1.0/\">" \
 75 "     <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">" \
 76 "        <rdf:Description rdf:about=\"\">" \
 77 "         <exif:MeteringMode>%d</exif:MeteringMode>" \
 78 "        </rdf:Description>" \
 79 "     </rdf:RDF></x:xmpmeta> "
 80 
 81 #define ORIENTATION_XMP	  \
 82 "   <x:xmpmeta   " \
 83 "      xmlns:x=\'adobe:ns:meta/\'" \
 84 "      xmlns:tiff=\"http://ns.adobe.com/tiff/1.0/\">" \
 85 "     <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">" \
 86 "        <rdf:Description rdf:about=\"\">" \
 87 "         <tiff:Orientation>%s</tiff:Orientation>" \
 88 "        </rdf:Description>" \
 89 "     </rdf:RDF></x:xmpmeta> "
 90 
 91 
 92 typedef struct {
 93 	const gchar *exif_value;
 94 	const gchar *nepomuk_translation;
 95 } ExifNepomuk;
 96 
 97 static ExifNepomuk METERING_MODES [] = {
 98 	{"0",  "nmm:metering-mode-other"},
 99 	{"1", "nmm:metering-mode-average"},
100 	{"2", "nmm:metering-mode-center-weighted-average"},
101 	{"3", "nmm:metering-mode-spot"},
102 	{"4", "nmm:metering-mode-multispot"},
103 	{"5", "nmm:metering-mode-pattern"},
104 	{"6", "nmm:metering-mode-partial"},
105 	{NULL, NULL}
106 };
107 
108 static ExifNepomuk ORIENTATIONS [] = {
109 	{"2", "nfo:orientation-top-mirror"},
110 	{"3", "nfo:orientation-bottom-mirror"},
111 	{"4", "nfo:orientation-bottom"},
112 	{"5", "nfo:orientation-left-mirror"},
113 	{"6", "nfo:orientation-right"},
114 	{"7", "nfo:orientation-right-mirror"},
115 	{"8", "nfo:orientation-left"},
116 	{"invalid value", "nfo:orientation-top"}
117 };
118 
119 static TrackerXmpData *
120 get_example_expected (void)
121 {
122 	TrackerXmpData *data;
123 
124 	data = g_new0 (TrackerXmpData, 1);
125 
126 	/* NS_DC */
127 	data->title = g_strdup ("Title of the content");
128 	data->rights = g_strdup ("CC share alike");
129 	data->creator = g_strdup ("The ultimate creator");
130 	data->description = g_strdup ("Description of the content");
131 	data->date = g_strdup ("2010-03-18T15:17:04Z");
132 	data->keywords = g_strdup ("test, data, xmp");
133 	data->subject = g_strdup ("Subject of the content");
134 
135 	data->publisher = g_strdup ("A honest developer");     /* publisher */
136 	data->contributor = g_strdup ("A honest contributor");
137 	data->type = NULL ;
138 	data->format = g_strdup ("application/pdf");
139 	data->identifier = g_strdup ("12345");
140 	data->source = g_strdup ("My dirty mind");
141 	data->language = g_strdup ("Spanglish");
142 	data->relation = g_strdup ("Single");
143 	data->coverage = g_strdup ("Pretty high after this test");
144 
145 	/* NS_CC */
146 	data->license = NULL;
147 
148 	/* NS_PDF */
149 	data->pdf_title = NULL;
150 	data->pdf_keywords = NULL;
151 
152 	/* NS_EXIF*/
153 	data->title2 = g_strdup ("Title in exif");
154 	data->time_original = g_strdup ("2010-03-18T15:17:04Z");
155 	data->artist = g_strdup ("Artist in exif");
156 	data->make = g_strdup ("Make in exif");
157 	data->model = g_strdup ("Model in exif");
158 	data->orientation = g_strdup ("nfo:orientation-top");
159 	data->flash = g_strdup ("nmm:flash-off");
160 	data->metering_mode = g_strdup ("nmm:metering-mode-spot");
161 	data->exposure_time = g_strdup ("1000");                      /* exposure time */
162 	data->fnumber = g_strdup ("12");                              /* fnumber */
163 	data->focal_length = g_strdup ("50");                         /* focal length */
164 
165 	data->iso_speed_ratings = g_strdup ("400");                   /* iso speed rating */
166 	data->white_balance = g_strdup ("nmm:white-balance-manual");
167 	data->copyright = g_strdup ("Copyright in exif");
168 
169 	/* NS_XAP */
170 	data->rating = NULL;
171 
172 	/* NS_IPTC4XMP */
173 	/* NS_PHOTOSHOP */
174 	data->address = NULL;                /* address */
175 	data->country = NULL;                /* country */
176 	data->state = NULL;                  /* state */
177 	data->city = NULL;                   /* city */
178 
179 	return data;
180 };
181 
182 static void
183 test_parsing_xmp (void)
184 {
185 	TrackerXmpData *data;
186 	TrackerXmpData *expected;
187 
188 	if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
189 		data = tracker_xmp_new (BROKEN_XMP, strlen (BROKEN_XMP), "test://file");
190 		g_assert (data != NULL);
191 
192 		tracker_xmp_free (data);
193 	}
194 
195 	g_test_trap_assert_stderr ("*parsing failure*");
196 
197 	data = tracker_xmp_new (EXAMPLE_XMP, strlen (EXAMPLE_XMP), "test://file");
198 	expected = get_example_expected ();
199 
200 	/* NS_DC */
201 	g_assert_cmpstr (data->format, ==, expected->format);
202 	g_assert_cmpstr (data->title, ==, expected->title);
203 	g_assert_cmpstr (data->rights, ==, expected->rights);
204 	g_assert_cmpstr (data->description, ==, expected->description);
205 	g_assert_cmpstr (data->date, ==, expected->date);
206 	g_assert_cmpstr (data->keywords, ==, expected->keywords);
207 	g_assert_cmpstr (data->subject, ==, expected->subject);
208 	g_assert_cmpstr (data->publisher, ==, expected->publisher);
209 	g_assert_cmpstr (data->contributor, ==, expected->contributor);
210 	g_assert_cmpstr (data->identifier, ==, expected->identifier);
211 	g_assert_cmpstr (data->source, ==, expected->source);
212 	g_assert_cmpstr (data->language, ==, expected->language);
213 	g_assert_cmpstr (data->relation, ==, expected->relation);
214 	g_assert_cmpstr (data->coverage, ==, expected->coverage);
215 	g_assert_cmpstr (data->creator, ==, expected->creator);
216 
217 	/* NS_EXIF*/
218 	g_assert_cmpstr (data->title2, ==, expected->title2);
219 	g_assert_cmpstr (data->time_original, ==, expected->time_original);
220 	g_assert_cmpstr (data->artist, ==, expected->artist);
221 	g_assert_cmpstr (data->make, ==, expected->make);
222 	g_assert_cmpstr (data->model, ==, expected->model);
223 	g_assert_cmpstr (data->orientation, ==, expected->orientation);
224 	g_assert_cmpstr (data->flash, ==, expected->flash);
225 	g_assert_cmpstr (data->metering_mode, ==, expected->metering_mode);
226 	g_assert_cmpstr (data->exposure_time, ==, expected->exposure_time);
227 	g_assert_cmpstr (data->fnumber, ==, expected->fnumber);
228 	g_assert_cmpstr (data->focal_length, ==, expected->focal_length);
229 
230 	g_assert_cmpstr (data->iso_speed_ratings, ==, expected->iso_speed_ratings);
231 	g_assert_cmpstr (data->white_balance, ==, expected->white_balance);
232 	g_assert_cmpstr (data->copyright, ==, expected->copyright);
233 
234 	tracker_xmp_free (expected);
235 	tracker_xmp_free (data);
236 }
237 
238 static void
239 test_xmp_metering_mode (void)
240 {
241 	gint i;
242 
243 	for (i = 0; METERING_MODES[i].exif_value != NULL; i++) {
244 		TrackerXmpData *data;
245 		gchar *xmp;
246 
247 		xmp = g_strdup_printf (METERING_MODE_XMP, i);
248 		data = tracker_xmp_new (xmp, strlen (xmp), "local://file");
249 		g_free (xmp);
250 
251 		g_assert_cmpstr (data->metering_mode, ==, METERING_MODES[i].nepomuk_translation);
252 		tracker_xmp_free (data);
253 	}
254 }
255 
256 static void
257 test_xmp_orientation (void)
258 {
259 	guint i;
260 
261 	for (i = 0; i < G_N_ELEMENTS (ORIENTATIONS); i++) {
262 		TrackerXmpData *data;
263 		gchar *xmp;
264 
265 		xmp = g_strdup_printf (ORIENTATION_XMP, ORIENTATIONS[i].exif_value);
266 		data = tracker_xmp_new (xmp, strlen (xmp), "local://file");
267 		g_free (xmp);
268 
269 		g_assert_cmpstr (data->orientation, ==, ORIENTATIONS[i].nepomuk_translation);
270 		tracker_xmp_free (data);
271 	}
272 }
273 
274 static void
275 test_xmp_apply (void)
276 {
277 	TrackerSparqlBuilder *metadata, *preupdate;
278 	GString *where;
279 	TrackerXmpData *data;
280 	const gchar *graph = NULL;
281 
282 	metadata = tracker_sparql_builder_new_update ();
283 	preupdate = tracker_sparql_builder_new_update ();
284 	where = g_string_new ("");
285 
286 	data = tracker_xmp_new (EXAMPLE_XMP, strlen (EXAMPLE_XMP), "urn:uuid:test");
287 	g_assert (data != NULL);
288 
289 	tracker_sparql_builder_insert_open (metadata, NULL);
290 	tracker_sparql_builder_subject_iri (metadata, "urn:uuid:test");
291 
292 	g_assert (tracker_xmp_apply (preupdate, metadata, graph, where, "urn:uuid:test", data));
293 
294 	tracker_sparql_builder_insert_close (metadata);
295 
296 	/* This is the only way to check the sparql is kinda correct */
297 
298 	/* Disabled this for 0.8.5. It was reporting 41 not 50, this
299 	 * test is not credible and I can't see how it can be trusted
300 	 * as a method for making sure the query is correct.
301 	 *
302 	 * -mr
303 	 */
304 
305 	/* g_assert_cmpint (tracker_sparql_builder_get_length (metadata), ==, 50); */
306         g_string_free (where, TRUE);
307         g_object_unref (metadata);
308         g_object_unref (preupdate);
309 
310         tracker_xmp_free (data);
311 }
312 
313 static void
314 test_xmp_apply_location (void)
315 {
316 	TrackerXmpData data = { 0, };
317 	TrackerSparqlBuilder *metadata, *preupdate;
318 	GString *where;
319 	const gchar *graph = NULL;
320 
321 	data.address = g_strdup ("Itamerenkatu 11-13");
322 	data.city = g_strdup ("Helsinki");
323 	data.state = g_strdup ("N/A");
324 	data.country = g_strdup ("Findland");
325 
326 	metadata = tracker_sparql_builder_new_update ();
327 	preupdate = tracker_sparql_builder_new_update ();
328 	where = g_string_new ("");
329 
330 	tracker_sparql_builder_insert_open (metadata, NULL);
331 	tracker_sparql_builder_subject_iri (metadata, "urn:uuid:test");
332 
333 	g_assert (tracker_xmp_apply (preupdate, metadata, graph, where, "urn:uuid:test", &data));
334 
335 	tracker_sparql_builder_insert_close (metadata);
336 
337 	/* This is the only way to check the sparql is kinda correct */
338 
339 	/* The builder just contains this:
340 	   <urn:uuid:test> slo:location [ a slo:GeoLocation ;
341 	   slo:postalAddress <urn:uuid:c50c4305-c617-4188-b3d3-42ba2291d0de>] .
342 	   } */
343 
344 	g_assert_cmpint (tracker_sparql_builder_get_length (metadata), >=, 3);
345 }
346 
347 
348 /*
349  * The generated sparql cannot be validated automatically.
350  * Debug function to print it in the terminal.
351  */
352 static void
353 debug_print_sparql (TrackerXmpData *data)
354 {
355 	/* To print the sparql */
356 	TrackerSparqlBuilder *metadata, *preupdate;
357 	GString *where;
358 	const gchar *graph = NULL;
359 
360 	metadata = tracker_sparql_builder_new_update ();
361 	preupdate = tracker_sparql_builder_new_update ();
362 	where = g_string_new ("");
363 
364 	tracker_sparql_builder_insert_open (metadata, NULL);
365 	tracker_sparql_builder_subject_iri (metadata, "urn:uuid:test");
366 
367 	tracker_xmp_apply (preupdate, metadata, graph, where, "urn:uuid:test", data);
368 
369 	tracker_sparql_builder_insert_close (metadata);
370 
371 	g_print ("%s\n", tracker_sparql_builder_get_result (preupdate));
372 	g_print ("%s\n", tracker_sparql_builder_get_result (metadata));
373 
374 	g_object_unref (metadata);
375 	g_object_unref (preupdate);
376 	g_string_free (where, TRUE);
377 }
378 
379 static void
380 test_xmp_regions (void)
381 {
382 	TrackerXmpData *data;
383 	TrackerXmpRegion *region;
384 
385 	GFile *f;
386 	gchar *contents;
387 	gsize  size;
388 	gchar *filepath;
389 
390 	filepath = g_build_filename (TOP_SRCDIR, "tests", "libtracker-extract", "areas.xmp", NULL);
391 	f = g_file_new_for_path (filepath);
392 	g_assert (g_file_load_contents (f, NULL, &contents, &size, NULL, NULL));
393 	g_object_unref (f);
394 	g_free (filepath);
395 
396 	data = tracker_xmp_new (contents, size, "test://file");
397 
398         g_free (contents);
399 
400 	g_assert_cmpint (2, ==, g_slist_length (data->regions));
401 
402 	region = g_slist_nth_data (data->regions, 1);
403 	g_assert_cmpstr (region->x, ==, "0.51");
404 	g_assert_cmpstr (region->y, ==, "0.51");
405 	g_assert_cmpstr (region->width, ==, "0.01");
406 	g_assert_cmpstr (region->height, ==, "0.09");
407 	g_assert_cmpstr (region->type, ==, "Pet");
408 	g_assert_cmpstr (region->title, ==, "Fido");
409 	g_assert_cmpstr (region->description, ==, "Fido looks happy!");
410 
411 	region = g_slist_nth_data (data->regions, 0);
412 	g_assert_cmpstr (region->x, ==, "0.5");
413 	g_assert_cmpstr (region->y, ==, "0.5");
414 	g_assert_cmpstr (region->width, ==, "0.06");
415 	g_assert_cmpstr (region->height, ==, "0.09");
416 	g_assert_cmpstr (region->type, ==, "Face");
417 	g_assert_cmpstr (region->title, ==, "John Doe");
418 
419 	if (0) {
420 		debug_print_sparql (data);
421 	}
422 
423 	tracker_xmp_free (data);
424 }
425 
426 static void
427 test_xmp_regions_quill (void)
428 {
429 	TrackerXmpData *data;
430 	TrackerXmpRegion *region;
431 
432 	GFile *f;
433 	gchar *contents;
434 	gsize  size;
435 	gchar *filepath;
436 
437 	filepath = g_build_filename (TOP_SRCDIR, "tests", "libtracker-extract", "areas-with-contacts.xmp", NULL);
438 	f = g_file_new_for_path (filepath);
439 	g_assert (g_file_load_contents (f, NULL, &contents, &size, NULL, NULL));
440 	g_object_unref (f);
441 	g_free (filepath);
442 
443 	data = tracker_xmp_new (contents, size, "test://file");
444 
445         g_free (contents);
446 
447 	g_assert_cmpint (2, ==, g_slist_length (data->regions));
448 
449 	region = g_slist_nth_data (data->regions, 1);
450 	g_assert_cmpstr (region->x, ==, "0.4");
451 	g_assert_cmpstr (region->y, ==, "0.3");
452 	g_assert_cmpstr (region->width, ==, "0.17");
453 	g_assert_cmpstr (region->height, ==, "0.15");
454 	g_assert_cmpstr (region->type, ==, "Face");
455 	g_assert_cmpstr (region->title, ==, "Dilbert");
456 	g_assert_cmpstr (region->link_class, ==, "nco:PersonContact");
457 	g_assert_cmpstr (region->link_uri, ==, "urn:uuid:2");
458 
459 	region = g_slist_nth_data (data->regions, 0);
460 	g_assert_cmpstr (region->x, ==, "0.3");
461 	g_assert_cmpstr (region->y, ==, "0.4");
462 	g_assert_cmpstr (region->width, ==, "0.15");
463 	g_assert_cmpstr (region->height, ==, "0.17");
464 	g_assert_cmpstr (region->type, ==, "Face");
465 	g_assert_cmpstr (region->title, ==, "Albert Einstein");
466 	g_assert_cmpstr (region->link_class, ==, "nco:PersonContact");
467 	g_assert_cmpstr (region->link_uri, ==, "urn:uuid:1");
468 
469 	//debug_print_sparql (data);
470 
471 	tracker_xmp_free (data);
472 }
473 
474 static void
475 test_xmp_regions_ns_prefix (void)
476 {
477 	TrackerXmpData *data;
478 	TrackerXmpRegion *region;
479 
480 	GFile *f;
481 	gchar *contents;
482 	gsize  size;
483 	gchar *filepath;
484 
485 	filepath = g_build_filename (TOP_SRCDIR, "tests", "libtracker-extract", "areas-ns.xmp", NULL);
486 	f = g_file_new_for_path (filepath);
487 	g_assert(g_file_load_contents (f, NULL, &contents, &size, NULL, NULL));
488 	g_object_unref (f);
489 	g_free (filepath);
490 
491 	data = tracker_xmp_new (contents, size, "test://file");
492 
493         g_free (contents);
494 
495 	g_assert_cmpint (2, ==, g_slist_length (data->regions));
496 
497 	region = g_slist_nth_data (data->regions, 1);
498 	g_assert_cmpstr (region->x, ==, "0.51");
499 	g_assert_cmpstr (region->y, ==, "0.51");
500 	g_assert_cmpstr (region->width, ==, "0.01");
501 	g_assert_cmpstr (region->height, ==, "0.09");
502 	g_assert_cmpstr (region->type, ==, "Pet");
503 	g_assert_cmpstr (region->title, ==, "Fidoz");
504 	g_assert_cmpstr (region->description, ==, "Fido looks happy!");
505 
506 	region = g_slist_nth_data (data->regions, 0);
507 	g_assert_cmpstr (region->x, ==, "0.5");
508 	g_assert_cmpstr (region->y, ==, "0.5");
509 	g_assert_cmpstr (region->width, ==, "0.06");
510 	g_assert_cmpstr (region->height, ==, "0.09");
511 	g_assert_cmpstr (region->type, ==, "Face");
512 	g_assert_cmpstr (region->title, ==, "Average Joe");
513 
514 	//debug_print_sparql (data);
515 
516 	tracker_xmp_free (data);
517 }
518 
519 static void
520 test_xmp_regions_nb282393 ()
521 {
522 	TrackerXmpData *data;
523 	TrackerXmpRegion *region;
524 
525 	GFile *f;
526 	gchar *contents;
527 	gsize  size;
528 	gchar *filepath;
529 
530 	filepath = g_build_filename (TOP_SRCDIR, "tests", "libtracker-extract", "nb282393.xmp", NULL);
531 	f = g_file_new_for_path (filepath);
532 	g_assert(g_file_load_contents (f, NULL, &contents, &size, NULL, NULL));
533 	g_object_unref (f);
534 	g_free (filepath);
535 
536 	data = tracker_xmp_new (contents, size, "test://file");
537 
538         g_free (contents);
539 
540 	g_assert_cmpint (1, ==, g_slist_length (data->regions));
541 
542 	/* Regions are stacked while parsing.*/
543 	region = g_slist_nth_data (data->regions, 0);
544 	g_assert_cmpstr (region->x, ==, "0.433333");
545 	g_assert_cmpstr (region->y, ==, "0.370000");
546 	g_assert_cmpstr (region->width, ==, "0.586667");
547 	g_assert_cmpstr (region->height, ==, "0.440000");
548 	g_assert_cmpstr (region->title, ==, " ");
549 
550 	//debug_print_sparql (data);
551 
552 	tracker_xmp_free (data);
553 }
554 
555 static void
556 test_xmp_regions_nb282393_2 ()
557 {
558 	TrackerXmpData *data;
559 	TrackerXmpRegion *region;
560 
561 	GFile *f;
562 	gchar *contents;
563 	gsize  size;
564 	gchar *filepath;
565 
566 	filepath = g_build_filename (TOP_SRCDIR, "tests", "libtracker-extract", "nb282393_simple.xmp", NULL);
567 	f = g_file_new_for_path (filepath);
568 	g_assert(g_file_load_contents (f, NULL, &contents, &size, NULL, NULL));
569 	g_object_unref (f);
570 	g_free (filepath);
571 
572 	data = tracker_xmp_new (contents, size, "test://file");
573 
574         g_free (contents);
575 
576 	g_assert_cmpint (1, ==, g_slist_length (data->regions));
577 
578 	/* Regions are stacked while parsing.*/
579 	region = g_slist_nth_data (data->regions, 0);
580 	g_assert_cmpstr (region->x, ==, "0.440000");
581 	g_assert_cmpstr (region->y, ==, "0.365000");
582 	g_assert_cmpstr (region->width, ==, "0.586667");
583 	g_assert_cmpstr (region->height, ==, "0.440000");
584 	g_assert_cmpstr (region->title, ==, " ");
585 
586         g_assert_cmpstr (region->link_class, ==, "nco:PersonContact");
587         g_assert_cmpstr (region->link_uri, ==, "urn:uuid:840a3c05-6cc6-48a1-bb56-fc50fae3345a");
588 
589 	//debug_print_sparql (data);
590 
591 	tracker_xmp_free (data);
592 }
593 
594 int
595 main (int    argc,
596       char **argv)
597 {
598 	gint result;
599 
600 	g_test_init (&argc, &argv, NULL);
601 
602 	g_test_message ("Testing XMP");
603 
604 #ifdef HAVE_EXEMPI
605 
606 	g_test_add_func ("/libtracker-extract/tracker-xmp/parsing_xmp",
607 	                 test_parsing_xmp);
608 
609 	g_test_add_func ("/libtracker-extract/tracker-xmp/metering-mode",
610 	                 test_xmp_metering_mode);
611 
612 	g_test_add_func ("/libtracker-extract/tracker-xmp/orientation",
613 	                 test_xmp_orientation);
614 
615 	g_test_add_func ("/libtracker-extract/tracker-xmp/sparql_translation",
616 	                 test_xmp_apply);
617 
618 	g_test_add_func ("/libtracker-extract/tracker-xmp/xmp_regions",
619 	                 test_xmp_regions);
620 
621 	g_test_add_func ("/libtracker-extract/tracker-xmp/xmp_regions_2",
622 	                 test_xmp_regions_quill);
623 
624         g_test_add_func ("/libtracker-extract/tracker-xmp/xmp_regions_crash_nb282393",
625                          test_xmp_regions_nb282393);
626 
627         g_test_add_func ("/libtracker-extract/tracker-xmp/xmp_regions_crash_nb282393_2",
628                          test_xmp_regions_nb282393_2);
629 
630 	g_test_add_func ("/libtracker-extract/tracker-xmp/xmp_regions_ns_prefix",
631 	                 test_xmp_regions_ns_prefix);
632 
633 #endif
634 	g_test_add_func ("/libtracker-extract/tracker-xmp/sparql_translation_location",
635 	                 test_xmp_apply_location);
636 
637 	result = g_test_run ();
638 
639 	return result;
640 }