[FFmpeg-cvslog] avutil/tests/opt: test av_opt_find2()

James Almer git at videolan.org
Wed Apr 24 05:56:05 EEST 2024


ffmpeg | branch: master | James Almer <jamrial at gmail.com> | Sat Apr 13 11:18:30 2024 -0300| [855d4b52547b2f8fc38b400e5d18cf44e621e163] | committer: James Almer

avutil/tests/opt: test av_opt_find2()

Signed-off-by: James Almer <jamrial at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=855d4b52547b2f8fc38b400e5d18cf44e621e163
---

 libavutil/tests/opt.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 tests/ref/fate/opt    |  7 +++++++
 2 files changed, 56 insertions(+)

diff --git a/libavutil/tests/opt.c b/libavutil/tests/opt.c
index 32301ba842..d43391025a 100644
--- a/libavutil/tests/opt.c
+++ b/libavutil/tests/opt.c
@@ -409,5 +409,54 @@ int main(void)
         av_opt_free(&test_ctx);
     }
 
+    printf("\nTesting av_opt_find2()\n");
+    {
+        TestContext test_ctx = { 0 };
+        ChildContext child_ctx = { 0 };
+        void *target;
+        const AVOption *opt;
+
+        test_ctx.class = &test_class;
+        child_ctx.class = &child_class;
+        test_ctx.child = &child_ctx;
+
+        av_log_set_level(AV_LOG_QUIET);
+
+        // Should succeed. num exists and has opt_flags 1
+        opt = av_opt_find2(&test_ctx, "num", NULL, 1, 0, &target);
+        if (opt && target == &test_ctx)
+            printf("OK    '%s'\n", opt->name);
+        else
+            printf("Error 'num'\n");
+
+        // Should fail. num64 exists but has opt_flags 1, not 2
+        opt = av_opt_find(&test_ctx, "num64", NULL, 2, 0);
+        if (opt)
+            printf("OK    '%s'\n", opt->name);
+        else
+            printf("Error 'num64'\n");
+
+        // Should fail. child_num exists but in a child object we're not searching
+        opt = av_opt_find(&test_ctx, "child_num", NULL, 0, 0);
+        if (opt)
+            printf("OK    '%s'\n", opt->name);
+        else
+            printf("Error 'child_num'\n");
+
+        // Should succeed. child_num exists in a child object we're searching
+        opt = av_opt_find2(&test_ctx, "child_num", NULL, 0, AV_OPT_SEARCH_CHILDREN, &target);
+        if (opt && target == &child_ctx)
+            printf("OK    '%s'\n", opt->name);
+        else
+            printf("Error 'child_num'\n");
+
+        // Should fail. foo doesn't exist
+        opt = av_opt_find(&test_ctx, "foo", NULL, 0, 0);
+        if (opt)
+            printf("OK    '%s'\n", opt->name);
+        else
+            printf("Error 'foo'\n");
+    }
+
     return 0;
 }
diff --git a/tests/ref/fate/opt b/tests/ref/fate/opt
index 43bf0929a3..f780097622 100644
--- a/tests/ref/fate/opt
+++ b/tests/ref/fate/opt
@@ -449,3 +449,10 @@ Setting options string 'a_very_long_option_name_that_will_need_to_be_ellipsized_
 Setting 'a_very_long_option_name_that_will_need_to_be_ellipsized_around_here' to value '42'
 Option 'a_very_long_option_name_that_will_need_to_be_ellipsized_around_here' not found
 Error 'a_very_long_option_name_that_will_need_to_be_ellipsized_around_here=42'
+
+Testing av_opt_find2()
+OK    'num'
+Error 'num64'
+Error 'child_num'
+OK    'child_num'
+Error 'foo'



More information about the ffmpeg-cvslog mailing list