summaryrefslogtreecommitdiff
path: root/tests/atk_test_util.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/atk_test_util.c')
-rw-r--r--tests/atk_test_util.c76
1 files changed, 60 insertions, 16 deletions
diff --git a/tests/atk_test_util.c b/tests/atk_test_util.c
index c776ae1..c932df8 100644
--- a/tests/atk_test_util.c
+++ b/tests/atk_test_util.c
@@ -38,8 +38,8 @@ run_app (const char *file_name)
{
child_pid = fork ();
if (child_pid == 0) {
- execlp ("./app-test",
- "./app-test",
+ execlp (TESTS_BUILD_DIR "/app-test",
+ TESTS_BUILD_DIR "/app-test",
"--test-data-file",
file_name,
NULL);
@@ -47,33 +47,77 @@ run_app (const char *file_name)
}
}
-AtspiAccessible * get_root_obj (const char *file_name)
+static AtspiAccessible *try_get_root_obj (AtspiAccessible *obj)
{
int i;
- AtspiAccessible *obj = NULL;
-
- run_app (file_name);
-
- /* sleep is needed to wait for fored test application*/
- sleep (1);
- obj = atspi_get_desktop (0);
gint child_count = atspi_accessible_get_child_count (obj, NULL);
if (child_count < 1) {
- g_test_message ("Fail, test application not found\n");
- g_test_fail ();
- kill (child_pid, SIGTERM);
return NULL;
}
for (i=0; i<child_count; i++) {
AtspiAccessible *child = atspi_accessible_get_child_at_index (obj,i, NULL);
- if (!strcmp (atspi_accessible_get_name (child, NULL), "root_object"))
+ if (child && !strcmp (atspi_accessible_get_name (child, NULL), "root_object"))
return child;
}
- g_test_message ("test object not found\n");
- g_test_fail ();
+ return NULL;
+}
+
+AtspiAccessible * get_root_obj (const char *file_name)
+{
+ int tries = 0;
+ AtspiAccessible *child;
+ struct timespec timeout = { .tv_sec = 0, .tv_nsec = 10 * 1000000 };
+ AtspiAccessible *obj = NULL;
+
+ run_app (file_name);
+
+ obj = atspi_get_desktop (0);
+
+ /* Wait for application to start, up to 100 times 10ms. */
+ while (++tries <= 100)
+ {
+ child = try_get_root_obj (obj);
+ if (child)
+ return child;
+
+ nanosleep(&timeout, NULL);
+ }
+
+ if (atspi_accessible_get_child_count (obj, NULL) < 1) {
+ g_test_message ("Fail, test application not found\n");
+ } else {
+ g_test_message ("test object not found\n");
+ }
+ g_test_fail ();
kill (child_pid, SIGTERM);
return NULL;
}
+
+void terminate_app (void)
+{
+ int tries = 0;
+
+ AtspiAccessible *child;
+ struct timespec timeout = { .tv_sec = 0, .tv_nsec = 10 * 1000000 };
+ AtspiAccessible *obj = NULL;
+
+ kill (child_pid, SIGTERM);
+
+ obj = atspi_get_desktop (0);
+
+ /* Wait for application to stop, up to 100 times 10ms. */
+ while (++tries <= 100)
+ {
+ child = try_get_root_obj (obj);
+ if (child == NULL)
+ return;
+
+ nanosleep(&timeout, NULL);
+ }
+
+ g_test_message ("Fail, test application still running\n");
+ g_test_fail ();
+}