Debian Codegraph @

tests/conform/units.c

raw ◀ ▶
1 Debian patch touch this file
1 #include <clutter/clutter.h>
2
3 static void
4 units_cache (void)
5 {
6 ClutterUnits units;
7 ClutterSettings *settings;
8 gfloat pixels;
9 gint old_dpi;
10
11 settings = clutter_settings_get_default ();
12 g_object_get (settings, "font-dpi", &old_dpi, NULL);
13
14 g_object_set (settings, "font-dpi", 96 * 1024, NULL);
15 clutter_units_from_em (&units, 1.0);
16 pixels = clutter_units_to_pixels (&units);
17
18 g_object_set (settings, "font-dpi", ((96 * 2) * 1024), NULL);
19 g_assert_cmpfloat (clutter_units_to_pixels (&units), !=, pixels);
20
21 g_object_set (settings, "font-dpi", (96 * 1024), NULL);
22 g_assert_cmpfloat (clutter_units_to_pixels (&units), ==, pixels);
23
24 g_object_set (settings, "font-dpi", old_dpi, NULL);
25 }
26
27 static void
28 units_constructors (void)
29 {
30 ClutterUnits units, units_cm;
31
32 clutter_units_from_pixels (&units, 100);
33 g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_PIXEL);
34 g_assert_cmpfloat (clutter_units_get_unit_value (&units), ==, 100.0);
35 g_assert_cmpfloat (clutter_units_to_pixels (&units), ==, 100.0);
36
37 clutter_units_from_em (&units, 5.0);
38 g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_EM);
39 g_assert_cmpfloat (clutter_units_get_unit_value (&units), ==, 5.0);
40 g_assert_cmpfloat (clutter_units_to_pixels (&units), !=, 5.0);
41
42 clutter_units_from_cm (&units_cm, 5.0);
43 g_assert (clutter_units_get_unit_type (&units_cm) == CLUTTER_UNIT_CM);
44 g_assert_cmpfloat (clutter_units_get_unit_value (&units_cm), ==, 5.0);
45 g_assert_cmpfloat (clutter_units_to_pixels (&units_cm), !=, 5.0);
46
47 clutter_units_from_mm (&units, 50.0);
48 g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_MM);
49 g_assert_cmpfloat (clutter_units_to_pixels (&units),
50 ==,
51 clutter_units_to_pixels (&units_cm));
52 }
53
54 static void
55 units_string (void)
56 {
57 ClutterUnits units;
58 gchar *string;
59
60 g_assert (clutter_units_from_string (&units, "") == FALSE);
61
62 g_assert (clutter_units_from_string (&units, "10") == TRUE);
63 g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_PIXEL);
64 g_assert_cmpfloat (clutter_units_get_unit_value (&units), ==, 10);
65
66 g_assert (clutter_units_from_string (&units, "10 px") == TRUE);
67 g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_PIXEL);
68
69 g_assert (clutter_units_from_string (&units, "10 mm") == TRUE);
70 g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_MM);
71
72 g_assert (clutter_units_from_string (&units, "10 cm") == TRUE);
73 g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_CM);
74
75 g_assert (clutter_units_from_string (&units, "10 ") == TRUE);
76 g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_PIXEL);
77 g_assert_cmpfloat (clutter_units_get_unit_value (&units), ==, 10);
78
79 g_assert (clutter_units_from_string (&units, "5 em") == TRUE);
80 g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_EM);
81 g_assert_cmpfloat (clutter_units_get_unit_value (&units), ==, 5);
82
83 g_assert (clutter_units_from_string (&units, "5 emeralds") == FALSE);
84
85 g_assert (clutter_units_from_string (&units, " 16 mm") == TRUE);
86 g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_MM);
87 g_assert_cmpfloat (clutter_units_get_unit_value (&units), ==, 16);
88
89 g_assert (clutter_units_from_string (&units, " 24 pt ") == TRUE);
90 g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_POINT);
91 g_assert_cmpfloat (clutter_units_get_unit_value (&units), ==, 24);
92
93 g_assert (clutter_units_from_string (&units, " 32 em garbage") == FALSE);
94
95 g_assert (clutter_units_from_string (&units, "5.1cm") == TRUE);
96 g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_CM);
•97 g_assert_cmpfloat_with_epsilon (clutter_units_get_unit_value (&units), 5.1f, 0.00001);
98
99 g_assert (clutter_units_from_string (&units, "5,mm") == FALSE);
100
101 g_assert (clutter_units_from_string (&units, ".5pt") == TRUE);
102 g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_POINT);
103 g_assert_cmpfloat (clutter_units_get_unit_value (&units), ==, 0.5f);
104
105 g_assert (clutter_units_from_string (&units, "1 omg!!pony") == FALSE);
106
107 clutter_units_from_pt (&units, 24.0);
108 string = clutter_units_to_string (&units);
109 g_assert_cmpstr (string, ==, "24.0 pt");
110 g_free (string);
111
112 clutter_units_from_em (&units, 3.0);
113 string = clutter_units_to_string (&units);
114 g_assert_cmpstr (string, ==, "3.00 em");
115
116 units.unit_type = CLUTTER_UNIT_PIXEL;
117 units.value = 0;
118
119 g_assert (clutter_units_from_string (&units, string) == TRUE);
120 g_assert (clutter_units_get_unit_type (&units) != CLUTTER_UNIT_PIXEL);
121 g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_EM);
122 g_assert_cmpint ((int) clutter_units_get_unit_value (&units), ==, 3);
123
124 g_free (string);
125 }
126
127 CLUTTER_TEST_SUITE (
128 CLUTTER_TEST_UNIT ("/units/string", units_string)
129 CLUTTER_TEST_UNIT ("/units/cache", units_cache)
130 CLUTTER_TEST_UNIT ("/units/constructors", units_constructors)
131 )