[FFmpeg-cvslog] avutil/tests/opt: add av_opt_get/av_opt_set tests

Marton Balint git at videolan.org
Fri Dec 27 22:58:06 EET 2019


ffmpeg | branch: master | Marton Balint <cus at passwd.hu> | Wed Dec 25 21:07:41 2019 +0100| [a619787a9ca87e0c4566cf124d52d23974a440d9] | committer: Marton Balint

avutil/tests/opt: add av_opt_get/av_opt_set tests

Signed-off-by: Marton Balint <cus at passwd.hu>

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

 libavutil/tests/opt.c | 41 +++++++++++++++++++++++++++++++++++++++++
 tests/ref/fate/opt    | 26 ++++++++++++++++++++++++++
 2 files changed, 67 insertions(+)

diff --git a/libavutil/tests/opt.c b/libavutil/tests/opt.c
index 1173ae8eba..3134ffd354 100644
--- a/libavutil/tests/opt.c
+++ b/libavutil/tests/opt.c
@@ -171,6 +171,47 @@ int main(void)
         av_opt_free(&test_ctx);
     }
 
+    printf("\nTesting av_opt_get/av_opt_set()\n");
+    {
+        TestContext test_ctx = { 0 };
+        TestContext test2_ctx = { 0 };
+        const AVOption *o = NULL;
+        test_ctx.class = &test_class;
+        test2_ctx.class = &test_class;
+
+        av_log_set_level(AV_LOG_QUIET);
+
+        av_opt_set_defaults(&test_ctx);
+
+        while (o = av_opt_next(&test_ctx, o)) {
+            char *value1 = NULL;
+            char *value2 = NULL;
+            int ret1 = AVERROR_BUG;
+            int ret2 = AVERROR_BUG;
+            int ret3 = AVERROR_BUG;
+
+            if (o->type == AV_OPT_TYPE_CONST)
+                continue;
+
+            ret1 = av_opt_get(&test_ctx, o->name, 0, (uint8_t **)&value1);
+            if (ret1 >= 0) {
+                ret2 = av_opt_set(&test2_ctx, o->name, value1, 0);
+                if (ret2 >= 0)
+                    ret3 = av_opt_get(&test2_ctx, o->name, 0, (uint8_t **)&value2);
+            }
+
+            printf("name: %-11s get: %-16s set: %-16s get: %-16s %s\n", o->name,
+                    ret1 >= 0 ? value1 : av_err2str(ret1),
+                    ret2 >= 0 ? "OK" : av_err2str(ret2),
+                    ret3 >= 0 ? value2 : av_err2str(ret3),
+                    ret1 >= 0 && ret2 >= 0 && ret3 >= 0 && !strcmp(value1, value2) ? "OK" : "Mismatch");
+            av_free(value1);
+            av_free(value2);
+        }
+        av_opt_free(&test_ctx);
+        av_opt_free(&test2_ctx);
+    }
+
     printf("\nTest av_opt_serialize()\n");
     {
         TestContext test_ctx = { 0 };
diff --git a/tests/ref/fate/opt b/tests/ref/fate/opt
index 4054d32295..46ea0652f8 100644
--- a/tests/ref/fate/opt
+++ b/tests/ref/fate/opt
@@ -102,6 +102,32 @@ name:     bool3 default:1 error:
 name:     dict1 default:1 error:
 name:     dict2 default:1 error:
 
+Testing av_opt_get/av_opt_set()
+name: num         get: 0                set: OK               get: 0                OK
+name: toggle      get: 1                set: OK               get: 1                OK
+name: rational    get: 1/1              set: OK               get: 1/1              OK
+name: string      get: default          set: OK               get: default          OK
+name: escape      get: \=,              set: OK               get: \=,              OK
+name: flags       get: 0x00000001       set: OK               get: 0x00000001       OK
+name: size        get: 200x300          set: OK               get: 200x300          OK
+name: pix_fmt     get: 0bgr             set: OK               get: 0bgr             OK
+name: sample_fmt  get: s16              set: OK               get: s16              OK
+name: video_rate  get: 25/1             set: OK               get: 25/1             OK
+name: duration    get: 0.001            set: OK               get: 0.001            OK
+name: color       get: 0xffc0cbff       set: OK               get: 0xffc0cbff       OK
+name: cl          get: 0x137            set: OK               get: 0x137            OK
+name: bin         get: 62696E00         set: OK               get: 62696E00         OK
+name: bin1        get:                  set: OK               get:                  OK
+name: bin2        get:                  set: OK               get:                  OK
+name: num64       get: 1                set: OK               get: 1                OK
+name: flt         get: 0.333333         set: OK               get: 0.333333         OK
+name: dbl         get: 0.333333         set: OK               get: 0.333333         OK
+name: bool1       get: auto             set: OK               get: auto             OK
+name: bool2       get: true             set: OK               get: true             OK
+name: bool3       get: false            set: OK               get: false            OK
+name: dict1       get:                  set: OK               get:                  OK
+name: dict2       get: happy=\:-)       set: OK               get: happy=\:-)       OK
+
 Test av_opt_serialize()
 num=0,toggle=1,rational=1/1,string=default,escape=\\\=\,,flags=0x00000001,size=200x300,pix_fmt=0bgr,sample_fmt=s16,video_rate=25/1,duration=0.001,color=0xffc0cbff,cl=0x137,bin=62696E00,bin1=,bin2=,num64=1,flt=0.333333,dbl=0.333333,bool1=auto,bool2=true,bool3=false,dict1=,dict2=happy\=\\:-)
 Setting entry with key 'num' to value '0'



More information about the ffmpeg-cvslog mailing list