1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
/*
* Copyright (C) 2020 Purism SPC
* SPDX-License-Identifier: GPL-3.0-or-later
* Author: Guido Günther <agx@sigxcpu.org>
*/
#include "testlib.h"
#include "server.h"
static gboolean
on_timer_expired (gpointer unused)
{
/* Compositor did not quit in time */
g_assert_not_reached ();
return FALSE;
}
static void
test_phoc_run_session_success (void)
{
PhocConfig *config = phoc_config_new_from_file (TEST_PHOC_INI);
g_autoptr (PhocServer) server = phoc_server_get_default ();
g_autoptr (GMainLoop) loop = g_main_loop_new (NULL, FALSE);
g_assert_true (PHOC_IS_SERVER (server));
g_assert_true (config);
g_assert_true (phoc_server_setup (server, config, "/bin/true", loop,
PHOC_SERVER_FLAG_NONE));
g_timeout_add_seconds (TEST_PHOC_CLIENT_TIMEOUT, on_timer_expired, NULL);
g_main_loop_run (loop);
g_assert_cmpint (phoc_server_get_session_exit_status (server), ==, 0);
}
static void
test_phoc_run_session_failure (void)
{
PhocConfig *config = phoc_config_new_from_file (TEST_PHOC_INI);
g_autoptr (PhocServer) server = phoc_server_get_default ();
g_autoptr (GMainLoop) loop = g_main_loop_new (NULL, FALSE);
g_assert_true (PHOC_IS_SERVER (server));
g_assert_true (config);
g_assert_true (phoc_server_setup (server, config, "/bin/false", loop,
PHOC_SERVER_FLAG_NONE));
g_timeout_add_seconds (TEST_PHOC_CLIENT_TIMEOUT, on_timer_expired, NULL);
g_main_loop_run (loop);
g_assert_cmpint (phoc_server_get_session_exit_status (server), ==, 1);
}
int
main (int argc, char *argv[])
{
g_test_init (&argc, &argv, NULL);
PHOC_TEST_ADD ("/phoc/run/session_success", test_phoc_run_session_success);
PHOC_TEST_ADD ("/phoc/run/session_failure", test_phoc_run_session_failure);
return g_test_run ();
}
|