From 6c3b75384570cfe06ea5435b0b6def7a0eb8c8e8 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=89595 --- telepathy-logger/log-store-xml.c | 3 ++- tests/dbus/test-tpl-log-iter-xml.c | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/telepathy-logger/log-store-xml.c b/telepathy-logger/log-store-xml.c index 03f5d3c..36e8ff3 100644 --- a/telepathy-logger/log-store-xml.c +++ b/telepathy-logger/log-store-xml.c @@ -1373,7 +1373,8 @@ log_store_xml_get_events_for_file (TplLogStoreXml *self, doc = xmlCtxtReadFile (ctxt, filename, NULL, 0); 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); g_free (self_id); return; diff --git a/tests/dbus/test-tpl-log-iter-xml.c b/tests/dbus/test-tpl-log-iter-xml.c index 044bf47..d1b05dc 100644 --- a/tests/dbus/test-tpl-log-iter-xml.c +++ b/tests/dbus/test-tpl-log-iter-xml.c @@ -71,7 +71,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; @@ -85,6 +85,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); @@ -215,8 +218,39 @@ test_get_events (XmlTestCaseFixture *fixture, g_object_unref (iter); + /* crazy shit */ + iter = tpl_log_iter_xml_new (fixture->store, fixture->account, user6, + TPL_EVENT_MASK_ANY); + + 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, ==, 1388741167); + message = tpl_text_event_get_message (TPL_TEXT_EVENT (events->data)); + g_assert_cmpstr (message, ==, "4"); + 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