File: test-keypad.c

package info (click to toggle)
phosh 0.53.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 9,868 kB
  • sloc: ansic: 83,377; xml: 3,981; python: 717; sh: 449; makefile: 34; lisp: 22; javascript: 6
file content (124 lines) | stat: -rw-r--r-- 3,075 bytes parent folder | download | duplicates (4)
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
 * Copyright (C) 2021 Purism SPC
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 *
 * based on LGPL-2.1+ HdyKeypad which is
 * Copyright (C) 2019 Purism SPC
 */

#include "keypad.h"

gint notified;


static void
notify_cb (GtkWidget *widget,
           gpointer   data)
{
  notified++;
}


static void
test_keypad_entry (void)
{
  g_autoptr (PhoshKeypad) keypad = NULL;
  g_autoptr (GtkEntry) entry = NULL;

  keypad = g_object_ref_sink (PHOSH_KEYPAD (phosh_keypad_new ()));
  entry = g_object_ref_sink (GTK_ENTRY (gtk_entry_new ()));

  notified = 0;
  g_signal_connect (keypad, "notify::entry", G_CALLBACK (notify_cb), NULL);

  g_assert_null (phosh_keypad_get_entry (keypad));

  phosh_keypad_set_entry (keypad, entry);
  g_assert_cmpint (notified, ==, 1);

  g_assert_true (phosh_keypad_get_entry (keypad) == entry);

  g_object_set (keypad, "entry", NULL, NULL);
  g_assert_cmpint (notified, ==, 2);

  g_assert_null (phosh_keypad_get_entry (keypad));
}


static void
test_keypad_start_action (void)
{
  g_autoptr (PhoshKeypad) keypad = NULL;
  g_autoptr (GtkWidget) button = NULL;

  keypad = g_object_ref_sink (PHOSH_KEYPAD (phosh_keypad_new ()));
  button = g_object_ref_sink (gtk_button_new ());

  notified = 0;
  g_signal_connect (keypad, "notify::start-action", G_CALLBACK (notify_cb), NULL);

  g_assert_null (phosh_keypad_get_start_action (keypad));

  phosh_keypad_set_start_action (keypad, button);
  g_assert_cmpint (notified, ==, 1);

  g_assert_true (phosh_keypad_get_start_action (keypad) == button);

  g_object_set (keypad, "start-action", NULL, NULL);
  g_assert_cmpint (notified, ==, 2);

  g_assert_null (phosh_keypad_get_start_action (keypad));
}


static void
test_keypad_end_action (void)
{
  g_autoptr (PhoshKeypad) keypad = NULL;
  g_autoptr (GtkWidget) button = NULL;

  keypad = g_object_ref_sink (PHOSH_KEYPAD (phosh_keypad_new ()));
  button = g_object_ref_sink (gtk_button_new ());

  notified = 0;
  g_signal_connect (keypad, "notify::end-action", G_CALLBACK (notify_cb), NULL);

  g_assert_null (phosh_keypad_get_end_action (keypad));

  phosh_keypad_set_end_action (keypad, button);
  g_assert_cmpint (notified, ==, 1);

  g_assert_true (phosh_keypad_get_end_action (keypad) == button);

  g_object_set (keypad, "end-action", NULL, NULL);
  g_assert_cmpint (notified, ==, 2);

  g_assert_null (phosh_keypad_get_end_action (keypad));
}


static void
test_keypad_shuffle (void)
{
  g_autoptr (PhoshKeypad) keypad = NULL;

  keypad = g_object_ref_sink (g_object_new (PHOSH_TYPE_KEYPAD,
                                            "shuffle", TRUE,
                                            NULL));
  g_assert_true (phosh_keypad_get_shuffle (keypad));
}


gint
main (gint argc, char *argv[])
{
  gtk_test_init (&argc, &argv, NULL);

  g_test_add_func ("/phosh/Keypad/entry", test_keypad_entry);
  g_test_add_func ("/phosh/Keypad/start_action", test_keypad_start_action);
  g_test_add_func ("/phosh/Keypad/end_action", test_keypad_end_action);
  g_test_add_func ("/phosh/Keypad/shuffle", test_keypad_shuffle);

  return g_test_run ();
}