File: test-end-session-dialog.c

package info (click to toggle)
phosh 0.53.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 9,936 kB
  • sloc: ansic: 83,383; xml: 3,981; python: 717; sh: 449; makefile: 34; lisp: 22; javascript: 6
file content (94 lines) | stat: -rw-r--r-- 2,564 bytes parent folder | download | duplicates (3)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
 * Copyright (C) 2021 Purism SPC
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 *
 * Author: Guido Günther <agx@sigxcpu.org>
 */

#include "testlib-compositor.h"

#include "end-session-dialog.h"

#include <glib.h>


static void
test_end_session_dialog_new (PhoshTestCompositorFixture *fixture, gconstpointer unused)
{
  GtkWidget *dialog;

  dialog = g_object_new (PHOSH_TYPE_END_SESSION_DIALOG,
                         "monitor", phosh_test_get_monitor (fixture->state),
                         "action", PHOSH_END_SESSION_ACTION_LOGOUT,
                         "timeout", 0,
                         "inhibitor-paths", NULL,
                         NULL);

  g_assert_true (PHOSH_IS_END_SESSION_DIALOG (dialog));

  gtk_widget_set_visible (dialog, TRUE);

  g_assert_true (gtk_widget_get_visible (dialog));
  g_assert_true (gtk_widget_get_mapped (dialog));
  gtk_widget_set_visible (dialog, FALSE);
  g_assert_false (gtk_widget_get_visible (dialog));
  g_assert_false (gtk_widget_get_mapped (dialog));
  gtk_widget_destroy (dialog);
}


static gboolean
on_expired (GMainLoop *mainloop)
{
  /* Make sure we don't wait forever */
  g_assert_not_reached ();
}


static void
on_closed (GMainLoop *mainloop)
{
  g_main_loop_quit (mainloop);
}


static void
test_end_session_dialog_timeout (PhoshTestCompositorFixture *fixture, gconstpointer unused)
{
  PhoshEndSessionDialog *dialog = NULL;
  g_autoptr (GMainLoop) mainloop = NULL;

  dialog = g_object_new (PHOSH_TYPE_END_SESSION_DIALOG,
                         "monitor", phosh_test_get_monitor (fixture->state),
                         "action", PHOSH_END_SESSION_ACTION_LOGOUT,
                         "timeout", 1,
                         "inhibitor-paths", NULL,
                         NULL);
  g_assert_true (PHOSH_IS_END_SESSION_DIALOG (dialog));

  mainloop = g_main_loop_new (NULL, FALSE);

  g_signal_connect_swapped (dialog, "closed", G_CALLBACK (on_closed), mainloop);
  g_timeout_add_seconds (3, (GSourceFunc)on_expired, mainloop);
  gtk_widget_set_visible (GTK_WIDGET (dialog), TRUE);

  g_main_loop_run (mainloop);
  /* Letting the dialog timeout means confirmation */
  g_assert_true (phosh_end_session_dialog_get_action_confirmed (dialog));

  gtk_widget_destroy (GTK_WIDGET (dialog));
}



int
main (int argc, char *argv[])
{
  g_test_init (&argc, &argv, NULL);

  PHOSH_COMPOSITOR_TEST_ADD ("/phosh/end-session-dialog/new", test_end_session_dialog_new);
  PHOSH_COMPOSITOR_TEST_ADD ("/phosh/end-session-dialog/timeout", test_end_session_dialog_timeout);

  return g_test_run ();
}