From 8867ec9433122b225a22667b1f25a53d21ca1fd1 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sun, 28 Oct 2012 01:54:45 +0200 Subject: set DeviceTest's gwarning/gcritical log func to one that prints no messages but accumulates the log count. This way we can both (a) silence in-console warnings that look like bugs in the test but are actually desirable warnings generated by fuzz testing, and (b) assert that we get exactly as many warnings/criticals as we expect to get. --- tests/test-device.cc | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'tests/test-device.cc') diff --git a/tests/test-device.cc b/tests/test-device.cc index a32e0e5..02493dc 100644 --- a/tests/test-device.cc +++ b/tests/test-device.cc @@ -37,15 +37,40 @@ namespace class DeviceTest : public ::testing::Test { + private: + + guint handler_id; + + int log_count; + + static void log_count_func (const gchar *log_domain, + GLogLevelFlags log_level, + const gchar *message, + gpointer user_data) + { + reinterpret_cast(user_data)->log_count++; + } + + protected: + + int expected_ipower_log_messages; + protected: virtual void SetUp() { + const GLogLevelFlags flags = GLogLevelFlags(G_LOG_LEVEL_CRITICAL|G_LOG_LEVEL_WARNING); + handler_id = g_log_set_handler ("Indicator-Power", flags, log_count_func, this); + expected_ipower_log_messages = 0; + log_count = 0; + ensure_glib_initialized (); } virtual void TearDown() { + ASSERT_EQ (expected_ipower_log_messages, log_count); + g_log_remove_handler ("Indicator-Power", handler_id); } protected: @@ -205,6 +230,7 @@ TEST_F(DeviceTest, BadAccessors) indicator_power_device_get_state (device); indicator_power_device_get_percentage (device); indicator_power_device_get_object_path (device); + expected_ipower_log_messages += 5; // test that these functions can handle being passed non-device GObjects device = reinterpret_cast(g_cancellable_new ()); @@ -213,6 +239,8 @@ TEST_F(DeviceTest, BadAccessors) indicator_power_device_get_state (device); indicator_power_device_get_percentage (device); indicator_power_device_get_object_path (device); + expected_ipower_log_messages += 5; + g_object_unref (device); } @@ -226,6 +254,7 @@ TEST_F(DeviceTest, IconNames) GObject * o = G_OBJECT(device); // bad arguments + expected_ipower_log_messages++; ASSERT_TRUE (indicator_power_device_get_icon_names (NULL) == NULL); // power @@ -452,9 +481,11 @@ TEST_F(DeviceTest, Labels) g_setenv ("LANG", "en_US.UTF-8", TRUE); // bad args: NULL device + expected_ipower_log_messages++; check_strings (NULL, NULL, NULL, NULL); // bad args: a GObject that isn't a device + expected_ipower_log_messages++; GObject * o = G_OBJECT(g_cancellable_new()); check_strings ((IndicatorPowerDevice*)o, NULL, NULL, NULL); g_object_unref (o); -- cgit v1.2.3