From 1d35d990cc2c925a2842cf121f4ff3a3ce5c195a Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Mon, 20 Apr 2015 13:38:07 +0200 Subject: [PATCH 2/3] 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 --- telepathy-logger/log-store-xml.c | 3 ++- tests/dbus/test-tpl-log-iter-xml.c | 46 +++++++++++++++++++++++++++++++++++++- 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); } -- 2.1.0