aboutsummaryrefslogtreecommitdiff
path: root/tests/glib-fixture.h
diff options
context:
space:
mode:
authorIain Lane <iain.lane@canonical.com>2015-09-09 16:40:41 +0000
committerCI Train Bot <ci-train-bot@canonical.com>2015-09-09 16:40:41 +0000
commit13bcfccd0c9038c4b4c20c37c8d3267a5e6fbfee (patch)
tree30705f0a3f047a46020c7204397649ff2c609936 /tests/glib-fixture.h
parentad2d17a82ebe369adca6b477d5ecb362e243f585 (diff)
parentec001e64b2225a3c80b7e89d9a570728fcbca830 (diff)
downloadayatana-indicator-datetime-13bcfccd0c9038c4b4c20c37c8d3267a5e6fbfee.tar.gz
ayatana-indicator-datetime-13bcfccd0c9038c4b4c20c37c8d3267a5e6fbfee.tar.bz2
ayatana-indicator-datetime-13bcfccd0c9038c4b4c20c37c8d3267a5e6fbfee.zip
Remove warnings from test logs. Swallow the ones that are expected and fail the test if they don't show up. In addition, fail tests if unexpected warnings show up again.
Approved by: Charles Kerr
Diffstat (limited to 'tests/glib-fixture.h')
-rw-r--r--tests/glib-fixture.h50
1 files changed, 9 insertions, 41 deletions
diff --git a/tests/glib-fixture.h b/tests/glib-fixture.h
index f888c59..4d309e6 100644
--- a/tests/glib-fixture.h
+++ b/tests/glib-fixture.h
@@ -36,34 +36,6 @@ class GlibFixture : public ::testing::Test
virtual ~GlibFixture() =default;
- private:
-
- //GLogFunc realLogHandler;
-
- protected:
-
- std::map<GLogLevelFlags,int> logCounts;
-
- void testLogCount(GLogLevelFlags log_level, int /*expected*/)
- {
-#if 0
- EXPECT_EQ(expected, logCounts[log_level]);
-#endif
-
- logCounts.erase(log_level);
- }
-
- private:
-
- static void default_log_handler(const gchar * log_domain,
- GLogLevelFlags log_level,
- const gchar * message,
- gpointer self)
- {
- g_print("%s - %d - %s\n", log_domain, (int)log_level, message);
- static_cast<GlibFixture*>(self)->logCounts[log_level]++;
- }
-
protected:
virtual void SetUp() override
@@ -72,34 +44,30 @@ class GlibFixture : public ::testing::Test
loop = g_main_loop_new(nullptr, false);
- //g_log_set_default_handler(default_log_handler, this);
-
// only use local, temporary settings
g_assert(g_setenv("GSETTINGS_SCHEMA_DIR", SCHEMA_DIR, true));
g_assert(g_setenv("GSETTINGS_BACKEND", "memory", true));
g_debug("SCHEMA_DIR is %s", SCHEMA_DIR);
+ // fail on unexpected messages from this domain
+ g_log_set_fatal_mask(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING);
+
g_unsetenv("DISPLAY");
}
virtual void TearDown() override
{
-#if 0
- // confirm there aren't any unexpected log messages
- EXPECT_EQ(0, logCounts[G_LOG_LEVEL_ERROR]);
- EXPECT_EQ(0, logCounts[G_LOG_LEVEL_CRITICAL]);
- EXPECT_EQ(0, logCounts[G_LOG_LEVEL_WARNING]);
- EXPECT_EQ(0, logCounts[G_LOG_LEVEL_MESSAGE]);
- EXPECT_EQ(0, logCounts[G_LOG_LEVEL_INFO]);
-#endif
-
- // revert to glib's log handler
- //g_log_set_default_handler(realLogHandler, this);
+ g_test_assert_expected_messages ();
g_clear_pointer(&loop, g_main_loop_unref);
}
+ void expectLogMessage (const gchar *domain, GLogLevelFlags level, const gchar *pattern)
+ {
+ g_test_expect_message (domain, level, pattern);
+ }
+
private:
static gboolean