[tracker/tracker-1.0] tests: Re-write guarantee metadata test to separate tests better
- From: Martyn James Russell <mr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/tracker-1.0] tests: Re-write guarantee metadata test to separate tests better
- Date: Fri, 22 Aug 2014 11:55:39 +0000 (UTC)
commit 65f09abb754722ff04697c3665848b706816ca21
Author: Martyn Russell <martyn lanedo com>
Date: Fri Aug 8 09:30:37 2014 +0100
tests: Re-write guarantee metadata test to separate tests better
Conflicts:
tests/libtracker-extract/tracker-guarantee-test.c
tests/libtracker-extract/tracker-guarantee-test.c | 213 +++++++++++----------
1 files changed, 114 insertions(+), 99 deletions(-)
---
diff --git a/tests/libtracker-extract/tracker-guarantee-test.c
b/tests/libtracker-extract/tracker-guarantee-test.c
index 40d6eb9..09e7bff 100644
--- a/tests/libtracker-extract/tracker-guarantee-test.c
+++ b/tests/libtracker-extract/tracker-guarantee-test.c
@@ -17,138 +17,153 @@
* Boston, MA 02110-1301, USA.
*/
#include "config.h"
+
+#include <locale.h>
+
#include <glib.h>
+
#include <libtracker-sparql/tracker-sparql.h>
#include <libtracker-extract/tracker-guarantee.h>
typedef struct {
- gchar *file_uri;
- gchar *extracted_title;
- gchar *expected_title;
-} TestCase;
-
-TestCase test_cases_title [] = {
- { "file:///a/b/a_video_with_metadata.avi", "extracted title", "extracted title" },
-
-#ifdef GUARANTEE_METADATA
- { "file:///a/b/a_video_with_no_metadata.avi", NULL, "a video with no metadata" },
- { "file:///a/b/a_video_with_no_metadata.avi", "", "a video with no metadata" },
- { "file:///a/b/a.video.with.no.metadata.avi", NULL, "a.video.with.no.metadata" },
- { "file:///a/b/a video without extension", NULL, "a video without extension" },
- { "file:///a/b/.hidden_file", NULL, "hidden file" },
-#endif
+ const gchar *test_name;
+ gchar *uri;
+ const gchar *extracted;
+ const gchar *expected;
+ TrackerSparqlBuilder *builder;
+} TestInfo;
+
+TestInfo title_tests [] = {
+ { "normal-extraction", "file:///a/b/a_video_with_metadata.avi", "extracted title", "extracted title"
},
+ { "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" },
+ { NULL, NULL, NULL }
+};
- { NULL, NULL, NULL}
+TestInfo date_tests [] = {
+ { "date-normal", "file:///does/not/matter/here", NULL, "2011-10-10T12:13:14Z0300" },
+ { "date-is-null", NULL, NULL, NULL },
+ { "date-is-empty-string", NULL, NULL, NULL },
+ { NULL, NULL, NULL }
};
-/*
- * @uri of the file that is being processed
- * @value is the title returned by the extractor
- * @expected can be either the title of the extractor (if not NULL or empty) or calculated from the filename
- */
static void
-internal_test_title (const gchar *uri,
- const gchar *value,
- const gchar *expected)
+test_title (TestInfo *info,
+ gconstpointer context)
{
- TrackerSparqlBuilder *builder;
- gchar *sparql;
- gchar *title_guaranteed;
-
- builder = tracker_sparql_builder_new_update ();
- tracker_sparql_builder_insert_open (builder, "test");
- tracker_sparql_builder_subject_iri (builder, "test://resource");
- g_assert (tracker_guarantee_title_from_file (builder,
- "nie:title",
- value,
- uri,
- &title_guaranteed));
- tracker_sparql_builder_insert_close (builder);
-
- sparql = g_strdup_printf ("INSERT INTO <test> {\n<test://resource> nie:title \"%s\" .\n}\n",
- expected);
- g_assert_cmpstr (sparql,
- ==,
- tracker_sparql_builder_get_result (builder));
-
- g_assert_cmpstr (title_guaranteed,
- ==,
- expected);
-
- g_object_unref (builder);
- g_free (sparql);
+#ifdef GUARANTEE_METADATA
+ gchar *sparql;
+ gchar *title_guaranteed;
+
+ tracker_sparql_builder_insert_open (info->builder, "test");
+ tracker_sparql_builder_subject_iri (info->builder, "test://resource");
+
+ 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);
+ g_assert_cmpstr (sparql, ==, tracker_sparql_builder_get_result (info->builder));
+ g_assert_cmpstr (title_guaranteed, ==, info->expected);
+
+ g_free (title_guaranteed);
+ g_free (sparql);
+#else
+ g_test_skip ("Guarantee metadata API disabled, see ./configure --help for details");
+#endif
}
static void
-internal_test_date (const gchar *uri,
- const gchar *value)
+test_date (TestInfo *info,
+ gconstpointer context)
{
- TrackerSparqlBuilder *builder;
-
- builder = tracker_sparql_builder_new_update ();
- tracker_sparql_builder_insert_open (builder, "test");
- tracker_sparql_builder_subject_iri (builder, "test://resource");
- g_assert (tracker_guarantee_date_from_file_mtime (builder,
- "test:mtime",
- value,
- uri));
- tracker_sparql_builder_insert_close (builder);
- /* mtime can change in the file so we just check that the property is in the output */
- g_assert (g_strstr_len (tracker_sparql_builder_get_result (builder), -1, "test:mtime"));
-
- g_object_unref (builder);
+#ifdef GUARANTEE_METADATA
+ 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));
+ 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
+ g_test_skip ("Guarantee metadata API disabled, see ./configure --help for details");
+#endif
}
static void
-test_guarantee_title (void)
+setup (TestInfo *info,
+ gint i)
{
- int i;
+ info->builder = tracker_sparql_builder_new_update ();
+ g_assert_nonnull (info->builder);
- for (i = 0; test_cases_title[i].file_uri != NULL; i++) {
- internal_test_title (test_cases_title[i].file_uri,
- test_cases_title[i].extracted_title,
- test_cases_title[i].expected_title);
- }
+ if (strstr (info->test_name, "date")) {
+ GFile *f;
-#ifdef GUARANTEE_METADATA
- g_print ("%d test cases (guarantee metadata enabled)\n", i);
-#else
- g_print ("%d test cases (guarantee metadata disabled)\n", i);
-#endif
+ f = g_file_new_for_path (TOP_SRCDIR "/tests/libtracker-extract/guarantee-mtime-test.txt");
+ info->uri = g_file_get_uri (f);
+ g_object_unref (f);
+ }
}
static void
-test_guarantee_date (void)
+setup_title (TestInfo *info,
+ gconstpointer context)
{
-#ifdef GUARANTEE_METADATA
- GFile *f;
- gchar *uri;
-#endif
+ gint i = GPOINTER_TO_INT (context);
- internal_test_date ("file:///does/not/matter/here", "2011-10-10T12:13:14Z0300");
+ *info = title_tests[i];
+ setup (info, i);
+}
-#ifdef GUARANTEE_METADATA
- f = g_file_new_for_path (TOP_SRCDIR "/tests/libtracker-extract/guarantee-mtime-test.txt");
- uri = g_file_get_uri (f);
-
- internal_test_date (uri, NULL);
- internal_test_date (uri, "");
+static void
+setup_date (TestInfo *info,
+ gconstpointer context)
+{
+ gint i = GPOINTER_TO_INT (context);
- g_free (uri);
- g_object_unref (f);
-#endif
+ *info = date_tests[i];
+ setup (info, i);
}
+static void
+teardown (TestInfo *info,
+ gconstpointer context)
+{
+ if (strstr (info->test_name, "date")) {
+ g_free (info->uri);
+ }
+
+ g_object_unref (info->builder);
+}
int
main (int argc, char** argv)
{
- g_test_init (&argc, &argv, NULL);
+ gint i;
+
+ setlocale (LC_COLLATE, "en_US.utf8");
+
+ g_test_init (&argc, &argv, NULL);
+
+ for (i = 0; title_tests[i].test_name != NULL; i++) {
+ gchar *testpath;
+
+ testpath = g_strdup_printf ("/libtracker-extract/guarantee/title/%s",
title_tests[i].test_name);
+ g_test_add (testpath, TestInfo, GINT_TO_POINTER(i), setup_title, test_title, teardown);
+ g_free (testpath);
+ }
+
+ for (i = 0; date_tests[i].test_name != NULL; i++) {
+ gchar *testpath;
- g_test_add_func ("/libtracker-extract/guarantee/title",
- test_guarantee_title);
- g_test_add_func ("/libtracker-extract/guarantee/date",
- test_guarantee_date);
+ testpath = g_strdup_printf ("/libtracker-extract/guarantee/date/%s", date_tests[i].test_name);
+ g_test_add (testpath, TestInfo, GINT_TO_POINTER(i), setup_date, test_date, teardown);
+ g_free (testpath);
+ }
- return g_test_run ();
+ return g_test_run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]