1 // Copyright 2018 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_localevalue.h"
6
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 namespace {
10
11 // We don't expect more precision than a float's worth from this code.
MakeDoubleNumAsFloat(const wchar_t * str)12 float MakeDoubleNumAsFloat(const wchar_t* str) {
13 return static_cast<float>(
14 CXFA_LocaleValue(XFA_VT_FLOAT, str, nullptr).GetDoubleNum());
15 }
16
17 } // namespace
18
TEST(CXFALocaleValueTest,GetDoubleNum)19 TEST(CXFALocaleValueTest, GetDoubleNum) {
20 EXPECT_EQ(0.0, MakeDoubleNumAsFloat(L""));
21 EXPECT_EQ(0.0, MakeDoubleNumAsFloat(L"0"));
22 EXPECT_EQ(0.0, MakeDoubleNumAsFloat(L"0."));
23 EXPECT_EQ(0.0, MakeDoubleNumAsFloat(L"0.0"));
24 EXPECT_EQ(0.0, MakeDoubleNumAsFloat(L"0.x"));
25 EXPECT_EQ(7.0, MakeDoubleNumAsFloat(L"7.x"));
26 EXPECT_FLOAT_EQ(0.54321f, MakeDoubleNumAsFloat(L".54321"));
27 EXPECT_FLOAT_EQ(0.54321f, MakeDoubleNumAsFloat(L"0.54321"));
28 EXPECT_FLOAT_EQ(0.54321f, MakeDoubleNumAsFloat(L"+0.54321"));
29 EXPECT_FLOAT_EQ(0.54321f, MakeDoubleNumAsFloat(L" +0.54321"));
30 EXPECT_FLOAT_EQ(-0.54321f, MakeDoubleNumAsFloat(L"-.54321"));
31 EXPECT_FLOAT_EQ(-0.54321f, MakeDoubleNumAsFloat(L"-0.54321"));
32 EXPECT_FLOAT_EQ(-0.54321f, MakeDoubleNumAsFloat(L" -0.54321"));
33 EXPECT_FLOAT_EQ(-0.054321f, MakeDoubleNumAsFloat(L"-0.54321e-1"));
34 EXPECT_FLOAT_EQ(-0.54321f, MakeDoubleNumAsFloat(L"-0.54321e0"));
35 EXPECT_FLOAT_EQ(-5.4321f, MakeDoubleNumAsFloat(L"-0.54321e1"));
36 }
37