19
typedef std::function<gchar*()> ErrorStringFunc;
20
static gchar* DefaultErrorString() { return nullptr; }
22
static void WaitUntilMSec(bool& success, unsigned max_wait = 500, ErrorStringFunc const& error_func = &Utils::DefaultErrorString)
24
WaitUntilMSec([&success] {return success;}, true, max_wait, error_func);
27
static void WaitUntil(bool& success, unsigned max_wait = 1, ErrorStringFunc const& error_func = &Utils::DefaultErrorString)
29
WaitUntilMSec(success, max_wait * 1000, error_func);
32
static void WaitUntilMSec(std::function<bool()> const& check_function, bool expected_result = true, unsigned max_wait = 500, ErrorStringFunc const& error_func = &Utils::DefaultErrorString)
19
static void WaitUntilMSec(bool& success, unsigned max_wait = 500, std::string const& error_msg = "")
21
WaitUntilMSec([&success] {return success;}, true, max_wait, error_msg);
24
static void WaitUntil(bool& success, unsigned max_wait = 1, std::string const& error_msg = "")
26
WaitUntilMSec(success, max_wait * 1000, error_msg);
29
static void WaitUntilMSec(std::function<bool()> const& check_function, bool expected_result = true, unsigned max_wait = 500, std::string const& error_msg = "")
34
31
ASSERT_NE(check_function, nullptr);
49
46
if (result == expected_result)
50
47
g_source_remove(timeout_id);
52
glib::String error(error_func());
55
EXPECT_EQ(result, expected_result) << "Error: " << error;
59
EXPECT_EQ(result, expected_result);
49
EXPECT_EQ(result, expected_result) << (error_msg.empty() ? "" : ("Error: " + error_msg));
63
static void WaitUntil(std::function<bool()> const& check_function, bool result = true, unsigned max_wait = 1, ErrorStringFunc const& error_func = &Utils::DefaultErrorString)
52
static void WaitUntil(std::function<bool()> const& check_function, bool result = true, unsigned max_wait = 1, std::string const& error_msg = "")
65
WaitUntilMSec(check_function, result, max_wait * 1000, error_func);
54
WaitUntilMSec(check_function, result, max_wait * 1000, error_msg);
68
57
static guint32 ScheduleTimeout(bool* timeout_reached, unsigned timeout_duration = 10)
70
return g_timeout_add(timeout_duration, TimeoutCallback, timeout_reached);
59
return g_timeout_add_full(G_PRIORITY_DEFAULT+10, timeout_duration, TimeoutCallback, timeout_reached, nullptr);
73
62
static void WaitForTimeout(unsigned timeout_duration = 1)
81
70
ScheduleTimeout(&timeout_reached, timeout_duration);
83
72
while (!timeout_reached)
84
g_main_context_iteration(g_main_context_get_thread_default(), TRUE);
73
g_main_context_iteration(nullptr, TRUE);
87
76
static void init_gsettings_test_environment()
97
86
g_unsetenv("GSETTINGS_BACKEND");
89
static void WaitPendingEvents(unsigned max_wait_ms = 5000)
91
gint64 start_time = g_get_monotonic_time();
93
while (g_main_context_pending(nullptr) &&
94
(g_get_monotonic_time() - start_time) / 1000 < max_wait_ms)
96
g_main_context_iteration(nullptr, TRUE);
101
101
static gboolean TimeoutCallback(gpointer data)