avutil/eval-test: Check av_expr_parse_and_eval() for failure and also check it in the fate test

Fixes CID1361940

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
pull/102/merge
Michael Niedermayer 9 years ago
parent e0706e9cc8
commit b50bd69516
  1. 17
      libavutil/eval-test.c
  2. 26
      tests/ref/fate/eval

@ -139,33 +139,42 @@ int main(int argc, char **argv)
"clip(0, 0/0, 1)",
NULL
};
int ret;
for (expr = exprs; *expr; expr++) {
printf("Evaluating '%s'\n", *expr);
av_expr_parse_and_eval(&d, *expr,
ret = av_expr_parse_and_eval(&d, *expr,
const_names, const_values,
NULL, NULL, NULL, NULL, NULL, 0, NULL);
if (isnan(d))
printf("'%s' -> nan\n\n", *expr);
else
printf("'%s' -> %f\n\n", *expr, d);
if (ret < 0)
printf("av_expr_parse_and_eval failed\n");
}
av_expr_parse_and_eval(&d, "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)",
ret = av_expr_parse_and_eval(&d, "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)",
const_names, const_values,
NULL, NULL, NULL, NULL, NULL, 0, NULL);
printf("%f == 12.7\n", d);
av_expr_parse_and_eval(&d, "80G/80Gi",
if (ret < 0)
printf("av_expr_parse_and_eval failed\n");
ret = av_expr_parse_and_eval(&d, "80G/80Gi",
const_names, const_values,
NULL, NULL, NULL, NULL, NULL, 0, NULL);
printf("%f == 0.931322575\n", d);
if (ret < 0)
printf("av_expr_parse_and_eval failed\n");
if (argc > 1 && !strcmp(argv[1], "-t")) {
for (i = 0; i < 1050; i++) {
START_TIMER;
av_expr_parse_and_eval(&d, "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)",
ret = av_expr_parse_and_eval(&d, "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)",
const_names, const_values,
NULL, NULL, NULL, NULL, NULL, 0, NULL);
if (ret < 0)
printf("av_expr_parse_and_eval failed\n");
STOP_TIMER("av_expr_parse_and_eval");
}
}

@ -1,6 +1,7 @@
Evaluating ''
'' -> nan
av_expr_parse_and_eval failed
Evaluating '1;2'
'1;2' -> 2.000000
@ -28,45 +29,58 @@ Evaluating '1Gi'
Evaluating '1gi'
'1gi' -> nan
av_expr_parse_and_eval failed
Evaluating '1GiFoo'
'1GiFoo' -> nan
av_expr_parse_and_eval failed
Evaluating '1k+1k'
'1k+1k' -> 2000.000000
Evaluating '1Gi*3foo'
'1Gi*3foo' -> nan
av_expr_parse_and_eval failed
Evaluating 'foo'
'foo' -> nan
av_expr_parse_and_eval failed
Evaluating 'foo('
'foo(' -> nan
av_expr_parse_and_eval failed
Evaluating 'foo()'
'foo()' -> nan
av_expr_parse_and_eval failed
Evaluating 'foo)'
'foo)' -> nan
av_expr_parse_and_eval failed
Evaluating 'sin'
'sin' -> nan
av_expr_parse_and_eval failed
Evaluating 'sin('
'sin(' -> nan
av_expr_parse_and_eval failed
Evaluating 'sin()'
'sin()' -> nan
av_expr_parse_and_eval failed
Evaluating 'sin)'
'sin)' -> nan
av_expr_parse_and_eval failed
Evaluating 'sin 10'
'sin 10' -> nan
av_expr_parse_and_eval failed
Evaluating 'sin(1,2,3)'
'sin(1,2,3)' -> nan
av_expr_parse_and_eval failed
Evaluating 'sin(1 )'
'sin(1 )' -> 0.841471
@ -76,15 +90,19 @@ Evaluating '1'
Evaluating '1foo'
'1foo' -> nan
av_expr_parse_and_eval failed
Evaluating 'bar + PI + E + 100f*2 + foo'
'bar + PI + E + 100f*2 + foo' -> nan
av_expr_parse_and_eval failed
Evaluating '13k + 12f - foo(1, 2)'
'13k + 12f - foo(1, 2)' -> nan
av_expr_parse_and_eval failed
Evaluating '1gi'
'1gi' -> nan
av_expr_parse_and_eval failed
Evaluating '1Gi'
'1Gi' -> 1073741824.000000
@ -127,6 +145,7 @@ Evaluating 'st(1, 1); st(2, 2); st(0, 1); while(lte(ld(0),10), st(3, ld(1)+ld(2)
Evaluating 'while(0, 10)'
'while(0, 10)' -> nan
av_expr_parse_and_eval failed
Evaluating 'st(0, 1); while(lte(ld(0),100), st(1, ld(1)+ld(0)); st(0, ld(0)+1))'
'st(0, 1); while(lte(ld(0),100), st(1, ld(1)+ld(0)); st(0, ld(0)+1))' -> 101.000000
@ -151,6 +170,7 @@ Evaluating 'isinf(INF)'
Evaluating 'floor(NAN)'
'floor(NAN)' -> nan
av_expr_parse_and_eval failed
Evaluating 'floor(123.123)'
'floor(123.123)' -> 123.000000
@ -202,6 +222,7 @@ Evaluating 'PI^1.23'
Evaluating 'pow(-1,1.23)'
'pow(-1,1.23)' -> nan
av_expr_parse_and_eval failed
Evaluating 'if(1, 2)'
'if(1, 2)' -> 2.000000
@ -259,6 +280,7 @@ Evaluating 'bitand(42, 12)'
Evaluating 'bitand(NAN, 1)'
'bitand(NAN, 1)' -> nan
av_expr_parse_and_eval failed
Evaluating 'between(10, -3, 10)'
'between(10, -3, 10)' -> 1.000000
@ -268,14 +290,18 @@ Evaluating 'between(-4, -2, -1)'
Evaluating 'between(1,2)'
'between(1,2)' -> nan
av_expr_parse_and_eval failed
Evaluating 'clip(0, 2, 1)'
'clip(0, 2, 1)' -> nan
av_expr_parse_and_eval failed
Evaluating 'clip(0/0, 1, 2)'
'clip(0/0, 1, 2)' -> nan
av_expr_parse_and_eval failed
Evaluating 'clip(0, 0/0, 1)'
'clip(0, 0/0, 1)' -> nan
av_expr_parse_and_eval failed
12.700000 == 12.7
0.931323 == 0.931322575

Loading…
Cancel
Save