From 65f3162c91607071322967ea064a4a11e3904722 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Tue, 24 Oct 2017 08:36:44 -0700 Subject: Add more tests for FPDFText methods. BUG=pdfium:921 Change-Id: I6973359e6ac112c56843f66eb0b70462f42f9cae Reviewed-on: https://pdfium-review.googlesource.com/16630 Reviewed-by: Ryan Harrison Commit-Queue: Lei Zhang --- fpdfsdk/fpdftext_embeddertest.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'fpdfsdk') diff --git a/fpdfsdk/fpdftext_embeddertest.cpp b/fpdfsdk/fpdftext_embeddertest.cpp index 7e8e033ae0..1536c8679b 100644 --- a/fpdfsdk/fpdftext_embeddertest.cpp +++ b/fpdfsdk/fpdftext_embeddertest.cpp @@ -494,3 +494,34 @@ TEST_F(FPDFTextEmbeddertest, ToUnicode) { FPDFText_ClosePage(textpage); UnloadPage(page); } + +TEST_F(FPDFTextEmbeddertest, Bug_921) { + EXPECT_TRUE(OpenDocument("bug_921.pdf")); + FPDF_PAGE page = LoadPage(0); + EXPECT_TRUE(page); + + FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page); + EXPECT_TRUE(textpage); + + static constexpr unsigned int kData[] = { + 1095, 1077, 1083, 1086, 1074, 1077, 1095, 1077, 1089, 1082, 1086, 1077, + 32, 1089, 1090, 1088, 1072, 1076, 1072, 1085, 1080, 1077, 46, 32}; + static constexpr int kStartIndex = 238; + + ASSERT_EQ(268, FPDFText_CountChars(textpage)); + for (size_t i = 0; i < FX_ArraySize(kData); ++i) + EXPECT_EQ(kData[i], FPDFText_GetUnicode(textpage, kStartIndex + i)); + + unsigned short buffer[FX_ArraySize(kData) + 1]; + memset(buffer, 0xbd, sizeof(buffer)); + int count = + FPDFText_GetText(textpage, kStartIndex, FX_ArraySize(buffer), buffer); + ASSERT_GT(count, 0); + ASSERT_EQ(FX_ArraySize(kData) + 1, static_cast(count)); + for (size_t i = 0; i < FX_ArraySize(kData); ++i) + EXPECT_EQ(kData[i], buffer[i]); + EXPECT_EQ(0, buffer[FX_ArraySize(kData)]); + + FPDFText_ClosePage(textpage); + UnloadPage(page); +} -- cgit v1.2.3