File: test-run.c

package info (click to toggle)
phoc 0.52.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,052 kB
  • sloc: ansic: 107,165; xml: 3,765; sh: 138; makefile: 33; javascript: 5
file content (61 lines) | stat: -rw-r--r-- 1,812 bytes parent folder | download
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 ();
}