1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Authors: see git history
7 * Copyright (C) 2010 Authors
8 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
10 #include "svg/svg-box.h"
15 #include <gtest/gtest.h>
20 const std::string str
;
29 const std::string out
;
33 read_test_t read_tests
[5] = {
36 {"1 2 3 4", 1, 2, 3, 4},
37 {"1,2,3,4", 1, 2, 3, 4},
38 {"2cm 4cm", 76, 151, 76, 151},
40 const char* fail_tests
[4] = {
46 write_test_t write_tests
[7] = {
51 {"4cm 2in", "151.18111 192"},
52 {"7 2 4cm", "7 2 151.18111"},
55 read_test_t set_tests
[3] = {
58 {"1 2 3 4", 1, 2, 3, 4},
62 TEST(SvgBoxTest
, testRead
)
64 for (size_t i
= 0; i
< G_N_ELEMENTS(read_tests
); i
++) {
66 ASSERT_TRUE(box
.read(read_tests
[i
].str
, Geom::Scale(1))) << read_tests
[i
].str
;
67 ASSERT_EQ(round(box
.top().computed
), read_tests
[i
].top
) << read_tests
[i
].str
;
68 ASSERT_EQ(round(box
.right().computed
), read_tests
[i
].right
) << read_tests
[i
].str
;
69 ASSERT_EQ(round(box
.bottom().computed
), read_tests
[i
].bottom
) << read_tests
[i
].str
;
70 ASSERT_EQ(round(box
.left().computed
), read_tests
[i
].left
) << read_tests
[i
].str
;
74 TEST(SvgBoxTest
, testFailures
)
76 for (size_t i
= 0; i
< G_N_ELEMENTS(fail_tests
); i
++) {
78 ASSERT_TRUE( !box
.read(fail_tests
[i
])) << fail_tests
[i
];
82 TEST(SvgBoxTest
, testWrite
)
84 for (size_t i
= 0; i
< G_N_ELEMENTS(write_tests
); i
++) {
86 ASSERT_TRUE(box
.read(write_tests
[i
].in
, Geom::Scale(1))) << write_tests
[i
].in
;
87 ASSERT_EQ(box
.write(), write_tests
[i
].out
) << write_tests
[i
].in
;
91 TEST(SvgBoxTest
, testSet
)
93 for (auto t
: set_tests
) {
95 box
.set(t
.top
, t
.right
, t
.bottom
, t
.left
);
96 ASSERT_EQ(box
.write(), t
.str
);
100 TEST(SvgBoxTest
, testToFromString
)
103 ASSERT_TRUE(box
.fromString("10mm 5", "mm", Geom::Scale(5)));
104 ASSERT_EQ(box
.toString("mm", Geom::Scale(5)), "10mm 5.0000001mm");
105 // This result is mm to px (internal conversion) plus scale test.
106 ASSERT_EQ(box
.write(), "7.5590553 3.7795277");
109 TEST(SvgBoxTest
, testConfine
)
112 box
.set(10, 20, 10, 20);
113 ASSERT_EQ(box
.write(), "10 20");
114 box
.set(BOX_TOP
, 5, true);
115 ASSERT_EQ(box
.write(), "5 20");
116 box
.set(BOX_LEFT
, 10, true);
117 ASSERT_EQ(box
.write(), "5 10");
118 box
.set(BOX_LEFT
, 5, true);
119 ASSERT_EQ(box
.write(), "5");
120 box
.set(BOX_BOTTOM
, 7, true);
121 ASSERT_EQ(box
.write(), "7");
124 // vim: filetype=cpp:expandtab:shiftwidth=4:softtabstop=4:fileencoding=utf-8:textwidth=99 :