2 * This file is part of Libav.
4 * Libav is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * Libav is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with Libav; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
29 typedef struct TestContext {
38 #define OFFSET(x) offsetof(TestContext, x)
40 #define TEST_FLAG_COOL 01
41 #define TEST_FLAG_LAME 02
42 #define TEST_FLAG_MU 04
44 static const AVOption test_options[] = {
45 { "num", "set num", OFFSET(num), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 100 },
46 { "toggle", "set toggle", OFFSET(toggle), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1 },
47 { "rational", "set rational", OFFSET(rational), AV_OPT_TYPE_RATIONAL, { .dbl = 0 }, 0, 10 },
48 { "string", "set string", OFFSET(string), AV_OPT_TYPE_STRING, { 0 }, CHAR_MIN, CHAR_MAX },
49 { "flags", "set flags", OFFSET(flags), AV_OPT_TYPE_FLAGS, { .i64 = 0 }, 0, INT_MAX, 0, "flags"},
50 { "cool", "set cool flag ", 0, AV_OPT_TYPE_CONST, { .i64 = TEST_FLAG_COOL }, INT_MIN, INT_MAX, 0, "flags"},
51 { "lame", "set lame flag ", 0, AV_OPT_TYPE_CONST, { .i64 = TEST_FLAG_LAME }, INT_MIN, INT_MAX, 0, "flags"},
52 { "mu", "set mu flag ", 0, AV_OPT_TYPE_CONST, { .i64 = TEST_FLAG_MU }, INT_MIN, INT_MAX, 0, "flags"},
56 static const char *test_get_name(void *ctx)
61 static const AVClass test_class = {
70 TestContext test_ctx = { .class = &test_class };
71 static const char *options[] = {
87 "flags=+mu-lame : num=42: toggle=0",
88 "num=42 : string=blahblah",
89 "rational=0 : rational=1/2 : rational=1/-1",
93 printf("\nTesting av_set_options_string()\n");
95 av_opt_set_defaults(&test_ctx);
96 test_ctx.string = av_strdup("default");
98 return AVERROR(ENOMEM);
100 av_log_set_level(AV_LOG_DEBUG);
102 for (i = 0; i < FF_ARRAY_ELEMS(options); i++) {
103 av_log(&test_ctx, AV_LOG_DEBUG, "Setting options string '%s'\n", options[i]);
104 if (av_set_options_string(&test_ctx, options[i], "=", ":") < 0)
105 av_log(&test_ctx, AV_LOG_ERROR, "Error setting options string: '%s'\n", options[i]);