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/test_support.h" |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 CFX_WideString::FromUTF16LE(buf, 13)); | 99 CFX_WideString::FromUTF16LE(buf, 13)); |
100 | 100 |
101 EXPECT_EQ(nullptr, FPDFBookmark_GetNextSibling(document(), sibling)); | 101 EXPECT_EQ(nullptr, FPDFBookmark_GetNextSibling(document(), sibling)); |
102 } | 102 } |
103 | 103 |
104 TEST_F(FPDFDocEmbeddertest, FindBookmarks) { | 104 TEST_F(FPDFDocEmbeddertest, FindBookmarks) { |
105 // Open a file with two bookmarks. | 105 // Open a file with two bookmarks. |
106 EXPECT_TRUE(OpenDocument("bookmarks.pdf")); | 106 EXPECT_TRUE(OpenDocument("bookmarks.pdf")); |
107 | 107 |
108 // Find the first one, based on its known title. | 108 // Find the first one, based on its known title. |
109 FPDF_WIDESTRING title = GetFPDFWideString(L"A Good Beginning"); | 109 std::unique_ptr<unsigned short, pdfium::FreeDeleter> title = |
110 FPDF_BOOKMARK child = FPDFBookmark_Find(document(), title); | 110 GetFPDFWideString(L"A Good Beginning"); |
| 111 FPDF_BOOKMARK child = FPDFBookmark_Find(document(), title.get()); |
111 EXPECT_NE(nullptr, child); | 112 EXPECT_NE(nullptr, child); |
112 | 113 |
113 // Check that the string matches. | 114 // Check that the string matches. |
114 unsigned short buf[128]; | 115 unsigned short buf[128]; |
115 EXPECT_EQ(34, FPDFBookmark_GetTitle(child, buf, sizeof(buf))); | 116 EXPECT_EQ(34, FPDFBookmark_GetTitle(child, buf, sizeof(buf))); |
116 EXPECT_EQ(CFX_WideString(L"A Good Beginning"), | 117 EXPECT_EQ(CFX_WideString(L"A Good Beginning"), |
117 CFX_WideString::FromUTF16LE(buf, 16)); | 118 CFX_WideString::FromUTF16LE(buf, 16)); |
118 | 119 |
119 // Check that it is them same as the one returned by GetFirstChild. | 120 // Check that it is them same as the one returned by GetFirstChild. |
120 EXPECT_EQ(child, FPDFBookmark_GetFirstChild(document(), nullptr)); | 121 EXPECT_EQ(child, FPDFBookmark_GetFirstChild(document(), nullptr)); |
121 | 122 |
122 // Try to find one using a non-existent title. | 123 // Try to find one using a non-existent title. |
123 FPDF_WIDESTRING bad_title = GetFPDFWideString(L"A BAD Beginning"); | 124 std::unique_ptr<unsigned short, pdfium::FreeDeleter> bad_title = |
124 EXPECT_EQ(nullptr, FPDFBookmark_Find(document(), bad_title)); | 125 GetFPDFWideString(L"A BAD Beginning"); |
125 | 126 EXPECT_EQ(nullptr, FPDFBookmark_Find(document(), bad_title.get())); |
126 // Alas, the typedef includes the "const". | |
127 free(const_cast<unsigned short*>(title)); | |
128 free(const_cast<unsigned short*>(bad_title)); | |
129 } | 127 } |
OLD | NEW |