summaryrefslogtreecommitdiff
path: root/fpdfsdk
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2015-10-14 09:26:32 -0700
committerTom Sepez <tsepez@chromium.org>2015-10-14 09:26:32 -0700
commit758ae14e113c07285126274577d7a5cab559fa65 (patch)
treef8725d73309e87d59e5279db86eae70aedfe922e /fpdfsdk
parent468e5896007c7fe7bb283c0161d807a76f403308 (diff)
downloadpdfium-758ae14e113c07285126274577d7a5cab559fa65.tar.xz
Merge to XFA: Add unit test for top-level bookmarks.
Original Review URL: https://codereview.chromium.org/1404723002 . (cherry picked from commit 7d54a9f70f977ce9b72959ef55dc6300713ccafe) R=thestig@chromium.org TBR=thestig@chromium.org Review URL: https://codereview.chromium.org/1404193002 .
Diffstat (limited to 'fpdfsdk')
-rw-r--r--fpdfsdk/src/fpdfdoc_embeddertest.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/fpdfsdk/src/fpdfdoc_embeddertest.cpp b/fpdfsdk/src/fpdfdoc_embeddertest.cpp
index 8b1c4fb3e8..c83b2eb958 100644
--- a/fpdfsdk/src/fpdfdoc_embeddertest.cpp
+++ b/fpdfsdk/src/fpdfdoc_embeddertest.cpp
@@ -2,9 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "../../core/include/fxcrt/fx_string.h"
#include "../../public/fpdf_doc.h"
#include "../../public/fpdfview.h"
#include "../../testing/embedder_test.h"
+#include "../../testing/fx_string_testhelpers.h"
#include "testing/gtest/include/gtest/gtest.h"
class FPDFDocEmbeddertest : public EmbedderTest {};
@@ -60,3 +62,40 @@ TEST_F(FPDFDocEmbeddertest, ActionGetFilePath) {
FPDF_ClosePage(page);
}
+
+TEST_F(FPDFDocEmbeddertest, NoBookmarks) {
+ // Open a file with no bookmarks.
+ EXPECT_TRUE(OpenDocument("testing/resources/named_dests.pdf"));
+
+ // The non-existent top-level bookmark has no title.
+ unsigned short buf[128];
+ EXPECT_EQ(0, FPDFBookmark_GetTitle(nullptr, buf, sizeof(buf)));
+
+ // The non-existent top-level bookmark has no children.
+ EXPECT_EQ(nullptr, FPDFBookmark_GetFirstChild(document(), nullptr));
+}
+
+TEST_F(FPDFDocEmbeddertest, Bookmarks) {
+ // Open a file with two bookmarks.
+ EXPECT_TRUE(OpenDocument("testing/resources/bookmarks.pdf"));
+
+ // The existent top-level bookmark has no title.
+ unsigned short buf[128];
+ EXPECT_EQ(0, FPDFBookmark_GetTitle(nullptr, buf, sizeof(buf)));
+
+ FPDF_BOOKMARK child = FPDFBookmark_GetFirstChild(document(), nullptr);
+ EXPECT_NE(nullptr, child);
+ EXPECT_EQ(34, FPDFBookmark_GetTitle(child, buf, sizeof(buf)));
+ EXPECT_EQ(CFX_WideString(L"A Good Beginning"),
+ CFX_WideString::FromUTF16LE(buf, 16));
+
+ EXPECT_EQ(nullptr, FPDFBookmark_GetFirstChild(document(), child));
+
+ FPDF_BOOKMARK sibling = FPDFBookmark_GetNextSibling(document(), child);
+ EXPECT_NE(nullptr, sibling);
+ EXPECT_EQ(28, FPDFBookmark_GetTitle(sibling, buf, sizeof(buf)));
+ EXPECT_EQ(CFX_WideString(L"A Good Ending"),
+ CFX_WideString::FromUTF16LE(buf, 13));
+
+ EXPECT_EQ(nullptr, FPDFBookmark_GetNextSibling(document(), sibling));
+}