summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDebarshi Ray <debarshir@freedesktop.org>2015-04-20 11:38:07 (GMT)
committerDebarshi Ray <debarshir@freedesktop.org>2015-04-20 12:07:48 (GMT)
commit1d35d990cc2c925a2842cf121f4ff3a3ce5c195a (patch)
tree6195da8298a3b3bf805537bab5b73656d24883a6
parent89ad4c941816b7b09c20c7111086d965d87861e7 (diff)
downloadtelepathy-logger-1d35d990cc2c925a2842cf121f4ff3a3ce5c195a.tar.gz
tests: Add a test for log-iter-xml/get-events
... to cover files with invalid XML. Since WARNINGs interfere with the test, we suppress them when testmode is on. https://bugs.freedesktop.org/show_bug.cgi?id=40675 https://bugs.freedesktop.org/show_bug.cgi?id=89595
-rw-r--r--telepathy-logger/log-store-xml.c3
-rw-r--r--tests/dbus/test-tpl-log-iter-xml.c46
2 files changed, 47 insertions, 2 deletions
diff --git a/telepathy-logger/log-store-xml.c b/telepathy-logger/log-store-xml.c
index 7ba27ed..be881d0 100644
--- a/telepathy-logger/log-store-xml.c
+++ b/telepathy-logger/log-store-xml.c
@@ -1369,7 +1369,8 @@ log_store_xml_get_events_for_file (TplLogStoreXml *self,
doc = xmlCtxtReadFile (ctxt, filename, NULL, XML_PARSE_RECOVER);
if (!doc)
{
- g_warning ("Failed to parse file:'%s'", filename);
+ if (!self->priv->test_mode)
+ g_warning ("Failed to parse file:'%s'", filename);
xmlFreeParserCtxt (ctxt);
return;
}
diff --git a/tests/dbus/test-tpl-log-iter-xml.c b/tests/dbus/test-tpl-log-iter-xml.c
index a8f865d..1f29017 100644
--- a/tests/dbus/test-tpl-log-iter-xml.c
+++ b/tests/dbus/test-tpl-log-iter-xml.c
@@ -87,7 +87,7 @@ static void
test_get_events (XmlTestCaseFixture *fixture,
gconstpointer user_data)
{
- TplEntity *user2, *user4;
+ TplEntity *user2, *user4, *user6;
TplLogIter *iter;
GList *events;
GError *error = NULL;
@@ -101,6 +101,9 @@ test_get_events (XmlTestCaseFixture *fixture,
user4 = tpl_entity_new ("user4@collabora.co.uk", TPL_ENTITY_CONTACT,
"User4", "");
+ user6 = tpl_entity_new ("user6@collabora.co.uk", TPL_ENTITY_CONTACT,
+ "User6", "");
+
/* Text events spanning multiple days */
iter = tpl_log_iter_xml_new (fixture->store, fixture->account, user2,
TPL_EVENT_MASK_ANY);
@@ -231,8 +234,49 @@ test_get_events (XmlTestCaseFixture *fixture,
g_object_unref (iter);
+ /* Files with invalid XML */
+ iter = tpl_log_iter_xml_new (fixture->store, fixture->account, user6,
+ TPL_EVENT_MASK_ANY);
+
+ events = tpl_log_iter_get_events (iter, 2, &error);
+ g_assert_no_error (error);
+ g_assert (events != NULL);
+ g_assert_cmpint (g_list_length (events), ==, 2);
+ timestamp = tpl_event_get_timestamp (TPL_EVENT (events->data));
+ g_assert_cmpint (timestamp, ==, 1388680071);
+ message = tpl_text_event_get_message (TPL_TEXT_EVENT (events->data));
+ g_assert_cmpstr (message, ==, "34");
+ g_list_free_full (events, g_object_unref);
+
+ events = tpl_log_iter_get_events (iter, 1, &error);
+ g_assert_no_error (error);
+ g_assert (events != NULL);
+ g_assert_cmpint (g_list_length (events), ==, 1);
+ timestamp = tpl_event_get_timestamp (TPL_EVENT (events->data));
+ g_assert_cmpint (timestamp, ==, 1388680070);
+ message = tpl_text_event_get_message (TPL_TEXT_EVENT (events->data));
+ g_assert_cmpstr (message, ==, "");
+ g_list_free_full (events, g_object_unref);
+
+ events = tpl_log_iter_get_events (iter, 2, &error);
+ g_assert_no_error (error);
+ g_assert (events != NULL);
+ g_assert_cmpint (g_list_length (events), ==, 2);
+ timestamp = tpl_event_get_timestamp (TPL_EVENT (events->data));
+ g_assert_cmpint (timestamp, ==, 1388568367);
+ message = tpl_text_event_get_message (TPL_TEXT_EVENT (events->data));
+ g_assert_cmpstr (message, ==, "1");
+ g_list_free_full (events, g_object_unref);
+
+ events = tpl_log_iter_get_events (iter, 2, &error);
+ g_assert_no_error (error);
+ g_assert (events == NULL);
+
+ g_object_unref (iter);
+
g_object_unref (user2);
g_object_unref (user4);
+ g_object_unref (user6);
}