diff options
Diffstat (limited to 'fpdfsdk')
-rw-r--r-- | fpdfsdk/src/fpdfdoc_embeddertest.cpp | 23 | ||||
-rw-r--r-- | fpdfsdk/src/fpdftext_embeddertest.cpp | 16 |
2 files changed, 27 insertions, 12 deletions
diff --git a/fpdfsdk/src/fpdfdoc_embeddertest.cpp b/fpdfsdk/src/fpdfdoc_embeddertest.cpp index 38a366268c..260f25f309 100644 --- a/fpdfsdk/src/fpdfdoc_embeddertest.cpp +++ b/fpdfsdk/src/fpdfdoc_embeddertest.cpp @@ -7,6 +7,7 @@ #include "public/fpdfview.h" #include "testing/embedder_test.h" #include "testing/fx_string_testhelpers.h" +#include "testing/test_support.h" #include "testing/gtest/include/gtest/gtest.h" class FPDFDocEmbeddertest : public EmbedderTest {}; @@ -101,20 +102,28 @@ TEST_F(FPDFDocEmbeddertest, Bookmarks) { } TEST_F(FPDFDocEmbeddertest, FindBookmarks) { - // Open a file with two bookmarks, and extract the first. + // Open a file with two bookmarks. EXPECT_TRUE(OpenDocument("bookmarks.pdf")); - unsigned short buf[128]; - FPDF_BOOKMARK child = FPDFBookmark_GetFirstChild(document(), nullptr); + // Find the first one, based on its known title. + FPDF_WIDESTRING title = GetFPDFWideString(L"A Good Beginning"); + FPDF_BOOKMARK child = FPDFBookmark_Find(document(), title); EXPECT_NE(nullptr, child); + + // Check that the string matches. + unsigned short buf[128]; EXPECT_EQ(34, FPDFBookmark_GetTitle(child, buf, sizeof(buf))); EXPECT_EQ(CFX_WideString(L"A Good Beginning"), CFX_WideString::FromUTF16LE(buf, 16)); - // Find the same one again using the title. - EXPECT_EQ(child, FPDFBookmark_Find(document(), buf)); + // Check that it is them same as the one returned by GetFirstChild. + EXPECT_EQ(child, FPDFBookmark_GetFirstChild(document(), nullptr)); // Try to find one using a non-existent title. - buf[0] = 'X'; - EXPECT_EQ(nullptr, FPDFBookmark_Find(document(), buf)); + FPDF_WIDESTRING bad_title = GetFPDFWideString(L"A BAD Beginning"); + EXPECT_EQ(nullptr, FPDFBookmark_Find(document(), bad_title)); + + // Alas, the typedef includes the "const". + free(const_cast<unsigned short*>(title)); + free(const_cast<unsigned short*>(bad_title)); } diff --git a/fpdfsdk/src/fpdftext_embeddertest.cpp b/fpdfsdk/src/fpdftext_embeddertest.cpp index 6c1ae4ceb8..3772686c88 100644 --- a/fpdfsdk/src/fpdftext_embeddertest.cpp +++ b/fpdfsdk/src/fpdftext_embeddertest.cpp @@ -5,6 +5,7 @@ #include "public/fpdf_text.h" #include "public/fpdfview.h" #include "testing/embedder_test.h" +#include "testing/test_support.h" #include "testing/gtest/include/gtest/gtest.h" namespace { @@ -143,11 +144,10 @@ TEST_F(FPDFTextEmbeddertest, TextSearch) { FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page); EXPECT_NE(nullptr, textpage); - // Avoid issues with system wchar_t width vs. FPDF_WideString. - const unsigned short nope[] = {'n', 'o', 'p', 'e', '\0'}; - const unsigned short world[] = {'w', 'o', 'r', 'l', 'd', '\0'}; - const unsigned short world_caps[] = {'W', 'O', 'R', 'L', 'D', '\0'}; - const unsigned short world_substr[] = {'o', 'r', 'l', 'd', '\0'}; + FPDF_WIDESTRING nope = GetFPDFWideString(L"nope"); + FPDF_WIDESTRING world = GetFPDFWideString(L"world"); + FPDF_WIDESTRING world_caps = GetFPDFWideString(L"WORLD"); + FPDF_WIDESTRING world_substr = GetFPDFWideString(L"orld"); // No occurences of "nope" in test page. FPDF_SCHHANDLE search = FPDFText_FindStart(textpage, nope, 0, 0); @@ -239,6 +239,12 @@ TEST_F(FPDFTextEmbeddertest, TextSearch) { FPDFText_ClosePage(textpage); UnloadPage(page); + + // Alas, the typedef includes the "const". + free(const_cast<unsigned short*>(nope)); + free(const_cast<unsigned short*>(world)); + free(const_cast<unsigned short*>(world_caps)); + free(const_cast<unsigned short*>(world_substr)); } // Test that the page has characters despite a bad stream length. |