aboutsummaryrefslogtreecommitdiff
path: root/tests/test-device.cc
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2012-10-28 01:54:45 +0200
committerCharles Kerr <charles.kerr@canonical.com>2012-10-28 01:54:45 +0200
commit8867ec9433122b225a22667b1f25a53d21ca1fd1 (patch)
treea6c26946c29130607cb3cdaf95bb15a5e22bbd10 /tests/test-device.cc
parent7c0d274cb162da46198c63f288b67b1a54e70238 (diff)
downloadayatana-indicator-power-8867ec9433122b225a22667b1f25a53d21ca1fd1.tar.gz
ayatana-indicator-power-8867ec9433122b225a22667b1f25a53d21ca1fd1.tar.bz2
ayatana-indicator-power-8867ec9433122b225a22667b1f25a53d21ca1fd1.zip
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.
Diffstat (limited to 'tests/test-device.cc')
-rw-r--r--tests/test-device.cc31
1 files changed, 31 insertions, 0 deletions
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<DeviceTest*>(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<IndicatorPowerDevice*>(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);