Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH 1/3 v2] avutil/tests/opt: test negative values for INT and INT64 types
@ 2024-02-27 20:30 James Almer
  2024-02-27 20:30 ` [FFmpeg-devel] [PATCH 2/3] avutil/tests/opt: test values > INT_MAX for INT64 type James Almer
  2024-02-27 20:30 ` [FFmpeg-devel] [PATCH 3/3 v2] avutil/opt: add an unsigned option type James Almer
  0 siblings, 2 replies; 3+ messages in thread
From: James Almer @ 2024-02-27 20:30 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavutil/tests/opt.c | 11 +++++++++--
 tests/ref/fate/opt    | 35 ++++++++++++++++++++++++++++++-----
 2 files changed, 39 insertions(+), 7 deletions(-)

diff --git a/libavutil/tests/opt.c b/libavutil/tests/opt.c
index e2582cc93d..a914d0359a 100644
--- a/libavutil/tests/opt.c
+++ b/libavutil/tests/opt.c
@@ -66,7 +66,7 @@ typedef struct TestContext {
 #define TEST_FLAG_MU   04
 
 static const AVOption test_options[]= {
-    {"num",        "set num",            OFFSET(num),            AV_OPT_TYPE_INT,            { .i64 = 0 },                      0,       100, 1 },
+    {"num",        "set num",            OFFSET(num),            AV_OPT_TYPE_INT,            { .i64 = 0 },                     -1,       100, 1 },
     {"toggle",     "set toggle",         OFFSET(toggle),         AV_OPT_TYPE_INT,            { .i64 = 1 },                      0,         1, 1 },
     {"rational",   "set rational",       OFFSET(rational),       AV_OPT_TYPE_RATIONAL,       { .dbl = 1 },                      0,        10, 1 },
     {"string",     "set string",         OFFSET(string),         AV_OPT_TYPE_STRING,         { .str = "default" },       CHAR_MIN,  CHAR_MAX, 1 },
@@ -85,7 +85,7 @@ static const AVOption test_options[]= {
     {"bin",        "set binary value",   OFFSET(binary),         AV_OPT_TYPE_BINARY,         { .str="62696e00" },               0,         0, 1 },
     {"bin1",       "set binary value",   OFFSET(binary1),        AV_OPT_TYPE_BINARY,         { .str=NULL },                     0,         0, 1 },
     {"bin2",       "set binary value",   OFFSET(binary2),        AV_OPT_TYPE_BINARY,         { .str="" },                       0,         0, 1 },
-    {"num64",      "set num 64bit",      OFFSET(num64),          AV_OPT_TYPE_INT64,          { .i64 = 1 },                      0,       100, 1 },
+    {"num64",      "set num 64bit",      OFFSET(num64),          AV_OPT_TYPE_INT64,          { .i64 = 1 },                     -1,       100, 1 },
     {"flt",        "set float",          OFFSET(flt),            AV_OPT_TYPE_FLOAT,          { .dbl = 1.0 / 3 },                0,       100, 1 },
     {"dbl",        "set double",         OFFSET(dbl),            AV_OPT_TYPE_DOUBLE,         { .dbl = 1.0 / 3 },                0,       100, 1 },
     {"bool1",      "set boolean value",  OFFSET(bool1),          AV_OPT_TYPE_BOOL,           { .i64 = -1 },                    -1,         1, 1 },
@@ -285,10 +285,17 @@ int main(void)
             "bin=boguss",
             "bin=111",
             "bin=ffff",
+            "num=bogus",
+            "num=44",
+            "num=44.4",
+            "num=-1",
+            "num=-2",
+            "num=101",
             "num64=bogus",
             "num64=44",
             "num64=44.4",
             "num64=-1",
+            "num64=-2",
             "num64=101",
             "flt=bogus",
             "flt=2",
diff --git a/tests/ref/fate/opt b/tests/ref/fate/opt
index 832f9cc8a9..2da155aa2b 100644
--- a/tests/ref/fate/opt
+++ b/tests/ref/fate/opt
@@ -18,7 +18,7 @@ num64=1
 flt=0.333333
 dbl=0.333333
 TestContext AVOptions:
-  -num               <int>        E.......... set num (from 0 to 100) (default 0)
+  -num               <int>        E.......... set num (from -1 to 100) (default 0)
   -toggle            <int>        E.......... set toggle (from 0 to 1) (default 1)
   -rational          <rational>   E.......... set rational (from 0 to 10) (default 1/1)
   -string            <string>     E.......... set string (default "default")
@@ -37,7 +37,7 @@ TestContext AVOptions:
   -bin               <binary>     E.......... set binary value
   -bin1              <binary>     E.......... set binary value
   -bin2              <binary>     E.......... set binary value
-  -num64             <int64>      E.......... set num 64bit (from 0 to 100) (default 1)
+  -num64             <int64>      E.......... set num 64bit (from -1 to 100) (default 1)
   -flt               <float>      E.......... set float (from 0 to 100) (default 0.333333)
   -dbl               <double>     E.......... set double (from 0 to 100) (default 0.333333)
   -bool1             <boolean>    E.......... set boolean value (default auto)
@@ -312,6 +312,28 @@ Error 'bin=111'
 Setting options string 'bin=ffff'
 Setting entry with key 'bin' to value 'ffff'
 OK    'bin=ffff'
+Setting options string 'num=bogus'
+Setting entry with key 'num' to value 'bogus'
+Undefined constant or missing '(' in 'bogus'
+Unable to parse option value "bogus"
+Error 'num=bogus'
+Setting options string 'num=44'
+Setting entry with key 'num' to value '44'
+OK    'num=44'
+Setting options string 'num=44.4'
+Setting entry with key 'num' to value '44.4'
+OK    'num=44.4'
+Setting options string 'num=-1'
+Setting entry with key 'num' to value '-1'
+OK    'num=-1'
+Setting options string 'num=-2'
+Setting entry with key 'num' to value '-2'
+Value -2.000000 for parameter 'num' out of range [-1 - 100]
+Error 'num=-2'
+Setting options string 'num=101'
+Setting entry with key 'num' to value '101'
+Value 101.000000 for parameter 'num' out of range [-1 - 100]
+Error 'num=101'
 Setting options string 'num64=bogus'
 Setting entry with key 'num64' to value 'bogus'
 Undefined constant or missing '(' in 'bogus'
@@ -325,11 +347,14 @@ Setting entry with key 'num64' to value '44.4'
 OK    'num64=44.4'
 Setting options string 'num64=-1'
 Setting entry with key 'num64' to value '-1'
-Value -1.000000 for parameter 'num64' out of range [0 - 100]
-Error 'num64=-1'
+OK    'num64=-1'
+Setting options string 'num64=-2'
+Setting entry with key 'num64' to value '-2'
+Value -2.000000 for parameter 'num64' out of range [-1 - 100]
+Error 'num64=-2'
 Setting options string 'num64=101'
 Setting entry with key 'num64' to value '101'
-Value 101.000000 for parameter 'num64' out of range [0 - 100]
+Value 101.000000 for parameter 'num64' out of range [-1 - 100]
 Error 'num64=101'
 Setting options string 'flt=bogus'
 Setting entry with key 'flt' to value 'bogus'
-- 
2.43.2

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [FFmpeg-devel] [PATCH 2/3] avutil/tests/opt: test values > INT_MAX for INT64 type
  2024-02-27 20:30 [FFmpeg-devel] [PATCH 1/3 v2] avutil/tests/opt: test negative values for INT and INT64 types James Almer
@ 2024-02-27 20:30 ` James Almer
  2024-02-27 20:30 ` [FFmpeg-devel] [PATCH 3/3 v2] avutil/opt: add an unsigned option type James Almer
  1 sibling, 0 replies; 3+ messages in thread
From: James Almer @ 2024-02-27 20:30 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavutil/tests/opt.c |  5 +++--
 tests/ref/fate/opt    | 25 ++++++++++++++-----------
 2 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/libavutil/tests/opt.c b/libavutil/tests/opt.c
index a914d0359a..11f29468fb 100644
--- a/libavutil/tests/opt.c
+++ b/libavutil/tests/opt.c
@@ -85,7 +85,7 @@ static const AVOption test_options[]= {
     {"bin",        "set binary value",   OFFSET(binary),         AV_OPT_TYPE_BINARY,         { .str="62696e00" },               0,         0, 1 },
     {"bin1",       "set binary value",   OFFSET(binary1),        AV_OPT_TYPE_BINARY,         { .str=NULL },                     0,         0, 1 },
     {"bin2",       "set binary value",   OFFSET(binary2),        AV_OPT_TYPE_BINARY,         { .str="" },                       0,         0, 1 },
-    {"num64",      "set num 64bit",      OFFSET(num64),          AV_OPT_TYPE_INT64,          { .i64 = 1 },                     -1,       100, 1 },
+    {"num64",      "set num 64bit",      OFFSET(num64),          AV_OPT_TYPE_INT64,          { .i64 = 1LL << 32 },             -1, 1LL << 32, 1 },
     {"flt",        "set float",          OFFSET(flt),            AV_OPT_TYPE_FLOAT,          { .dbl = 1.0 / 3 },                0,       100, 1 },
     {"dbl",        "set double",         OFFSET(dbl),            AV_OPT_TYPE_DOUBLE,         { .dbl = 1.0 / 3 },                0,       100, 1 },
     {"bool1",      "set boolean value",  OFFSET(bool1),          AV_OPT_TYPE_BOOL,           { .i64 = -1 },                    -1,         1, 1 },
@@ -296,7 +296,8 @@ int main(void)
             "num64=44.4",
             "num64=-1",
             "num64=-2",
-            "num64=101",
+            "num64=4294967296",
+            "num64=4294967297",
             "flt=bogus",
             "flt=2",
             "flt=2.2",
diff --git a/tests/ref/fate/opt b/tests/ref/fate/opt
index 2da155aa2b..d164b9eb0c 100644
--- a/tests/ref/fate/opt
+++ b/tests/ref/fate/opt
@@ -14,7 +14,7 @@ color=255 192 203 255
 channel_layout=311=311
 binary=62 69 6e 0
 binary_size=4
-num64=1
+num64=4294967296
 flt=0.333333
 dbl=0.333333
 TestContext AVOptions:
@@ -37,7 +37,7 @@ TestContext AVOptions:
   -bin               <binary>     E.......... set binary value
   -bin1              <binary>     E.......... set binary value
   -bin2              <binary>     E.......... set binary value
-  -num64             <int64>      E.......... set num 64bit (from -1 to 100) (default 1)
+  -num64             <int64>      E.......... set num 64bit (from -1 to 4.29497e+09) (default 4294967296)
   -flt               <float>      E.......... set float (from 0 to 100) (default 0.333333)
   -dbl               <double>     E.......... set double (from 0 to 100) (default 0.333333)
   -bool1             <boolean>    E.......... set boolean value (default auto)
@@ -119,7 +119,7 @@ name: cl          get: hexagonal        set: OK               get: hexagonal
 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: num64       get: 4294967296       set: OK               get: 4294967296       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
@@ -129,7 +129,7 @@ name: dict1       get:                  set: OK               get:
 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=hexagonal,bin=62696E00,bin1=,bin2=,num64=1,flt=0.333333,dbl=0.333333,bool1=auto,bool2=true,bool3=false,dict1=,dict2=happy\=\\:-)
+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=hexagonal,bin=62696E00,bin1=,bin2=,num64=4294967296,flt=0.333333,dbl=0.333333,bool1=auto,bool2=true,bool3=false,dict1=,dict2=happy\=\\:-)
 Setting entry with key 'num' to value '0'
 Setting entry with key 'toggle' to value '1'
 Setting entry with key 'rational' to value '1/1'
@@ -146,7 +146,7 @@ Setting entry with key 'cl' to value 'hexagonal'
 Setting entry with key 'bin' to value '62696E00'
 Setting entry with key 'bin1' to value ''
 Setting entry with key 'bin2' to value ''
-Setting entry with key 'num64' to value '1'
+Setting entry with key 'num64' to value '4294967296'
 Setting entry with key 'flt' to value '0.333333'
 Setting entry with key 'dbl' to value '0.333333'
 Setting entry with key 'bool1' to value 'auto'
@@ -154,7 +154,7 @@ Setting entry with key 'bool2' to value 'true'
 Setting entry with key 'bool3' to value 'false'
 Setting entry with key 'dict1' to value ''
 Setting entry with key 'dict2' to value 'happy=\:-)'
-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=hexagonal,bin=62696E00,bin1=,bin2=,num64=1,flt=0.333333,dbl=0.333333,bool1=auto,bool2=true,bool3=false,dict1=,dict2=happy\=\\:-)
+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=hexagonal,bin=62696E00,bin1=,bin2=,num64=4294967296,flt=0.333333,dbl=0.333333,bool1=auto,bool2=true,bool3=false,dict1=,dict2=happy\=\\:-)
 
 Testing av_set_options_string()
 Setting options string ''
