1 // Copyright 2019 PDFium Authors. All rights reserved.
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 
TEST(CXFAMeasurementTest,ToString)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 
TEST(CXFAMeasurementTest,GetUnitFromString)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