OLD | NEW |
1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/fxcrt/include/fx_basic.h" | 5 #include "core/fxcrt/include/fx_basic.h" |
6 #include "testing/fx_string_testhelpers.h" | 6 #include "testing/fx_string_testhelpers.h" |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 | 8 |
9 namespace { | 9 namespace { |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... |
21 | 21 |
22 TEST(fxge, GetBits32) { | 22 TEST(fxge, GetBits32) { |
23 unsigned char data[] = {0xDE, 0x3F, 0xB1, 0x7C, 0x12, 0x9A, 0x04, 0x56}; | 23 unsigned char data[] = {0xDE, 0x3F, 0xB1, 0x7C, 0x12, 0x9A, 0x04, 0x56}; |
24 for (int nbits = 1; nbits <= 32; ++nbits) { | 24 for (int nbits = 1; nbits <= 32; ++nbits) { |
25 for (int bitpos = 0; bitpos < (int)sizeof(data) * 8 - nbits; ++bitpos) { | 25 for (int bitpos = 0; bitpos < (int)sizeof(data) * 8 - nbits; ++bitpos) { |
26 EXPECT_EQ(ReferenceGetBits32(data, bitpos, nbits), | 26 EXPECT_EQ(ReferenceGetBits32(data, bitpos, nbits), |
27 GetBits32(data, bitpos, nbits)); | 27 GetBits32(data, bitpos, nbits)); |
28 } | 28 } |
29 } | 29 } |
30 } | 30 } |
| 31 |
| 32 TEST(fxcrt, FX_atonum) { |
| 33 int i; |
| 34 EXPECT_TRUE(FX_atonum("10", &i)); |
| 35 EXPECT_EQ(10, i); |
| 36 |
| 37 EXPECT_TRUE(FX_atonum("-10", &i)); |
| 38 EXPECT_EQ(-10, i); |
| 39 |
| 40 EXPECT_TRUE(FX_atonum("+10", &i)); |
| 41 EXPECT_EQ(10, i); |
| 42 |
| 43 // Value overflows. |
| 44 EXPECT_TRUE(FX_atonum("4223423494965252", &i)); |
| 45 EXPECT_EQ(0, i); |
| 46 |
| 47 // No explicit sign will allow the number to go negative. This is for things |
| 48 // like the encryption Permissions flag (Table 3.20 PDF 1.7 spec) |
| 49 EXPECT_TRUE(FX_atonum("4294965252", &i)); |
| 50 EXPECT_EQ(-2044, i); |
| 51 |
| 52 EXPECT_TRUE(FX_atonum("-4294965252", &i)); |
| 53 EXPECT_EQ(0, i); |
| 54 |
| 55 EXPECT_TRUE(FX_atonum("+4294965252", &i)); |
| 56 EXPECT_EQ(0, i); |
| 57 |
| 58 float f; |
| 59 EXPECT_FALSE(FX_atonum("3.24", &f)); |
| 60 EXPECT_FLOAT_EQ(3.24f, f); |
| 61 } |
OLD | NEW |