@@ -350,12 +350,15 @@ Setting entry with key 'num64' to value '-1'
 OK    'num64=-1'
 Setting options string 'num64=-2'
 Setting entry with key 'num64' to value '-2'
-Value -2.000000 for parameter 'num64' out of range [-1 - 100]
+Value -2.000000 for parameter 'num64' out of range [-1 - 4.29497e+09]
 Error 'num64=-2'
-Setting options string 'num64=101'
-Setting entry with key 'num64' to value '101'
-Value 101.000000 for parameter 'num64' out of range [-1 - 100]
-Error 'num64=101'
+Setting options string 'num64=4294967296'
+Setting entry with key 'num64' to value '4294967296'
+OK    'num64=4294967296'
+Setting options string 'num64=4294967297'
+Setting entry with key 'num64' to value '4294967297'
+Value 4294967297.000000 for parameter 'num64' out of range [-1 - 4.29497e+09]
+Error 'num64=4294967297'
 Setting options string 'flt=bogus'
 Setting entry with key 'flt' to value 'bogus'
 Undefined constant or missing '(' in 'bogus'
-- 
2.43.2

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [FFmpeg-devel] [PATCH 3/3 v2] avutil/opt: add an unsigned option type
  2024-02-27 20:30 [FFmpeg-devel] [PATCH 1/3 v2] avutil/tests/opt: test negative values for INT and INT64 types James Almer
  2024-02-27 20:30 ` [FFmpeg-devel] [PATCH 2/3] avutil/tests/opt: test values > INT_MAX for INT64 type James Almer
@ 2024-02-27 20:30 ` James Almer
  1 sibling, 0 replies; 3+ messages in thread
