Fix comparison of empty properties to numbers and add test cases.

This commit is contained in:
Mike McCormack 2005-11-14 11:24:14 +00:00 committed by Alexandre Julliard
parent 0940654da7
commit fc0cc66b54
2 changed files with 82 additions and 2 deletions

View File

@ -75,6 +75,30 @@ static INT compare_and_free_strings( LPWSTR a, INT op, LPWSTR b )
return r;
}
static BOOL num_from_prop( LPCWSTR p, INT *val )
{
INT ret = 0, sign = 1;
if (!p)
return FALSE;
if (*p == '-')
{
sign = -1;
p++;
}
if (!*p)
return FALSE;
while (*p)
{
if( *p < '0' || *p > '9' )
return FALSE;
ret = ret*10 + (*p - '0');
p++;
}
*val = ret*sign;
return TRUE;
}
%}
%pure-parser
@ -169,11 +193,13 @@ boolean_factor:
}
| symbol_s operator value_i
{
$$ = compare_int( $1 ? atoiW($1) : 0, $2, $3 );
int num;
$$ = num_from_prop( $1, &num ) && compare_int( num, $2, $3 );
}
| value_i operator symbol_s
{
$$ = compare_int( $1, $2, $3 ? atoiW($3) : 0 );
int num;
$$ = num_from_prop( $3, &num ) && compare_int( $1, $2, num );
}
| symbol_s operator symbol_s
{

View File

@ -593,6 +593,60 @@ void test_condition(void)
r = MsiEvaluateCondition(hpkg, "Installed<>\"\"");
ok( r == MSICONDITION_FALSE, "wrong return val\n");
r = MsiEvaluateCondition(hpkg, "NOT 1 AND 0");
ok( r == MSICONDITION_FALSE, "wrong return val\n");
r = MsiEvaluateCondition(hpkg, "bandalmael=0");
ok( r == MSICONDITION_FALSE, "wrong return val\n");
MsiSetProperty(hpkg, "bandalmael", "0" );
r = MsiEvaluateCondition(hpkg, "bandalmael=0");
ok( r == MSICONDITION_TRUE, "wrong return val\n");
MsiSetProperty(hpkg, "bandalmael", "" );
r = MsiEvaluateCondition(hpkg, "bandalmael=0");
ok( r == MSICONDITION_FALSE, "wrong return val\n");
MsiSetProperty(hpkg, "bandalmael", "asdf" );
r = MsiEvaluateCondition(hpkg, "bandalmael=0");
ok( r == MSICONDITION_FALSE, "wrong return val\n");
MsiSetProperty(hpkg, "bandalmael", "0asdf" );
r = MsiEvaluateCondition(hpkg, "bandalmael=0");
ok( r == MSICONDITION_FALSE, "wrong return val\n");
MsiSetProperty(hpkg, "bandalmael", "0 " );
r = MsiEvaluateCondition(hpkg, "bandalmael=0");
ok( r == MSICONDITION_FALSE, "wrong return val\n");
MsiSetProperty(hpkg, "bandalmael", "-0" );
r = MsiEvaluateCondition(hpkg, "bandalmael=0");
ok( r == MSICONDITION_TRUE, "wrong return val\n");
MsiSetProperty(hpkg, "bandalmael", "0000000000000" );
r = MsiEvaluateCondition(hpkg, "bandalmael=0");
ok( r == MSICONDITION_TRUE, "wrong return val\n");
MsiSetProperty(hpkg, "bandalmael", "--0" );
r = MsiEvaluateCondition(hpkg, "bandalmael=0");
ok( r == MSICONDITION_FALSE, "wrong return val\n");
MsiSetProperty(hpkg, "bandalmael", "0x00" );
r = MsiEvaluateCondition(hpkg, "bandalmael=0");
ok( r == MSICONDITION_FALSE, "wrong return val\n");
MsiSetProperty(hpkg, "bandalmael", "-" );
r = MsiEvaluateCondition(hpkg, "bandalmael=0");
ok( r == MSICONDITION_FALSE, "wrong return val\n");
MsiSetProperty(hpkg, "bandalmael", "+0" );
r = MsiEvaluateCondition(hpkg, "bandalmael=0");
ok( r == MSICONDITION_FALSE, "wrong return val\n");
MsiSetProperty(hpkg, "bandalmael", "0.0" );
r = MsiEvaluateCondition(hpkg, "bandalmael=0");
ok( r == MSICONDITION_FALSE, "wrong return val\n");
MsiCloseHandle( hpkg );
}