2
* Copyright (C) 2011, Nokia <ivan.frade@nokia.com>
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Lesser General Public
6
* License as published by the Free Software Foundation; either
7
* version 2.1 of the License, or (at your option) any later version.
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
* Lesser General Public License for more details.
14
* You should have received a copy of the GNU Lesser 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.
21
#include <libtracker-sparql/tracker-sparql.h>
22
#include <libtracker-extract/tracker-guarantee.h>
26
gchar *extracted_title;
27
gchar *expected_title;
30
TestCase test_cases_title [] = {
31
{ "file:///a/b/a_video_with_metadata.avi", "extracted title", "extracted title" },
33
#ifdef GUARANTEE_METADATA
34
{ "file:///a/b/a_video_with_no_metadata.avi", NULL, "a video with no metadata" },
35
{ "file:///a/b/a_video_with_no_metadata.avi", "", "a video with no metadata" },
36
{ "file:///a/b/a.video.with.no.metadata.avi", NULL, "a.video.with.no.metadata" },
37
{ "file:///a/b/a video without extension", NULL, "a video without extension" },
38
{ "file:///a/b/.hidden_file", NULL, "hidden file" },
46
* @uri of the file that is being processed
47
* @value is the title returned by the extractor
48
* @expected can be either the title of the extractor (if not NULL or empty) or calculated from the filename
51
internal_test_title (const gchar *uri,
53
const gchar *expected)
55
TrackerSparqlBuilder *builder;
58
builder = tracker_sparql_builder_new_update ();
59
tracker_sparql_builder_insert_open (builder, "test");
60
tracker_sparql_builder_subject_iri (builder, "test://resource");
61
g_assert (tracker_guarantee_title_from_file (builder,
65
tracker_sparql_builder_insert_close (builder);
67
sparql = g_strdup_printf ("INSERT INTO <test> {\n<test://resource> nie:title \"%s\" .\n}\n",
69
g_assert_cmpstr (sparql,
71
tracker_sparql_builder_get_result (builder));
73
g_object_unref (builder);
78
internal_test_date (const gchar *uri,
81
TrackerSparqlBuilder *builder;
83
builder = tracker_sparql_builder_new_update ();
84
tracker_sparql_builder_insert_open (builder, "test");
85
tracker_sparql_builder_subject_iri (builder, "test://resource");
86
g_assert (tracker_guarantee_date_from_file_mtime (builder,
90
tracker_sparql_builder_insert_close (builder);
91
/* mtime can change in the file so we just check that the property is in the output */
92
g_assert (g_strstr_len (tracker_sparql_builder_get_result (builder), -1, "test:mtime"));
94
g_object_unref (builder);
98
test_guarantee_title ()
102
for (i = 0; test_cases_title[i].file_uri != NULL; i++) {
103
internal_test_title (test_cases_title[i].file_uri,
104
test_cases_title[i].extracted_title,
105
test_cases_title[i].expected_title);
108
#ifdef GUARANTEE_METADATA
109
g_print ("%d test cases (guarantee metadata enabled) ", i);
111
g_print ("%d test cases (guarantee metadata disabled) ", i);
116
test_guarantee_date ()
121
internal_test_date ("file:///does/not/matter/here", "2011-10-10T12:13:14Z0300");
123
#ifdef GUARANTEE_METADATA
125
f = g_file_new_for_path (TOP_SRCDIR "/tests/libtracker-extract/guarantee-mtime-test.txt");
126
uri = g_file_get_uri (f);
128
internal_test_date (uri, NULL);
129
internal_test_date (uri, "");
138
main (int argc, char** argv)
141
g_test_init (&argc, &argv, NULL);
143
g_test_add_func ("/libtracker-extract/guarantee/title",
144
test_guarantee_title);
145
g_test_add_func ("/libtracker-extract/guarantee/date",
146
test_guarantee_date);
148
return g_test_run ();