summaryrefslogtreecommitdiff
path: root/xfa/fxfa/parser/cxfa_localevalue_unittest.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-04-17 17:59:58 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-04-17 17:59:58 +0000
commit8b4a3c7ef32b2ffb4874e4cc65b38ee555d8806e (patch)
tree241abd93b51b9c0d0f0a05c20092a3a1749af8a4 /xfa/fxfa/parser/cxfa_localevalue_unittest.cpp
parent1dbfe996b946f0d2a1afc52669ff5fca22a85070 (diff)
downloadpdfium-chromium/3399.tar.xz
Use span in CXFA_LocaleValue::GetDoubleNum()chromium/3399
Get runtime checks instead of just asserts. Use early return while at it to save some indentation. Fix one out-of-bounds case noted by inspection. Add tests, and fix bugs that gave the wrong answers. This should be removed at our earliest convenience. Its likely to still be wrong. Change-Id: I2a68edc854c8b28c434fe28397b7834e5c9c3670 Reviewed-on: https://pdfium-review.googlesource.com/30530 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fxfa/parser/cxfa_localevalue_unittest.cpp')
-rw-r--r--xfa/fxfa/parser/cxfa_localevalue_unittest.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/xfa/fxfa/parser/cxfa_localevalue_unittest.cpp b/xfa/fxfa/parser/cxfa_localevalue_unittest.cpp
new file mode 100644
index 0000000000..5b97eb3785
--- /dev/null
+++ b/xfa/fxfa/parser/cxfa_localevalue_unittest.cpp
@@ -0,0 +1,37 @@
+// Copyright 2018 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "xfa/fxfa/parser/cxfa_localevalue.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+#include "testing/test_support.h"
+
+namespace {
+
+// We don't expect more precision than a float's worth from this code.
+float MakeDoubleNumAsFloat(const wchar_t* str) {
+ return static_cast<float>(
+ CXFA_LocaleValue(XFA_VT_FLOAT, str, nullptr).GetDoubleNum());
+}
+
+} // namespace
+
+TEST(CXFALocaleValueTest, GetDoubleNum) {
+ EXPECT_EQ(0.0, MakeDoubleNumAsFloat(L""));
+ EXPECT_EQ(0.0, MakeDoubleNumAsFloat(L"0"));
+ EXPECT_EQ(0.0, MakeDoubleNumAsFloat(L"0."));
+ EXPECT_EQ(0.0, MakeDoubleNumAsFloat(L"0.0"));
+ EXPECT_EQ(0.0, MakeDoubleNumAsFloat(L"0.x"));
+ EXPECT_EQ(7.0, MakeDoubleNumAsFloat(L"7.x"));
+ EXPECT_FLOAT_EQ(0.54321f, MakeDoubleNumAsFloat(L".54321"));
+ EXPECT_FLOAT_EQ(0.54321f, MakeDoubleNumAsFloat(L"0.54321"));
+ EXPECT_FLOAT_EQ(0.54321f, MakeDoubleNumAsFloat(L"+0.54321"));
+ EXPECT_FLOAT_EQ(0.54321f, MakeDoubleNumAsFloat(L" +0.54321"));
+ EXPECT_FLOAT_EQ(-0.54321f, MakeDoubleNumAsFloat(L"-.54321"));
+ EXPECT_FLOAT_EQ(-0.54321f, MakeDoubleNumAsFloat(L"-0.54321"));
+ EXPECT_FLOAT_EQ(-0.54321f, MakeDoubleNumAsFloat(L" -0.54321"));
+ EXPECT_FLOAT_EQ(-0.054321f, MakeDoubleNumAsFloat(L"-0.54321e-1"));
+ EXPECT_FLOAT_EQ(-0.54321f, MakeDoubleNumAsFloat(L"-0.54321e0"));
+ EXPECT_FLOAT_EQ(-5.4321f, MakeDoubleNumAsFloat(L"-0.54321e1"));
+}