From 8ab45eafebfd510554920e09e5ee85e94701dea9 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Tue, 5 Jan 2016 10:17:30 -0800 Subject: Merge to XFA: Make FPDF_WIDESTRING work regardless of endianness. Original Review URL: https://codereview.chromium.org/1554363002 . (cherry picked from commit ed34cdf99d5a4b33e57f81f9244a311f6fb86db3) TBR=thestig@chromium.org Review URL: https://codereview.chromium.org/1559373002 . --- fpdfsdk/src/fpdfdoc_embeddertest.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'fpdfsdk/src/fpdfdoc_embeddertest.cpp') 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(title)); + free(const_cast(bad_title)); } -- cgit v1.2.3