1 /* tooltips.c: Unit test for GtkWidget tooltip accessors
2 *
3 * SPDX-License-Identifier: LGPL-2.1-or-later
4 * Copyright 2020 GNOME Foundation
5 */
6
7 #include <gtk/gtk.h>
8
9 static void
test_tooltips_widget_accessors(void)10 test_tooltips_widget_accessors (void)
11 {
12 GtkWidget *w;
13 const char *text, *markup;
14
15 g_test_message ("A button using tooltip-markup");
16 w = gtk_check_button_new_with_label ("This one uses the tooltip-markup property");
17 g_object_ref_sink (w);
18 gtk_widget_set_tooltip_text (w, "Hello, I am a static tooltip.");
19
20 text = gtk_widget_get_tooltip_text (w);
21 markup = gtk_widget_get_tooltip_markup (w);
22 g_assert_cmpstr (text, ==, "Hello, I am a static tooltip.");
23 g_assert_cmpstr (markup, ==, "Hello, I am a static tooltip.");
24 g_object_unref (w);
25
26 g_test_message ("A label using tooltip-text");
27 w = gtk_label_new ("I am just a label");
28 g_object_ref_sink (w);
29 gtk_widget_set_tooltip_text (w, "Label & and tooltip");
30
31 text = gtk_widget_get_tooltip_text (w);
32 markup = gtk_widget_get_tooltip_markup (w);
33 g_assert_cmpstr (text, ==, "Label & and tooltip");
34 g_assert_cmpstr (markup, ==, "Label & and tooltip");
35 g_object_unref (w);
36
37 g_test_message ("A label using tooltip-markup");
38 w = gtk_label_new ("I am a selectable label");
39 g_object_ref_sink (w);
40 gtk_label_set_selectable (GTK_LABEL (w), TRUE);
41 gtk_widget_set_tooltip_markup (w, "<b>Another</b> Label tooltip");
42
43 text = gtk_widget_get_tooltip_text (w);
44 markup = gtk_widget_get_tooltip_markup (w);
45 g_assert_cmpstr (text, ==, "Another Label tooltip");
46 g_assert_cmpstr (markup, ==,"<b>Another</b> Label tooltip");
47 g_object_unref (w);
48 }
49
50 int
main(int argc,char * argv[])51 main (int argc,
52 char *argv[])
53 {
54 gtk_test_init (&argc, &argv);
55
56 g_test_add_func ("/tooltips/widget-accessors", test_tooltips_widget_accessors);
57
58 return g_test_run ();
59 }
60