1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-28 20:53:54 +02:00

avutil/tests/channel_layout: Also test non-AVBPrint variants

Reviewed-by: Nicolas George <george@nsup.org>
Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt 2023-08-06 11:28:03 +02:00
parent c4f35ba808
commit fcaff9b495

View File

@ -19,32 +19,104 @@
*/ */
#include "libavutil/channel_layout.c" #include "libavutil/channel_layout.c"
#include "libavutil/mem.h"
#define BPRINT_ARGS1(bp, ...) (bp), __VA_ARGS__
#define BPRINT_ARGS0(bp, ...) __VA_ARGS__, (bp)
#define ORD_ARGS1(str, size, ...) (str), (size), __VA_ARGS__
#define ORD_ARGS0(str, size, ...) __VA_ARGS__, (str), (size)
// This macro presumes the AVBPrint to have been cleared before usage.
#define CMP_BPRINT_AND_NONBPRINT(bp, func_name, ARG_ORDER, ...) do { \
char *str; \
int size; \
func_name ## _bprint(BPRINT_ARGS ## ARG_ORDER((bp), __VA_ARGS__)); \
if (strlen((bp)->str) != (bp)->len) { \
printf("strlen of AVBPrint-string returned by "#func_name"_bprint" \
" differs from AVBPrint.len: %"SIZE_SPECIFIER" vs. %u\n", \
strlen((bp)->str), (bp)->len); \
break; \
} \
size = func_name(ORD_ARGS ## ARG_ORDER(NULL, 0, __VA_ARGS__)); \
if (size <= 0) { \
printf(#func_name " returned %d\n", size); \
break; \
} \
if ((bp)->len != size - 1) { \
printf("Return value %d of " #func_name " inconsistent with length"\
" %u obtained from corresponding bprint version\n", \
size, (bp)->len); \
break; \
} \
str = av_malloc(size); \
if (!str) { \
printf("string of size %d could not be allocated.\n", size); \
break; \
} \
size = func_name(ORD_ARGS ## ARG_ORDER(str, size, __VA_ARGS__)); \
if (size <= 0 || (bp)->len != size - 1) { \
printf("Return value %d of " #func_name " inconsistent with length"\
" %d obtained in first pass.\n", size, (bp)->len); \
av_free(str); \
break; \
} \
if (strcmp(str, (bp)->str)) { \
printf("Ordinary and _bprint versions of "#func_name" disagree: " \
"'%s' vs. '%s'\n", str, (bp)->str); \
av_free(str); \
break; \
} \
av_free(str); \
} while (0)
static void channel_name(AVBPrint *bp, enum AVChannel channel)
{
av_bprint_clear(bp);
CMP_BPRINT_AND_NONBPRINT(bp, av_channel_name, 1, channel);
}
static void channel_description(AVBPrint *bp, enum AVChannel channel)
{
av_bprint_clear(bp);
CMP_BPRINT_AND_NONBPRINT(bp, av_channel_description, 1, channel);
}
static void channel_layout_from_mask(AVChannelLayout *layout,
AVBPrint *bp, uint64_t channel_layout)
{
av_channel_layout_uninit(layout);
av_bprint_clear(bp);
if (!av_channel_layout_from_mask(layout, channel_layout) &&
av_channel_layout_check(layout))
CMP_BPRINT_AND_NONBPRINT(bp, av_channel_layout_describe, 0, layout);
else
av_bprintf(bp, "fail");
}
static void channel_layout_from_string(AVChannelLayout *layout,
AVBPrint *bp, const char *channel_layout)
{
av_channel_layout_uninit(layout);
av_bprint_clear(bp);
if (!av_channel_layout_from_string(layout, channel_layout) &&
av_channel_layout_check(layout))
CMP_BPRINT_AND_NONBPRINT(bp, av_channel_layout_describe, 0, layout);
else
av_bprintf(bp, "fail");
}
#define CHANNEL_NAME(x) \ #define CHANNEL_NAME(x) \
av_bprint_clear(&bp); \ channel_name(&bp, (x));
av_channel_name_bprint(&bp, x);
#define CHANNEL_DESCRIPTION(x) \ #define CHANNEL_DESCRIPTION(x) \
av_bprint_clear(&bp); \ channel_description(&bp, (x));
av_channel_description_bprint(&bp, x);
#define CHANNEL_LAYOUT_FROM_MASK(x) \ #define CHANNEL_LAYOUT_FROM_MASK(x) \
av_channel_layout_uninit(&layout); \ channel_layout_from_mask(&layout, &bp, (x));
av_bprint_clear(&bp); \
if (!av_channel_layout_from_mask(&layout, x) && \
av_channel_layout_check(&layout)) \
av_channel_layout_describe_bprint(&layout, &bp); \
else \
av_bprintf(&bp, "fail");
#define CHANNEL_LAYOUT_FROM_STRING(x) \ #define CHANNEL_LAYOUT_FROM_STRING(x) \
av_channel_layout_uninit(&layout); \ channel_layout_from_string(&layout, &bp, (x));
av_bprint_clear(&bp); \
if (!av_channel_layout_from_string(&layout, x) && \
av_channel_layout_check(&layout)) \
av_channel_layout_describe_bprint(&layout, &bp); \
else \
av_bprintf(&bp, "fail");
#define CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(x) \ #define CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(x) \
ret = av_channel_layout_channel_from_index(&layout, x); \ ret = av_channel_layout_channel_from_index(&layout, x); \