summaryrefslogtreecommitdiff
path: root/core/fxcrt/fx_string_unittest.cpp
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-08-31 16:03:17 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-08-31 20:21:44 +0000
commit2a1c8ac53f249bfe2789ea95170f11d308992449 (patch)
treebe3fae81a04ac8fdfc851bf2f9f25cf60967835d /core/fxcrt/fx_string_unittest.cpp
parent203188ac4275f83cf984b8a807b07b74ab139236 (diff)
downloadpdfium-2a1c8ac53f249bfe2789ea95170f11d308992449.tar.xz
Move fx_extension implementation to cpp file
This CL moves the GetBits32 implemenation into fx_extension.cpp. It also moves some of the fx_basic unittests to the correct unittest files. Change-Id: I2cf8657c228375508db0f02baa628d62a3b2ab25 Reviewed-on: https://pdfium-review.googlesource.com/12673 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core/fxcrt/fx_string_unittest.cpp')
-rw-r--r--core/fxcrt/fx_string_unittest.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/core/fxcrt/fx_string_unittest.cpp b/core/fxcrt/fx_string_unittest.cpp
new file mode 100644
index 0000000000..b311165638
--- /dev/null
+++ b/core/fxcrt/fx_string_unittest.cpp
@@ -0,0 +1,53 @@
+// Copyright 2016 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 <limits>
+
+#include "core/fxcrt/fx_string.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+TEST(fxstring, FX_atonum) {
+ int i;
+ EXPECT_TRUE(FX_atonum("10", &i));
+ EXPECT_EQ(10, i);
+
+ EXPECT_TRUE(FX_atonum("-10", &i));
+ EXPECT_EQ(-10, i);
+
+ EXPECT_TRUE(FX_atonum("+10", &i));
+ EXPECT_EQ(10, i);
+
+ EXPECT_TRUE(FX_atonum("-2147483648", &i));
+ EXPECT_EQ(std::numeric_limits<int>::min(), i);
+
+ EXPECT_TRUE(FX_atonum("2147483647", &i));
+ EXPECT_EQ(2147483647, i);
+
+ // Value overflows.
+ EXPECT_TRUE(FX_atonum("-2147483649", &i));
+ EXPECT_EQ(0, i);
+
+ // Value overflows.
+ EXPECT_TRUE(FX_atonum("+2147483648", &i));
+ EXPECT_EQ(0, i);
+
+ // Value overflows.
+ EXPECT_TRUE(FX_atonum("4223423494965252", &i));
+ EXPECT_EQ(0, i);
+
+ // No explicit sign will allow the number to go negative. This is for things
+ // like the encryption Permissions flag (Table 3.20 PDF 1.7 spec)
+ EXPECT_TRUE(FX_atonum("4294965252", &i));
+ EXPECT_EQ(-2044, i);
+
+ EXPECT_TRUE(FX_atonum("-4294965252", &i));
+ EXPECT_EQ(0, i);
+
+ EXPECT_TRUE(FX_atonum("+4294965252", &i));
+ EXPECT_EQ(0, i);
+
+ float f;
+ EXPECT_FALSE(FX_atonum("3.24", &f));
+ EXPECT_FLOAT_EQ(3.24f, f);
+}