]> git.sesse.net Git - ffmpeg/blobdiff - libavutil/tests/opt.c
x86/tx_float: Fixes compilation with old yasm
[ffmpeg] / libavutil / tests / opt.c
index f4cfa590aa9a0e8b8951e3d41b05c73b7ba0ebc2..3134ffd354d8d08a47d20e9a45def54db6577da7 100644 (file)
@@ -55,6 +55,8 @@ typedef struct TestContext {
     int bool1;
     int bool2;
     int bool3;
+    AVDictionary *dict1;
+    AVDictionary *dict2;
 } TestContext;
 
 #define OFFSET(x) offsetof(TestContext, x)
@@ -89,6 +91,8 @@ static const AVOption test_options[]= {
     {"bool1",      "set boolean value",  OFFSET(bool1),          AV_OPT_TYPE_BOOL,           { .i64 = -1 },                    -1,         1, 1 },
     {"bool2",      "set boolean value",  OFFSET(bool2),          AV_OPT_TYPE_BOOL,           { .i64 = 1 },                     -1,         1, 1 },
     {"bool3",      "set boolean value",  OFFSET(bool3),          AV_OPT_TYPE_BOOL,           { .i64 = 0 },                      0,         1, 1 },
+    {"dict1",      "set dictionary value", OFFSET(dict1),        AV_OPT_TYPE_DICT,           { .str = NULL},                    0,         0, 1 },
+    {"dict2",      "set dictionary value", OFFSET(dict2),        AV_OPT_TYPE_DICT,           { .str = "happy=':-)'"},           0,         0, 1 },
     { NULL },
 };
 
@@ -167,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 };
@@ -256,6 +301,7 @@ int main(void)
             "dbl=101",
             "bool1=true",
             "bool2=auto",
+            "dict1='happy=\\:-):sad=\\:-('",
         };
 
         test_ctx.class = &test_class;