[FFmpeg-devel] [PATCH 3/3] avutil/tests/opt: test av_opt_find2()

James Almer jamrial at gmail.com
Sat Apr 13 17:21:28 EEST 2024


Signed-off-by: James Almer <jamrial at gmail.com>
---
 libavutil/tests/opt.c | 29 +++++++++++++++++++++++++++++
 tests/ref/fate/opt    |  4 ++++
 2 files changed, 33 insertions(+)

diff --git a/libavutil/tests/opt.c b/libavutil/tests/opt.c
index bac0e80bd5..dc968567eb 100644
--- a/libavutil/tests/opt.c
+++ b/libavutil/tests/opt.c
@@ -452,5 +452,34 @@ 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;
+        test_ctx.child = &child_ctx;
+        child_ctx.class = &child_class;
+        av_opt_set_defaults(&test_ctx);
+        av_opt_set_defaults(&child_ctx);
+
+        av_log_set_level(AV_LOG_QUIET);
+
+        opt = av_opt_find2(&test_ctx, "num", NULL, 0, 0, &target);
+        if (opt && target == &test_ctx)
+            printf("OK    '%s'\n", opt->name);
+        else
+            printf("Error '%s'\n", "num");
+
+        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 '%s'\n", "child_num");
+        av_opt_free(&test_ctx);
+    }
+
     return 0;
 }
diff --git a/tests/ref/fate/opt b/tests/ref/fate/opt
index 05d57066a1..39659b2248 100644
--- a/tests/ref/fate/opt
+++ b/tests/ref/fate/opt
@@ -449,3 +449,7 @@ 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'
+OK    'child_num'
-- 
2.44.0



More information about the ffmpeg-devel mailing list