1 // Copyright 2016 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 <limits> 6 7 #include "core/fxcrt/fx_string.h" 8 #include "testing/gtest/include/gtest/gtest.h" 9 10 TEST(fxstring, FX_atonum) { 11 int i; 12 EXPECT_TRUE(FX_atonum("10", &i)); 13 EXPECT_EQ(10, i); 14 15 EXPECT_TRUE(FX_atonum("-10", &i)); 16 EXPECT_EQ(-10, i); 17 18 EXPECT_TRUE(FX_atonum("+10", &i)); 19 EXPECT_EQ(10, i); 20 21 EXPECT_TRUE(FX_atonum("-2147483648", &i)); 22 EXPECT_EQ(std::numeric_limits<int>::min(), i); 23 24 EXPECT_TRUE(FX_atonum("2147483647", &i)); 25 EXPECT_EQ(2147483647, i); 26 27 // Value overflows. 28 EXPECT_TRUE(FX_atonum("-2147483649", &i)); 29 EXPECT_EQ(0, i); 30 31 // Value overflows. 32 EXPECT_TRUE(FX_atonum("+2147483648", &i)); 33 EXPECT_EQ(0, i); 34 35 // Value overflows. 36 EXPECT_TRUE(FX_atonum("4223423494965252", &i)); 37 EXPECT_EQ(0, i); 38 39 // No explicit sign will allow the number to go negative. This is for things 40 // like the encryption Permissions flag (Table 3.20 PDF 1.7 spec) 41 EXPECT_TRUE(FX_atonum("4294965252", &i)); 42 EXPECT_EQ(-2044, i); 43 44 EXPECT_TRUE(FX_atonum("-4294965252", &i)); 45 EXPECT_EQ(0, i); 46 47 EXPECT_TRUE(FX_atonum("+4294965252", &i)); 48 EXPECT_EQ(0, i); 49 50 float f; 51 EXPECT_FALSE(FX_atonum("3.24", &f)); 52 EXPECT_FLOAT_EQ(3.24f, f); 53 } 54