1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 2011 Red Hat, Inc.
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.
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.
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/>.
25 p = gtk_paper_size_new (GTK_PAPER_NAME_A4);
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);
35 p = gtk_paper_size_new (GTK_PAPER_NAME_B5);
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);
45 p = gtk_paper_size_new (GTK_PAPER_NAME_EXECUTIVE);
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);
55 p = gtk_paper_size_new ("iso_a4_210x297mm");
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);
65 p = gtk_paper_size_new ("custom_w1_20x30in");
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);
78 GtkPaperSize *a1, *a2, *b, *c;
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");
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));
90 gtk_paper_size_free (a1);
91 gtk_paper_size_free (a2);
92 gtk_paper_size_free (b);
93 gtk_paper_size_free (c);
101 p = gtk_paper_size_new (GTK_PAPER_NAME_A4);
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);
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);
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);
113 gtk_paper_size_free (p);
117 main (int argc, char *argv[])
119 gtk_test_init (&argc, &argv);
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);