aboutsummaryrefslogtreecommitdiff
path: root/tests/glib-fixture.h
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2014-01-14 23:07:10 -0600
committerCharles Kerr <charles.kerr@canonical.com>2014-01-14 23:07:10 -0600
commitee64bb2698adfe27e55615a8856b0e2c78ad8469 (patch)
treeb8fb6e1440ac700f7f51e5c765303abb315c6399 /tests/glib-fixture.h
parent3b8833efe6ab21387b6f73b4a4ef757445801623 (diff)
downloadayatana-indicator-datetime-ee64bb2698adfe27e55615a8856b0e2c78ad8469.tar.gz
ayatana-indicator-datetime-ee64bb2698adfe27e55615a8856b0e2c78ad8469.tar.bz2
ayatana-indicator-datetime-ee64bb2698adfe27e55615a8856b0e2c78ad8469.zip
Function: add fully-tested ActionGroups, per-profile Menus, state object.
Form: Add code annotations/comments. Remove dead code. Use Mir style guide. Todo: GSettings toggles, sync with new dbus-test-runner API, get GNOME Panel building again
Diffstat (limited to 'tests/glib-fixture.h')
-rw-r--r--tests/glib-fixture.h85
1 files changed, 46 insertions, 39 deletions
diff --git a/tests/glib-fixture.h b/tests/glib-fixture.h
index 043b7e3..3f517d4 100644
--- a/tests/glib-fixture.h
+++ b/tests/glib-fixture.h
@@ -25,6 +25,8 @@
#include <gtest/gtest.h>
+#include <locale.h> // setlocale()
+
class GlibFixture : public ::testing::Test
{
private:
@@ -35,96 +37,101 @@ class GlibFixture : public ::testing::Test
std::map<GLogLevelFlags,int> logCounts;
- void testLogCount (GLogLevelFlags log_level, int expected G_GNUC_UNUSED)
+ void testLogCount(GLogLevelFlags log_level, int /*expected*/)
{
#if 0
- EXPECT_EQ (expected, logCounts[log_level]);
+ EXPECT_EQ(expected, logCounts[log_level]);
#endif
- logCounts.erase (log_level);
+ logCounts.erase(log_level);
}
private:
- static void default_log_handler (const gchar * log_domain,
- GLogLevelFlags log_level,
- const gchar * message,
- gpointer self)
+ 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);
+ g_print("%s - %d - %s\n", log_domain, (int)log_level, message);
static_cast<GlibFixture*>(self)->logCounts[log_level]++;
}
protected:
- virtual void SetUp ()
+ virtual void SetUp()
{
- loop = g_main_loop_new (NULL, FALSE);
+ setlocale(LC_ALL, "");
+
+ loop = g_main_loop_new(nullptr, false);
- //g_log_set_default_handler (default_log_handler, this);
+ //g_log_set_default_handler(default_log_handler, this);
// only use local, temporary settings
- g_setenv ("GSETTINGS_SCHEMA_DIR", SCHEMA_DIR, TRUE);
- g_setenv ("GSETTINGS_BACKEND", "memory", TRUE);
- g_debug ("SCHEMA_DIR is %s", SCHEMA_DIR);
+ 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);
+
+ g_unsetenv("DISPLAY");
+
}
virtual void TearDown()
{
#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]);
+ 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_log_set_default_handler(realLogHandler, this);
- g_clear_pointer (&loop, g_main_loop_unref);
+ g_clear_pointer(&loop, g_main_loop_unref);
}
private:
static gboolean
- wait_for_signal__timeout (gpointer name)
+ wait_for_signal__timeout(gpointer name)
{
- g_error ("%s: timed out waiting for signal '%s'", G_STRLOC, (char*)name);
+ g_error("%s: timed out waiting for signal '%s'", G_STRLOC, (char*)name);
return G_SOURCE_REMOVE;
}
static gboolean
- wait_msec__timeout (gpointer loop)
+ wait_msec__timeout(gpointer loop)
{
- g_main_loop_quit (static_cast<GMainLoop*>(loop));
+ g_main_loop_quit(static_cast<GMainLoop*>(loop));
return G_SOURCE_CONTINUE;
}
protected:
/* convenience func to loop while waiting for a GObject's signal */
- void wait_for_signal (gpointer o, const gchar * signal, const int timeout_seconds=5)
+ void wait_for_signal(gpointer o, const gchar * signal, const int timeout_seconds=5)
{
// wait for the signal or for timeout, whichever comes first
- const auto handler_id = g_signal_connect_swapped (o, signal,
- G_CALLBACK(g_main_loop_quit),
- loop);
- const auto timeout_id = g_timeout_add_seconds (timeout_seconds,
- wait_for_signal__timeout,
- loop);
- g_main_loop_run (loop);
- g_source_remove (timeout_id);
- g_signal_handler_disconnect (o, handler_id);
+ const auto handler_id = g_signal_connect_swapped(o, signal,
+ G_CALLBACK(g_main_loop_quit),
+ loop);
+ const auto timeout_id = g_timeout_add_seconds(timeout_seconds,
+ wait_for_signal__timeout,
+ loop);
+ g_main_loop_run(loop);
+ g_source_remove(timeout_id);
+ g_signal_handler_disconnect(o, handler_id);
}
/* convenience func to loop for N msec */
- void wait_msec (int msec=50)
+ void wait_msec(int msec=50)
{
- const auto id = g_timeout_add (msec, wait_msec__timeout, loop);
- g_main_loop_run (loop);
- g_source_remove (id);
+ const auto id = g_timeout_add(msec, wait_msec__timeout, loop);
+ g_main_loop_run(loop);
+ g_source_remove(id);
}
GMainLoop * loop;