From: James Almer @ 2024-02-27 20:30 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavutil/opt.c       | 19 +++++++++++++++++++
 libavutil/opt.h       |  2 ++
 libavutil/tests/opt.c |  9 +++++++++
 tests/ref/fate/opt    | 32 ++++++++++++++++++++++++++++++--
 4 files changed, 60 insertions(+), 2 deletions(-)

diff --git a/libavutil/opt.c b/libavutil/opt.c
index 0681b19896..d37f0dda69 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -72,6 +72,9 @@ static int read_number(const AVOption *o, const void *dst, double *num, int *den
     case AV_OPT_TYPE_INT:
         *intnum = *(int *)dst;
         return 0;
+    case AV_OPT_TYPE_UINT:
+        *intnum = *(unsigned int *)dst;
+        return 0;
 #if FF_API_OLD_CHANNEL_LAYOUT
 FF_DISABLE_DEPRECATION_WARNINGS
     case AV_OPT_TYPE_CHANNEL_LAYOUT:
@@ -128,6 +131,7 @@ static int write_number(void *obj, const AVOption *o, void *dst, double num, int
     case AV_OPT_TYPE_BOOL:
     case AV_OPT_TYPE_FLAGS:
     case AV_OPT_TYPE_INT:
+    case AV_OPT_TYPE_UINT:
         *(int *)dst = llrint(num / den) * intnum;
         break;
     case AV_OPT_TYPE_DURATION:
@@ -231,6 +235,7 @@ static int set_string(void *obj, const AVOption *o, const char *val, uint8_t **d
                               opt->type == AV_OPT_TYPE_UINT64 || \
                               opt->type == AV_OPT_TYPE_CONST || \
                               opt->type == AV_OPT_TYPE_FLAGS || \
+                              opt->type == AV_OPT_TYPE_UINT  || \
                               opt->type == AV_OPT_TYPE_INT)     \
                              ? opt->default_val.i64             \
                              : opt->default_val.dbl)
@@ -529,6 +534,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
         return set_string_binary(obj, o, val, dst);
     case AV_OPT_TYPE_FLAGS:
     case AV_OPT_TYPE_INT:
+    case AV_OPT_TYPE_UINT:
     case AV_OPT_TYPE_INT64:
     case AV_OPT_TYPE_UINT64:
     case AV_OPT_TYPE_FLOAT:
@@ -610,6 +616,7 @@ int av_opt_eval_ ## name(void *obj, const AVOption *o,                  \
 
 OPT_EVAL_NUMBER(flags,  AV_OPT_TYPE_FLAGS,    int)
 OPT_EVAL_NUMBER(int,    AV_OPT_TYPE_INT,      int)
+OPT_EVAL_NUMBER(uint,   AV_OPT_TYPE_UINT,     unsigned int)
 OPT_EVAL_NUMBER(int64,  AV_OPT_TYPE_INT64,    int64_t)
 OPT_EVAL_NUMBER(float,  AV_OPT_TYPE_FLOAT,    float)
 OPT_EVAL_NUMBER(double, AV_OPT_TYPE_DOUBLE,   double)
@@ -871,6 +878,9 @@ int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
     case AV_OPT_TYPE_INT:
         ret = snprintf(buf, sizeof(buf), "%d", *(int *)dst);
         break;
+    case AV_OPT_TYPE_UINT:
+        ret = snprintf(buf, sizeof(buf), "%u", *(unsigned int *)dst);
+        break;
     case AV_OPT_TYPE_INT64:
         ret = snprintf(buf, sizeof(buf), "%"PRId64, *(int64_t *)dst);
         break;
@@ -1276,6 +1286,9 @@ static void opt_list(void *obj, void *av_log_obj, const char *unit,
             case AV_OPT_TYPE_INT:
                 av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<int>");
                 break;
+            case AV_OPT_TYPE_UINT:
+                av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<unsigned>");
+                break;
             case AV_OPT_TYPE_INT64:
                 av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<int64>");
                 break;
@@ -1358,6 +1371,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
         if (av_opt_query_ranges(&r, obj, opt->name, AV_OPT_SEARCH_FAKE_OBJ) >= 0) {
             switch (opt->type) {
             case AV_OPT_TYPE_INT:
+            case AV_OPT_TYPE_UINT:
             case AV_OPT_TYPE_INT64:
             case AV_OPT_TYPE_UINT64:
             case AV_OPT_TYPE_DOUBLE:
@@ -1405,6 +1419,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
                 av_log(av_log_obj, AV_LOG_INFO, "%s", buf);
                 break;
             }
+            case AV_OPT_TYPE_UINT:
             case AV_OPT_TYPE_INT:
             case AV_OPT_TYPE_UINT64:
             case AV_OPT_TYPE_INT64: {
@@ -1490,6 +1505,7 @@ void av_opt_set_defaults2(void *s, int mask, int flags)
             case AV_OPT_TYPE_BOOL:
             case AV_OPT_TYPE_FLAGS:
             case AV_OPT_TYPE_INT:
+            case AV_OPT_TYPE_UINT:
             case AV_OPT_TYPE_INT64:
             case AV_OPT_TYPE_UINT64:
             case AV_OPT_TYPE_DURATION:
@@ -1858,6 +1874,7 @@ static int opt_size(enum AVOptionType type)
     switch(type) {
     case AV_OPT_TYPE_BOOL:
     case AV_OPT_TYPE_INT:
+    case AV_OPT_TYPE_UINT:
     case AV_OPT_TYPE_FLAGS:
         return sizeof(int);
     case AV_OPT_TYPE_DURATION:
@@ -1997,6 +2014,7 @@ int av_opt_query_ranges_default(AVOptionRanges **ranges_arg, void *obj, const ch
     switch (field->type) {
     case AV_OPT_TYPE_BOOL:
     case AV_OPT_TYPE_INT:
+    case AV_OPT_TYPE_UINT:
     case AV_OPT_TYPE_INT64:
     case AV_OPT_TYPE_UINT64:
     case AV_OPT_TYPE_PIXEL_FMT:
@@ -2089,6 +2107,7 @@ int av_opt_is_set_to_default(void *obj, const AVOption *o)
     case AV_OPT_TYPE_PIXEL_FMT:
     case AV_OPT_TYPE_SAMPLE_FMT:
     case AV_OPT_TYPE_INT:
+    case AV_OPT_TYPE_UINT:
 #if FF_API_OLD_CHANNEL_LAYOUT
 FF_DISABLE_DEPRECATION_WARNINGS
     case AV_OPT_TYPE_CHANNEL_LAYOUT:
diff --git a/libavutil/opt.h b/libavutil/opt.h
index 461b5d3b6b..ba494f0fcf 100644
--- a/libavutil/opt.h
+++ b/libavutil/opt.h
@@ -243,6 +243,7 @@ enum AVOptionType{
 #endif
     AV_OPT_TYPE_BOOL,
     AV_OPT_TYPE_CHLAYOUT,
+    AV_OPT_TYPE_UINT,
 };
 
 /**
@@ -552,6 +553,7 @@ enum {
  */
 int av_opt_eval_flags (void *obj, const AVOption *o, const char *val, int        *flags_out);
 int av_opt_eval_int   (void *obj, const AVOption *o, const char *val, int        *int_out);
+int av_opt_eval_uint  (void *obj, const AVOption *o, const char *val, unsigned   *uint_out);
 int av_opt_eval_int64 (void *obj, const AVOption *o, const char *val, int64_t    *int64_out);
 int av_opt_eval_float (void *obj, const AVOption *o, const char *val, float      *float_out);
 int av_opt_eval_double(void *obj, const AVOption *o, const char *val, double     *double_out);
diff --git a/libavutil/tests/opt.c b/libavutil/tests/opt.c
index 11f29468fb..faeaa00f30 100644
--- a/libavutil/tests/opt.c
+++ b/libavutil/tests/opt.c
@@ -31,6 +31,7 @@
 typedef struct TestContext {
     const AVClass *class;
     int num;
+    unsigned unum;
     int toggle;
     char *string;
     int flags;
@@ -67,6 +68,7 @@ typedef struct TestContext {
 
 static const AVOption test_options[]= {
     {"num",        "set num",            OFFSET(num),            AV_OPT_TYPE_INT,            { .i64 = 0 },                     -1,       100, 1 },
+    {"unum",       "set unum",           OFFSET(unum),           AV_OPT_TYPE_UINT,           { .i64 = 1U << 31 },               0,  1U << 31, 1 },
     {"toggle",     "set toggle",         OFFSET(toggle),         AV_OPT_TYPE_INT,            { .i64 = 1 },                      0,         1, 1 },
     {"rational",   "set rational",       OFFSET(rational),       AV_OPT_TYPE_RATIONAL,       { .dbl = 1 },                      0,        10, 1 },
     {"string",     "set string",         OFFSET(string),         AV_OPT_TYPE_STRING,         { .str = "default" },       CHAR_MIN,  CHAR_MAX, 1 },
@@ -127,6 +129,7 @@ int main(void)
         av_opt_set_defaults(&test_ctx);
 
         printf("num=%d\n", test_ctx.num);
+        printf("unum=%u\n", test_ctx.unum);
         printf("toggle=%d\n", test_ctx.toggle);
         printf("string=%s\n", test_ctx.string);
         printf("escape=%s\n", test_ctx.escape);
@@ -291,6 +294,12 @@ int main(void)
             "num=-1",
             "num=-2",
             "num=101",
+            "unum=bogus",
+            "unum=44",
+            "unum=44.4",
+            "unum=-1",
+            "unum=2147483648",
+            "unum=2147483649",
             "num64=bogus",
             "num64=44",
             "num64=44.4",
diff --git a/tests/ref/fate/opt b/tests/ref/fate/opt
index d164b9eb0c..408467e77c 100644
--- a/tests/ref/fate/opt
+++ b/tests/ref/fate/opt
@@ -1,5 +1,6 @@
 Testing default values
 num=0
+unum=2147483648
 toggle=1
 string=default
 escape=\=,
@@ -19,6 +20,7 @@ flt=0.333333
 dbl=0.333333
 TestContext AVOptions:
   -num               <int>        E.......... set num (from -1 to 100) (default 0)
+  -unum              <unsigned>   E.......... set unum (from 0 to 2.14748e+09) (default 2147483648)
   -toggle            <int>        E.......... set toggle (from 0 to 1) (default 1)
   -rational          <rational>   E.......... set rational (from 0 to 10) (default 1/1)
   -string            <string>     E.......... set string (default "default")
@@ -48,6 +50,7 @@ TestContext AVOptions:
 
 Testing av_opt_is_set_to_default()
 name:       num default:1 error:
+name:      unum default:0 error:
 name:    toggle default:0 error:
 name:  rational default:0 error:
 name:    string default:0 error:
@@ -75,6 +78,7 @@ name:     bool3 default:1 error:
 name:     dict1 default:1 error:
 name:     dict2 default:0 error:
 name:       num default:1 error:
+name:      unum default:1 error:
 name:    toggle default:1 error:
 name:  rational default:1 error:
 name:    string default:1 error:
@@ -104,6 +108,7 @@ name:     dict2 default:1 error:
 
 Testing av_opt_get/av_opt_set()
 name: num         get: 0                set: OK               get: 0                OK
+name: unum        get: 2147483648       set: OK               get: 2147483648       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
@@ -129,8 +134,9 @@ name: dict1       get:                  set: OK               get:
 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=hexagonal,bin=62696E00,bin1=,bin2=,num64=4294967296,flt=0.333333,dbl=0.333333,bool1=auto,bool2=true,bool3=false,dict1=,dict2=happy\=\\:-)
+num=0,unum=2147483648,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=hexagonal,bin=62696E00,bin1=,bin2=,num64=4294967296,flt=0.333333,dbl=0.333333,bool1=auto,bool2=true,bool3=false,dict1=,dict2=happy\=\\:-)
 Setting entry with key 'num' to value '0'
+Setting entry with key 'unum' to value '2147483648'
 Setting entry with key 'toggle' to value '1'
 Setting entry with key 'rational' to value '1/1'
 Setting entry with key 'string' to value 'default'
@@ -154,7 +160,7 @@ Setting entry with key 'bool2' to value 'true'
 Setting entry with key 'bool3' to value 'false'
 Setting entry with key 'dict1' to value ''
 Setting entry with key 'dict2' to value 'happy=\:-)'
-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=hexagonal,bin=62696E00,bin1=,bin2=,num64=4294967296,flt=0.333333,dbl=0.333333,bool1=auto,bool2=true,bool3=false,dict1=,dict2=happy\=\\:-)
+num=0,unum=2147483648,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=hexagonal,bin=62696E00,bin1=,bin2=,num64=4294967296,flt=0.333333,dbl=0.333333,bool1=auto,bool2=true,bool3=false,dict1=,dict2=happy\=\\:-)
 
 Testing av_set_options_string()
 Setting options string ''
@@ -334,6 +340,28 @@ Setting options string 'num=101'
 Setting entry with key 'num' to value '101'
 Value 101.000000 for parameter 'num' out of range [-1 - 100]
 Error 'num=101'
+Setting options string 'unum=bogus'
+Setting entry with key 'unum' to value 'bogus'
+Undefined constant or missing '(' in 'bogus'
+Unable to parse option value "bogus"
+Error 'unum=bogus'
+Setting options string 'unum=44'
+Setting entry with key 'unum' to value '44'
+OK    'unum=44'
+Setting options string 'unum=44.4'
+Setting entry with key 'unum' to value '44.4'
+OK    'unum=44.4'
+Setting options string 'unum=-1'
+Setting entry with key 'unum' to value '-1'
+Value -1.000000 for parameter 'unum' out of range [0 - 2.14748e+09]
+Error 'unum=-1'
+Setting options string 'unum=2147483648'
+Setting entry with key 'unum' to value '2147483648'
+OK    'unum=2147483648'
+Setting options string 'unum=2147483649'
+Setting entry with key 'unum' to value '2147483649'
+Value 2147483649.000000 for parameter 'unum' out of range [0 - 2.14748e+09]
+Error 'unum=2147483649'
 Setting options string 'num64=bogus'
 Setting entry with key 'num64' to value 'bogus'
 Undefined constant or missing '(' in 'bogus'
-- 
2.43.2

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-02-27 20:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-27 20:30 [FFmpeg-devel] [PATCH 1/3 v2] avutil/tests/opt: test negative values for INT and INT64 types James Almer
2024-02-27 20:30 ` [FFmpeg-devel] [PATCH 2/3] avutil/tests/opt: test values > INT_MAX for INT64 type James Almer
2024-02-27 20:30 ` [FFmpeg-devel] [PATCH 3/3 v2] avutil/opt: add an unsigned option type James Almer

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git