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 "core/include/fxcrt/fx_string.h" |
6 #include "../../testing/embedder_test.h" | |
7 #include "../../testing/fx_string_testhelpers.h" | |
8 #include "public/fpdf_doc.h" | 6 #include "public/fpdf_doc.h" |
9 #include "public/fpdfview.h" | 7 #include "public/fpdfview.h" |
| 8 #include "testing/embedder_test.h" |
| 9 #include "testing/fx_string_testhelpers.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 | 11 |
12 class FPDFDocEmbeddertest : public EmbedderTest {}; | 12 class FPDFDocEmbeddertest : public EmbedderTest {}; |
13 | 13 |
14 TEST_F(FPDFDocEmbeddertest, DestGetPageIndex) { | 14 TEST_F(FPDFDocEmbeddertest, DestGetPageIndex) { |
15 EXPECT_TRUE(OpenDocument("testing/resources/named_dests.pdf")); | 15 EXPECT_TRUE(OpenDocument("named_dests.pdf")); |
16 | 16 |
17 // NULL FPDF_DEST case. | 17 // NULL FPDF_DEST case. |
18 EXPECT_EQ(0U, FPDFDest_GetPageIndex(document(), nullptr)); | 18 EXPECT_EQ(0U, FPDFDest_GetPageIndex(document(), nullptr)); |
19 | 19 |
20 // Page number directly in item from Dests NameTree. | 20 // Page number directly in item from Dests NameTree. |
21 FPDF_DEST dest = FPDF_GetNamedDestByName(document(), "First"); | 21 FPDF_DEST dest = FPDF_GetNamedDestByName(document(), "First"); |
22 EXPECT_NE(nullptr, dest); | 22 EXPECT_NE(nullptr, dest); |
23 EXPECT_EQ(1U, FPDFDest_GetPageIndex(document(), dest)); | 23 EXPECT_EQ(1U, FPDFDest_GetPageIndex(document(), dest)); |
24 | 24 |
25 // Page number via object reference in item from Dests NameTree. | 25 // Page number via object reference in item from Dests NameTree. |
26 dest = FPDF_GetNamedDestByName(document(), "Next"); | 26 dest = FPDF_GetNamedDestByName(document(), "Next"); |
27 EXPECT_NE(nullptr, dest); | 27 EXPECT_NE(nullptr, dest); |
28 EXPECT_EQ(1U, FPDFDest_GetPageIndex(document(), dest)); | 28 EXPECT_EQ(1U, FPDFDest_GetPageIndex(document(), dest)); |
29 | 29 |
30 // Page number directly in item from Dests dictionary. | 30 // Page number directly in item from Dests dictionary. |
31 dest = FPDF_GetNamedDestByName(document(), "FirstAlternate"); | 31 dest = FPDF_GetNamedDestByName(document(), "FirstAlternate"); |
32 EXPECT_NE(nullptr, dest); | 32 EXPECT_NE(nullptr, dest); |
33 EXPECT_EQ(11U, FPDFDest_GetPageIndex(document(), dest)); | 33 EXPECT_EQ(11U, FPDFDest_GetPageIndex(document(), dest)); |
34 | 34 |
35 // Invalid object reference in item from Dests NameTree. | 35 // Invalid object reference in item from Dests NameTree. |
36 dest = FPDF_GetNamedDestByName(document(), "LastAlternate"); | 36 dest = FPDF_GetNamedDestByName(document(), "LastAlternate"); |
37 EXPECT_NE(nullptr, dest); | 37 EXPECT_NE(nullptr, dest); |
38 EXPECT_EQ(0U, FPDFDest_GetPageIndex(document(), dest)); | 38 EXPECT_EQ(0U, FPDFDest_GetPageIndex(document(), dest)); |
39 } | 39 } |
40 | 40 |
41 TEST_F(FPDFDocEmbeddertest, ActionGetFilePath) { | 41 TEST_F(FPDFDocEmbeddertest, ActionGetFilePath) { |
42 EXPECT_TRUE(OpenDocument("testing/resources/launch_action.pdf")); | 42 EXPECT_TRUE(OpenDocument("launch_action.pdf")); |
43 | 43 |
44 FPDF_PAGE page = FPDF_LoadPage(document(), 0); | 44 FPDF_PAGE page = FPDF_LoadPage(document(), 0); |
45 ASSERT_TRUE(page); | 45 ASSERT_TRUE(page); |
46 | 46 |
47 // The target action is nearly the size of the whole page. | 47 // The target action is nearly the size of the whole page. |
48 FPDF_LINK link = FPDFLink_GetLinkAtPoint(page, 100, 100); | 48 FPDF_LINK link = FPDFLink_GetLinkAtPoint(page, 100, 100); |
49 ASSERT_TRUE(link); | 49 ASSERT_TRUE(link); |
50 | 50 |
51 FPDF_ACTION action = FPDFLink_GetAction(link); | 51 FPDF_ACTION action = FPDFLink_GetAction(link); |
52 ASSERT_TRUE(action); | 52 ASSERT_TRUE(action); |
53 | 53 |
54 const char kExpectedResult[] = "test.pdf"; | 54 const char kExpectedResult[] = "test.pdf"; |
55 const unsigned long kExpectedLength = sizeof(kExpectedResult); | 55 const unsigned long kExpectedLength = sizeof(kExpectedResult); |
56 unsigned long bufsize = FPDFAction_GetFilePath(action, nullptr, 0); | 56 unsigned long bufsize = FPDFAction_GetFilePath(action, nullptr, 0); |
57 ASSERT_EQ(kExpectedLength, bufsize); | 57 ASSERT_EQ(kExpectedLength, bufsize); |
58 | 58 |
59 char buf[kExpectedLength]; | 59 char buf[kExpectedLength]; |
60 EXPECT_EQ(bufsize, FPDFAction_GetFilePath(action, buf, bufsize)); | 60 EXPECT_EQ(bufsize, FPDFAction_GetFilePath(action, buf, bufsize)); |
61 EXPECT_EQ(std::string(kExpectedResult), std::string(buf)); | 61 EXPECT_EQ(std::string(kExpectedResult), std::string(buf)); |
62 | 62 |
63 FPDF_ClosePage(page); | 63 FPDF_ClosePage(page); |
64 } | 64 } |
65 | 65 |
66 TEST_F(FPDFDocEmbeddertest, NoBookmarks) { | 66 TEST_F(FPDFDocEmbeddertest, NoBookmarks) { |
67 // Open a file with no bookmarks. | 67 // Open a file with no bookmarks. |
68 EXPECT_TRUE(OpenDocument("testing/resources/named_dests.pdf")); | 68 EXPECT_TRUE(OpenDocument("named_dests.pdf")); |
69 | 69 |
70 // The non-existent top-level bookmark has no title. | 70 // The non-existent top-level bookmark has no title. |
71 unsigned short buf[128]; | 71 unsigned short buf[128]; |
72 EXPECT_EQ(0, FPDFBookmark_GetTitle(nullptr, buf, sizeof(buf))); | 72 EXPECT_EQ(0, FPDFBookmark_GetTitle(nullptr, buf, sizeof(buf))); |
73 | 73 |
74 // The non-existent top-level bookmark has no children. | 74 // The non-existent top-level bookmark has no children. |
75 EXPECT_EQ(nullptr, FPDFBookmark_GetFirstChild(document(), nullptr)); | 75 EXPECT_EQ(nullptr, FPDFBookmark_GetFirstChild(document(), nullptr)); |
76 } | 76 } |
77 | 77 |
78 TEST_F(FPDFDocEmbeddertest, Bookmarks) { | 78 TEST_F(FPDFDocEmbeddertest, Bookmarks) { |
79 // Open a file with two bookmarks. | 79 // Open a file with two bookmarks. |
80 EXPECT_TRUE(OpenDocument("testing/resources/bookmarks.pdf")); | 80 EXPECT_TRUE(OpenDocument("bookmarks.pdf")); |
81 | 81 |
82 // The existent top-level bookmark has no title. | 82 // The existent top-level bookmark has no title. |
83 unsigned short buf[128]; | 83 unsigned short buf[128]; |
84 EXPECT_EQ(0, FPDFBookmark_GetTitle(nullptr, buf, sizeof(buf))); | 84 EXPECT_EQ(0, FPDFBookmark_GetTitle(nullptr, buf, sizeof(buf))); |
85 | 85 |
86 FPDF_BOOKMARK child = FPDFBookmark_GetFirstChild(document(), nullptr); | 86 FPDF_BOOKMARK child = FPDFBookmark_GetFirstChild(document(), nullptr); |
87 EXPECT_NE(nullptr, child); | 87 EXPECT_NE(nullptr, child); |
88 EXPECT_EQ(34, FPDFBookmark_GetTitle(child, buf, sizeof(buf))); | 88 EXPECT_EQ(34, FPDFBookmark_GetTitle(child, buf, sizeof(buf))); |
89 EXPECT_EQ(CFX_WideString(L"A Good Beginning"), | 89 EXPECT_EQ(CFX_WideString(L"A Good Beginning"), |
90 CFX_WideString::FromUTF16LE(buf, 16)); | 90 CFX_WideString::FromUTF16LE(buf, 16)); |
91 | 91 |
92 EXPECT_EQ(nullptr, FPDFBookmark_GetFirstChild(document(), child)); | 92 EXPECT_EQ(nullptr, FPDFBookmark_GetFirstChild(document(), child)); |
93 | 93 |
94 FPDF_BOOKMARK sibling = FPDFBookmark_GetNextSibling(document(), child); | 94 FPDF_BOOKMARK sibling = FPDFBookmark_GetNextSibling(document(), child); |
95 EXPECT_NE(nullptr, sibling); | 95 EXPECT_NE(nullptr, sibling); |
96 EXPECT_EQ(28, FPDFBookmark_GetTitle(sibling, buf, sizeof(buf))); | 96 EXPECT_EQ(28, FPDFBookmark_GetTitle(sibling, buf, sizeof(buf))); |
97 EXPECT_EQ(CFX_WideString(L"A Good Ending"), | 97 EXPECT_EQ(CFX_WideString(L"A Good Ending"), |
98 CFX_WideString::FromUTF16LE(buf, 13)); | 98 CFX_WideString::FromUTF16LE(buf, 13)); |
99 | 99 |
100 EXPECT_EQ(nullptr, FPDFBookmark_GetNextSibling(document(), sibling)); | 100 EXPECT_EQ(nullptr, FPDFBookmark_GetNextSibling(document(), sibling)); |
101 } | 101 } |
OLD | NEW |