summaryrefslogtreecommitdiff
path: root/Build/source/texk/dvisvgm/dvisvgm-1.0.8/tests/LengthTest.cpp
blob: c7c38f755c4e7f1c77193df63ad04e7de539b13d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*************************************************************************
** LengthTest.cpp                                                       **
**                                                                      **
** This file is part of dvisvgm -- the DVI to SVG converter             **
** Copyright (C) 2005-2011 Martin Gieseking <martin.gieseking@uos.de>   **
**                                                                      **
** This program is free software; you can redistribute it and/or        **
** modify it under the terms of the GNU General Public License as       **
** published by the Free Software Foundation; either version 3 of       **
** the License, or (at your option) any later version.                  **
**                                                                      **
** This program is distributed in the hope that it will be useful, but  **
** WITHOUT ANY WARRANTY; without even the implied warranty of           **
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the         **
** GNU General Public License for more details.                         **
**                                                                      **
** You should have received a copy of the GNU General Public License    **
** along with this program; if not, see <http://www.gnu.org/licenses/>. **
*************************************************************************/

#include <gtest/gtest.h>
#include "Length.h"

TEST(LengthTest, set1) {
	Length len;
	len.set(1, Length::PT);
	EXPECT_EQ(len.pt(), 1);
	
	len.set(72, Length::BP);
	EXPECT_EQ(len.pt(), 72.27);
	EXPECT_EQ(len.bp(), 72);
	EXPECT_EQ(len.in(), 1);

	len.set(1, Length::IN);
	EXPECT_EQ(len.pt(), 72.27);

	len.set(12, Length::PC);
	EXPECT_EQ(len.pt(), 72.27);
	EXPECT_EQ(len.in(), 1);

	len.set(2.54, Length::CM);
	EXPECT_EQ(len.pt(), 72.27);
	EXPECT_EQ(len.cm(), 2.54);
	EXPECT_EQ(len.mm(), 25.4);

	len.set(25.4, Length::MM);
	EXPECT_EQ(len.pt(), 72.27);
	EXPECT_EQ(len.cm(), 2.54);
	EXPECT_EQ(len.mm(), 25.4);
}


TEST(LengthTest, set2) {
	Length len;
	len.set(1, "pt");
	EXPECT_EQ(len.pt(), 1);
	
	len.set(72, "bp");
	EXPECT_EQ(len.pt(), 72.27);
	EXPECT_EQ(len.bp(), 72);
	EXPECT_EQ(len.in(), 1);
	EXPECT_EQ(len.pc(), 12);

	len.set(1, "in");
	EXPECT_EQ(len.pt(), 72.27);

	len.set(12, "pc");
	EXPECT_EQ(len.pt(), 72.27);
	EXPECT_EQ(len.in(), 1);
	EXPECT_EQ(len.pc(), 12);

	len.set(2.54, "cm");
	EXPECT_EQ(len.pt(), 72.27);
	EXPECT_EQ(len.cm(), 2.54);
	EXPECT_EQ(len.mm(), 25.4);

	len.set(10, "mm");
	EXPECT_EQ(len.cm(), 1);
	EXPECT_EQ(len.mm(), 10);

	len.set(1, "");
	EXPECT_EQ(len.pt(), 1);

	ASSERT_THROW(len.set(1, "xy"), UnitException);
}

TEST(LengthTest, set3) {
	Length len;
	len.set("1pt");
	EXPECT_EQ(len.pt(), 1);
	
	len.set("72bp");
	EXPECT_EQ(len.pt(), 72.27);
	EXPECT_EQ(len.bp(), 72);
	EXPECT_EQ(len.in(), 1);
	EXPECT_EQ(len.pc(), 12);

	len.set("1in");
	EXPECT_EQ(len.pt(), 72.27);

	len.set("12pc");
	EXPECT_EQ(len.pt(), 72.27);
	EXPECT_EQ(len.in(), 1);
	EXPECT_EQ(len.pc(), 12);

	len.set("2.54cm");
	EXPECT_EQ(len.pt(), 72.27);
	EXPECT_EQ(len.cm(), 2.54);
	EXPECT_EQ(len.mm(), 25.4);

	len.set("10mm");
	EXPECT_EQ(len.cm(), 1);
	EXPECT_EQ(len.mm(), 10);

	len.set("1");
	EXPECT_EQ(len.pt(), 1);

	ASSERT_THROW(len.set("1xy"), UnitException);
	ASSERT_THROW(len.set("pt"), UnitException);
}