| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * This file is part of FFmpeg. | ||
| 3 | * | ||
| 4 | * FFmpeg is free software; you can redistribute it and/or | ||
| 5 | * modify it under the terms of the GNU Lesser General Public | ||
| 6 | * License as published by the Free Software Foundation; either | ||
| 7 | * version 2.1 of the License, or (at your option) any later version. | ||
| 8 | * | ||
| 9 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 12 | * Lesser General Public License for more details. | ||
| 13 | * | ||
| 14 | * You should have received a copy of the GNU Lesser General Public | ||
| 15 | * License along with FFmpeg; if not, write to the Free Software | ||
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 17 | */ | ||
| 18 | |||
| 19 | #include <limits.h> | ||
| 20 | #include <stdint.h> | ||
| 21 | #include <stdio.h> | ||
| 22 | |||
| 23 | #include "libavutil/mem.h" | ||
| 24 | #include "libavutil/tdrdi.h" | ||
| 25 | |||
| 26 | 1 | int main(void) | |
| 27 | { | ||
| 28 | AV3DReferenceDisplaysInfo *tdrdi; | ||
| 29 | AV3DReferenceDisplay *display; | ||
| 30 | size_t size; | ||
| 31 | |||
| 32 | /* av_tdrdi_alloc with 1 display */ | ||
| 33 | 1 | printf("Testing av_tdrdi_alloc()\n"); | |
| 34 | 1 | tdrdi = av_tdrdi_alloc(1, &size); | |
| 35 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (tdrdi) { |
| 36 | 1 | printf("alloc 1: size>0=%s, num_ref_displays=%u\n", | |
| 37 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | size > 0 ? "yes" : "no", tdrdi->num_ref_displays); |
| 38 | |||
| 39 | 1 | display = av_tdrdi_get_display(tdrdi, 0); | |
| 40 | /* pointer consistency check */ | ||
| 41 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if ((uint8_t *)display != (uint8_t *)tdrdi + tdrdi->entries_offset) |
| 42 | ✗ | printf("display 0: pointer inconsistent with entries_offset\n"); | |
| 43 | |||
| 44 | /* write and read back */ | ||
| 45 | 1 | display->exponent_ref_display_width = 3; | |
| 46 | 1 | display->mantissa_ref_display_width = 100; | |
| 47 | 1 | display->left_view_id = 0; | |
| 48 | 1 | display->right_view_id = 1; | |
| 49 | 1 | display = av_tdrdi_get_display(tdrdi, 0); | |
| 50 | 1 | printf("display 0: width_exp=%u width_man=%u left=%u right=%u\n", | |
| 51 | 1 | display->exponent_ref_display_width, | |
| 52 | 1 | display->mantissa_ref_display_width, | |
| 53 | 1 | display->left_view_id, display->right_view_id); | |
| 54 | 1 | av_free(tdrdi); | |
| 55 | } | ||
| 56 | |||
| 57 | /* alloc with multiple displays */ | ||
| 58 | 1 | printf("\nTesting multiple displays\n"); | |
| 59 | 1 | tdrdi = av_tdrdi_alloc(3, &size); | |
| 60 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (tdrdi) { |
| 61 | 1 | printf("alloc 3: num_ref_displays=%u\n", tdrdi->num_ref_displays); | |
| 62 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
|
4 | for (int i = 0; i < 3; i++) { |
| 63 | 3 | display = av_tdrdi_get_display(tdrdi, i); | |
| 64 | /* verify stride consistency */ | ||
| 65 | 3 | if ((uint8_t *)display != (uint8_t *)tdrdi + tdrdi->entries_offset + | |
| 66 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | (size_t)i * tdrdi->entry_size) |
| 67 | ✗ | printf("display %d: pointer inconsistent\n", i); | |
| 68 | 3 | display->exponent_ref_display_width = i + 1; | |
| 69 | } | ||
| 70 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
|
4 | for (int i = 0; i < 3; i++) { |
| 71 | 3 | display = av_tdrdi_get_display(tdrdi, i); | |
| 72 | 3 | printf("display %d: width_exp=%u\n", i, | |
| 73 | 3 | display->exponent_ref_display_width); | |
| 74 | } | ||
| 75 | 1 | av_free(tdrdi); | |
| 76 | } | ||
| 77 | |||
| 78 | /* alloc with NULL size */ | ||
| 79 | 1 | tdrdi = av_tdrdi_alloc(1, NULL); | |
| 80 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | printf("\nalloc (no size): %s\n", tdrdi ? "OK" : "FAIL"); |
| 81 | 1 | av_free(tdrdi); | |
| 82 | |||
| 83 | /* OOM paths via av_max_alloc */ | ||
| 84 | 1 | printf("\nTesting OOM paths\n"); | |
| 85 | 1 | av_max_alloc(1); | |
| 86 | 1 | tdrdi = av_tdrdi_alloc(1, &size); | |
| 87 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | printf("alloc OOM: %s\n", tdrdi ? "FAIL" : "OK"); |
| 88 | 1 | av_free(tdrdi); | |
| 89 | 1 | av_max_alloc(INT_MAX); | |
| 90 | |||
| 91 | 1 | return 0; | |
| 92 | } | ||
| 93 |