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

Side by Side Diff: fpdfsdk/fpdftext_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 | « fpdfsdk/fpdfsave_embeddertest.cpp ('k') | fpdfsdk/fpdfview.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 "core/fxcrt/include/fx_basic.h" 5 #include "core/fxcrt/include/fx_basic.h"
6 #include "public/fpdf_text.h" 6 #include "public/fpdf_text.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/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "testing/test_support.h" 10 #include "testing/test_support.h"
(...skipping 30 matching lines...) Expand all
41 unsigned short fixed_buffer[128]; 41 unsigned short fixed_buffer[128];
42 memset(fixed_buffer, 0xbd, sizeof(fixed_buffer)); 42 memset(fixed_buffer, 0xbd, sizeof(fixed_buffer));
43 43
44 // Check includes the terminating NUL that is provided. 44 // Check includes the terminating NUL that is provided.
45 int num_chars = FPDFText_GetText(textpage, 0, 128, fixed_buffer); 45 int num_chars = FPDFText_GetText(textpage, 0, 128, fixed_buffer);
46 ASSERT_GE(num_chars, 0); 46 ASSERT_GE(num_chars, 0);
47 EXPECT_EQ(sizeof(expected), static_cast<size_t>(num_chars)); 47 EXPECT_EQ(sizeof(expected), static_cast<size_t>(num_chars));
48 EXPECT_TRUE(check_unsigned_shorts(expected, fixed_buffer, sizeof(expected))); 48 EXPECT_TRUE(check_unsigned_shorts(expected, fixed_buffer, sizeof(expected)));
49 49
50 // Count does not include the terminating NUL in the string literal. 50 // Count does not include the terminating NUL in the string literal.
51 EXPECT_EQ(sizeof(expected) - 1, FPDFText_CountChars(textpage)); 51 EXPECT_EQ(sizeof(expected) - 1,
52 static_cast<size_t>(FPDFText_CountChars(textpage)));
52 for (size_t i = 0; i < sizeof(expected) - 1; ++i) { 53 for (size_t i = 0; i < sizeof(expected) - 1; ++i) {
53 EXPECT_EQ(static_cast<unsigned int>(expected[i]), 54 EXPECT_EQ(static_cast<unsigned int>(expected[i]),
54 FPDFText_GetUnicode(textpage, i)) 55 FPDFText_GetUnicode(textpage, i))
55 << " at " << i; 56 << " at " << i;
56 } 57 }
57 58
58 EXPECT_EQ(12.0, FPDFText_GetFontSize(textpage, 0)); 59 EXPECT_EQ(12.0, FPDFText_GetFontSize(textpage, 0));
59 EXPECT_EQ(16.0, FPDFText_GetFontSize(textpage, 15)); 60 EXPECT_EQ(16.0, FPDFText_GetFontSize(textpage, 15));
60 61
61 double left = 0.0; 62 double left = 0.0;
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 // Only a terminating NUL required for bogus links. 279 // Only a terminating NUL required for bogus links.
279 EXPECT_EQ(1, FPDFLink_GetURL(pagelink, 2, nullptr, 0)); 280 EXPECT_EQ(1, FPDFLink_GetURL(pagelink, 2, nullptr, 0));
280 EXPECT_EQ(1, FPDFLink_GetURL(pagelink, 1400, nullptr, 0)); 281 EXPECT_EQ(1, FPDFLink_GetURL(pagelink, 1400, nullptr, 0));
281 EXPECT_EQ(1, FPDFLink_GetURL(pagelink, -1, nullptr, 0)); 282 EXPECT_EQ(1, FPDFLink_GetURL(pagelink, -1, nullptr, 0));
282 283
283 // Query the number of characters required for each link (incl NUL). 284 // Query the number of characters required for each link (incl NUL).
284 EXPECT_EQ(25, FPDFLink_GetURL(pagelink, 0, nullptr, 0)); 285 EXPECT_EQ(25, FPDFLink_GetURL(pagelink, 0, nullptr, 0));
285 EXPECT_EQ(26, FPDFLink_GetURL(pagelink, 1, nullptr, 0)); 286 EXPECT_EQ(26, FPDFLink_GetURL(pagelink, 1, nullptr, 0));
286 287
287 static const char expected_url[] = "http://example.com?q=foo"; 288 static const char expected_url[] = "http://example.com?q=foo";
289 static const size_t expected_len = sizeof(expected_url);
288 unsigned short fixed_buffer[128]; 290 unsigned short fixed_buffer[128];
289 291
290 // Retrieve a link with too small a buffer. Buffer will not be 292 // Retrieve a link with too small a buffer. Buffer will not be
291 // NUL-terminated, but must not be modified past indicated length, 293 // NUL-terminated, but must not be modified past indicated length,
292 // so pre-fill with a pattern to check write bounds. 294 // so pre-fill with a pattern to check write bounds.
293 memset(fixed_buffer, 0xbd, sizeof(fixed_buffer)); 295 memset(fixed_buffer, 0xbd, sizeof(fixed_buffer));
294 EXPECT_EQ(1, FPDFLink_GetURL(pagelink, 0, fixed_buffer, 1)); 296 EXPECT_EQ(1, FPDFLink_GetURL(pagelink, 0, fixed_buffer, 1));
295 EXPECT_TRUE(check_unsigned_shorts(expected_url, fixed_buffer, 1)); 297 EXPECT_TRUE(check_unsigned_shorts(expected_url, fixed_buffer, 1));
296 EXPECT_EQ(0xbdbd, fixed_buffer[1]); 298 EXPECT_EQ(0xbdbd, fixed_buffer[1]);
297 299
298 // Check buffer that doesn't have space for a terminating NUL. 300 // Check buffer that doesn't have space for a terminating NUL.
299 memset(fixed_buffer, 0xbd, sizeof(fixed_buffer)); 301 memset(fixed_buffer, 0xbd, sizeof(fixed_buffer));
300 EXPECT_EQ( 302 EXPECT_EQ(static_cast<int>(expected_len - 1),
301 sizeof(expected_url) - 1, 303 FPDFLink_GetURL(pagelink, 0, fixed_buffer, expected_len - 1));
302 FPDFLink_GetURL(pagelink, 0, fixed_buffer, sizeof(expected_url) - 1)); 304 EXPECT_TRUE(
303 EXPECT_TRUE(check_unsigned_shorts(expected_url, fixed_buffer, 305 check_unsigned_shorts(expected_url, fixed_buffer, expected_len - 1));
304 sizeof(expected_url) - 1)); 306 EXPECT_EQ(0xbdbd, fixed_buffer[expected_len - 1]);
305 EXPECT_EQ(0xbdbd, fixed_buffer[sizeof(expected_url) - 1]);
306 307
307 // Retreive link with exactly-sized buffer. 308 // Retreive link with exactly-sized buffer.
308 memset(fixed_buffer, 0xbd, sizeof(fixed_buffer)); 309 memset(fixed_buffer, 0xbd, sizeof(fixed_buffer));
309 EXPECT_EQ(sizeof(expected_url), 310 EXPECT_EQ(static_cast<int>(expected_len),
310 FPDFLink_GetURL(pagelink, 0, fixed_buffer, sizeof(expected_url))); 311 FPDFLink_GetURL(pagelink, 0, fixed_buffer, expected_len));
311 EXPECT_TRUE( 312 EXPECT_TRUE(check_unsigned_shorts(expected_url, fixed_buffer, expected_len));
312 check_unsigned_shorts(expected_url, fixed_buffer, sizeof(expected_url))); 313 EXPECT_EQ(0u, fixed_buffer[expected_len - 1]);
313 EXPECT_EQ(0u, fixed_buffer[sizeof(expected_url) - 1]); 314 EXPECT_EQ(0xbdbd, fixed_buffer[expected_len]);
314 EXPECT_EQ(0xbdbd, fixed_buffer[sizeof(expected_url)]);
315 315
316 // Retreive link with ample-sized-buffer. 316 // Retreive link with ample-sized-buffer.
317 memset(fixed_buffer, 0xbd, sizeof(fixed_buffer)); 317 memset(fixed_buffer, 0xbd, sizeof(fixed_buffer));
318 EXPECT_EQ(sizeof(expected_url), 318 EXPECT_EQ(static_cast<int>(expected_len),
319 FPDFLink_GetURL(pagelink, 0, fixed_buffer, 128)); 319 FPDFLink_GetURL(pagelink, 0, fixed_buffer, 128));
320 EXPECT_TRUE( 320 EXPECT_TRUE(check_unsigned_shorts(expected_url, fixed_buffer, expected_len));
321 check_unsigned_shorts(expected_url, fixed_buffer, sizeof(expected_url))); 321 EXPECT_EQ(0u, fixed_buffer[expected_len - 1]);
322 EXPECT_EQ(0u, fixed_buffer[sizeof(expected_url) - 1]); 322 EXPECT_EQ(0xbdbd, fixed_buffer[expected_len]);
323 EXPECT_EQ(0xbdbd, fixed_buffer[sizeof(expected_url)]);
324 323
325 // Each link rendered in a single rect in this test page. 324 // Each link rendered in a single rect in this test page.
326 EXPECT_EQ(1, FPDFLink_CountRects(pagelink, 0)); 325 EXPECT_EQ(1, FPDFLink_CountRects(pagelink, 0));
327 EXPECT_EQ(1, FPDFLink_CountRects(pagelink, 1)); 326 EXPECT_EQ(1, FPDFLink_CountRects(pagelink, 1));
328 327
329 // Each link rendered in a single rect in this test page. 328 // Each link rendered in a single rect in this test page.
330 EXPECT_EQ(0, FPDFLink_CountRects(pagelink, -1)); 329 EXPECT_EQ(0, FPDFLink_CountRects(pagelink, -1));
331 EXPECT_EQ(0, FPDFLink_CountRects(pagelink, 2)); 330 EXPECT_EQ(0, FPDFLink_CountRects(pagelink, 2));
332 EXPECT_EQ(0, FPDFLink_CountRects(pagelink, 10000)); 331 EXPECT_EQ(0, FPDFLink_CountRects(pagelink, 10000));
333 332
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 EXPECT_NE(nullptr, page); 374 EXPECT_NE(nullptr, page);
376 375
377 FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page); 376 FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page);
378 EXPECT_NE(nullptr, textpage); 377 EXPECT_NE(nullptr, textpage);
379 378
380 const double kExpectedFontsSizes[] = {12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 379 const double kExpectedFontsSizes[] = {12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
381 12, 12, 12, 1, 1, 16, 16, 16, 16, 16, 380 12, 12, 12, 1, 1, 16, 16, 16, 16, 16,
382 16, 16, 16, 16, 16, 16, 16, 16, 16, 16}; 381 16, 16, 16, 16, 16, 16, 16, 16, 16, 16};
383 382
384 int count = FPDFText_CountChars(textpage); 383 int count = FPDFText_CountChars(textpage);
385 ASSERT_EQ(FX_ArraySize(kExpectedFontsSizes), count); 384 ASSERT_EQ(FX_ArraySize(kExpectedFontsSizes), static_cast<size_t>(count));
386 for (int i = 0; i < count; ++i) 385 for (int i = 0; i < count; ++i)
387 EXPECT_EQ(kExpectedFontsSizes[i], FPDFText_GetFontSize(textpage, i)) << i; 386 EXPECT_EQ(kExpectedFontsSizes[i], FPDFText_GetFontSize(textpage, i)) << i;
388 387
389 FPDFText_ClosePage(textpage); 388 FPDFText_ClosePage(textpage);
390 UnloadPage(page); 389 UnloadPage(page);
391 } 390 }
OLDNEW
« no previous file with comments | « fpdfsdk/fpdfsave_embeddertest.cpp ('k') | fpdfsdk/fpdfview.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698