OLD | NEW |
1 // Copyright 2015 PDFium Authors. All rights reserved. | 1 // Copyright 2015 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
| 5 #include "../../core/include/fxcrt/fx_string.h" |
5 #include "../../public/fpdf_doc.h" | 6 #include "../../public/fpdf_doc.h" |
6 #include "../../public/fpdfview.h" | 7 #include "../../public/fpdfview.h" |
7 #include "../../testing/embedder_test.h" | 8 #include "../../testing/embedder_test.h" |
| 9 #include "../../testing/fx_string_testhelpers.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
9 | 11 |
10 class FPDFDocEmbeddertest : public EmbedderTest {}; | 12 class FPDFDocEmbeddertest : public EmbedderTest {}; |
11 | 13 |
12 TEST_F(FPDFDocEmbeddertest, DestGetPageIndex) { | 14 TEST_F(FPDFDocEmbeddertest, DestGetPageIndex) { |
13 EXPECT_TRUE(OpenDocument("testing/resources/named_dests.pdf")); | 15 EXPECT_TRUE(OpenDocument("testing/resources/named_dests.pdf")); |
14 | 16 |
15 // NULL FPDF_DEST case. | 17 // NULL FPDF_DEST case. |
16 EXPECT_EQ(0U, FPDFDest_GetPageIndex(document(), nullptr)); | 18 EXPECT_EQ(0U, FPDFDest_GetPageIndex(document(), nullptr)); |
17 | 19 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 const unsigned long kExpectedLength = sizeof(kExpectedResult); | 55 const unsigned long kExpectedLength = sizeof(kExpectedResult); |
54 unsigned long bufsize = FPDFAction_GetFilePath(action, nullptr, 0); | 56 unsigned long bufsize = FPDFAction_GetFilePath(action, nullptr, 0); |
55 ASSERT_EQ(kExpectedLength, bufsize); | 57 ASSERT_EQ(kExpectedLength, bufsize); |
56 | 58 |
57 char buf[kExpectedLength]; | 59 char buf[kExpectedLength]; |
58 EXPECT_EQ(bufsize, FPDFAction_GetFilePath(action, buf, bufsize)); | 60 EXPECT_EQ(bufsize, FPDFAction_GetFilePath(action, buf, bufsize)); |
59 EXPECT_EQ(std::string(kExpectedResult), std::string(buf)); | 61 EXPECT_EQ(std::string(kExpectedResult), std::string(buf)); |
60 | 62 |
61 FPDF_ClosePage(page); | 63 FPDF_ClosePage(page); |
62 } | 64 } |
| 65 |
| 66 TEST_F(FPDFDocEmbeddertest, NoBookmarks) { |
| 67 // Open a file with no bookmarks. |
| 68 EXPECT_TRUE(OpenDocument("testing/resources/named_dests.pdf")); |
| 69 |
| 70 // The non-existent top-level bookmark has no title. |
| 71 unsigned short buf[128]; |
| 72 EXPECT_EQ(0, FPDFBookmark_GetTitle(nullptr, buf, sizeof(buf))); |
| 73 |
| 74 // The non-existent top-level bookmark has no children. |
| 75 EXPECT_EQ(nullptr, FPDFBookmark_GetFirstChild(document(), nullptr)); |
| 76 } |
| 77 |
| 78 TEST_F(FPDFDocEmbeddertest, Bookmarks) { |
| 79 // Open a file with two bookmarks. |
| 80 EXPECT_TRUE(OpenDocument("testing/resources/bookmarks.pdf")); |
| 81 |
| 82 // The existent top-level bookmark has no title. |
| 83 unsigned short buf[128]; |
| 84 EXPECT_EQ(0, FPDFBookmark_GetTitle(nullptr, buf, sizeof(buf))); |
| 85 |
| 86 FPDF_BOOKMARK child = FPDFBookmark_GetFirstChild(document(), nullptr); |
| 87 EXPECT_NE(nullptr, child); |
| 88 EXPECT_EQ(34, FPDFBookmark_GetTitle(child, buf, sizeof(buf))); |
| 89 EXPECT_EQ(CFX_WideString(L"A Good Beginning"), |
| 90 CFX_WideString::FromUTF16LE(buf, 16)); |
| 91 |
| 92 EXPECT_EQ(nullptr, FPDFBookmark_GetFirstChild(document(), child)); |
| 93 |
| 94 FPDF_BOOKMARK sibling = FPDFBookmark_GetNextSibling(document(), child); |
| 95 EXPECT_NE(nullptr, sibling); |
| 96 EXPECT_EQ(28, FPDFBookmark_GetTitle(sibling, buf, sizeof(buf))); |
| 97 EXPECT_EQ(CFX_WideString(L"A Good Ending"), |
| 98 CFX_WideString::FromUTF16LE(buf, 13)); |
| 99 |
| 100 EXPECT_EQ(nullptr, FPDFBookmark_GetNextSibling(document(), sibling)); |
| 101 } |
OLD | NEW |