aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLars Uebernickel <lars@uebernic.de>2015-09-09 18:16:41 +0200
committerLars Uebernickel <lars@uebernic.de>2015-09-09 18:16:41 +0200
commit046cd3a7dd67935eac5f8377996423c434f44419 (patch)
tree746b0670db87e76e29a803ceb26d8cfa67466f3a /tests
parent60f30453fb89d3769874af42a4f24c372bcad714 (diff)
downloadayatana-indicator-datetime-046cd3a7dd67935eac5f8377996423c434f44419.tar.gz
ayatana-indicator-datetime-046cd3a7dd67935eac5f8377996423c434f44419.tar.bz2
ayatana-indicator-datetime-046cd3a7dd67935eac5f8377996423c434f44419.zip
glib-fixture: fail tests on unexpected warnings
This requires specifying which warnings are expected to be thrown (only test-timezone-file needed this for now). However, only fail on warnings in the Indicator-Datetime log domain so that we don't fail on gstreamer (or other library) warnings for now.
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt1
-rw-r--r--tests/glib-fixture.h50
-rw-r--r--tests/test-timezone-timedated.cpp3
3 files changed, 12 insertions, 42 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 032b84e..0302da9 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -38,6 +38,7 @@ include_directories (${DBUSTEST_INCLUDE_DIRS})
add_definitions (-DSANDBOX="${CMAKE_CURRENT_BINARY_DIR}")
+add_definitions (-DG_LOG_DOMAIN="Indicator-Datetime")
function(add_test_by_name name)
set (TEST_NAME ${name})
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
diff --git a/tests/test-timezone-timedated.cpp b/tests/test-timezone-timedated.cpp
index 5cfc311..7300649 100644
--- a/tests/test-timezone-timedated.cpp
+++ b/tests/test-timezone-timedated.cpp
@@ -69,8 +69,8 @@ TEST_F(TimezoneFixture, NoFile)
remove(TIMEZONE_FILE);
ASSERT_FALSE(g_file_test(TIMEZONE_FILE, G_FILE_TEST_EXISTS));
+ expectLogMessage(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "*No such file or directory*");
TimedatedTimezone tz(TIMEZONE_FILE);
- testLogCount(G_LOG_LEVEL_WARNING, 1);
}
/**
@@ -82,6 +82,7 @@ TEST_F(TimezoneFixture, DefaultValueNoFile)
remove(TIMEZONE_FILE);
ASSERT_FALSE(g_file_test(TIMEZONE_FILE, G_FILE_TEST_EXISTS));
+ expectLogMessage(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "*No such file or directory*");
TimedatedTimezone tz(TIMEZONE_FILE);
ASSERT_EQ(expected_timezone, tz.timezone.get());
}