Changeset aaf962e6 in mainline for uspace/lib/riff/test/chunk.c
- Timestamp:
- 2020-09-21T21:41:53Z (4 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ea459d4
- Parents:
- d145ecb
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/riff/test/chunk.c
rd145ecb raaf962e6 327 327 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 328 328 329 //(void) remove(p);329 (void) remove(p); 330 330 } 331 331 332 /** Match specific chunk type in a RIFF file */ 333 PCUT_TEST(match_chunk) 334 { 335 char fname[L_tmpnam]; 336 char *p; 337 riffw_t *rw; 338 riffr_t *rr; 339 riff_wchunk_t wriffck; 340 riff_wchunk_t wdatack; 341 riff_rchunk_t rriffck; 342 riff_rchunk_t rdatack; 343 uint32_t rword; 344 errno_t rc; 345 346 p = tmpnam(fname); 347 PCUT_ASSERT_NOT_NULL(p); 348 349 /* Write RIFF file */ 350 351 rc = riff_wopen(p, &rw); 352 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 353 PCUT_ASSERT_NOT_NULL(rw); 354 355 rc = riff_wchunk_start(rw, CKID_RIFF, &wriffck); 356 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 357 358 /* Write first data chunk */ 359 360 rc = riff_wchunk_start(rw, CKID_dat1, &wdatack); 361 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 362 363 rc = riff_write_uint32(rw, 1); 364 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 365 366 rc = riff_wchunk_end(rw, &wdatack); 367 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 368 369 /* Write second data chunk */ 370 371 rc = riff_wchunk_start(rw, CKID_dat2, &wdatack); 372 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 373 374 rc = riff_write_uint32(rw, 2); 375 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 376 377 rc = riff_wchunk_end(rw, &wdatack); 378 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 379 380 /* Write third data chunk */ 381 382 rc = riff_wchunk_start(rw, CKID_dat1, &wdatack); 383 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 384 385 rc = riff_write_uint32(rw, 3); 386 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 387 388 rc = riff_wchunk_end(rw, &wdatack); 389 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 390 391 rc = riff_wchunk_end(rw, &wriffck); 392 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 393 394 rc = riff_wclose(rw); 395 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 396 397 /* Read back RIFF file */ 398 399 rc = riff_ropen(p, &rriffck, &rr); 400 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 401 PCUT_ASSERT_NOT_NULL(rr); 402 403 PCUT_ASSERT_INT_EQUALS(CKID_RIFF, rriffck.ckid); 404 405 /* Match second data chunk */ 406 407 rc = riff_rchunk_match(&rriffck, CKID_dat2, &rdatack); 408 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 409 PCUT_ASSERT_INT_EQUALS(CKID_dat2, rdatack.ckid); 410 411 rc = riff_read_uint32(&rdatack, &rword); 412 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 413 414 PCUT_ASSERT_INT_EQUALS(2, rword); 415 416 rc = riff_rchunk_end(&rdatack); 417 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 418 419 /* Try matching dat2 again (should not match) */ 420 421 rc = riff_rchunk_match(&rriffck, CKID_dat2, &rdatack); 422 PCUT_ASSERT_ERRNO_VAL(ENOENT, rc); 423 424 /* Try matching dat1 again (but there's nothing left) */ 425 426 rc = riff_rchunk_match(&rriffck, CKID_dat1, &rdatack); 427 PCUT_ASSERT_ERRNO_VAL(ENOENT, rc); 428 429 rc = riff_rclose(rr); 430 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 431 432 (void) remove(p); 433 } 434 435 /** Match specific LIST chunk type in a RIFF file */ 436 PCUT_TEST(list_match) 437 { 438 char fname[L_tmpnam]; 439 char *p; 440 riffw_t *rw; 441 riffr_t *rr; 442 riff_wchunk_t wriffck; 443 riff_wchunk_t wdatack; 444 riff_rchunk_t rriffck; 445 riff_rchunk_t rdatack; 446 uint32_t rword; 447 errno_t rc; 448 449 p = tmpnam(fname); 450 PCUT_ASSERT_NOT_NULL(p); 451 452 /* Write RIFF file */ 453 454 rc = riff_wopen(p, &rw); 455 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 456 PCUT_ASSERT_NOT_NULL(rw); 457 458 rc = riff_wchunk_start(rw, CKID_RIFF, &wriffck); 459 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 460 461 /* Write first LIST chunk */ 462 463 rc = riff_wchunk_start(rw, CKID_LIST, &wdatack); 464 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 465 466 rc = riff_write_uint32(rw, LTYPE_lst1); 467 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 468 469 rc = riff_write_uint32(rw, 1); 470 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 471 472 rc = riff_wchunk_end(rw, &wdatack); 473 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 474 475 /* Write second data chunk */ 476 477 rc = riff_wchunk_start(rw, CKID_LIST, &wdatack); 478 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 479 480 rc = riff_write_uint32(rw, LTYPE_lst2); 481 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 482 483 rc = riff_write_uint32(rw, 2); 484 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 485 486 rc = riff_wchunk_end(rw, &wdatack); 487 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 488 489 /* Write third data chunk */ 490 491 rc = riff_wchunk_start(rw, CKID_LIST, &wdatack); 492 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 493 494 rc = riff_write_uint32(rw, LTYPE_lst1); 495 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 496 497 rc = riff_write_uint32(rw, 3); 498 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 499 500 rc = riff_wchunk_end(rw, &wdatack); 501 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 502 503 rc = riff_wchunk_end(rw, &wriffck); 504 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 505 506 rc = riff_wclose(rw); 507 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 508 509 /* Read back RIFF file */ 510 511 rc = riff_ropen(p, &rriffck, &rr); 512 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 513 PCUT_ASSERT_NOT_NULL(rr); 514 515 PCUT_ASSERT_INT_EQUALS(CKID_RIFF, rriffck.ckid); 516 517 /* Match second LIST chunk */ 518 519 rc = riff_rchunk_list_match(&rriffck, LTYPE_lst2, &rdatack); 520 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 521 522 rc = riff_read_uint32(&rdatack, &rword); 523 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 524 525 PCUT_ASSERT_INT_EQUALS(2, rword); 526 527 rc = riff_rchunk_end(&rdatack); 528 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 529 530 /* Try matching lst2 again (should not match) */ 531 532 rc = riff_rchunk_list_match(&rriffck, LTYPE_lst2, &rdatack); 533 PCUT_ASSERT_ERRNO_VAL(ENOENT, rc); 534 535 /* Try matching lst1 again (but there's nothing left) */ 536 537 rc = riff_rchunk_list_match(&rriffck, LTYPE_lst1, &rdatack); 538 PCUT_ASSERT_ERRNO_VAL(ENOENT, rc); 539 540 rc = riff_rclose(rr); 541 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 542 543 (void) remove(p); 544 } 545 332 546 PCUT_EXPORT(chunk);
Note:
See TracChangeset
for help on using the changeset viewer.