diff options
Diffstat (limited to 'libavutil/tests/opt.c')
-rw-r--r-- | libavutil/tests/opt.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/libavutil/tests/opt.c b/libavutil/tests/opt.c index e2582cc93d..37437320cf 100644 --- a/libavutil/tests/opt.c +++ b/libavutil/tests/opt.c @@ -57,6 +57,15 @@ typedef struct TestContext { int bool3; AVDictionary *dict1; AVDictionary *dict2; + + int **array_int; + unsigned nb_array_int; + + char **array_str; + unsigned nb_array_str; + + AVDictionary **array_dict; + unsigned nb_array_dict; } TestContext; #define OFFSET(x) offsetof(TestContext, x) @@ -65,6 +74,17 @@ typedef struct TestContext { #define TEST_FLAG_LAME 02 #define TEST_FLAG_MU 04 +static const AVOptionArrayDef array_str = { + .sizeof_self = sizeof(AVOptionArrayDef), + .sep = '|', + .def = "str0|str\\|1|str\\\\2", +}; + +static const AVOptionArrayDef array_dict = { + .sizeof_self = sizeof(AVOptionArrayDef), + .def = "k00=v\\\\\\\\00:k01=v\\,01,k10=v\\\\=1\\\\:0", +}; + static const AVOption test_options[]= { {"num", "set num", OFFSET(num), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 100, 1 }, {"toggle", "set toggle", OFFSET(toggle), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, 1 }, @@ -93,6 +113,10 @@ static const AVOption test_options[]= { {"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 }, + {"array_int", "array of ints", OFFSET(array_int), AV_OPT_TYPE_INT | AV_OPT_TYPE_FLAG_ARRAY, .max = INT_MAX, .flags = AV_OPT_FLAG_RUNTIME_PARAM }, + {"array_str", "array of strings", OFFSET(array_str), AV_OPT_TYPE_STRING | AV_OPT_TYPE_FLAG_ARRAY, { .arr = &array_str }, .flags = AV_OPT_FLAG_RUNTIME_PARAM }, + // there are three levels of escaping - C string, array option, dict - so 8 backslashes are needed to get a literal one inside a dict key/val + {"array_dict", "array of dicts", OFFSET(array_dict), AV_OPT_TYPE_DICT | AV_OPT_TYPE_FLAG_ARRAY, { .arr = &array_dict }, .flags = AV_OPT_FLAG_RUNTIME_PARAM }, { NULL }, }; @@ -146,6 +170,17 @@ int main(void) printf("flt=%.6f\n", test_ctx.flt); printf("dbl=%.6f\n", test_ctx.dbl); + for (unsigned i = 0; i < test_ctx.nb_array_str; i++) + printf("array_str[%u]=%s\n", i, test_ctx.array_str[i]); + + for (unsigned i = 0; i < test_ctx.nb_array_dict; i++) { + AVDictionary *d = test_ctx.array_dict[i]; + const AVDictionaryEntry *e = NULL; + + while ((e = av_dict_iterate(d, e))) + printf("array_dict[%u]: %s\t%s\n", i, e->key, e->value); + } + av_opt_show2(&test_ctx, NULL, -1, 0); av_opt_free(&test_ctx); @@ -177,6 +212,9 @@ int main(void) TestContext test_ctx = { 0 }; TestContext test2_ctx = { 0 }; const AVOption *o = NULL; + char *val = NULL; + int ret; + test_ctx.class = &test_class; test2_ctx.class = &test_class; @@ -209,6 +247,17 @@ int main(void) av_free(value1); av_free(value2); } + + // av_opt_set(NULL) with an array option resets it + ret = av_opt_set(&test_ctx, "array_dict", NULL, 0); + printf("av_opt_set(\"array_dict\", NULL) -> %d\n", ret); + printf("array_dict=%sNULL; nb_array_dict=%u\n", + test_ctx.array_dict ? "non-" : "", test_ctx.nb_array_dict); + + // av_opt_get() on an empty array should return a NULL string + ret = av_opt_get(&test_ctx, "array_dict", AV_OPT_ALLOW_NULL, (uint8_t**)&val); + printf("av_opt_get(\"array_dict\") -> %s\n", val ? val : "NULL"); + av_opt_free(&test_ctx); av_opt_free(&test2_ctx); } @@ -303,6 +352,8 @@ int main(void) "bool1=true", "bool2=auto", "dict1='happy=\\:-):sad=\\:-('", + "array_int=0,32,2147483647", + "array_int=2147483648", // out of range, should fail }; test_ctx.class = &test_class; |