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 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
|
/*
* Copyright (C) 2018 Purism SPC
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include <adwaita.h>
static void
increment (int *data)
{
(*data)++;
}
static void
test_adw_action_row_add_remove (void)
{
AdwActionRow *row = g_object_ref_sink (ADW_ACTION_ROW (adw_action_row_new ()));
GtkWidget *prefix, *suffix;
g_assert_nonnull (row);
prefix = gtk_check_button_new ();
g_assert_nonnull (prefix);
suffix = gtk_check_button_new ();
g_assert_nonnull (suffix);
adw_action_row_add_prefix (row, prefix);
adw_action_row_add_suffix (row, suffix);
adw_action_row_remove (row, prefix);
adw_action_row_remove (row, suffix);
g_assert_finalize_object (row);
}
static void
test_adw_action_row_subtitle (void)
{
AdwActionRow *row = g_object_ref_sink (ADW_ACTION_ROW (adw_action_row_new ()));
int notified = 0;
g_assert_nonnull (row);
g_signal_connect_swapped (row, "notify::subtitle", G_CALLBACK (increment), ¬ified);
g_assert_cmpstr (adw_action_row_get_subtitle (row), ==, "");
g_assert_cmpint (notified, ==, 0);
adw_action_row_set_subtitle (row, "Dummy subtitle");
g_assert_cmpstr (adw_action_row_get_subtitle (row), ==, "Dummy subtitle");
g_assert_cmpint (notified, ==, 1);
adw_action_row_set_subtitle (row, "<b>Dummy subtitle</b>");
g_assert_cmpstr (adw_action_row_get_subtitle (row), ==, "<b>Dummy subtitle</b>");
g_assert_cmpint (notified, ==, 2);
adw_preferences_row_set_use_markup (ADW_PREFERENCES_ROW (row), FALSE);
adw_action_row_set_subtitle (row, "Invalid <b>markup");
g_assert_cmpstr (adw_action_row_get_subtitle (row), ==, "Invalid <b>markup");
g_assert_cmpint (notified, ==, 3);
g_assert_finalize_object (row);
}
static void
test_adw_action_row_title_lines (void)
{
AdwActionRow *row = g_object_ref_sink (ADW_ACTION_ROW (adw_action_row_new ()));
g_assert_nonnull (row);
g_assert_cmpint (adw_action_row_get_title_lines (row), ==, 0);
g_test_expect_message (ADW_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, "adw_action_row_set_title_lines: assertion 'title_lines >= 0' failed");
adw_action_row_set_title_lines (row, -1);
g_test_assert_expected_messages ();
g_assert_cmpint (adw_action_row_get_title_lines (row), ==, 0);
adw_action_row_set_title_lines (row, 1);
g_assert_cmpint (adw_action_row_get_title_lines (row), ==, 1);
g_assert_finalize_object (row);
}
static void
test_adw_action_row_subtitle_lines (void)
{
AdwActionRow *row = g_object_ref_sink (ADW_ACTION_ROW (adw_action_row_new ()));
g_assert_nonnull (row);
g_assert_cmpint (adw_action_row_get_subtitle_lines (row), ==, 0);
g_test_expect_message (ADW_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, "adw_action_row_set_subtitle_lines: assertion 'subtitle_lines >= 0' failed");
adw_action_row_set_subtitle_lines (row, -1);
g_test_assert_expected_messages ();
g_assert_cmpint (adw_action_row_get_subtitle_lines (row), ==, 0);
adw_action_row_set_subtitle_lines (row, 1);
g_assert_cmpint (adw_action_row_get_subtitle_lines (row), ==, 1);
g_assert_finalize_object (row);
}
static void
test_adw_action_row_subtitle_selectable (void)
{
AdwActionRow *row = g_object_ref_sink (ADW_ACTION_ROW (adw_action_row_new ()));
g_assert_nonnull (row);
g_assert_false (adw_action_row_get_subtitle_selectable (row));
adw_action_row_set_subtitle_selectable (row, TRUE);
g_assert_true (adw_action_row_get_subtitle_selectable (row));
adw_action_row_set_subtitle_selectable (row, FALSE);
g_assert_false (adw_action_row_get_subtitle_selectable (row));
g_assert_finalize_object (row);
}
static void
test_adw_action_row_activate (void)
{
AdwActionRow *row = g_object_ref_sink (ADW_ACTION_ROW (adw_action_row_new ()));
int activated = 0;
g_assert_nonnull (row);
g_signal_connect_swapped (row, "activated", G_CALLBACK (increment), &activated);
adw_action_row_activate (row);
g_assert_cmpint (activated, ==, 1);
g_assert_finalize_object (row);
}
int
main (int argc,
char *argv[])
{
gtk_test_init (&argc, &argv, NULL);
adw_init ();
g_test_add_func("/Adwaita/ActionRow/add_remove", test_adw_action_row_add_remove);
g_test_add_func("/Adwaita/ActionRow/subtitle", test_adw_action_row_subtitle);
g_test_add_func("/Adwaita/ActionRow/title_lines", test_adw_action_row_title_lines);
g_test_add_func("/Adwaita/ActionRow/subtitle_lines", test_adw_action_row_subtitle_lines);
g_test_add_func("/Adwaita/ActionRow/subtitle_selectable", test_adw_action_row_subtitle_selectable);
g_test_add_func("/Adwaita/ActionRow/activate", test_adw_action_row_activate);
return g_test_run();
}
|