1 | /* Pango |
2 | * testcontext.c: Test program for PangoContext |
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 | #include <pango/pangocairo.h> |
25 | |
26 | static void |
27 | test_list_families (void) |
28 | { |
29 | PangoContext *context; |
30 | PangoFontFamily **families = NULL; |
31 | int n_families = 0; |
32 | |
33 | context = pango_context_new (); |
34 | |
35 | pango_context_list_families (context, families: &families, n_families: &n_families); |
36 | g_assert_null (families); |
37 | g_assert_cmpint (n_families, ==, 0); |
38 | |
39 | pango_context_set_font_map (context, font_map: pango_cairo_font_map_get_default ()); |
40 | |
41 | pango_context_list_families (context, families: &families, n_families: &n_families); |
42 | g_assert_nonnull (families); |
43 | g_assert_cmpint (n_families, >, 0); |
44 | |
45 | g_free (mem: families); |
46 | |
47 | g_object_unref (object: context); |
48 | } |
49 | |
50 | static void |
51 | test_set_language (void) |
52 | { |
53 | PangoContext *context; |
54 | |
55 | context = pango_context_new (); |
56 | |
57 | pango_context_set_language (context, language: pango_language_from_string (language: "de-de" )); |
58 | g_assert_true (pango_context_get_language (context) == pango_language_from_string ("de-de" )); |
59 | |
60 | pango_context_set_language (context, NULL); |
61 | g_assert_null (pango_context_get_language (context)); |
62 | |
63 | g_object_unref (object: context); |
64 | } |
65 | |
66 | static void |
67 | test_set_base_dir (void) |
68 | { |
69 | PangoContext *context; |
70 | |
71 | context = pango_context_new (); |
72 | |
73 | pango_context_set_base_dir (context, direction: PANGO_DIRECTION_RTL); |
74 | g_assert_true (pango_context_get_base_dir (context) == PANGO_DIRECTION_RTL); |
75 | |
76 | pango_context_set_base_dir (context, direction: PANGO_DIRECTION_WEAK_LTR); |
77 | g_assert_true (pango_context_get_base_dir (context) == PANGO_DIRECTION_WEAK_LTR); |
78 | |
79 | g_object_unref (object: context); |
80 | } |
81 | |
82 | static void |
83 | test_set_base_gravity (void) |
84 | { |
85 | PangoContext *context; |
86 | |
87 | context = pango_context_new (); |
88 | |
89 | pango_context_set_base_gravity (context, gravity: PANGO_GRAVITY_SOUTH); |
90 | g_assert_true (pango_context_get_base_gravity (context) == PANGO_GRAVITY_SOUTH); |
91 | g_assert_true (pango_context_get_gravity (context) == PANGO_GRAVITY_SOUTH); |
92 | |
93 | pango_context_set_base_gravity (context, gravity: PANGO_GRAVITY_AUTO); |
94 | g_assert_true (pango_context_get_base_gravity (context) == PANGO_GRAVITY_AUTO); |
95 | g_assert_true (pango_context_get_gravity (context) == PANGO_GRAVITY_SOUTH); |
96 | |
97 | g_object_unref (object: context); |
98 | } |
99 | |
100 | static void |
101 | test_set_gravity_hint (void) |
102 | { |
103 | PangoContext *context; |
104 | |
105 | context = pango_context_new (); |
106 | |
107 | pango_context_set_gravity_hint (context, hint: PANGO_GRAVITY_HINT_NATURAL); |
108 | g_assert_true (pango_context_get_gravity_hint (context) == PANGO_GRAVITY_HINT_NATURAL); |
109 | |
110 | pango_context_set_gravity_hint (context, hint: PANGO_GRAVITY_HINT_STRONG); |
111 | g_assert_true (pango_context_get_gravity_hint (context) == PANGO_GRAVITY_HINT_STRONG); |
112 | |
113 | g_object_unref (object: context); |
114 | } |
115 | |
116 | static void |
117 | test_set_round_glyph_positions (void) |
118 | { |
119 | PangoContext *context; |
120 | |
121 | context = pango_context_new (); |
122 | |
123 | pango_context_set_round_glyph_positions (context, TRUE); |
124 | g_assert_true (pango_context_get_round_glyph_positions (context)); |
125 | |
126 | pango_context_set_round_glyph_positions (context, FALSE); |
127 | g_assert_false (pango_context_get_round_glyph_positions (context)); |
128 | |
129 | g_object_unref (object: context); |
130 | } |
131 | |
132 | int |
133 | main (int argc, char *argv[]) |
134 | { |
135 | g_test_init (argc: &argc, argv: &argv, NULL); |
136 | |
137 | g_test_add_func (testpath: "/context/list-families" , test_func: test_list_families); |
138 | g_test_add_func (testpath: "/context/set-language" , test_func: test_set_language); |
139 | g_test_add_func (testpath: "/context/set-base-dir" , test_func: test_set_base_dir); |
140 | g_test_add_func (testpath: "/context/set-base-gravity" , test_func: test_set_base_gravity); |
141 | g_test_add_func (testpath: "/context/set-gravity-hint" , test_func: test_set_gravity_hint); |
142 | g_test_add_func (testpath: "/context/set-round-glyph-positions" , test_func: test_set_round_glyph_positions); |
143 | |
144 | return g_test_run (); |
145 | } |
146 | |