From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
To: ffmpeg-devel@ffmpeg.org
Cc: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Subject: [FFmpeg-devel] [PATCH 4/7] avutil/tests/channel_layout: Also test non-AVBPrint variants
Date: Sun, 6 Aug 2023 12:13:20 +0200
Message-ID: <AS8P250MB07442164D42BF0E4E78D560A8F0FA@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <AS8P250MB074479F01FF411D108D29EC68F0FA@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavutil/tests/channel_layout.c | 108 +++++++++++++++++++++++++------
1 file changed, 90 insertions(+), 18 deletions(-)
diff --git a/libavutil/tests/channel_layout.c b/libavutil/tests/channel_layout.c
index 5516db0904..665ae6e277 100644
--- a/libavutil/tests/channel_layout.c
+++ b/libavutil/tests/channel_layout.c
@@ -19,32 +19,104 @@
*/
#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) \
- av_bprint_clear(&bp); \
- av_channel_name_bprint(&bp, x);
+ channel_name(&bp, (x));
#define CHANNEL_DESCRIPTION(x) \
- av_bprint_clear(&bp); \
- av_channel_description_bprint(&bp, x);
+ channel_description(&bp, (x));
#define CHANNEL_LAYOUT_FROM_MASK(x) \
- av_channel_layout_uninit(&layout); \
- 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");
+ channel_layout_from_mask(&layout, &bp, (x));
#define CHANNEL_LAYOUT_FROM_STRING(x) \
- av_channel_layout_uninit(&layout); \
- 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");
+ channel_layout_from_string(&layout, &bp, (x));
#define CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(x) \
ret = av_channel_layout_channel_from_index(&layout, x); \
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2023-08-06 10:12 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-06 10:10 [FFmpeg-devel] [PATCH 1/7] avutil/bprint: Don't use value of AV_BPRINT_SIZE_AUTOMATIC directly Andreas Rheinhardt
2023-08-06 10:13 ` [FFmpeg-devel] [PATCH 2/7] avutil/bprint: Allow size == 0 in av_bprint_init_for_buffer() Andreas Rheinhardt
2023-08-09 9:00 ` Andreas Rheinhardt
2023-08-09 10:08 ` Nicolas George
2023-08-09 11:32 ` James Almer
2023-08-09 12:58 ` Andreas Rheinhardt
2023-08-06 10:13 ` [FFmpeg-devel] [PATCH 3/7] avutil/channel_layout: Account for \0 in sizes Andreas Rheinhardt
2023-08-06 10:13 ` Andreas Rheinhardt [this message]
2023-08-06 10:13 ` [FFmpeg-devel] [PATCH 5/7] avutil/tests/channel_layout: Don't include lavu/channel_layout.c Andreas Rheinhardt
2023-08-06 10:13 ` [FFmpeg-devel] [PATCH 6/7] avutil/tests/channel_layout: Test av_channel_layout_copy() Andreas Rheinhardt
2023-08-06 10:13 ` [FFmpeg-devel] [PATCH 7/7] avcodec/amfenc: Fix declaration-after-statement warning Andreas Rheinhardt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=AS8P250MB07442164D42BF0E4E78D560A8F0FA@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM \
--to=andreas.rheinhardt@outlook.com \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git