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

Side by Side Diff: core/fxcodec/codec/fx_codec_jpx_unittest.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/fpdftext/fpdf_text_int_unittest.cpp ('k') | core/fxcrt/fx_basic_gcc_unittest.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 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "core/fxcodec/codec/codec_int.h" 9 #include "core/fxcodec/codec/codec_int.h"
10 #include "testing/fx_string_testhelpers.h" 10 #include "testing/fx_string_testhelpers.h"
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 289
290 // Note: Some care needs to be taken here because the skip/seek functions 290 // Note: Some care needs to be taken here because the skip/seek functions
291 // take OPJ_OFF_T's as arguments, which are typically a signed type. 291 // take OPJ_OFF_T's as arguments, which are typically a signed type.
292 TEST(fxcodec, DecodeDataSkip) { 292 TEST(fxcodec, DecodeDataSkip) {
293 unsigned char buffer[16]; 293 unsigned char buffer[16];
294 { 294 {
295 DecodeData dd(stream_data, sizeof(stream_data)); 295 DecodeData dd(stream_data, sizeof(stream_data));
296 296
297 // Skiping within buffer is allowed. 297 // Skiping within buffer is allowed.
298 memset(buffer, 0xbd, sizeof(buffer)); 298 memset(buffer, 0xbd, sizeof(buffer));
299 EXPECT_EQ(1, opj_skip_from_memory(1, &dd)); 299 EXPECT_EQ(1u, opj_skip_from_memory(1, &dd));
300 EXPECT_EQ(1u, opj_read_from_memory(buffer, 1, &dd)); 300 EXPECT_EQ(1u, opj_read_from_memory(buffer, 1, &dd));
301 EXPECT_EQ(0x01, buffer[0]); 301 EXPECT_EQ(0x01, buffer[0]);
302 EXPECT_EQ(0xbd, buffer[1]); 302 EXPECT_EQ(0xbd, buffer[1]);
303 303
304 // Skiping 0 bytes changes nothing. 304 // Skiping 0 bytes changes nothing.
305 memset(buffer, 0xbd, sizeof(buffer)); 305 memset(buffer, 0xbd, sizeof(buffer));
306 EXPECT_EQ(0, opj_skip_from_memory(0, &dd)); 306 EXPECT_EQ(0, opj_skip_from_memory(0, &dd));
307 EXPECT_EQ(1u, opj_read_from_memory(buffer, 1, &dd)); 307 EXPECT_EQ(1u, opj_read_from_memory(buffer, 1, &dd));
308 EXPECT_EQ(0x02, buffer[0]); 308 EXPECT_EQ(0x02, buffer[0]);
309 EXPECT_EQ(0xbd, buffer[1]); 309 EXPECT_EQ(0xbd, buffer[1]);
310 310
311 // Skiping to EOS-1 is possible. 311 // Skiping to EOS-1 is possible.
312 memset(buffer, 0xbd, sizeof(buffer)); 312 memset(buffer, 0xbd, sizeof(buffer));
313 EXPECT_EQ(4, opj_skip_from_memory(4, &dd)); 313 EXPECT_EQ(4u, opj_skip_from_memory(4, &dd));
314 EXPECT_EQ(1u, opj_read_from_memory(buffer, 1, &dd)); 314 EXPECT_EQ(1u, opj_read_from_memory(buffer, 1, &dd));
315 EXPECT_EQ(0x87, buffer[0]); 315 EXPECT_EQ(0x87, buffer[0]);
316 EXPECT_EQ(0xbd, buffer[1]); 316 EXPECT_EQ(0xbd, buffer[1]);
317 317
318 // Next read fails. 318 // Next read fails.
319 memset(buffer, 0xbd, sizeof(buffer)); 319 memset(buffer, 0xbd, sizeof(buffer));
320 EXPECT_EQ(kReadError, opj_read_from_memory(buffer, 1, &dd)); 320 EXPECT_EQ(kReadError, opj_read_from_memory(buffer, 1, &dd));
321 EXPECT_EQ(0xbd, buffer[0]); 321 EXPECT_EQ(0xbd, buffer[0]);
322 } 322 }
323 { 323 {
324 DecodeData dd(stream_data, sizeof(stream_data)); 324 DecodeData dd(stream_data, sizeof(stream_data));
325 325
326 // Skiping directly to EOS is allowed. 326 // Skiping directly to EOS is allowed.
327 memset(buffer, 0xbd, sizeof(buffer)); 327 memset(buffer, 0xbd, sizeof(buffer));
328 EXPECT_EQ(8, opj_skip_from_memory(8, &dd)); 328 EXPECT_EQ(8u, opj_skip_from_memory(8, &dd));
329 329
330 // Next read fails. 330 // Next read fails.
331 EXPECT_EQ(kReadError, opj_read_from_memory(buffer, 1, &dd)); 331 EXPECT_EQ(kReadError, opj_read_from_memory(buffer, 1, &dd));
332 EXPECT_EQ(0xbd, buffer[0]); 332 EXPECT_EQ(0xbd, buffer[0]);
333 } 333 }
334 { 334 {
335 DecodeData dd(stream_data, sizeof(stream_data)); 335 DecodeData dd(stream_data, sizeof(stream_data));
336 336
337 // Skipping beyond end of stream is allowed and returns full distance. 337 // Skipping beyond end of stream is allowed and returns full distance.
338 memset(buffer, 0xbd, sizeof(buffer)); 338 memset(buffer, 0xbd, sizeof(buffer));
339 EXPECT_EQ(9, opj_skip_from_memory(9, &dd)); 339 EXPECT_EQ(9u, opj_skip_from_memory(9, &dd));
340 340
341 // Next read fails. 341 // Next read fails.
342 EXPECT_EQ(kReadError, opj_read_from_memory(buffer, 1, &dd)); 342 EXPECT_EQ(kReadError, opj_read_from_memory(buffer, 1, &dd));
343 EXPECT_EQ(0xbd, buffer[0]); 343 EXPECT_EQ(0xbd, buffer[0]);
344 } 344 }
345 { 345 {
346 DecodeData dd(stream_data, sizeof(stream_data)); 346 DecodeData dd(stream_data, sizeof(stream_data));
347 347
348 // Skipping way beyond EOS is allowd, doesn't wrap, and returns 348 // Skipping way beyond EOS is allowd, doesn't wrap, and returns
349 // full distance. 349 // full distance.
350 memset(buffer, 0xbd, sizeof(buffer)); 350 memset(buffer, 0xbd, sizeof(buffer));
351 EXPECT_EQ(4, opj_skip_from_memory(4, &dd)); 351 EXPECT_EQ(4u, opj_skip_from_memory(4, &dd));
352 EXPECT_EQ(std::numeric_limits<OPJ_OFF_T>::max(), 352 EXPECT_EQ(std::numeric_limits<OPJ_OFF_T>::max(),
353 opj_skip_from_memory(std::numeric_limits<OPJ_OFF_T>::max(), &dd)); 353 opj_skip_from_memory(std::numeric_limits<OPJ_OFF_T>::max(), &dd));
354 354
355 // Next read fails. If it succeeds, it may mean we wrapped. 355 // Next read fails. If it succeeds, it may mean we wrapped.
356 EXPECT_EQ(kReadError, opj_read_from_memory(buffer, 1, &dd)); 356 EXPECT_EQ(kReadError, opj_read_from_memory(buffer, 1, &dd));
357 EXPECT_EQ(0xbd, buffer[0]); 357 EXPECT_EQ(0xbd, buffer[0]);
358 } 358 }
359 { 359 {
360 DecodeData dd(stream_data, sizeof(stream_data)); 360 DecodeData dd(stream_data, sizeof(stream_data));
361 361
362 // Negative skip within buffer not is allowed, position unchanged. 362 // Negative skip within buffer not is allowed, position unchanged.
363 memset(buffer, 0xbd, sizeof(buffer)); 363 memset(buffer, 0xbd, sizeof(buffer));
364 EXPECT_EQ(4, opj_skip_from_memory(4, &dd)); 364 EXPECT_EQ(4u, opj_skip_from_memory(4, &dd));
365 EXPECT_EQ(kSkipError, opj_skip_from_memory(-2, &dd)); 365 EXPECT_EQ(kSkipError, opj_skip_from_memory(-2, &dd));
366 366
367 // Next read succeeds as if nothing has happenned. 367 // Next read succeeds as if nothing has happenned.
368 EXPECT_EQ(1u, opj_read_from_memory(buffer, 1, &dd)); 368 EXPECT_EQ(1u, opj_read_from_memory(buffer, 1, &dd));
369 EXPECT_EQ(0x84, buffer[0]); 369 EXPECT_EQ(0x84, buffer[0]);
370 EXPECT_EQ(0xbd, buffer[1]); 370 EXPECT_EQ(0xbd, buffer[1]);
371 371
372 // Negative skip before buffer is not allowed, position unchanged. 372 // Negative skip before buffer is not allowed, position unchanged.
373 memset(buffer, 0xbd, sizeof(buffer)); 373 memset(buffer, 0xbd, sizeof(buffer));
374 EXPECT_EQ(kSkipError, opj_skip_from_memory(-4, &dd)); 374 EXPECT_EQ(kSkipError, opj_skip_from_memory(-4, &dd));
375 375
376 // Next read succeeds as if nothing has happenned. 376 // Next read succeeds as if nothing has happenned.
377 EXPECT_EQ(1u, opj_read_from_memory(buffer, 1, &dd)); 377 EXPECT_EQ(1u, opj_read_from_memory(buffer, 1, &dd));
378 EXPECT_EQ(0x85, buffer[0]); 378 EXPECT_EQ(0x85, buffer[0]);
379 EXPECT_EQ(0xbd, buffer[1]); 379 EXPECT_EQ(0xbd, buffer[1]);
380 } 380 }
381 { 381 {
382 DecodeData dd(stream_data, sizeof(stream_data)); 382 DecodeData dd(stream_data, sizeof(stream_data));
383 383
384 // Negative skip way before buffer is not allowed, doesn't wrap 384 // Negative skip way before buffer is not allowed, doesn't wrap
385 memset(buffer, 0xbd, sizeof(buffer)); 385 memset(buffer, 0xbd, sizeof(buffer));
386 EXPECT_EQ(4, opj_skip_from_memory(4, &dd)); 386 EXPECT_EQ(4u, opj_skip_from_memory(4, &dd));
387 EXPECT_EQ(kSkipError, 387 EXPECT_EQ(kSkipError,
388 opj_skip_from_memory(std::numeric_limits<OPJ_OFF_T>::min(), &dd)); 388 opj_skip_from_memory(std::numeric_limits<OPJ_OFF_T>::min(), &dd));
389 389
390 // Next read succeeds. If it fails, it may mean we wrapped. 390 // Next read succeeds. If it fails, it may mean we wrapped.
391 EXPECT_EQ(1, opj_read_from_memory(buffer, 1, &dd)); 391 EXPECT_EQ(1u, opj_read_from_memory(buffer, 1, &dd));
392 EXPECT_EQ(0x84, buffer[0]); 392 EXPECT_EQ(0x84, buffer[0]);
393 EXPECT_EQ(0xbd, buffer[1]); 393 EXPECT_EQ(0xbd, buffer[1]);
394 } 394 }
395 { 395 {
396 DecodeData dd(stream_data, sizeof(stream_data)); 396 DecodeData dd(stream_data, sizeof(stream_data));
397 397
398 // Negative skip after EOS isn't alowed, still EOS. 398 // Negative skip after EOS isn't alowed, still EOS.
399 memset(buffer, 0xbd, sizeof(buffer)); 399 memset(buffer, 0xbd, sizeof(buffer));
400 EXPECT_EQ(8, opj_skip_from_memory(8, &dd)); 400 EXPECT_EQ(8u, opj_skip_from_memory(8, &dd));
401 EXPECT_EQ(kSkipError, opj_skip_from_memory(-4, &dd)); 401 EXPECT_EQ(kSkipError, opj_skip_from_memory(-4, &dd));
402 402
403 // Next read fails. 403 // Next read fails.
404 EXPECT_EQ(kReadError, opj_read_from_memory(buffer, 1, &dd)); 404 EXPECT_EQ(kReadError, opj_read_from_memory(buffer, 1, &dd));
405 EXPECT_EQ(0xbd, buffer[0]); 405 EXPECT_EQ(0xbd, buffer[0]);
406 } 406 }
407 } 407 }
408 408
409 TEST(fxcodec, DecodeDataSeek) { 409 TEST(fxcodec, DecodeDataSeek) {
410 unsigned char buffer[16]; 410 unsigned char buffer[16];
411 DecodeData dd(stream_data, sizeof(stream_data)); 411 DecodeData dd(stream_data, sizeof(stream_data));
412 412
413 // Seeking within buffer is allowed and read succeeds 413 // Seeking within buffer is allowed and read succeeds
414 memset(buffer, 0xbd, sizeof(buffer)); 414 memset(buffer, 0xbd, sizeof(buffer));
415 EXPECT_TRUE(opj_seek_from_memory(1, &dd)); 415 EXPECT_TRUE(opj_seek_from_memory(1, &dd));
416 EXPECT_EQ(1u, opj_read_from_memory(buffer, 1, &dd)); 416 EXPECT_EQ(1u, opj_read_from_memory(buffer, 1, &dd));
417 EXPECT_EQ(0x01, buffer[0]); 417 EXPECT_EQ(0x01, buffer[0]);
418 EXPECT_EQ(0xbd, buffer[1]); 418 EXPECT_EQ(0xbd, buffer[1]);
419 419
420 // Seeking before start returns error leaving position unchanged. 420 // Seeking before start returns error leaving position unchanged.
421 memset(buffer, 0xbd, sizeof(buffer)); 421 memset(buffer, 0xbd, sizeof(buffer));
422 EXPECT_FALSE(opj_seek_from_memory(-1, &dd)); 422 EXPECT_FALSE(opj_seek_from_memory(-1, &dd));
423 EXPECT_EQ(1, opj_read_from_memory(buffer, 1, &dd)); 423 EXPECT_EQ(1u, opj_read_from_memory(buffer, 1, &dd));
424 EXPECT_EQ(0x02, buffer[0]); 424 EXPECT_EQ(0x02, buffer[0]);
425 EXPECT_EQ(0xbd, buffer[1]); 425 EXPECT_EQ(0xbd, buffer[1]);
426 426
427 // Seeking way before start returns error leaving position unchanged. 427 // Seeking way before start returns error leaving position unchanged.
428 memset(buffer, 0xbd, sizeof(buffer)); 428 memset(buffer, 0xbd, sizeof(buffer));
429 EXPECT_FALSE( 429 EXPECT_FALSE(
430 opj_seek_from_memory(std::numeric_limits<OPJ_OFF_T>::min(), &dd)); 430 opj_seek_from_memory(std::numeric_limits<OPJ_OFF_T>::min(), &dd));
431 EXPECT_EQ(1, opj_read_from_memory(buffer, 1, &dd)); 431 EXPECT_EQ(1u, opj_read_from_memory(buffer, 1, &dd));
432 EXPECT_EQ(0x03, buffer[0]); 432 EXPECT_EQ(0x03, buffer[0]);
433 EXPECT_EQ(0xbd, buffer[1]); 433 EXPECT_EQ(0xbd, buffer[1]);
434 434
435 // Seeking exactly to EOS is allowed but read fails. 435 // Seeking exactly to EOS is allowed but read fails.
436 memset(buffer, 0xbd, sizeof(buffer)); 436 memset(buffer, 0xbd, sizeof(buffer));
437 EXPECT_TRUE(opj_seek_from_memory(8, &dd)); 437 EXPECT_TRUE(opj_seek_from_memory(8, &dd));
438 EXPECT_EQ(kReadError, opj_read_from_memory(buffer, 1, &dd)); 438 EXPECT_EQ(kReadError, opj_read_from_memory(buffer, 1, &dd));
439 EXPECT_EQ(0xbd, buffer[0]); 439 EXPECT_EQ(0xbd, buffer[0]);
440 440
441 // Seeking back to zero offset is allowed and read succeeds. 441 // Seeking back to zero offset is allowed and read succeeds.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 opj_image_t img; 491 opj_image_t img;
492 memset(&img, 0, sizeof(img)); 492 memset(&img, 0, sizeof(img));
493 img.numcomps = 3; 493 img.numcomps = 3;
494 img.color_space = OPJ_CLRSPC_SYCC; 494 img.color_space = OPJ_CLRSPC_SYCC;
495 img.comps = FX_Alloc(opj_image_comp_t, 3); 495 img.comps = FX_Alloc(opj_image_comp_t, 3);
496 const struct { 496 const struct {
497 OPJ_UINT32 w; 497 OPJ_UINT32 w;
498 bool expected; 498 bool expected;
499 } cases[] = {{0, false}, {1, false}, {30, false}, {31, true}, 499 } cases[] = {{0, false}, {1, false}, {30, false}, {31, true},
500 {32, true}, {33, false}, {34, false}, {UINT_MAX, false}}; 500 {32, true}, {33, false}, {34, false}, {UINT_MAX, false}};
501 for (int i = 0; i < sizeof(cases) / sizeof(cases[0]); ++i) { 501 for (size_t i = 0; i < sizeof(cases) / sizeof(cases[0]); ++i) {
502 y.w = cases[i].w; 502 y.w = cases[i].w;
503 y.h = y.w; 503 y.h = y.w;
504 img.x1 = y.w; 504 img.x1 = y.w;
505 img.y1 = y.h; 505 img.y1 = y.h;
506 y.data = FX_Alloc(OPJ_INT32, y.w * y.h); 506 y.data = FX_Alloc(OPJ_INT32, y.w * y.h);
507 memset(y.data, 1, y.w * y.h * sizeof(OPJ_INT32)); 507 memset(y.data, 1, y.w * y.h * sizeof(OPJ_INT32));
508 u.data = FX_Alloc(OPJ_INT32, u.w * u.h); 508 u.data = FX_Alloc(OPJ_INT32, u.w * u.h);
509 memset(u.data, 0, u.w * u.h * sizeof(OPJ_INT32)); 509 memset(u.data, 0, u.w * u.h * sizeof(OPJ_INT32));
510 v.data = FX_Alloc(OPJ_INT32, v.w * v.h); 510 v.data = FX_Alloc(OPJ_INT32, v.w * v.h);
511 memset(v.data, 0, v.w * v.h * sizeof(OPJ_INT32)); 511 memset(v.data, 0, v.w * v.h * sizeof(OPJ_INT32));
(...skipping 11 matching lines...) Expand all
523 EXPECT_NE(img.comps[0].h, img.comps[1].h); 523 EXPECT_NE(img.comps[0].h, img.comps[1].h);
524 EXPECT_NE(img.comps[0].w, img.comps[2].w); 524 EXPECT_NE(img.comps[0].w, img.comps[2].w);
525 EXPECT_NE(img.comps[0].h, img.comps[2].h); 525 EXPECT_NE(img.comps[0].h, img.comps[2].h);
526 } 526 }
527 FX_Free(img.comps[0].data); 527 FX_Free(img.comps[0].data);
528 FX_Free(img.comps[1].data); 528 FX_Free(img.comps[1].data);
529 FX_Free(img.comps[2].data); 529 FX_Free(img.comps[2].data);
530 } 530 }
531 FX_Free(img.comps); 531 FX_Free(img.comps);
532 } 532 }
OLDNEW
« no previous file with comments | « core/fpdftext/fpdf_text_int_unittest.cpp ('k') | core/fxcrt/fx_basic_gcc_unittest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698