~ubuntu-branches/ubuntu/raring/tracker/raring

« back to all changes in this revision

Viewing changes to tests/libtracker-extract/tracker-guarantee-test.c

  • Committer: Package Import Robot
  • Author(s): Michael Biebl
  • Date: 2011-10-21 16:42:59 UTC
  • mfrom: (4.4.28 experimental)
  • Revision ID: package-import@ubuntu.com-20111021164259-322n6i3db3icfyna
Tags: 0.12.6-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2011, 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 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.
 
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
 * Lesser General Public License for more details.
 
13
 *
 
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.
 
18
 */
 
19
#include "config.h"
 
20
#include <glib.h>
 
21
#include <libtracker-sparql/tracker-sparql.h>
 
22
#include <libtracker-extract/tracker-guarantee.h>
 
23
 
 
24
typedef struct {
 
25
        gchar *file_uri;
 
26
        gchar *extracted_title;
 
27
        gchar *expected_title;
 
28
} TestCase;
 
29
 
 
30
TestCase test_cases_title [] = {
 
31
        { "file:///a/b/a_video_with_metadata.avi", "extracted title", "extracted title" },
 
32
 
 
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" },
 
39
#endif
 
40
 
 
41
        { NULL, NULL, NULL}
 
42
};
 
43
 
 
44
 
 
45
/*
 
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
 
49
 */
 
50
void
 
51
internal_test_title (const gchar *uri,
 
52
                     const gchar *value,
 
53
                     const gchar *expected)
 
54
{
 
55
        TrackerSparqlBuilder *builder;
 
56
        gchar                *sparql;
 
57
 
 
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, 
 
62
                                                     "nie:title",
 
63
                                                     value,
 
64
                                                     uri));
 
65
        tracker_sparql_builder_insert_close (builder);
 
66
 
 
67
        sparql = g_strdup_printf ("INSERT INTO <test> {\n<test://resource> nie:title \"%s\" .\n}\n",
 
68
                                  expected);
 
69
        g_assert_cmpstr (sparql,
 
70
                         ==,
 
71
                         tracker_sparql_builder_get_result (builder));
 
72
 
 
73
        g_object_unref (builder);
 
74
        g_free (sparql);
 
75
}
 
76
 
 
77
void
 
78
internal_test_date (const gchar *uri,
 
79
                    const gchar *value)
 
80
{
 
81
        TrackerSparqlBuilder *builder;
 
82
 
 
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, 
 
87
                                                          "test:mtime",
 
88
                                                          value,
 
89
                                                          uri));
 
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"));
 
93
 
 
94
        g_object_unref (builder);
 
95
}
 
96
 
 
97
void
 
98
test_guarantee_title ()
 
99
{
 
100
        int i;
 
101
 
 
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);
 
106
        }
 
107
 
 
108
#ifdef GUARANTEE_METADATA        
 
109
        g_print ("%d test cases (guarantee metadata enabled) ", i);
 
110
#else
 
111
        g_print ("%d test cases (guarantee metadata disabled) ", i);
 
112
#endif
 
113
}
 
114
 
 
115
void
 
116
test_guarantee_date ()
 
117
{
 
118
        GFile *f;
 
119
        gchar *uri;
 
120
 
 
121
        internal_test_date ("file:///does/not/matter/here", "2011-10-10T12:13:14Z0300");
 
122
 
 
123
#ifdef GUARANTEE_METADATA        
 
124
        
 
125
        f = g_file_new_for_path (TOP_SRCDIR "/tests/libtracker-extract/guarantee-mtime-test.txt");
 
126
        uri = g_file_get_uri (f);
 
127
        
 
128
        internal_test_date (uri, NULL);
 
129
        internal_test_date (uri, "");
 
130
 
 
131
        g_free (uri);
 
132
        g_object_unref (f);
 
133
#endif
 
134
}
 
135
 
 
136
 
 
137
int
 
138
main (int argc, char** argv)
 
139
{
 
140
        g_type_init ();
 
141
        g_test_init (&argc, &argv, NULL);
 
142
 
 
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);
 
147
 
 
148
        return g_test_run ();
 
149
}