Commit be88f003 authored by Martyn Russell's avatar Martyn Russell

libtracker-extract: Fix unit tests and return value for guarantee API

- Return FALSE when we don't add to the TrackerSparqlBuilder, TRUE otherwise
- Skip any unit tests when --enable-guarantee-metadata is not configured
parent ecb703e4
......@@ -87,7 +87,7 @@ get_date_from_file_mtime (const gchar *uri)
* (before the "." and extension of the file) as the title. If the
* title has any "_" characters, they are also converted into spaces.
*
* Returns: %TRUE on success, otherwise %FALSE.
* Returns: %TRUE on success and content was added to @metadata, otherwise %FALSE.
*
* Since: 0.10
**/
......@@ -98,6 +98,8 @@ tracker_guarantee_title_from_file (TrackerSparqlBuilder *metadata,
const gchar *uri,
gchar **p_new_value)
{
gboolean success = TRUE;
#ifdef GUARANTEE_METADATA
g_return_val_if_fail (metadata != NULL, FALSE);
g_return_val_if_fail (key != NULL, FALSE);
......@@ -115,7 +117,12 @@ tracker_guarantee_title_from_file (TrackerSparqlBuilder *metadata,
gchar *value;
value = get_title_from_file (uri);
tracker_sparql_builder_object_unvalidated (metadata, value);
if (!value && value[0] != '\0') {
tracker_sparql_builder_object_unvalidated (metadata, value);
} else {
success = FALSE;
}
if (p_new_value != NULL) {
*p_new_value = value;
......@@ -131,10 +138,12 @@ tracker_guarantee_title_from_file (TrackerSparqlBuilder *metadata,
if (p_new_value != NULL) {
*p_new_value = g_strdup (current_value);
}
} else {
success = FALSE;
}
#endif /* GUARANTEE_METADATA */
return TRUE;
return success;
}
/**
......@@ -151,7 +160,7 @@ tracker_guarantee_title_from_file (TrackerSparqlBuilder *metadata,
* When parsing @uri, stat() is called on the file to create a
* date based on the file's mtime.
*
* Returns: %TRUE on success, otherwise %FALSE.
* Returns: %TRUE on success and content was added to @metadata, otherwise %FALSE.
*
* Since: 0.10
**/
......@@ -161,6 +170,8 @@ tracker_guarantee_date_from_file_mtime (TrackerSparqlBuilder *metadata,
const gchar *current_value,
const gchar *uri)
{
gboolean success = TRUE;
#ifdef GUARANTEE_METADATA
g_return_val_if_fail (metadata != NULL, FALSE);
g_return_val_if_fail (key != NULL, FALSE);
......@@ -174,15 +185,23 @@ tracker_guarantee_date_from_file_mtime (TrackerSparqlBuilder *metadata,
gchar *value;
value = get_date_from_file_mtime (uri);
tracker_sparql_builder_object_unvalidated (metadata, value);
if (value && *value != '\0') {
tracker_sparql_builder_object_unvalidated (metadata, value);
} else {
success = FALSE;
}
g_free (value);
}
#else /* GUARANTEE_METADATA */
if (current_value && *current_value != '\0') {
tracker_sparql_builder_predicate (metadata, key);
tracker_sparql_builder_object_unvalidated (metadata, current_value);
} else {
success = FALSE;
}
#endif /* GUARANTEE_METADATA */
return TRUE;
return success;
}
......@@ -35,26 +35,19 @@ typedef struct {
TestInfo title_tests [] = {
{ "normal-extraction", "file:///a/b/a_video_with_metadata.avi", "extracted title", "extracted title" },
#ifdef GUARANTEE_METADATA
{ "empty-extraction", "file:///a/b/a_video_with_no_metadata.avi", NULL, "a video with no metadata" },
{ "underscore-separators", "file:///a/b/a_video_with_no_metadata.avi", "", "a video with no metadata" },
{ "dot-separators", "file:///a/b/a.video.with.no.metadata.avi", NULL, "a.video.with.no.metadata" },
{ "no-extension", "file:///a/b/a video without extension", NULL, "a video without extension" },
{ "hidden-files", "file:///a/b/.hidden_file", NULL, "hidden file" },
#endif
{ NULL, NULL, NULL }
};
TestInfo date_tests [] = {
{ "date-normal", "file:///does/not/matter/here", NULL, "2011-10-10T12:13:14Z0300" },
#ifdef GUARANTEE_METADATA
{ "date-is-null", NULL, NULL, NULL },
{ "date-is-empty-string", NULL, NULL, NULL },
#endif
{ NULL, NULL, NULL }
};
......@@ -62,13 +55,16 @@ static void
test_title (TestInfo *info,
gconstpointer context)
{
#ifdef GUARANTEE_METADATA
gchar *sparql;
gchar *title_guaranteed;
gboolean title_retrieved;
tracker_sparql_builder_insert_open (info->builder, "test");
tracker_sparql_builder_subject_iri (info->builder, "test://resource");
title_retrieved = tracker_guarantee_title_from_file (info->builder, "nie:title", info->extracted, info->uri, &title_guaranteed);
g_assert_true (title_retrieved);
g_assert_true (tracker_guarantee_title_from_file (info->builder, "nie:title", info->extracted, info->uri, &title_guaranteed));
tracker_sparql_builder_insert_close (info->builder);
sparql = g_strdup_printf ("INSERT INTO <test> {\n<test://resource> nie:title \"%s\" .\n}\n", info->expected);
......@@ -77,20 +73,31 @@ test_title (TestInfo *info,
g_free (title_guaranteed);
g_free (sparql);
#else /* GUARANTEE_METADATA */
g_test_skip ("Not built with --enable-guarantee-metadata");
#endif /* GUARANTEE_METADATA */
}
static void
test_date (TestInfo *info,
gconstpointer context)
{
#ifdef GUARANTEE_METADATA
gboolean date_retrieved;
tracker_sparql_builder_insert_open (info->builder, "test");
tracker_sparql_builder_subject_iri (info->builder, "test://resource");
g_assert_true (tracker_guarantee_date_from_file_mtime (info->builder, "test:mtime", info->extracted, info->uri));
date_retrieved = tracker_guarantee_date_from_file_mtime (info->builder, "test:mtime", info->extracted, info->uri);
g_assert_true (date_retrieved);
tracker_sparql_builder_insert_close (info->builder);
/* mtime can change in the file so we just check that the property is in the output */
g_assert_nonnull (g_strstr_len (tracker_sparql_builder_get_result (info->builder), -1, "test:mtime"));
#else /* GUARANTEE_METADATA */
g_test_skip ("Not built with --enable-guarantee-metadata");
#endif /* GUARANTEE_METADATA */
}
static void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment