1/* Pango
2 * testtabs.c: Test program for PangoTabArray
3 *
4 * Copyright (C) 2021 Matthias Clasen
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
20 */
21
22#include <glib.h>
23#include <pango/pango.h>
24
25static void
26test_tabs_basic (void)
27{
28 PangoTabArray *tabs;
29 PangoTabAlign align;
30 int location;
31
32 tabs = pango_tab_array_new (initial_size: 1, TRUE);
33
34 g_assert_true (pango_tab_array_get_positions_in_pixels (tabs));
35 g_assert_true (pango_tab_array_get_size (tabs) == 1);
36
37 pango_tab_array_set_tab (tab_array: tabs, tab_index: 0, alignment: PANGO_TAB_LEFT, location: 10);
38 pango_tab_array_get_tab (tab_array: tabs, tab_index: 0, alignment: &align, location: &location);
39 g_assert_true (align == PANGO_TAB_LEFT);
40 g_assert_true (location == 10);
41
42 pango_tab_array_free (tab_array: tabs);
43}
44
45static void
46test_tabs_copy (void)
47{
48 PangoTabArray *tabs, *tabs2;
49 PangoTabAlign *alignments;
50 int *locations;
51
52 tabs = pango_tab_array_new_with_positions (size: 2, TRUE,
53 first_alignment: PANGO_TAB_LEFT, first_position: 10,
54 PANGO_TAB_LEFT, 20);
55
56 tabs2 = pango_tab_array_copy (src: tabs);
57 pango_tab_array_get_tabs (tab_array: tabs2, alignments: &alignments, locations: &locations);
58 g_assert_true (alignments[0] == PANGO_TAB_LEFT);
59 g_assert_true (alignments[1] == PANGO_TAB_LEFT);
60 g_assert_true (locations[0] == 10);
61 g_assert_true (locations[1] == 20);
62
63 g_free (mem: alignments);
64 g_free (mem: locations);
65
66 pango_tab_array_free (tab_array: tabs);
67 pango_tab_array_free (tab_array: tabs2);
68}
69
70static void
71test_tabs_resize (void)
72{
73 PangoTabArray *tabs;
74 PangoTabAlign *alignments;
75 int *locations;
76
77 tabs = pango_tab_array_new (initial_size: 1, TRUE);
78
79 pango_tab_array_set_tab (tab_array: tabs, tab_index: 0, alignment: PANGO_TAB_LEFT, location: 10);
80
81 g_assert_cmpint (pango_tab_array_get_size (tabs), ==, 1);
82
83 pango_tab_array_resize (tab_array: tabs, new_size: 2);
84 g_assert_cmpint (pango_tab_array_get_size (tabs), ==, 2);
85
86 pango_tab_array_set_tab (tab_array: tabs, tab_index: 1, alignment: PANGO_TAB_RIGHT, location: 20);
87 pango_tab_array_set_tab (tab_array: tabs, tab_index: 2, alignment: PANGO_TAB_CENTER, location: 30);
88 pango_tab_array_set_tab (tab_array: tabs, tab_index: 3, alignment: PANGO_TAB_DECIMAL, location: 40);
89
90 g_assert_cmpint (pango_tab_array_get_size (tabs), ==, 4);
91
92 pango_tab_array_get_tabs (tab_array: tabs, alignments: &alignments, locations: &locations);
93 g_assert_cmpint (alignments[0], ==, PANGO_TAB_LEFT);
94 g_assert_cmpint (alignments[1], ==, PANGO_TAB_RIGHT);
95 g_assert_cmpint (alignments[2], ==, PANGO_TAB_CENTER);
96 g_assert_cmpint (alignments[3], ==, PANGO_TAB_DECIMAL);
97 g_assert_cmpint (locations[0], ==, 10);
98 g_assert_cmpint (locations[1], ==, 20);
99 g_assert_cmpint (locations[2], ==, 30);
100 g_assert_cmpint (locations[3], ==, 40);
101
102 g_free (mem: alignments);
103 g_free (mem: locations);
104
105 pango_tab_array_free (tab_array: tabs);
106}
107
108int
109main (int argc, char *argv[])
110{
111 g_test_init (argc: &argc, argv: &argv, NULL);
112
113 g_test_add_func (testpath: "/tabs/basic", test_func: test_tabs_basic);
114 g_test_add_func (testpath: "/tabs/copy", test_func: test_tabs_copy);
115 g_test_add_func (testpath: "/tabs/resize", test_func: test_tabs_resize);
116
117 return g_test_run ();
118}
119

source code of gtk/subprojects/pango/tests/testtabs.c