tests: Move orientation helper to monitor test utils
It was used by both the orientation tests, and the monitor configuration tests. Lets move the helper to common ground. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2030>
This commit is contained in:
parent
20686f3354
commit
67425bf653
@ -874,3 +874,149 @@ void check_monitor_scales (MonitorTestCaseExpect *expect,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *
|
||||||
|
meta_orientation_to_string (MetaOrientation orientation)
|
||||||
|
{
|
||||||
|
switch (orientation)
|
||||||
|
{
|
||||||
|
case META_ORIENTATION_UNDEFINED:
|
||||||
|
return "(undefined)";
|
||||||
|
case META_ORIENTATION_NORMAL:
|
||||||
|
return "normal";
|
||||||
|
case META_ORIENTATION_BOTTOM_UP:
|
||||||
|
return "bottom-up";
|
||||||
|
case META_ORIENTATION_LEFT_UP:
|
||||||
|
return "left-up";
|
||||||
|
case META_ORIENTATION_RIGHT_UP:
|
||||||
|
return "right-up";
|
||||||
|
default:
|
||||||
|
return "(invalid)";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
MetaOrientation expected;
|
||||||
|
MetaOrientation orientation;
|
||||||
|
gulong connection_id;
|
||||||
|
guint timeout_id;
|
||||||
|
unsigned int times_signalled;
|
||||||
|
} WaitForOrientation;
|
||||||
|
|
||||||
|
static void
|
||||||
|
on_orientation_changed (WaitForOrientation *wfo,
|
||||||
|
MetaOrientationManager *orientation_manager)
|
||||||
|
{
|
||||||
|
wfo->orientation = meta_orientation_manager_get_orientation (orientation_manager);
|
||||||
|
wfo->times_signalled++;
|
||||||
|
|
||||||
|
g_test_message ("wait_for_orientation_changes: Orientation changed to %d: %s",
|
||||||
|
wfo->orientation, meta_orientation_to_string (wfo->orientation));
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
on_max_wait_timeout (gpointer data)
|
||||||
|
{
|
||||||
|
WaitForOrientation *wfo = data;
|
||||||
|
|
||||||
|
wfo->timeout_id = 0;
|
||||||
|
return G_SOURCE_REMOVE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Assert that the orientation eventually changes to @orientation.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
meta_wait_for_orientation (MetaOrientationManager *orientation_manager,
|
||||||
|
MetaOrientation orientation,
|
||||||
|
unsigned int *times_signalled_out)
|
||||||
|
{
|
||||||
|
WaitForOrientation wfo = {
|
||||||
|
.expected = orientation,
|
||||||
|
};
|
||||||
|
|
||||||
|
wfo.orientation = meta_orientation_manager_get_orientation (orientation_manager);
|
||||||
|
g_test_message ("%s: Waiting for orientation to change from "
|
||||||
|
"%d: %s to %d: %s...",
|
||||||
|
G_STRFUNC, wfo.orientation,
|
||||||
|
meta_orientation_to_string (wfo.orientation),
|
||||||
|
orientation, meta_orientation_to_string (orientation));
|
||||||
|
|
||||||
|
/* This timeout can be relatively generous because we don't expect to
|
||||||
|
* reach it: if we do, that's a test failure. */
|
||||||
|
wfo.timeout_id = g_timeout_add_seconds (10, on_max_wait_timeout, &wfo);
|
||||||
|
wfo.connection_id = g_signal_connect_swapped (orientation_manager,
|
||||||
|
"orientation-changed",
|
||||||
|
G_CALLBACK (on_orientation_changed),
|
||||||
|
&wfo);
|
||||||
|
|
||||||
|
while (wfo.orientation != orientation && wfo.timeout_id != 0)
|
||||||
|
g_main_context_iteration (NULL, TRUE);
|
||||||
|
|
||||||
|
if (wfo.orientation != orientation)
|
||||||
|
{
|
||||||
|
g_error ("Timed out waiting for orientation to change from %s to %s "
|
||||||
|
"(received %u orientation-changed signal(s) while waiting)",
|
||||||
|
meta_orientation_to_string (wfo.orientation),
|
||||||
|
meta_orientation_to_string (orientation),
|
||||||
|
wfo.times_signalled);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_test_message ("%s: Orientation is now %d: %s",
|
||||||
|
G_STRFUNC, orientation,
|
||||||
|
meta_orientation_to_string (orientation));
|
||||||
|
|
||||||
|
g_clear_handle_id (&wfo.timeout_id, g_source_remove);
|
||||||
|
g_signal_handler_disconnect (orientation_manager, wfo.connection_id);
|
||||||
|
|
||||||
|
if (times_signalled_out != NULL)
|
||||||
|
*times_signalled_out = wfo.times_signalled;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Wait for a possible orientation change, but don't assert that one occurs.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
meta_wait_for_possible_orientation_change (MetaOrientationManager *orientation_manager,
|
||||||
|
unsigned int *times_signalled_out)
|
||||||
|
{
|
||||||
|
WaitForOrientation wfo = {
|
||||||
|
.expected = META_ORIENTATION_UNDEFINED,
|
||||||
|
};
|
||||||
|
|
||||||
|
wfo.orientation = meta_orientation_manager_get_orientation (orientation_manager);
|
||||||
|
g_test_message ("%s: Waiting for orientation to maybe change from %d: %s...",
|
||||||
|
G_STRFUNC, wfo.orientation,
|
||||||
|
meta_orientation_to_string (wfo.orientation));
|
||||||
|
|
||||||
|
/* This can't be as long as the timeout for meta_wait_for_orientation(),
|
||||||
|
* because in the usual case we expect to reach this timeout: we're
|
||||||
|
* only waiting so that if the orientation (incorrectly?) changed here,
|
||||||
|
* we'd have a chance to detect that. */
|
||||||
|
wfo.timeout_id = g_timeout_add (1000, on_max_wait_timeout, &wfo);
|
||||||
|
wfo.connection_id = g_signal_connect_swapped (orientation_manager,
|
||||||
|
"orientation-changed",
|
||||||
|
G_CALLBACK (on_orientation_changed),
|
||||||
|
&wfo);
|
||||||
|
|
||||||
|
while (wfo.times_signalled == 0 && wfo.timeout_id != 0)
|
||||||
|
g_main_context_iteration (NULL, TRUE);
|
||||||
|
|
||||||
|
if (wfo.timeout_id == 0)
|
||||||
|
{
|
||||||
|
g_test_message ("%s: Orientation didn't change", G_STRFUNC);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
g_test_message ("%s: Orientation is now %d: %s",
|
||||||
|
G_STRFUNC, wfo.orientation,
|
||||||
|
meta_orientation_to_string (wfo.orientation));
|
||||||
|
}
|
||||||
|
|
||||||
|
g_clear_handle_id (&wfo.timeout_id, g_source_remove);
|
||||||
|
g_signal_handler_disconnect (orientation_manager, wfo.connection_id);
|
||||||
|
|
||||||
|
if (times_signalled_out != NULL)
|
||||||
|
*times_signalled_out = wfo.times_signalled;
|
||||||
|
}
|
||||||
|
@ -212,4 +212,13 @@ void check_monitor_scales (MonitorTestCaseExpect *expect,
|
|||||||
MetaMonitorTestSetup * create_monitor_test_setup (MonitorTestCaseSetup *setup,
|
MetaMonitorTestSetup * create_monitor_test_setup (MonitorTestCaseSetup *setup,
|
||||||
MonitorTestFlag flags);
|
MonitorTestFlag flags);
|
||||||
|
|
||||||
|
const char * meta_orientation_to_string (MetaOrientation orientation);
|
||||||
|
|
||||||
|
void meta_wait_for_orientation (MetaOrientationManager *orientation_manager,
|
||||||
|
MetaOrientation orientation,
|
||||||
|
unsigned int *times_signalled_out);
|
||||||
|
|
||||||
|
void meta_wait_for_possible_orientation_change (MetaOrientationManager *orientation_manager,
|
||||||
|
unsigned int *times_signalled_out);
|
||||||
|
|
||||||
#endif /* MONITOR_TEST_UTILS_H */
|
#endif /* MONITOR_TEST_UTILS_H */
|
||||||
|
@ -36,7 +36,6 @@
|
|||||||
#include "tests/monitor-test-utils.h"
|
#include "tests/monitor-test-utils.h"
|
||||||
#include "tests/meta-test-utils.h"
|
#include "tests/meta-test-utils.h"
|
||||||
#include "tests/unit-tests.h"
|
#include "tests/unit-tests.h"
|
||||||
#include "tests/orientation-manager-unit-tests.h"
|
|
||||||
#include "x11/meta-x11-display-private.h"
|
#include "x11/meta-x11-display-private.h"
|
||||||
|
|
||||||
static MonitorTestCase initial_test_case = {
|
static MonitorTestCase initial_test_case = {
|
||||||
@ -3564,7 +3563,7 @@ meta_sensors_proxy_reset (MetaSensorsProxyMock *proxy)
|
|||||||
g_test_message ("Resetting proxy");
|
g_test_message ("Resetting proxy");
|
||||||
meta_sensors_proxy_mock_set_orientation (proxy,
|
meta_sensors_proxy_mock_set_orientation (proxy,
|
||||||
META_ORIENTATION_NORMAL);
|
META_ORIENTATION_NORMAL);
|
||||||
wait_for_orientation (orientation_manager, META_ORIENTATION_NORMAL, NULL);
|
meta_wait_for_orientation (orientation_manager, META_ORIENTATION_NORMAL, NULL);
|
||||||
g_object_unref (proxy);
|
g_object_unref (proxy);
|
||||||
}
|
}
|
||||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (MetaSensorsProxyAutoResetMock,
|
G_DEFINE_AUTOPTR_CLEANUP_FUNC (MetaSensorsProxyAutoResetMock,
|
||||||
@ -3889,7 +3888,8 @@ meta_test_monitor_orientation_initial_rotated (void)
|
|||||||
touch_device = meta_test_add_touch_device (backend);
|
touch_device = meta_test_add_touch_device (backend);
|
||||||
orientation = META_ORIENTATION_LEFT_UP;
|
orientation = META_ORIENTATION_LEFT_UP;
|
||||||
meta_sensors_proxy_mock_set_orientation (orientation_mock, orientation);
|
meta_sensors_proxy_mock_set_orientation (orientation_mock, orientation);
|
||||||
wait_for_orientation (orientation_manager, orientation, ×_signalled);
|
meta_wait_for_orientation (orientation_manager, orientation,
|
||||||
|
×_signalled);
|
||||||
g_assert_cmpuint (times_signalled, <=, 1);
|
g_assert_cmpuint (times_signalled, <=, 1);
|
||||||
|
|
||||||
test_setup = create_monitor_test_setup (&test_case.setup,
|
test_setup = create_monitor_test_setup (&test_case.setup,
|
||||||
@ -3995,7 +3995,8 @@ meta_test_monitor_orientation_initial_rotated_no_touch_mode (void)
|
|||||||
orientation_mock = meta_sensors_proxy_mock_get ();
|
orientation_mock = meta_sensors_proxy_mock_get ();
|
||||||
orientation = META_ORIENTATION_LEFT_UP;
|
orientation = META_ORIENTATION_LEFT_UP;
|
||||||
meta_sensors_proxy_mock_set_orientation (orientation_mock, orientation);
|
meta_sensors_proxy_mock_set_orientation (orientation_mock, orientation);
|
||||||
wait_for_orientation (orientation_manager, orientation, ×_signalled);
|
meta_wait_for_orientation (orientation_manager, orientation,
|
||||||
|
×_signalled);
|
||||||
g_assert_cmpuint (times_signalled, <=, 1);
|
g_assert_cmpuint (times_signalled, <=, 1);
|
||||||
|
|
||||||
test_setup = create_monitor_test_setup (&test_case.setup,
|
test_setup = create_monitor_test_setup (&test_case.setup,
|
||||||
@ -4111,7 +4112,8 @@ meta_test_monitor_orientation_initial_stored_rotated (void)
|
|||||||
touch_device = meta_test_add_touch_device (backend);
|
touch_device = meta_test_add_touch_device (backend);
|
||||||
orientation = META_ORIENTATION_RIGHT_UP;
|
orientation = META_ORIENTATION_RIGHT_UP;
|
||||||
meta_sensors_proxy_mock_set_orientation (orientation_mock, orientation);
|
meta_sensors_proxy_mock_set_orientation (orientation_mock, orientation);
|
||||||
wait_for_orientation (orientation_manager, orientation, ×_signalled);
|
meta_wait_for_orientation (orientation_manager, orientation,
|
||||||
|
×_signalled);
|
||||||
g_assert_cmpuint (times_signalled, <=, 1);
|
g_assert_cmpuint (times_signalled, <=, 1);
|
||||||
|
|
||||||
test_setup = create_monitor_test_setup (&test_case.setup,
|
test_setup = create_monitor_test_setup (&test_case.setup,
|
||||||
@ -4136,7 +4138,8 @@ meta_test_monitor_orientation_initial_stored_rotated (void)
|
|||||||
g_test_message ("Rotating to left-up");
|
g_test_message ("Rotating to left-up");
|
||||||
orientation = META_ORIENTATION_LEFT_UP;
|
orientation = META_ORIENTATION_LEFT_UP;
|
||||||
meta_sensors_proxy_mock_set_orientation (orientation_mock, orientation);
|
meta_sensors_proxy_mock_set_orientation (orientation_mock, orientation);
|
||||||
wait_for_orientation (orientation_manager, orientation, ×_signalled);
|
meta_wait_for_orientation (orientation_manager, orientation,
|
||||||
|
×_signalled);
|
||||||
g_assert_cmpuint (times_signalled, <=, 1);
|
g_assert_cmpuint (times_signalled, <=, 1);
|
||||||
|
|
||||||
meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), FALSE);
|
meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), FALSE);
|
||||||
@ -4154,7 +4157,8 @@ meta_test_monitor_orientation_initial_stored_rotated (void)
|
|||||||
g_test_message ("Rotating to right-up");
|
g_test_message ("Rotating to right-up");
|
||||||
orientation = META_ORIENTATION_RIGHT_UP;
|
orientation = META_ORIENTATION_RIGHT_UP;
|
||||||
meta_sensors_proxy_mock_set_orientation (orientation_mock, orientation);
|
meta_sensors_proxy_mock_set_orientation (orientation_mock, orientation);
|
||||||
wait_for_orientation (orientation_manager, orientation, ×_signalled);
|
meta_wait_for_orientation (orientation_manager, orientation,
|
||||||
|
×_signalled);
|
||||||
g_assert_cmpuint (times_signalled, <=, 1);
|
g_assert_cmpuint (times_signalled, <=, 1);
|
||||||
|
|
||||||
META_TEST_LOG_CALL ("Checking configuration per orientation",
|
META_TEST_LOG_CALL ("Checking configuration per orientation",
|
||||||
@ -4265,7 +4269,8 @@ meta_test_monitor_orientation_initial_stored_rotated_no_touch (void)
|
|||||||
orientation_mock = meta_sensors_proxy_mock_get ();
|
orientation_mock = meta_sensors_proxy_mock_get ();
|
||||||
orientation = META_ORIENTATION_RIGHT_UP;
|
orientation = META_ORIENTATION_RIGHT_UP;
|
||||||
meta_sensors_proxy_mock_set_orientation (orientation_mock, orientation);
|
meta_sensors_proxy_mock_set_orientation (orientation_mock, orientation);
|
||||||
wait_for_orientation (orientation_manager, orientation, ×_signalled);
|
meta_wait_for_orientation (orientation_manager, orientation,
|
||||||
|
×_signalled);
|
||||||
g_assert_cmpuint (times_signalled, <=, 1);
|
g_assert_cmpuint (times_signalled, <=, 1);
|
||||||
|
|
||||||
test_setup = create_monitor_test_setup (&test_case.setup,
|
test_setup = create_monitor_test_setup (&test_case.setup,
|
||||||
@ -4414,7 +4419,7 @@ meta_test_monitor_orientation_changes (void)
|
|||||||
|
|
||||||
got_monitors_changed = FALSE;
|
got_monitors_changed = FALSE;
|
||||||
meta_sensors_proxy_mock_set_orientation (orientation_mock, i);
|
meta_sensors_proxy_mock_set_orientation (orientation_mock, i);
|
||||||
wait_for_orientation (orientation_manager, i, ×_signalled);
|
meta_wait_for_orientation (orientation_manager, i, ×_signalled);
|
||||||
g_assert_cmpuint (times_signalled, <=, 1);
|
g_assert_cmpuint (times_signalled, <=, 1);
|
||||||
|
|
||||||
META_TEST_LOG_CALL ("Checking configuration per orientation",
|
META_TEST_LOG_CALL ("Checking configuration per orientation",
|
||||||
@ -4443,7 +4448,7 @@ meta_test_monitor_orientation_changes (void)
|
|||||||
got_monitors_changed = FALSE;
|
got_monitors_changed = FALSE;
|
||||||
meta_sensors_proxy_mock_set_orientation (orientation_mock,
|
meta_sensors_proxy_mock_set_orientation (orientation_mock,
|
||||||
META_ORIENTATION_NORMAL);
|
META_ORIENTATION_NORMAL);
|
||||||
wait_for_orientation (orientation_manager, META_ORIENTATION_NORMAL,
|
meta_wait_for_orientation (orientation_manager, META_ORIENTATION_NORMAL,
|
||||||
×_signalled);
|
×_signalled);
|
||||||
g_assert_cmpuint (times_signalled, ==, 0);
|
g_assert_cmpuint (times_signalled, ==, 0);
|
||||||
META_TEST_LOG_CALL ("Checking configuration per orientation",
|
META_TEST_LOG_CALL ("Checking configuration per orientation",
|
||||||
@ -4466,7 +4471,7 @@ meta_test_monitor_orientation_changes (void)
|
|||||||
|
|
||||||
got_monitors_changed = FALSE;
|
got_monitors_changed = FALSE;
|
||||||
meta_sensors_proxy_mock_set_orientation (orientation_mock, i);
|
meta_sensors_proxy_mock_set_orientation (orientation_mock, i);
|
||||||
wait_for_orientation (orientation_manager, i, ×_signalled);
|
meta_wait_for_orientation (orientation_manager, i, ×_signalled);
|
||||||
g_assert_cmpuint (times_signalled, <=, 1);
|
g_assert_cmpuint (times_signalled, <=, 1);
|
||||||
|
|
||||||
META_TEST_LOG_CALL ("Checking configuration per orientation",
|
META_TEST_LOG_CALL ("Checking configuration per orientation",
|
||||||
@ -4610,7 +4615,7 @@ meta_test_monitor_orientation_changes_for_transformed_panel (void)
|
|||||||
|
|
||||||
got_monitors_changed = FALSE;
|
got_monitors_changed = FALSE;
|
||||||
meta_sensors_proxy_mock_set_orientation (orientation_mock, i);
|
meta_sensors_proxy_mock_set_orientation (orientation_mock, i);
|
||||||
wait_for_orientation (orientation_manager, i, ×_signalled);
|
meta_wait_for_orientation (orientation_manager, i, ×_signalled);
|
||||||
g_assert_cmpuint (times_signalled, <=, 1);
|
g_assert_cmpuint (times_signalled, <=, 1);
|
||||||
|
|
||||||
META_TEST_LOG_CALL ("Checking configuration per orientation",
|
META_TEST_LOG_CALL ("Checking configuration per orientation",
|
||||||
@ -4639,7 +4644,7 @@ meta_test_monitor_orientation_changes_for_transformed_panel (void)
|
|||||||
got_monitors_changed = FALSE;
|
got_monitors_changed = FALSE;
|
||||||
meta_sensors_proxy_mock_set_orientation (orientation_mock,
|
meta_sensors_proxy_mock_set_orientation (orientation_mock,
|
||||||
META_ORIENTATION_NORMAL);
|
META_ORIENTATION_NORMAL);
|
||||||
wait_for_orientation (orientation_manager, META_ORIENTATION_NORMAL,
|
meta_wait_for_orientation (orientation_manager, META_ORIENTATION_NORMAL,
|
||||||
×_signalled);
|
×_signalled);
|
||||||
g_assert_cmpuint (times_signalled, ==, 0);
|
g_assert_cmpuint (times_signalled, ==, 0);
|
||||||
META_TEST_LOG_CALL ("Checking configuration per orientation",
|
META_TEST_LOG_CALL ("Checking configuration per orientation",
|
||||||
@ -4662,7 +4667,7 @@ meta_test_monitor_orientation_changes_for_transformed_panel (void)
|
|||||||
|
|
||||||
got_monitors_changed = FALSE;
|
got_monitors_changed = FALSE;
|
||||||
meta_sensors_proxy_mock_set_orientation (orientation_mock, i);
|
meta_sensors_proxy_mock_set_orientation (orientation_mock, i);
|
||||||
wait_for_orientation (orientation_manager, i, ×_signalled);
|
meta_wait_for_orientation (orientation_manager, i, ×_signalled);
|
||||||
g_assert_cmpuint (times_signalled, <=, 1);
|
g_assert_cmpuint (times_signalled, <=, 1);
|
||||||
|
|
||||||
META_TEST_LOG_CALL ("Checking configuration per orientation",
|
META_TEST_LOG_CALL ("Checking configuration per orientation",
|
||||||
@ -4687,7 +4692,7 @@ meta_test_monitor_orientation_changes_for_transformed_panel (void)
|
|||||||
got_monitors_changed = FALSE;
|
got_monitors_changed = FALSE;
|
||||||
meta_sensors_proxy_mock_set_orientation (orientation_mock,
|
meta_sensors_proxy_mock_set_orientation (orientation_mock,
|
||||||
META_ORIENTATION_RIGHT_UP);
|
META_ORIENTATION_RIGHT_UP);
|
||||||
wait_for_orientation (orientation_manager,
|
meta_wait_for_orientation (orientation_manager,
|
||||||
META_ORIENTATION_RIGHT_UP,
|
META_ORIENTATION_RIGHT_UP,
|
||||||
×_signalled);
|
×_signalled);
|
||||||
g_assert_cmpuint (times_signalled, <=, 1);
|
g_assert_cmpuint (times_signalled, <=, 1);
|
||||||
@ -4859,7 +4864,7 @@ meta_test_monitor_orientation_changes_with_hotplugging (void)
|
|||||||
for (i = META_N_ORIENTATIONS - 1; i > META_ORIENTATION_UNDEFINED; i--)
|
for (i = META_N_ORIENTATIONS - 1; i > META_ORIENTATION_UNDEFINED; i--)
|
||||||
{
|
{
|
||||||
meta_sensors_proxy_mock_set_orientation (orientation_mock, i);
|
meta_sensors_proxy_mock_set_orientation (orientation_mock, i);
|
||||||
wait_for_orientation (orientation_manager, i, ×_signalled);
|
meta_wait_for_orientation (orientation_manager, i, ×_signalled);
|
||||||
g_assert_cmpuint (times_signalled, <=, 1);
|
g_assert_cmpuint (times_signalled, <=, 1);
|
||||||
|
|
||||||
META_TEST_LOG_CALL ("Checking configuration per orientation",
|
META_TEST_LOG_CALL ("Checking configuration per orientation",
|
||||||
@ -4869,7 +4874,7 @@ meta_test_monitor_orientation_changes_with_hotplugging (void)
|
|||||||
|
|
||||||
meta_sensors_proxy_mock_set_orientation (orientation_mock,
|
meta_sensors_proxy_mock_set_orientation (orientation_mock,
|
||||||
META_ORIENTATION_NORMAL);
|
META_ORIENTATION_NORMAL);
|
||||||
wait_for_orientation (orientation_manager, META_ORIENTATION_NORMAL,
|
meta_wait_for_orientation (orientation_manager, META_ORIENTATION_NORMAL,
|
||||||
×_signalled);
|
×_signalled);
|
||||||
g_assert_cmpuint (times_signalled, <=, 1);
|
g_assert_cmpuint (times_signalled, <=, 1);
|
||||||
check_monitor_configuration (&test_case.expect);
|
check_monitor_configuration (&test_case.expect);
|
||||||
@ -4892,7 +4897,7 @@ meta_test_monitor_orientation_changes_with_hotplugging (void)
|
|||||||
for (i = META_N_ORIENTATIONS - 1; i > META_ORIENTATION_UNDEFINED; i--)
|
for (i = META_N_ORIENTATIONS - 1; i > META_ORIENTATION_UNDEFINED; i--)
|
||||||
{
|
{
|
||||||
meta_sensors_proxy_mock_set_orientation (orientation_mock, i);
|
meta_sensors_proxy_mock_set_orientation (orientation_mock, i);
|
||||||
wait_for_orientation (orientation_manager, i, ×_signalled);
|
meta_wait_for_orientation (orientation_manager, i, ×_signalled);
|
||||||
g_assert_cmpuint (times_signalled, <=, 1);
|
g_assert_cmpuint (times_signalled, <=, 1);
|
||||||
|
|
||||||
META_TEST_LOG_CALL ("Checking configuration per orientation",
|
META_TEST_LOG_CALL ("Checking configuration per orientation",
|
||||||
@ -4902,7 +4907,7 @@ meta_test_monitor_orientation_changes_with_hotplugging (void)
|
|||||||
|
|
||||||
meta_sensors_proxy_mock_set_orientation (orientation_mock,
|
meta_sensors_proxy_mock_set_orientation (orientation_mock,
|
||||||
META_ORIENTATION_NORMAL);
|
META_ORIENTATION_NORMAL);
|
||||||
wait_for_orientation (orientation_manager, META_ORIENTATION_NORMAL,
|
meta_wait_for_orientation (orientation_manager, META_ORIENTATION_NORMAL,
|
||||||
×_signalled);
|
×_signalled);
|
||||||
g_assert_cmpuint (times_signalled, <=, 1);
|
g_assert_cmpuint (times_signalled, <=, 1);
|
||||||
check_monitor_configuration (&test_case.expect);
|
check_monitor_configuration (&test_case.expect);
|
||||||
@ -4924,14 +4929,14 @@ meta_test_monitor_orientation_changes_with_hotplugging (void)
|
|||||||
for (i = META_N_ORIENTATIONS - 1; i > META_ORIENTATION_UNDEFINED; i--)
|
for (i = META_N_ORIENTATIONS - 1; i > META_ORIENTATION_UNDEFINED; i--)
|
||||||
{
|
{
|
||||||
meta_sensors_proxy_mock_set_orientation (orientation_mock, i);
|
meta_sensors_proxy_mock_set_orientation (orientation_mock, i);
|
||||||
wait_for_orientation (orientation_manager, i, ×_signalled);
|
meta_wait_for_orientation (orientation_manager, i, ×_signalled);
|
||||||
g_assert_cmpuint (times_signalled, <=, 1);
|
g_assert_cmpuint (times_signalled, <=, 1);
|
||||||
check_monitor_configuration (&test_case.expect);
|
check_monitor_configuration (&test_case.expect);
|
||||||
}
|
}
|
||||||
|
|
||||||
meta_sensors_proxy_mock_set_orientation (orientation_mock,
|
meta_sensors_proxy_mock_set_orientation (orientation_mock,
|
||||||
META_ORIENTATION_NORMAL);
|
META_ORIENTATION_NORMAL);
|
||||||
wait_for_orientation (orientation_manager, META_ORIENTATION_NORMAL,
|
meta_wait_for_orientation (orientation_manager, META_ORIENTATION_NORMAL,
|
||||||
×_signalled);
|
×_signalled);
|
||||||
g_assert_cmpuint (times_signalled, <=, 1);
|
g_assert_cmpuint (times_signalled, <=, 1);
|
||||||
|
|
||||||
@ -4976,7 +4981,7 @@ meta_test_monitor_orientation_changes_with_hotplugging (void)
|
|||||||
|
|
||||||
/* Change orientation */
|
/* Change orientation */
|
||||||
meta_sensors_proxy_mock_set_orientation (orientation_mock, i);
|
meta_sensors_proxy_mock_set_orientation (orientation_mock, i);
|
||||||
wait_for_orientation (orientation_manager, i, ×_signalled);
|
meta_wait_for_orientation (orientation_manager, i, ×_signalled);
|
||||||
g_assert_cmpuint (times_signalled, <=, 1);
|
g_assert_cmpuint (times_signalled, <=, 1);
|
||||||
check_monitor_configuration (&test_case.expect);
|
check_monitor_configuration (&test_case.expect);
|
||||||
|
|
||||||
@ -4996,7 +5001,8 @@ meta_test_monitor_orientation_changes_with_hotplugging (void)
|
|||||||
/* We don't actually expect the orientation to change here, so we
|
/* We don't actually expect the orientation to change here, so we
|
||||||
* just wait for a moment (so that if the orientation *did* change,
|
* just wait for a moment (so that if the orientation *did* change,
|
||||||
* mutter has had a chance to process it), and then continue. */
|
* mutter has had a chance to process it), and then continue. */
|
||||||
wait_for_possible_orientation_change (orientation_manager, ×_signalled);
|
meta_wait_for_possible_orientation_change (orientation_manager,
|
||||||
|
×_signalled);
|
||||||
g_assert_cmpuint (times_signalled, ==, 0);
|
g_assert_cmpuint (times_signalled, ==, 0);
|
||||||
|
|
||||||
META_TEST_LOG_CALL ("Checking configuration per orientation",
|
META_TEST_LOG_CALL ("Checking configuration per orientation",
|
||||||
@ -5035,7 +5041,7 @@ meta_test_monitor_orientation_changes_with_hotplugging (void)
|
|||||||
|
|
||||||
meta_sensors_proxy_mock_set_orientation (orientation_mock,
|
meta_sensors_proxy_mock_set_orientation (orientation_mock,
|
||||||
META_ORIENTATION_NORMAL);
|
META_ORIENTATION_NORMAL);
|
||||||
wait_for_orientation (orientation_manager, META_ORIENTATION_NORMAL,
|
meta_wait_for_orientation (orientation_manager, META_ORIENTATION_NORMAL,
|
||||||
×_signalled);
|
×_signalled);
|
||||||
g_assert_cmpuint (times_signalled, <=, 1);
|
g_assert_cmpuint (times_signalled, <=, 1);
|
||||||
}
|
}
|
||||||
|
@ -23,151 +23,7 @@
|
|||||||
#include "orientation-manager-unit-tests.h"
|
#include "orientation-manager-unit-tests.h"
|
||||||
|
|
||||||
#include "tests/meta-sensors-proxy-mock.h"
|
#include "tests/meta-sensors-proxy-mock.h"
|
||||||
|
#include "tests/monitor-test-utils.h"
|
||||||
const char *
|
|
||||||
orientation_to_string (MetaOrientation orientation)
|
|
||||||
{
|
|
||||||
switch (orientation)
|
|
||||||
{
|
|
||||||
case META_ORIENTATION_UNDEFINED:
|
|
||||||
return "(undefined)";
|
|
||||||
case META_ORIENTATION_NORMAL:
|
|
||||||
return "normal";
|
|
||||||
case META_ORIENTATION_BOTTOM_UP:
|
|
||||||
return "bottom-up";
|
|
||||||
case META_ORIENTATION_LEFT_UP:
|
|
||||||
return "left-up";
|
|
||||||
case META_ORIENTATION_RIGHT_UP:
|
|
||||||
return "right-up";
|
|
||||||
default:
|
|
||||||
return "(invalid)";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
MetaOrientation expected;
|
|
||||||
MetaOrientation orientation;
|
|
||||||
gulong connection_id;
|
|
||||||
guint timeout_id;
|
|
||||||
unsigned int times_signalled;
|
|
||||||
} WaitForOrientation;
|
|
||||||
|
|
||||||
static void
|
|
||||||
on_orientation_changed (WaitForOrientation *wfo,
|
|
||||||
MetaOrientationManager *orientation_manager)
|
|
||||||
{
|
|
||||||
wfo->orientation = meta_orientation_manager_get_orientation (orientation_manager);
|
|
||||||
wfo->times_signalled++;
|
|
||||||
|
|
||||||
g_test_message ("wait_for_orientation_changes: Orientation changed to %d: %s",
|
|
||||||
wfo->orientation, orientation_to_string (wfo->orientation));
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
on_max_wait_timeout (gpointer data)
|
|
||||||
{
|
|
||||||
WaitForOrientation *wfo = data;
|
|
||||||
|
|
||||||
wfo->timeout_id = 0;
|
|
||||||
return G_SOURCE_REMOVE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Assert that the orientation eventually changes to @orientation.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
wait_for_orientation (MetaOrientationManager *orientation_manager,
|
|
||||||
MetaOrientation orientation,
|
|
||||||
unsigned int *times_signalled_out)
|
|
||||||
{
|
|
||||||
WaitForOrientation wfo = {
|
|
||||||
.expected = orientation,
|
|
||||||
};
|
|
||||||
|
|
||||||
wfo.orientation = meta_orientation_manager_get_orientation (orientation_manager);
|
|
||||||
g_test_message ("%s: Waiting for orientation to change from "
|
|
||||||
"%d: %s to %d: %s...",
|
|
||||||
G_STRFUNC, wfo.orientation,
|
|
||||||
orientation_to_string (wfo.orientation),
|
|
||||||
orientation, orientation_to_string (orientation));
|
|
||||||
|
|
||||||
/* This timeout can be relatively generous because we don't expect to
|
|
||||||
* reach it: if we do, that's a test failure. */
|
|
||||||
wfo.timeout_id = g_timeout_add_seconds (10, on_max_wait_timeout, &wfo);
|
|
||||||
wfo.connection_id = g_signal_connect_swapped (orientation_manager,
|
|
||||||
"orientation-changed",
|
|
||||||
G_CALLBACK (on_orientation_changed),
|
|
||||||
&wfo);
|
|
||||||
|
|
||||||
while (wfo.orientation != orientation && wfo.timeout_id != 0)
|
|
||||||
g_main_context_iteration (NULL, TRUE);
|
|
||||||
|
|
||||||
if (wfo.orientation != orientation)
|
|
||||||
{
|
|
||||||
g_error ("Timed out waiting for orientation to change from %s to %s "
|
|
||||||
"(received %u orientation-changed signal(s) while waiting)",
|
|
||||||
orientation_to_string (wfo.orientation),
|
|
||||||
orientation_to_string (orientation),
|
|
||||||
wfo.times_signalled);
|
|
||||||
}
|
|
||||||
|
|
||||||
g_test_message ("%s: Orientation is now %d: %s",
|
|
||||||
G_STRFUNC, orientation, orientation_to_string (orientation));
|
|
||||||
|
|
||||||
g_clear_handle_id (&wfo.timeout_id, g_source_remove);
|
|
||||||
g_signal_handler_disconnect (orientation_manager, wfo.connection_id);
|
|
||||||
|
|
||||||
if (times_signalled_out != NULL)
|
|
||||||
*times_signalled_out = wfo.times_signalled;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Wait for a possible orientation change, but don't assert that one occurs.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
wait_for_possible_orientation_change (MetaOrientationManager *orientation_manager,
|
|
||||||
unsigned int *times_signalled_out)
|
|
||||||
{
|
|
||||||
WaitForOrientation wfo = {
|
|
||||||
.expected = META_ORIENTATION_UNDEFINED,
|
|
||||||
};
|
|
||||||
|
|
||||||
wfo.orientation = meta_orientation_manager_get_orientation (orientation_manager);
|
|
||||||
g_test_message ("%s: Waiting for orientation to maybe change from %d: %s...",
|
|
||||||
G_STRFUNC, wfo.orientation,
|
|
||||||
orientation_to_string (wfo.orientation));
|
|
||||||
|
|
||||||
/* This can't be as long as the timeout for wait_for_orientation(),
|
|
||||||
* because in the usual case we expect to reach this timeout: we're
|
|
||||||
* only waiting so that if the orientation (incorrectly?) changed here,
|
|
||||||
* we'd have a chance to detect that. */
|
|
||||||
wfo.timeout_id = g_timeout_add (1000, on_max_wait_timeout, &wfo);
|
|
||||||
wfo.connection_id = g_signal_connect_swapped (orientation_manager,
|
|
||||||
"orientation-changed",
|
|
||||||
G_CALLBACK (on_orientation_changed),
|
|
||||||
&wfo);
|
|
||||||
|
|
||||||
while (wfo.times_signalled == 0 && wfo.timeout_id != 0)
|
|
||||||
g_main_context_iteration (NULL, TRUE);
|
|
||||||
|
|
||||||
if (wfo.timeout_id == 0)
|
|
||||||
{
|
|
||||||
g_test_message ("%s: Orientation didn't change", G_STRFUNC);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
g_test_message ("%s: Orientation is now %d: %s",
|
|
||||||
G_STRFUNC, wfo.orientation,
|
|
||||||
orientation_to_string (wfo.orientation));
|
|
||||||
}
|
|
||||||
|
|
||||||
g_clear_handle_id (&wfo.timeout_id, g_source_remove);
|
|
||||||
g_signal_handler_disconnect (orientation_manager, wfo.connection_id);
|
|
||||||
|
|
||||||
if (times_signalled_out != NULL)
|
|
||||||
*times_signalled_out = wfo.times_signalled;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
meta_test_orientation_manager_no_daemon (void)
|
meta_test_orientation_manager_no_daemon (void)
|
||||||
@ -268,7 +124,7 @@ meta_test_orientation_manager_accelerometer_orientations (void)
|
|||||||
changed_called = FALSE;
|
changed_called = FALSE;
|
||||||
g_debug ("Checking orientation %d", i);
|
g_debug ("Checking orientation %d", i);
|
||||||
meta_sensors_proxy_mock_set_orientation (orientation_mock, i);
|
meta_sensors_proxy_mock_set_orientation (orientation_mock, i);
|
||||||
wait_for_orientation (manager, i, ×_signalled);
|
meta_wait_for_orientation (manager, i, ×_signalled);
|
||||||
g_assert_cmpuint (times_signalled, <=, 1);
|
g_assert_cmpuint (times_signalled, <=, 1);
|
||||||
|
|
||||||
if (i != META_ORIENTATION_UNDEFINED)
|
if (i != META_ORIENTATION_UNDEFINED)
|
||||||
|
@ -25,12 +25,4 @@
|
|||||||
|
|
||||||
void init_orientation_manager_tests (void);
|
void init_orientation_manager_tests (void);
|
||||||
|
|
||||||
void wait_for_orientation (MetaOrientationManager *orientation_manager,
|
|
||||||
MetaOrientation orientation,
|
|
||||||
unsigned int *times_signalled_out);
|
|
||||||
void wait_for_possible_orientation_change (MetaOrientationManager *orientation_manager,
|
|
||||||
unsigned int *times_signalled_out);
|
|
||||||
|
|
||||||
const char * orientation_to_string (MetaOrientation orientation);
|
|
||||||
|
|
||||||
#endif /* ORIENTATION_MANAGER_UNIT_TESTS_H */
|
#endif /* ORIENTATION_MANAGER_UNIT_TESTS_H */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user