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

Side by Side Diff: fpdfsdk/fpdfdoc_embeddertest.cpp

Issue 1841643002: Code change to avoid signed/unsigned mismatch warnings (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: rebase Created 4 years, 8 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/include/fpdfdoc/fpdf_doc.h ('k') | fpdfsdk/fpdfsave_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/fpdfview.h" 9 #include "public/fpdfview.h"
10 #include "testing/embedder_test.h" 10 #include "testing/embedder_test.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 65
66 FPDF_ClosePage(page); 66 FPDF_ClosePage(page);
67 } 67 }
68 68
69 TEST_F(FPDFDocEmbeddertest, NoBookmarks) { 69 TEST_F(FPDFDocEmbeddertest, NoBookmarks) {
70 // Open a file with no bookmarks. 70 // Open a file with no bookmarks.
71 EXPECT_TRUE(OpenDocument("named_dests.pdf")); 71 EXPECT_TRUE(OpenDocument("named_dests.pdf"));
72 72
73 // The non-existent top-level bookmark has no title. 73 // The non-existent top-level bookmark has no title.
74 unsigned short buf[128]; 74 unsigned short buf[128];
75 EXPECT_EQ(0, FPDFBookmark_GetTitle(nullptr, buf, sizeof(buf))); 75 EXPECT_EQ(0u, FPDFBookmark_GetTitle(nullptr, buf, sizeof(buf)));
76 76
77 // The non-existent top-level bookmark has no children. 77 // The non-existent top-level bookmark has no children.
78 EXPECT_EQ(nullptr, FPDFBookmark_GetFirstChild(document(), nullptr)); 78 EXPECT_EQ(nullptr, FPDFBookmark_GetFirstChild(document(), nullptr));
79 } 79 }
80 80
81 TEST_F(FPDFDocEmbeddertest, Bookmarks) { 81 TEST_F(FPDFDocEmbeddertest, Bookmarks) {
82 // Open a file with two bookmarks. 82 // Open a file with two bookmarks.
83 EXPECT_TRUE(OpenDocument("bookmarks.pdf")); 83 EXPECT_TRUE(OpenDocument("bookmarks.pdf"));
84 84
85 // The existent top-level bookmark has no title. 85 // The existent top-level bookmark has no title.
86 unsigned short buf[128]; 86 unsigned short buf[128];
87 EXPECT_EQ(0, FPDFBookmark_GetTitle(nullptr, buf, sizeof(buf))); 87 EXPECT_EQ(0u, FPDFBookmark_GetTitle(nullptr, buf, sizeof(buf)));
88 88
89 FPDF_BOOKMARK child = FPDFBookmark_GetFirstChild(document(), nullptr); 89 FPDF_BOOKMARK child = FPDFBookmark_GetFirstChild(document(), nullptr);
90 EXPECT_NE(nullptr, child); 90 EXPECT_NE(nullptr, child);
91 EXPECT_EQ(34, FPDFBookmark_GetTitle(child, buf, sizeof(buf))); 91 EXPECT_EQ(34u, FPDFBookmark_GetTitle(child, buf, sizeof(buf)));
92 EXPECT_EQ(CFX_WideString(L"A Good Beginning"), 92 EXPECT_EQ(CFX_WideString(L"A Good Beginning"),
93 CFX_WideString::FromUTF16LE(buf, 16)); 93 CFX_WideString::FromUTF16LE(buf, 16));
94 94
95 EXPECT_EQ(nullptr, FPDFBookmark_GetFirstChild(document(), child)); 95 EXPECT_EQ(nullptr, FPDFBookmark_GetFirstChild(document(), child));
96 96
97 FPDF_BOOKMARK sibling = FPDFBookmark_GetNextSibling(document(), child); 97 FPDF_BOOKMARK sibling = FPDFBookmark_GetNextSibling(document(), child);
98 EXPECT_NE(nullptr, sibling); 98 EXPECT_NE(nullptr, sibling);
99 EXPECT_EQ(28, FPDFBookmark_GetTitle(sibling, buf, sizeof(buf))); 99 EXPECT_EQ(28u, FPDFBookmark_GetTitle(sibling, buf, sizeof(buf)));
100 EXPECT_EQ(CFX_WideString(L"A Good Ending"), 100 EXPECT_EQ(CFX_WideString(L"A Good Ending"),
101 CFX_WideString::FromUTF16LE(buf, 13)); 101 CFX_WideString::FromUTF16LE(buf, 13));
102 102
103 EXPECT_EQ(nullptr, FPDFBookmark_GetNextSibling(document(), sibling)); 103 EXPECT_EQ(nullptr, FPDFBookmark_GetNextSibling(document(), sibling));
104 } 104 }
105 105
106 TEST_F(FPDFDocEmbeddertest, FindBookmarks) { 106 TEST_F(FPDFDocEmbeddertest, FindBookmarks) {
107 // Open a file with two bookmarks. 107 // Open a file with two bookmarks.
108 EXPECT_TRUE(OpenDocument("bookmarks.pdf")); 108 EXPECT_TRUE(OpenDocument("bookmarks.pdf"));
109 109
110 // Find the first one, based on its known title. 110 // Find the first one, based on its known title.
111 std::unique_ptr<unsigned short, pdfium::FreeDeleter> title = 111 std::unique_ptr<unsigned short, pdfium::FreeDeleter> title =
112 GetFPDFWideString(L"A Good Beginning"); 112 GetFPDFWideString(L"A Good Beginning");
113 FPDF_BOOKMARK child = FPDFBookmark_Find(document(), title.get()); 113 FPDF_BOOKMARK child = FPDFBookmark_Find(document(), title.get());
114 EXPECT_NE(nullptr, child); 114 EXPECT_NE(nullptr, child);
115 115
116 // Check that the string matches. 116 // Check that the string matches.
117 unsigned short buf[128]; 117 unsigned short buf[128];
118 EXPECT_EQ(34, FPDFBookmark_GetTitle(child, buf, sizeof(buf))); 118 EXPECT_EQ(34u, FPDFBookmark_GetTitle(child, buf, sizeof(buf)));
119 EXPECT_EQ(CFX_WideString(L"A Good Beginning"), 119 EXPECT_EQ(CFX_WideString(L"A Good Beginning"),
120 CFX_WideString::FromUTF16LE(buf, 16)); 120 CFX_WideString::FromUTF16LE(buf, 16));
121 121
122 // Check that it is them same as the one returned by GetFirstChild. 122 // Check that it is them same as the one returned by GetFirstChild.
123 EXPECT_EQ(child, FPDFBookmark_GetFirstChild(document(), nullptr)); 123 EXPECT_EQ(child, FPDFBookmark_GetFirstChild(document(), nullptr));
124 124
125 // Try to find one using a non-existent title. 125 // Try to find one using a non-existent title.
126 std::unique_ptr<unsigned short, pdfium::FreeDeleter> bad_title = 126 std::unique_ptr<unsigned short, pdfium::FreeDeleter> bad_title =
127 GetFPDFWideString(L"A BAD Beginning"); 127 GetFPDFWideString(L"A BAD Beginning");
128 EXPECT_EQ(nullptr, FPDFBookmark_Find(document(), bad_title.get())); 128 EXPECT_EQ(nullptr, FPDFBookmark_Find(document(), bad_title.get()));
129 } 129 }
130 130
131 // Check circular bookmarks will not cause infinite loop. 131 // Check circular bookmarks will not cause infinite loop.
132 TEST_F(FPDFDocEmbeddertest, FindBookmarks_bug420) { 132 TEST_F(FPDFDocEmbeddertest, FindBookmarks_bug420) {
133 // Open a file with circular bookmarks. 133 // Open a file with circular bookmarks.
134 EXPECT_TRUE(OpenDocument("bookmarks_circular.pdf")); 134 EXPECT_TRUE(OpenDocument("bookmarks_circular.pdf"));
135 135
136 // Try to find a title. 136 // Try to find a title.
137 std::unique_ptr<unsigned short, pdfium::FreeDeleter> title = 137 std::unique_ptr<unsigned short, pdfium::FreeDeleter> title =
138 GetFPDFWideString(L"anything"); 138 GetFPDFWideString(L"anything");
139 EXPECT_EQ(nullptr, FPDFBookmark_Find(document(), title.get())); 139 EXPECT_EQ(nullptr, FPDFBookmark_Find(document(), title.get()));
140 } 140 }
OLDNEW
« no previous file with comments | « core/include/fpdfdoc/fpdf_doc.h ('k') | fpdfsdk/fpdfsave_embeddertest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698