]> Pileus Git - ~andy/gtk/blob - gtk/tests/papersize.c
Change FSF Address
[~andy/gtk] / gtk / tests / papersize.c
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 2011 Red Hat, Inc.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 #include <gtk/gtk.h>
19
20 static void
21 test_parse (void)
22 {
23   GtkPaperSize *p;
24
25   p = gtk_paper_size_new (GTK_PAPER_NAME_A4);
26   g_assert (p != NULL);
27   g_assert_cmpint (gtk_paper_size_get_width (p, GTK_UNIT_MM), ==, 210);
28   g_assert_cmpint (gtk_paper_size_get_height (p, GTK_UNIT_MM), ==, 297);
29   g_assert_cmpstr (gtk_paper_size_get_name (p), ==, "iso_a4");
30   g_assert_cmpstr (gtk_paper_size_get_display_name (p), ==, "A4");
31   g_assert_cmpstr (gtk_paper_size_get_ppd_name (p), ==, "A4");
32   g_assert (!gtk_paper_size_is_custom (p));
33   gtk_paper_size_free (p);
34
35   p = gtk_paper_size_new (GTK_PAPER_NAME_B5);
36   g_assert (p != NULL);
37   g_assert_cmpint (gtk_paper_size_get_width (p, GTK_UNIT_MM), ==, 176);
38   g_assert_cmpint (gtk_paper_size_get_height (p, GTK_UNIT_MM), ==, 250);
39   g_assert_cmpstr (gtk_paper_size_get_name (p), ==, "iso_b5");
40   g_assert_cmpstr (gtk_paper_size_get_display_name (p), ==, "B5");
41   g_assert_cmpstr (gtk_paper_size_get_ppd_name (p), ==, "ISOB5");
42   g_assert (!gtk_paper_size_is_custom (p));
43   gtk_paper_size_free (p);
44
45   p = gtk_paper_size_new (GTK_PAPER_NAME_EXECUTIVE);
46   g_assert (p != NULL);
47   g_assert_cmpint (gtk_paper_size_get_width (p, GTK_UNIT_MM), ==, 184);
48   g_assert_cmpint (gtk_paper_size_get_height (p, GTK_UNIT_MM), ==, 266);
49   g_assert_cmpstr (gtk_paper_size_get_name (p), ==, "na_executive");
50   g_assert_cmpstr (gtk_paper_size_get_display_name (p), ==, "Executive");
51   g_assert_cmpstr (gtk_paper_size_get_ppd_name (p), ==, "Executive");
52   g_assert (!gtk_paper_size_is_custom (p));
53   gtk_paper_size_free (p);
54
55   p = gtk_paper_size_new ("iso_a4_210x297mm");
56   g_assert (p != NULL);
57   g_assert_cmpint (gtk_paper_size_get_width (p, GTK_UNIT_MM), ==, 210);
58   g_assert_cmpint (gtk_paper_size_get_height (p, GTK_UNIT_MM), ==, 297);
59   g_assert_cmpstr (gtk_paper_size_get_name (p), ==, "iso_a4");
60   g_assert_cmpstr (gtk_paper_size_get_display_name (p), ==, "A4");
61   g_assert_cmpstr (gtk_paper_size_get_ppd_name (p), ==, "A4");
62   g_assert (!gtk_paper_size_is_custom (p));
63   gtk_paper_size_free (p);
64
65   p = gtk_paper_size_new ("custom_w1_20x30in");
66   g_assert (p != NULL);
67   g_assert_cmpint (gtk_paper_size_get_width (p, GTK_UNIT_INCH), ==, 20);
68   g_assert_cmpint (gtk_paper_size_get_height (p, GTK_UNIT_INCH), ==, 30);
69   g_assert_cmpstr (gtk_paper_size_get_name (p), ==, "custom_w1");
70   g_assert_cmpstr (gtk_paper_size_get_display_name (p), ==, "custom_w1");
71   g_assert (gtk_paper_size_is_custom (p));
72   gtk_paper_size_free (p);
73 }
74
75 static void
76 test_compare (void)
77 {
78   GtkPaperSize *a1, *a2, *b, *c;
79
80   a1 = gtk_paper_size_new (GTK_PAPER_NAME_A4);
81   a2 = gtk_paper_size_new ("iso_a4_210x297mm");
82   b = gtk_paper_size_new (GTK_PAPER_NAME_B5);
83   c = gtk_paper_size_new ("custom_w1_20x30in");
84
85   g_assert (gtk_paper_size_is_equal (a1, a2));
86   g_assert (!gtk_paper_size_is_equal (a1, b));
87   g_assert (!gtk_paper_size_is_equal (a1, c));
88   g_assert (!gtk_paper_size_is_equal (b, c));
89
90   gtk_paper_size_free (a1);
91   gtk_paper_size_free (a2);
92   gtk_paper_size_free (b);
93   gtk_paper_size_free (c);
94 }
95
96 static void
97 test_units (void)
98 {
99   GtkPaperSize *p;
100
101   p = gtk_paper_size_new (GTK_PAPER_NAME_A4);
102
103   g_assert_cmpint (gtk_paper_size_get_width (p, GTK_UNIT_MM), ==, 210);
104   g_assert_cmpint (gtk_paper_size_get_height (p, GTK_UNIT_MM), ==, 297);
105
106   /* compare up to 2 decimals */
107   g_assert_cmpint (100 * gtk_paper_size_get_width (p, GTK_UNIT_INCH), ==, 100 * 8.26);
108   g_assert_cmpint (100 * gtk_paper_size_get_height (p, GTK_UNIT_INCH), ==, 100 * 11.69);
109
110   g_assert_cmpint (gtk_paper_size_get_width (p, GTK_UNIT_POINTS), ==, 595);
111   g_assert_cmpint (gtk_paper_size_get_height (p, GTK_UNIT_POINTS), ==, 841);
112
113   gtk_paper_size_free (p);
114 }
115
116 int
117 main (int argc, char *argv[])
118 {
119   gtk_test_init (&argc, &argv);
120
121   g_test_add_func ("/paper-size/parse", test_parse);
122   g_test_add_func ("/paper-size/compare", test_compare);
123   g_test_add_func ("/paper-size/units", test_units);
124
125   return g_test_run();
126 }