Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: fpdfsdk/fpdfdoc_embeddertest.cpp

Issue 2032613003: Get rid of NULLs in core/ (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: Fix a bad merge Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/fxge/win32/win32_int.h ('k') | fpdfsdk/fpdftext_embeddertest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <string> 5 #include <string>
6 6
7 #include "core/fxcrt/include/fx_string.h" 7 #include "core/fxcrt/include/fx_string.h"
8 #include "public/fpdf_doc.h" 8 #include "public/fpdf_doc.h"
9 #include "public/fpdf_edit.h" 9 #include "public/fpdf_edit.h"
10 #include "public/fpdfview.h" 10 #include "public/fpdfview.h"
11 #include "testing/embedder_test.h" 11 #include "testing/embedder_test.h"
12 #include "testing/fx_string_testhelpers.h" 12 #include "testing/fx_string_testhelpers.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "testing/test_support.h" 14 #include "testing/test_support.h"
15 15
16 class FPDFDocEmbeddertest : public EmbedderTest {}; 16 class FPDFDocEmbeddertest : public EmbedderTest {};
17 17
18 TEST_F(FPDFDocEmbeddertest, DestGetPageIndex) { 18 TEST_F(FPDFDocEmbeddertest, DestGetPageIndex) {
19 EXPECT_TRUE(OpenDocument("named_dests.pdf")); 19 EXPECT_TRUE(OpenDocument("named_dests.pdf"));
20 20
21 // NULL FPDF_DEST case. 21 // NULL FPDF_DEST case.
22 EXPECT_EQ(0U, FPDFDest_GetPageIndex(document(), nullptr)); 22 EXPECT_EQ(0U, FPDFDest_GetPageIndex(document(), nullptr));
23 23
24 // Page number directly in item from Dests NameTree. 24 // Page number directly in item from Dests NameTree.
25 FPDF_DEST dest = FPDF_GetNamedDestByName(document(), "First"); 25 FPDF_DEST dest = FPDF_GetNamedDestByName(document(), "First");
26 EXPECT_NE(nullptr, dest); 26 EXPECT_TRUE(dest);
27 EXPECT_EQ(1U, FPDFDest_GetPageIndex(document(), dest)); 27 EXPECT_EQ(1U, FPDFDest_GetPageIndex(document(), dest));
28 28
29 // Page number via object reference in item from Dests NameTree. 29 // Page number via object reference in item from Dests NameTree.
30 dest = FPDF_GetNamedDestByName(document(), "Next"); 30 dest = FPDF_GetNamedDestByName(document(), "Next");
31 EXPECT_NE(nullptr, dest); 31 EXPECT_TRUE(dest);
32 EXPECT_EQ(1U, FPDFDest_GetPageIndex(document(), dest)); 32 EXPECT_EQ(1U, FPDFDest_GetPageIndex(document(), dest));
33 33
34 // Page number directly in item from Dests dictionary. 34 // Page number directly in item from Dests dictionary.
35 dest = FPDF_GetNamedDestByName(document(), "FirstAlternate"); 35 dest = FPDF_GetNamedDestByName(document(), "FirstAlternate");
36 EXPECT_NE(nullptr, dest); 36 EXPECT_TRUE(dest);
37 EXPECT_EQ(11U, FPDFDest_GetPageIndex(document(), dest)); 37 EXPECT_EQ(11U, FPDFDest_GetPageIndex(document(), dest));
38 38
39 // Invalid object reference in item from Dests NameTree. 39 // Invalid object reference in item from Dests NameTree.
40 dest = FPDF_GetNamedDestByName(document(), "LastAlternate"); 40 dest = FPDF_GetNamedDestByName(document(), "LastAlternate");
41 EXPECT_NE(nullptr, dest); 41 EXPECT_TRUE(dest);
42 EXPECT_EQ(0U, FPDFDest_GetPageIndex(document(), dest)); 42 EXPECT_EQ(0U, FPDFDest_GetPageIndex(document(), dest));
43 } 43 }
44 44
45 TEST_F(FPDFDocEmbeddertest, ActionGetFilePath) { 45 TEST_F(FPDFDocEmbeddertest, ActionGetFilePath) {
46 EXPECT_TRUE(OpenDocument("launch_action.pdf")); 46 EXPECT_TRUE(OpenDocument("launch_action.pdf"));
47 47
48 FPDF_PAGE page = FPDF_LoadPage(document(), 0); 48 FPDF_PAGE page = FPDF_LoadPage(document(), 0);
49 ASSERT_TRUE(page); 49 ASSERT_TRUE(page);
50 50
51 // The target action is nearly the size of the whole page. 51 // The target action is nearly the size of the whole page.
(...skipping 29 matching lines...) Expand all
81 81
82 TEST_F(FPDFDocEmbeddertest, Bookmarks) { 82 TEST_F(FPDFDocEmbeddertest, Bookmarks) {
83 // Open a file with two bookmarks. 83 // Open a file with two bookmarks.
84 EXPECT_TRUE(OpenDocument("bookmarks.pdf")); 84 EXPECT_TRUE(OpenDocument("bookmarks.pdf"));
85 85
86 // The existent top-level bookmark has no title. 86 // The existent top-level bookmark has no title.
87 unsigned short buf[128]; 87 unsigned short buf[128];
88 EXPECT_EQ(0u, FPDFBookmark_GetTitle(nullptr, buf, sizeof(buf))); 88 EXPECT_EQ(0u, FPDFBookmark_GetTitle(nullptr, buf, sizeof(buf)));
89 89
90 FPDF_BOOKMARK child = FPDFBookmark_GetFirstChild(document(), nullptr); 90 FPDF_BOOKMARK child = FPDFBookmark_GetFirstChild(document(), nullptr);
91 EXPECT_NE(nullptr, child); 91 EXPECT_TRUE(child);
92 EXPECT_EQ(34u, FPDFBookmark_GetTitle(child, buf, sizeof(buf))); 92 EXPECT_EQ(34u, FPDFBookmark_GetTitle(child, buf, sizeof(buf)));
93 EXPECT_EQ(CFX_WideString(L"A Good Beginning"), 93 EXPECT_EQ(CFX_WideString(L"A Good Beginning"),
94 CFX_WideString::FromUTF16LE(buf, 16)); 94 CFX_WideString::FromUTF16LE(buf, 16));
95 95
96 EXPECT_EQ(nullptr, FPDFBookmark_GetFirstChild(document(), child)); 96 EXPECT_EQ(nullptr, FPDFBookmark_GetFirstChild(document(), child));
97 97
98 FPDF_BOOKMARK sibling = FPDFBookmark_GetNextSibling(document(), child); 98 FPDF_BOOKMARK sibling = FPDFBookmark_GetNextSibling(document(), child);
99 EXPECT_NE(nullptr, sibling); 99 EXPECT_TRUE(sibling);
100 EXPECT_EQ(28u, FPDFBookmark_GetTitle(sibling, buf, sizeof(buf))); 100 EXPECT_EQ(28u, FPDFBookmark_GetTitle(sibling, buf, sizeof(buf)));
101 EXPECT_EQ(CFX_WideString(L"A Good Ending"), 101 EXPECT_EQ(CFX_WideString(L"A Good Ending"),
102 CFX_WideString::FromUTF16LE(buf, 13)); 102 CFX_WideString::FromUTF16LE(buf, 13));
103 103
104 EXPECT_EQ(nullptr, FPDFBookmark_GetNextSibling(document(), sibling)); 104 EXPECT_EQ(nullptr, FPDFBookmark_GetNextSibling(document(), sibling));
105 } 105 }
106 106
107 TEST_F(FPDFDocEmbeddertest, FindBookmarks) { 107 TEST_F(FPDFDocEmbeddertest, FindBookmarks) {
108 // Open a file with two bookmarks. 108 // Open a file with two bookmarks.
109 EXPECT_TRUE(OpenDocument("bookmarks.pdf")); 109 EXPECT_TRUE(OpenDocument("bookmarks.pdf"));
110 110
111 // Find the first one, based on its known title. 111 // Find the first one, based on its known title.
112 std::unique_ptr<unsigned short, pdfium::FreeDeleter> title = 112 std::unique_ptr<unsigned short, pdfium::FreeDeleter> title =
113 GetFPDFWideString(L"A Good Beginning"); 113 GetFPDFWideString(L"A Good Beginning");
114 FPDF_BOOKMARK child = FPDFBookmark_Find(document(), title.get()); 114 FPDF_BOOKMARK child = FPDFBookmark_Find(document(), title.get());
115 EXPECT_NE(nullptr, child); 115 EXPECT_TRUE(child);
116 116
117 // Check that the string matches. 117 // Check that the string matches.
118 unsigned short buf[128]; 118 unsigned short buf[128];
119 EXPECT_EQ(34u, FPDFBookmark_GetTitle(child, buf, sizeof(buf))); 119 EXPECT_EQ(34u, FPDFBookmark_GetTitle(child, buf, sizeof(buf)));
120 EXPECT_EQ(CFX_WideString(L"A Good Beginning"), 120 EXPECT_EQ(CFX_WideString(L"A Good Beginning"),
121 CFX_WideString::FromUTF16LE(buf, 16)); 121 CFX_WideString::FromUTF16LE(buf, 16));
122 122
123 // Check that it is them same as the one returned by GetFirstChild. 123 // Check that it is them same as the one returned by GetFirstChild.
124 EXPECT_EQ(child, FPDFBookmark_GetFirstChild(document(), nullptr)); 124 EXPECT_EQ(child, FPDFBookmark_GetFirstChild(document(), nullptr));
125 125
(...skipping 13 matching lines...) Expand all
139 GetFPDFWideString(L"anything"); 139 GetFPDFWideString(L"anything");
140 EXPECT_EQ(nullptr, FPDFBookmark_Find(document(), title.get())); 140 EXPECT_EQ(nullptr, FPDFBookmark_Find(document(), title.get()));
141 } 141 }
142 142
143 TEST_F(FPDFDocEmbeddertest, DeletePage) { 143 TEST_F(FPDFDocEmbeddertest, DeletePage) {
144 EXPECT_TRUE(OpenDocument("hello_world.pdf")); 144 EXPECT_TRUE(OpenDocument("hello_world.pdf"));
145 EXPECT_EQ(1, FPDF_GetPageCount(document())); 145 EXPECT_EQ(1, FPDF_GetPageCount(document()));
146 FPDFPage_Delete(document(), 0); 146 FPDFPage_Delete(document(), 0);
147 EXPECT_EQ(0, FPDF_GetPageCount(document())); 147 EXPECT_EQ(0, FPDF_GetPageCount(document()));
148 } 148 }
OLDNEW
« no previous file with comments | « core/fxge/win32/win32_int.h ('k') | fpdfsdk/fpdftext_embeddertest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698