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 "public/fpdf_doc.h" | 6 #include "public/fpdf_doc.h" |
7 #include "public/fpdfview.h" | 7 #include "public/fpdfview.h" |
8 #include "testing/embedder_test.h" | 8 #include "testing/embedder_test.h" |
9 #include "testing/fx_string_testhelpers.h" | 9 #include "testing/fx_string_testhelpers.h" |
10 #include "testing/test_support.h" | |
10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
11 | 12 |
12 class FPDFDocEmbeddertest : public EmbedderTest {}; | 13 class FPDFDocEmbeddertest : public EmbedderTest {}; |
13 | 14 |
14 TEST_F(FPDFDocEmbeddertest, DestGetPageIndex) { | 15 TEST_F(FPDFDocEmbeddertest, DestGetPageIndex) { |
15 EXPECT_TRUE(OpenDocument("named_dests.pdf")); | 16 EXPECT_TRUE(OpenDocument("named_dests.pdf")); |
16 | 17 |
17 // NULL FPDF_DEST case. | 18 // NULL FPDF_DEST case. |
18 EXPECT_EQ(0U, FPDFDest_GetPageIndex(document(), nullptr)); | 19 EXPECT_EQ(0U, FPDFDest_GetPageIndex(document(), nullptr)); |
19 | 20 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 FPDF_BOOKMARK sibling = FPDFBookmark_GetNextSibling(document(), child); | 95 FPDF_BOOKMARK sibling = FPDFBookmark_GetNextSibling(document(), child); |
95 EXPECT_NE(nullptr, sibling); | 96 EXPECT_NE(nullptr, sibling); |
96 EXPECT_EQ(28, FPDFBookmark_GetTitle(sibling, buf, sizeof(buf))); | 97 EXPECT_EQ(28, FPDFBookmark_GetTitle(sibling, buf, sizeof(buf))); |
97 EXPECT_EQ(CFX_WideString(L"A Good Ending"), | 98 EXPECT_EQ(CFX_WideString(L"A Good Ending"), |
98 CFX_WideString::FromUTF16LE(buf, 13)); | 99 CFX_WideString::FromUTF16LE(buf, 13)); |
99 | 100 |
100 EXPECT_EQ(nullptr, FPDFBookmark_GetNextSibling(document(), sibling)); | 101 EXPECT_EQ(nullptr, FPDFBookmark_GetNextSibling(document(), sibling)); |
101 } | 102 } |
102 | 103 |
103 TEST_F(FPDFDocEmbeddertest, FindBookmarks) { | 104 TEST_F(FPDFDocEmbeddertest, FindBookmarks) { |
104 // Open a file with two bookmarks, and extract the first. | 105 // Open a file with two bookmarks. |
105 EXPECT_TRUE(OpenDocument("bookmarks.pdf")); | 106 EXPECT_TRUE(OpenDocument("bookmarks.pdf")); |
106 | 107 |
108 // Find the first one, based on its known title. | |
109 FPDF_WIDESTRING title = GetFPDFWideString(L"A Good Beginning"); | |
110 FPDF_BOOKMARK child = FPDFBookmark_Find(document(), title); | |
111 EXPECT_NE(nullptr, child); | |
112 | |
113 // Check that the string matches. | |
107 unsigned short buf[128]; | 114 unsigned short buf[128]; |
108 FPDF_BOOKMARK child = FPDFBookmark_GetFirstChild(document(), nullptr); | |
109 EXPECT_NE(nullptr, child); | |
110 EXPECT_EQ(34, FPDFBookmark_GetTitle(child, buf, sizeof(buf))); | 115 EXPECT_EQ(34, FPDFBookmark_GetTitle(child, buf, sizeof(buf))); |
111 EXPECT_EQ(CFX_WideString(L"A Good Beginning"), | 116 EXPECT_EQ(CFX_WideString(L"A Good Beginning"), |
112 CFX_WideString::FromUTF16LE(buf, 16)); | 117 CFX_WideString::FromUTF16LE(buf, 16)); |
113 | 118 |
114 // Find the same one again using the title. | 119 // Check that it is them same as the one returned by GetFirstChild. |
115 EXPECT_EQ(child, FPDFBookmark_Find(document(), buf)); | 120 EXPECT_EQ(child, FPDFBookmark_GetFirstChild(document(), nullptr)); |
116 | 121 |
117 // Try to find one using a non-existent title. | 122 // Try to find one using a non-existent title. |
118 buf[0] = 'X'; | 123 FPDF_WIDESTRING bad_title = GetFPDFWideString(L"A BAD Beginning"); |
119 EXPECT_EQ(nullptr, FPDFBookmark_Find(document(), buf)); | 124 EXPECT_EQ(nullptr, FPDFBookmark_Find(document(), bad_title)); |
125 | |
126 // Alas, the typedef includes the "const". | |
Lei Zhang
2016/01/05 02:34:09
Do you want to make a custom unique_ptr deleter fo
Tom Sepez
2016/01/05 18:06:23
I'll do that in a follow-up. The GetFileContents(
| |
127 free(const_cast<unsigned short*>(title)); | |
128 free(const_cast<unsigned short*>(bad_title)); | |
120 } | 129 } |
OLD | NEW |