From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> To: ffmpeg-devel@ffmpeg.org Cc: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Subject: [FFmpeg-devel] [PATCH] avutil/tests/dict: Explicitly test av_dict_iterate() Date: Sat, 3 Dec 2022 18:25:04 +0100 Message-ID: <GV1P250MB07374B410C76CAC0F061E9248F169@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM> (raw) This commit tests it in a way that automatically checks that using av_dict_iterate() is equivalent to using av_dict_get() with key "" and AV_DICT_IGNORE_SUFFIX. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavutil/tests/dict.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/libavutil/tests/dict.c b/libavutil/tests/dict.c index 91567289c2..bececefb31 100644 --- a/libavutil/tests/dict.c +++ b/libavutil/tests/dict.c @@ -20,10 +20,30 @@ #include "libavutil/dict.c" +static const AVDictionaryEntry *dict_iterate(const AVDictionary *m, + const AVDictionaryEntry *prev) +{ + const AVDictionaryEntry *dict_get = av_dict_get(m, "", prev, AV_DICT_IGNORE_SUFFIX); + const AVDictionaryEntry *dict_iterate = av_dict_iterate(m, prev); + + if (dict_get != dict_iterate) { +#define GET(entry, mem) ((entry) ? (entry)->mem : "N/A") + printf("Iterating with av_dict_iterate() yields a different result " + "than iterating with av_dict_get() and AV_DICT_IGNORE_SUFFIX " + "(prev: %p, key %s; av_dict_iterate() %p, key %s, value %s; " + "av_dict_get() %p, key %s, value %s)\n", + prev, GET(prev, key), + dict_iterate, GET(dict_iterate, key), GET(dict_iterate, value), + dict_get, GET(dict_get, key), GET(dict_get, value)); +#undef GET + } + return dict_iterate; +} + static void print_dict(const AVDictionary *m) { - AVDictionaryEntry *t = NULL; - while ((t = av_dict_get(m, "", t, AV_DICT_IGNORE_SUFFIX))) + const AVDictionaryEntry *t = NULL; + while ((t = dict_iterate(m, t))) printf("%s %s ", t->key, t->value); printf("\n"); } @@ -94,7 +114,7 @@ int main(void) if (av_dict_get(dict, NULL, NULL, 0)) printf("av_dict_get() does not correctly handle NULL key.\n"); e = NULL; - while ((e = av_dict_get(dict, "", e, AV_DICT_IGNORE_SUFFIX))) + while ((e = dict_iterate(dict, e))) printf("%s %s\n", e->key, e->value); av_dict_free(&dict); @@ -106,7 +126,7 @@ int main(void) printf("av_dict_set does not correctly handle NULL key\n"); e = NULL; - while ((e = av_dict_get(dict, "", e, AV_DICT_IGNORE_SUFFIX))) + while ((e = dict_iterate(dict, e))) printf("'%s' '%s'\n", e->key, e->value); av_dict_free(&dict); @@ -122,7 +142,7 @@ int main(void) av_dict_set_int(&dict, "12", 1, 0); av_dict_set_int(&dict, "12", 2, AV_DICT_APPEND); e = NULL; - while ((e = av_dict_get(dict, "", e, AV_DICT_IGNORE_SUFFIX))) + while ((e = dict_iterate(dict, e))) printf("%s %s\n", e->key, e->value); av_dict_free(&dict); -- 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 reply other threads:[~2022-12-03 17:25 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-12-03 17:25 Andreas Rheinhardt [this message] 2022-12-05 6:23 ` 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=GV1P250MB07374B410C76CAC0F061E9248F169@GV1P250MB0737.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