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 |
10 | test_tooltips_widget_accessors (void) |
11 | { |
12 | GtkWidget *w; |
13 | const char *text, *markup; |
14 | |
15 | g_test_message (format: "A button using tooltip-markup" ); |
16 | w = gtk_check_button_new_with_label (label: "This one uses the tooltip-markup property" ); |
17 | g_object_ref_sink (w); |
18 | gtk_widget_set_tooltip_text (widget: w, text: "Hello, I am a static tooltip." ); |
19 | |
20 | text = gtk_widget_get_tooltip_text (widget: w); |
21 | markup = gtk_widget_get_tooltip_markup (widget: 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 (object: w); |
25 | |
26 | g_test_message (format: "A label using tooltip-text" ); |
27 | w = gtk_label_new (str: "I am just a label" ); |
28 | g_object_ref_sink (w); |
29 | gtk_widget_set_tooltip_text (widget: w, text: "Label & and tooltip" ); |
30 | |
31 | text = gtk_widget_get_tooltip_text (widget: w); |
32 | markup = gtk_widget_get_tooltip_markup (widget: w); |
33 | g_assert_cmpstr (text, ==, "Label & and tooltip" ); |
34 | g_assert_cmpstr (markup, ==, "Label & and tooltip" ); |
35 | g_object_unref (object: w); |
36 | |
37 | g_test_message (format: "A label using tooltip-markup" ); |
38 | w = gtk_label_new (str: "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 (widget: w, markup: "<b>Another</b> Label tooltip" ); |
42 | |
43 | text = gtk_widget_get_tooltip_text (widget: w); |
44 | markup = gtk_widget_get_tooltip_markup (widget: w); |
45 | g_assert_cmpstr (text, ==, "Another Label tooltip" ); |
46 | g_assert_cmpstr (markup, ==,"<b>Another</b> Label tooltip" ); |
47 | g_object_unref (object: w); |
48 | } |
49 | |
50 | int |
51 | main (int argc, |
52 | char *argv[]) |
53 | { |
54 | gtk_test_init (argcp: &argc, argvp: &argv); |
55 | |
56 | g_test_add_func (testpath: "/tooltips/widget-accessors" , test_func: test_tooltips_widget_accessors); |
57 | |
58 | return g_test_run (); |
59 | } |
60 | |