diff options
Diffstat (limited to 'fpdfsdk')
-rw-r--r-- | fpdfsdk/fpdf_text_embeddertest.cpp | 46 |
1 files changed, 22 insertions, 24 deletions
diff --git a/fpdfsdk/fpdf_text_embeddertest.cpp b/fpdfsdk/fpdf_text_embeddertest.cpp index a808ffd710..c7ad8250df 100644 --- a/fpdfsdk/fpdf_text_embeddertest.cpp +++ b/fpdfsdk/fpdf_text_embeddertest.cpp @@ -13,6 +13,9 @@ namespace { +constexpr char kHelloGoodbyeText[] = "Hello, world!\r\nGoodbye, world!"; +constexpr int kHelloGoodbyeTextSize = FX_ArraySize(kHelloGoodbyeText); + bool check_unsigned_shorts(const char* expected, const unsigned short* actual, size_t length) { @@ -38,7 +41,6 @@ TEST_F(FPDFTextEmbeddertest, Text) { FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page); ASSERT_TRUE(textpage); - static const char kExpected[] = "Hello, world!\r\nGoodbye, world!"; unsigned short buffer[128]; memset(buffer, 0xbd, sizeof(buffer)); @@ -52,20 +54,19 @@ TEST_F(FPDFTextEmbeddertest, Text) { // Keep going and check the next case. memset(buffer, 0xbd, sizeof(buffer)); EXPECT_EQ(2, FPDFText_GetText(textpage, 0, 1, buffer)); - EXPECT_EQ(kExpected[0], buffer[0]); + EXPECT_EQ(kHelloGoodbyeText[0], buffer[0]); EXPECT_EQ(0, buffer[1]); // Check includes the terminating NUL that is provided. int num_chars = FPDFText_GetText(textpage, 0, 128, buffer); - ASSERT_GE(num_chars, 0); - EXPECT_EQ(sizeof(kExpected), static_cast<size_t>(num_chars)); - EXPECT_TRUE(check_unsigned_shorts(kExpected, buffer, sizeof(kExpected))); + ASSERT_EQ(kHelloGoodbyeTextSize, num_chars); + EXPECT_TRUE( + check_unsigned_shorts(kHelloGoodbyeText, buffer, kHelloGoodbyeTextSize)); // Count does not include the terminating NUL in the string literal. - EXPECT_EQ(sizeof(kExpected) - 1, - static_cast<size_t>(FPDFText_CountChars(textpage))); - for (size_t i = 0; i < sizeof(kExpected) - 1; ++i) { - EXPECT_EQ(static_cast<unsigned int>(kExpected[i]), + EXPECT_EQ(kHelloGoodbyeTextSize - 1, FPDFText_CountChars(textpage)); + for (size_t i = 0; i < kHelloGoodbyeTextSize - 1; ++i) { + EXPECT_EQ(static_cast<unsigned int>(kHelloGoodbyeText[i]), FPDFText_GetUnicode(textpage, i)) << " at " << i; } @@ -125,7 +126,7 @@ TEST_F(FPDFTextEmbeddertest, Text) { EXPECT_EQ(-1, FPDFText_GetCharIndexAtPos(textpage, -1.0, 50.0, 1.0, 1.0)); // Count does not include the terminating NUL in the string literal. - EXPECT_EQ(2, FPDFText_CountRects(textpage, 0, sizeof(kExpected) - 1)); + EXPECT_EQ(2, FPDFText_CountRects(textpage, 0, kHelloGoodbyeTextSize - 1)); left = 0.0; right = 0.0; @@ -164,19 +165,19 @@ TEST_F(FPDFTextEmbeddertest, Text) { memset(buffer, 0xbd, sizeof(buffer)); EXPECT_EQ( 1, FPDFText_GetBoundedText(textpage, 41.0, 56.0, 82.0, 48.0, buffer, 1)); - EXPECT_TRUE(check_unsigned_shorts(kExpected + 4, buffer, 1)); + EXPECT_TRUE(check_unsigned_shorts(kHelloGoodbyeText + 4, buffer, 1)); EXPECT_EQ(0xbdbd, buffer[1]); memset(buffer, 0xbd, sizeof(buffer)); EXPECT_EQ( 9, FPDFText_GetBoundedText(textpage, 41.0, 56.0, 82.0, 48.0, buffer, 9)); - EXPECT_TRUE(check_unsigned_shorts(kExpected + 4, buffer, 9)); + EXPECT_TRUE(check_unsigned_shorts(kHelloGoodbyeText + 4, buffer, 9)); EXPECT_EQ(0xbdbd, buffer[9]); memset(buffer, 0xbd, sizeof(buffer)); EXPECT_EQ(10, FPDFText_GetBoundedText(textpage, 41.0, 56.0, 82.0, 48.0, buffer, 128)); - EXPECT_TRUE(check_unsigned_shorts(kExpected + 4, buffer, 9)); + EXPECT_TRUE(check_unsigned_shorts(kHelloGoodbyeText + 4, buffer, 9)); EXPECT_EQ(0u, buffer[9]); EXPECT_EQ(0xbdbd, buffer[10]); @@ -509,7 +510,7 @@ TEST_F(FPDFTextEmbeddertest, ToUnicode) { ASSERT_TRUE(textpage); ASSERT_EQ(1, FPDFText_CountChars(textpage)); - EXPECT_EQ(static_cast<unsigned int>(0), FPDFText_GetUnicode(textpage, 0)); + EXPECT_EQ(0U, FPDFText_GetUnicode(textpage, 0)); FPDFText_ClosePage(textpage); UnloadPage(page); @@ -613,14 +614,12 @@ TEST_F(FPDFTextEmbeddertest, ControlCharacters) { ASSERT_TRUE(textpage); // Should not include the control characters in the output - static const char expected[] = "Hello, world!\r\nGoodbye, world!"; unsigned short buffer[128]; memset(buffer, 0xbd, sizeof(buffer)); int num_chars = FPDFText_GetText(textpage, 0, 128, buffer); - - ASSERT_GE(num_chars, 0); - EXPECT_EQ(sizeof(expected), static_cast<size_t>(num_chars)); - EXPECT_TRUE(check_unsigned_shorts(expected, buffer, sizeof(expected))); + ASSERT_EQ(kHelloGoodbyeTextSize, num_chars); + EXPECT_TRUE( + check_unsigned_shorts(kHelloGoodbyeText, buffer, kHelloGoodbyeTextSize)); // Attempting to get a chunk of text after the control characters static const char expected_substring[] = "Goodbye, world!"; @@ -691,13 +690,12 @@ TEST_F(FPDFTextEmbeddertest, CountRects) { // Sanity check hello_world.pdf. // |num_chars| check includes the terminating NUL that is provided. - static const char kExpected[] = "Hello, world!\r\nGoodbye, world!"; { unsigned short buffer[128]; int num_chars = FPDFText_GetText(textpage, 0, 128, buffer); - ASSERT_GE(num_chars, 0); - EXPECT_EQ(sizeof(kExpected), static_cast<size_t>(num_chars)); - EXPECT_TRUE(check_unsigned_shorts(kExpected, buffer, sizeof(kExpected))); + ASSERT_EQ(kHelloGoodbyeTextSize, num_chars); + EXPECT_TRUE(check_unsigned_shorts(kHelloGoodbyeText, buffer, + kHelloGoodbyeTextSize)); } // Now test FPDFText_CountRects(). @@ -732,7 +730,7 @@ TEST_F(FPDFTextEmbeddertest, CountRects) { } // Now test larger start values. - const int kExpectedLength = strlen(kExpected); + const int kExpectedLength = strlen(kHelloGoodbyeText); for (int start = kGoodbyeWorldStart + 1; start < kExpectedLength; ++start) { EXPECT_EQ(1, FPDFText_CountRects(textpage, start, -1)); EXPECT_EQ(0, FPDFText_CountRects(textpage, start, 0)); |