OLD | NEW |
1 // Copyright 2015 PDFium Authors. All rights reserved. | 1 // Copyright 2015 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 "../../public/fpdf_text.h" | 5 #include "../../public/fpdf_text.h" |
6 #include "../../public/fpdfview.h" | 6 #include "../../public/fpdfview.h" |
7 #include "../../testing/embedder_test.h" | 7 #include "../../testing/embedder_test.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 namespace { | 10 namespace { |
(...skipping 22 matching lines...) Expand all Loading... |
33 EXPECT_NE(nullptr, page); | 33 EXPECT_NE(nullptr, page); |
34 | 34 |
35 FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page); | 35 FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page); |
36 EXPECT_NE(nullptr, textpage); | 36 EXPECT_NE(nullptr, textpage); |
37 | 37 |
38 static const char expected[] = "Hello, world!\r\nGoodbye, world!"; | 38 static const char expected[] = "Hello, world!\r\nGoodbye, world!"; |
39 unsigned short fixed_buffer[128]; | 39 unsigned short fixed_buffer[128]; |
40 memset(fixed_buffer, 0xbd, sizeof(fixed_buffer)); | 40 memset(fixed_buffer, 0xbd, sizeof(fixed_buffer)); |
41 | 41 |
42 // Check includes the terminating NUL that is provided. | 42 // Check includes the terminating NUL that is provided. |
43 EXPECT_EQ(sizeof(expected), FPDFText_GetText(textpage, 0, 128, fixed_buffer)); | 43 int num_chars = FPDFText_GetText(textpage, 0, 128, fixed_buffer); |
| 44 ASSERT_GE(num_chars, 0); |
| 45 EXPECT_EQ(sizeof(expected), static_cast<size_t>(num_chars)); |
44 EXPECT_TRUE(check_unsigned_shorts(expected, fixed_buffer, sizeof(expected))); | 46 EXPECT_TRUE(check_unsigned_shorts(expected, fixed_buffer, sizeof(expected))); |
45 | 47 |
46 // Count does not include the terminating NUL in the string literal. | 48 // Count does not include the terminating NUL in the string literal. |
47 EXPECT_EQ(sizeof(expected) - 1, FPDFText_CountChars(textpage)); | 49 EXPECT_EQ(sizeof(expected) - 1, FPDFText_CountChars(textpage)); |
48 for (size_t i = 0; i < sizeof(expected) - 1; ++i) { | 50 for (size_t i = 0; i < sizeof(expected) - 1; ++i) { |
49 EXPECT_EQ(expected[i], FPDFText_GetUnicode(textpage, i)) << " at " << i; | 51 EXPECT_EQ(static_cast<unsigned int>(expected[i]), |
| 52 FPDFText_GetUnicode(textpage, i)) |
| 53 << " at " << i; |
50 } | 54 } |
51 | 55 |
52 EXPECT_EQ(12.0, FPDFText_GetFontSize(textpage, 0)); | 56 EXPECT_EQ(12.0, FPDFText_GetFontSize(textpage, 0)); |
53 EXPECT_EQ(16.0, FPDFText_GetFontSize(textpage, 15)); | 57 EXPECT_EQ(16.0, FPDFText_GetFontSize(textpage, 15)); |
54 | 58 |
55 double left = 0.0; | 59 double left = 0.0; |
56 double right = 0.0; | 60 double right = 0.0; |
57 double bottom = 0.0; | 61 double bottom = 0.0; |
58 double top = 0.0; | 62 double top = 0.0; |
59 FPDFText_GetCharBox(textpage, 4, &left, &right, &bottom, &top); | 63 FPDFText_GetCharBox(textpage, 4, &left, &right, &bottom, &top); |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 FPDFLink_GetRect(pagelink, -1, 0, &left, &top, &right, &bottom); | 355 FPDFLink_GetRect(pagelink, -1, 0, &left, &top, &right, &bottom); |
352 EXPECT_EQ(-2.0, left); | 356 EXPECT_EQ(-2.0, left); |
353 EXPECT_EQ(-2.0, right); | 357 EXPECT_EQ(-2.0, right); |
354 EXPECT_EQ(-2.0, bottom); | 358 EXPECT_EQ(-2.0, bottom); |
355 EXPECT_EQ(-2.0, top); | 359 EXPECT_EQ(-2.0, top); |
356 | 360 |
357 FPDFLink_CloseWebLinks(pagelink); | 361 FPDFLink_CloseWebLinks(pagelink); |
358 FPDFText_ClosePage(textpage); | 362 FPDFText_ClosePage(textpage); |
359 UnloadPage(page); | 363 UnloadPage(page); |
360 } | 364 } |
OLD | NEW |