]> Pileus Git - ~andy/gtk/blob - gtk/tests/papersize.c
62e7a90e87c2f728d63647d94a1c26029d9babbe
[~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, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include <gtk/gtk.h>
21
22 static void
23 test_parse (void)
24 {
25   GtkPaperSize *p;
26
27   p = gtk_paper_size_new (GTK_PAPER_NAME_A4);
28   g_assert (p != NULL);
29   g_assert_cmpint (gtk_paper_size_get_width (p, GTK_UNIT_MM), ==, 210);
30   g_assert_cmpint (gtk_paper_size_get_height (p, GTK_UNIT_MM), ==, 297);
31   g_assert_cmpstr (gtk_paper_size_get_name (p), ==, "iso_a4");
32   g_assert_cmpstr (gtk_paper_size_get_display_name (p), ==, "A4");
33   g_assert_cmpstr (gtk_paper_size_get_ppd_name (p), ==, "A4");
34   g_assert (!gtk_paper_size_is_custom (p));
35   gtk_paper_size_free (p);
36
37   p = gtk_paper_size_new (GTK_PAPER_NAME_B5);
38   g_assert (p != NULL);
39   g_assert_cmpint (gtk_paper_size_get_width (p, GTK_UNIT_MM), ==, 176);
40   g_assert_cmpint (gtk_paper_size_get_height (p, GTK_UNIT_MM), ==, 250);
41   g_assert_cmpstr (gtk_paper_size_get_name (p), ==, "iso_b5");
42   g_assert_cmpstr (gtk_paper_size_get_display_name (p), ==, "B5");
43   g_assert_cmpstr (gtk_paper_size_get_ppd_name (p), ==, "ISOB5");
44   g_assert (!gtk_paper_size_is_custom (p));
45   gtk_paper_size_free (p);
46
47   p = gtk_paper_size_new (GTK_PAPER_NAME_EXECUTIVE);
48   g_assert (p != NULL);
49   g_assert_cmpint (gtk_paper_size_get_width (p, GTK_UNIT_MM), ==, 184);
50   g_assert_cmpint (gtk_paper_size_get_height (p, GTK_UNIT_MM), ==, 266);
51   g_assert_cmpstr (gtk_paper_size_get_name (p), ==, "na_executive");
52   g_assert_cmpstr (gtk_paper_size_get_display_name (p), ==, "Executive");
53   g_assert_cmpstr (gtk_paper_size_get_ppd_name (p), ==, "Executive");
54   g_assert (!gtk_paper_size_is_custom (p));
55   gtk_paper_size_free (p);
56
57   p = gtk_paper_size_new ("iso_a4_210x297mm");
58   g_assert (p != NULL);
59   g_assert_cmpint (gtk_paper_size_get_width (p, GTK_UNIT_MM), ==, 210);
60   g_assert_cmpint (gtk_paper_size_get_height (p, GTK_UNIT_MM), ==, 297);
61   g_assert_cmpstr (gtk_paper_size_get_name (p), ==, "iso_a4");
62   g_assert_cmpstr (gtk_paper_size_get_display_name (p), ==, "A4");
63   g_assert_cmpstr (gtk_paper_size_get_ppd_name (p), ==, "A4");
64   g_assert (!gtk_paper_size_is_custom (p));
65   gtk_paper_size_free (p);
66
67   p = gtk_paper_size_new ("custom_w1_20x30in");
68   g_assert (p != NULL);
69   g_assert_cmpint (gtk_paper_size_get_width (p, GTK_UNIT_INCH), ==, 20);
70   g_assert_cmpint (gtk_paper_size_get_height (p, GTK_UNIT_INCH), ==, 30);
71   g_assert_cmpstr (gtk_paper_size_get_name (p), ==, "custom_w1");
72   g_assert_cmpstr (gtk_paper_size_get_display_name (p), ==, "custom_w1");
73   g_assert (gtk_paper_size_is_custom (p));
74   gtk_paper_size_free (p);
75 }
76
77 static void
78 test_compare (void)
79 {
80   GtkPaperSize *a1, *a2, *b, *c;
81
82   a1 = gtk_paper_size_new (GTK_PAPER_NAME_A4);
83   a2 = gtk_paper_size_new ("iso_a4_210x297mm");
84   b = gtk_paper_size_new (GTK_PAPER_NAME_B5);
85   c = gtk_paper_size_new ("custom_w1_20x30in");
86
87   g_assert (gtk_paper_size_is_equal (a1, a2));
88   g_assert (!gtk_paper_size_is_equal (a1, b));
89   g_assert (!gtk_paper_size_is_equal (a1, c));
90   g_assert (!gtk_paper_size_is_equal (b, c));
91
92   gtk_paper_size_free (a1);
93   gtk_paper_size_free (a2);
94   gtk_paper_size_free (b);
95   gtk_paper_size_free (c);
96 }
97
98 static void
99 test_units (void)
100 {
101   GtkPaperSize *p;
102
103   p = gtk_paper_size_new (GTK_PAPER_NAME_A4);
104
105   g_assert_cmpint (gtk_paper_size_get_width (p, GTK_UNIT_MM), ==, 210);
106   g_assert_cmpint (gtk_paper_size_get_height (p, GTK_UNIT_MM), ==, 297);
107
108   /* compare up to 2 decimals */
109   g_assert_cmpint (100 * gtk_paper_size_get_width (p, GTK_UNIT_INCH), ==, 100 * 8.26);
110   g_assert_cmpint (100 * gtk_paper_size_get_height (p, GTK_UNIT_INCH), ==, 100 * 11.69);
111
112   g_assert_cmpint (gtk_paper_size_get_width (p, GTK_UNIT_POINTS), ==, 595);
113   g_assert_cmpint (gtk_paper_size_get_height (p, GTK_UNIT_POINTS), ==, 841);
114
115   gtk_paper_size_free (p);
116 }
117
118 int
119 main (int argc, char *argv[])
120 {
121   gtk_test_init (&argc, &argv);
122
123   g_test_add_func ("/paper-size/parse", test_parse);
124   g_test_add_func ("/paper-size/compare", test_compare);
125   g_test_add_func ("/paper-size/units", test_units);
126
127   return g_test_run();
128 }