Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cxfa_measurement_unittest.cpp
Go to the documentation of this file.
1
// Copyright 2019 The PDFium Authors
2
// Use of this source code is governed by a BSD-style license that can be
3
// found in the LICENSE file.
4
5
#
include
"xfa/fxfa/parser/cxfa_measurement.h"
6
7
#
include
"testing/gtest/include/gtest/gtest.h"
8
9
TEST
(
CXFAMeasurementTest
,
ToString
) {
10
CXFA_Measurement
measurement;
11
12
measurement
.
Set
(
0.1f
,
XFA_Unit
::
Percent
)
;
13
EXPECT_STREQ(L"0.1%", measurement
.
ToString
(
)
.
c_str
(
)
);
14
measurement
.
Set
(
1.0f
,
XFA_Unit
::
Em
)
;
15
EXPECT_STREQ(L"1em", measurement
.
ToString
(
)
.
c_str
(
)
);
16
measurement
.
Set
(
1.1f
,
XFA_Unit
::
Pt
)
;
17
EXPECT_STREQ(L"1.1pt", measurement
.
ToString
(
)
.
c_str
(
)
);
18
measurement
.
Set
(
1.0000001f
,
XFA_Unit
::
In
)
;
19
EXPECT_STREQ(L"1.0000001in", measurement
.
ToString
(
)
.
c_str
(
)
);
20
measurement
.
Set
(
1234.0f
,
XFA_Unit
::
Pc
)
;
21
EXPECT_STREQ(L"1234pc", measurement
.
ToString
(
)
.
c_str
(
)
);
22
measurement
.
Set
(
987654321.0123456789f
,
XFA_Unit
::
Cm
)
;
23
EXPECT_STREQ(L"9.8765434e+08cm", measurement
.
ToString
(
)
.
c_str
(
)
);
24
measurement
.
Set
(
0.0f
,
XFA_Unit
::
Mm
)
;
25
EXPECT_STREQ(L"0mm", measurement
.
ToString
(
)
.
c_str
(
)
);
26
measurement
.
Set
(
-2.0f
,
XFA_Unit
::
Mp
)
;
27
EXPECT_STREQ(L"-2mp", measurement
.
ToString
(
)
.
c_str
(
)
);
28
}
29
30
TEST
(
CXFAMeasurementTest
,
GetUnitFromString
) {
31
EXPECT_EQ(
XFA_Unit
::
Percent
,
CXFA_Measurement
::
GetUnitFromString
(L"%"));
32
EXPECT_EQ(
XFA_Unit
::
Em
,
CXFA_Measurement
::
GetUnitFromString
(L"em"));
33
EXPECT_EQ(
XFA_Unit
::
Pt
,
CXFA_Measurement
::
GetUnitFromString
(L"pt"));
34
EXPECT_EQ(
XFA_Unit
::
In
,
CXFA_Measurement
::
GetUnitFromString
(L"in"));
35
EXPECT_EQ(
XFA_Unit
::
Pc
,
CXFA_Measurement
::
GetUnitFromString
(L"pc"));
36
EXPECT_EQ(
XFA_Unit
::
Cm
,
CXFA_Measurement
::
GetUnitFromString
(L"cm"));
37
EXPECT_EQ(
XFA_Unit
::
Mm
,
CXFA_Measurement
::
GetUnitFromString
(L"mm"));
38
EXPECT_EQ(
XFA_Unit
::
Mp
,
CXFA_Measurement
::
GetUnitFromString
(L"mp"));
39
40
EXPECT_EQ(
XFA_Unit
::
Unknown
,
CXFA_Measurement
::
GetUnitFromString
(L""));
41
EXPECT_EQ(
XFA_Unit
::
Unknown
,
CXFA_Measurement
::
GetUnitFromString
(L"foo"));
42
EXPECT_EQ(
XFA_Unit
::
Unknown
,
CXFA_Measurement
::
GetUnitFromString
(L"!"));
43
EXPECT_EQ(
XFA_Unit
::
Unknown
,
CXFA_Measurement
::
GetUnitFromString
(L"CM"));
44
EXPECT_EQ(
XFA_Unit
::
Unknown
,
CXFA_Measurement
::
GetUnitFromString
(L"Cm"));
45
EXPECT_EQ(
XFA_Unit
::
Unknown
,
CXFA_Measurement
::
GetUnitFromString
(L"cM"));
46
}
47
48
TEST
(
CXFAMeasurementTest
,
EqualsPrefix
) {
49
CXFA_Measurement
no_unit(L"=5");
50
EXPECT_EQ(
XFA_Unit
::
Unknown
, no_unit
.
GetUnit
(
)
);
51
EXPECT_FLOAT_EQ(5.0f, no_unit
.
GetValue
(
)
);
52
53
CXFA_Measurement
mm_unit(L"=5mm");
54
EXPECT_EQ(
XFA_Unit
::
Mm
, mm_unit
.
GetUnit
(
)
);
55
EXPECT_FLOAT_EQ(5.0f, mm_unit
.
GetValue
(
)
);
56
}
57
58
TEST
(
CXFAMeasurementTest
,
NoPrefix
) {
59
CXFA_Measurement
no_unit(L"5");
60
EXPECT_EQ(
XFA_Unit
::
Unknown
, no_unit
.
GetUnit
(
)
);
61
EXPECT_FLOAT_EQ(5.0f, no_unit
.
GetValue
(
)
);
62
63
CXFA_Measurement
mm_unit(L"5mm");
64
EXPECT_EQ(
XFA_Unit
::
Mm
, mm_unit
.
GetUnit
(
)
);
65
EXPECT_FLOAT_EQ(5.0f, mm_unit
.
GetValue
(
)
);
66
}
67
68
TEST
(
CXFAMeasurementTest
,
InvalidValues
) {
69
CXFA_Measurement
empty(L"");
70
EXPECT_EQ(
XFA_Unit
::
Unknown
, empty
.
GetUnit
(
)
);
71
EXPECT_FLOAT_EQ(0.0f, empty
.
GetValue
(
)
);
72
73
CXFA_Measurement
equals(L"=");
74
EXPECT_EQ(
XFA_Unit
::
Unknown
, equals
.
GetUnit
(
)
);
75
EXPECT_FLOAT_EQ(0.0f, equals
.
GetValue
(
)
);
76
}
CXFA_Measurement
Definition
cxfa_measurement.h:13
CXFA_Measurement::Set
void Set(float fValue, XFA_Unit eUnit)
Definition
cxfa_measurement.h:21
CXFA_Measurement::GetValue
float GetValue() const
Definition
cxfa_measurement.h:27
CXFA_Measurement::GetUnitFromString
static XFA_Unit GetUnitFromString(WideStringView wsUnit)
Definition
cxfa_measurement.cpp:135
CXFA_Measurement::ToString
WideString ToString() const
Definition
cxfa_measurement.cpp:54
CXFA_Measurement::GetUnit
XFA_Unit GetUnit() const
Definition
cxfa_measurement.h:26
fxcrt::WideString::c_str
const wchar_t * c_str() const
Definition
widestring.h:81
TEST
TEST(FXCRYPT, MD5GenerateEmtpyData)
Definition
fx_crypt_unittest.cpp:45
XFA_Unit
XFA_Unit
Definition
fxfa_basic.h:91
XFA_Unit::Mm
@ Mm
XFA_Unit::Cm
@ Cm
XFA_Unit::Em
@ Em
XFA_Unit::Unknown
@ Unknown
XFA_Unit::Pt
@ Pt
XFA_Unit::Percent
@ Percent
XFA_Unit::Pc
@ Pc
XFA_Unit::Mp
@ Mp
XFA_Unit::In
@ In
qtwebengine
src
3rdparty
chromium
third_party
pdfium
xfa
fxfa
parser
cxfa_measurement_unittest.cpp
Generated on Sat Sep 21 2024 01:03:38 for Qt by
1.12.0