diff mbox series

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

Message ID 20240413142128.2889-1-jamrial@gmail.com
State New
Headers show
Series [FFmpeg-devel,1/2] avutil/test/opt: test the AV_OPT_SERIALIZE_SKIP_DEFAULTS flag | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

James Almer April 13, 2024, 2:21 p.m. UTC
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavutil/tests/opt.c | 29 +++++++++++++++++++++++++++++
 tests/ref/fate/opt    |  4 ++++
 2 files changed, 33 insertions(+)
diff mbox series

Patch

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'