Bad usage of ok() macro in tests
Hi, While trying to manage to fix warning about unused values, I've found a problem about some usages of ok() macro. ok() macros is defined in include/wine/test.h as: #define ok_(file, line) (winetest_set_location(file, line), 0) ? 0 : winetest_ok #define ok ok_(__FILE__, __LINE__) One good example: ok( val != NULL, "Invalid value\n"); is expanded as (winetest_set_location(file, line), 0) ? 0 : winetest_ok(val != NULL, "Invalid value\n"); One bad example: if (!ok( val != NULL, "Invalid value\n")) is expanded as if (!(winetest_set_location(file, line), 0) ? 0 : winetest_ok(val != NULL, "Invalid value\n")) And is then evaluated as 1) if ( !(0) ? 0 : winetest_ok(val != NULL, "Invalid value\n")) 2) if ( 1 ? 0 : winetest_ok(val != NULL, "Invalid value\n")) ^ ouch ! 3) if (0) So this is pretty useless. Hopefully, this is only of limited use in wine test suite: find . -type d -name tests | xargs grep -r '[=\!][[:space:](]*ok[[:space:]]*(' returns only four cases: ./dlls/user32/tests/scroll.c: if ( !ok( hMainWnd != NULL, "Failed to create parent window. Tests aborted.\n" ) ) ./dlls/kernel32/tests/file.c: !ok( UnlockFile( handle, 100, 0, 10, 0 ), "UnlockFile 100,10 failed\n" ); ./dlls/comctl32/tests/treeview.c: if ( !ok(hMainWnd != NULL, "Failed to create parent window. Tests aborted.\n") ) ./dlls/shell32/tests/autocomplete.c: if(!ok(hMainWnd != NULL, "Failed to create parent window. Tests aborted.\n")) There's only 3 case with a real problem. The fourth is something very strange: the !ok() in ./dlls/kernel32/tests/file.c seems to be a typo, or someone wanted to disable the test. Regards. -- Yann Droneaud
Le mercredi 24 février 2010 à 15:47 +0100, Yann Droneaud a écrit :
Hi,
While trying to manage to fix warning about unused values, I've found a problem about some usages of ok() macro.
ok() macros is defined in include/wine/test.h as:
#define ok_(file, line) (winetest_set_location(file, line), 0) ? 0 : winetest_ok #define ok ok_(__FILE__, __LINE__)
Hopefully, this is only of limited use in wine test suite: find . -type d -name tests | xargs grep -r '[=\!][[:space:](]*ok[[:space:]]*(' returns only four cases:
In fact, it seems there's no more than those construct which use ok() return value. Try : find . -type d -and -name 'tests' | xargs grep -nr 'if[[:space:]]*([[:space:]]*\!\?[[:space:](]*ok[[:space:]]*(' find . -type d -and -name 'tests' | xargs grep -r '[=\!]\ +[[:space:](]*ok[[:space:]]*(' So I think it's a good opportunity to simplify ok() and let's it return void: #define ok winetest_set_location(__FILE__, __LINE__), winetest_ok Regards -- Yann Droneaud
On Wed, Feb 24, 2010 at 9:25 AM, Yann Droneaud <yann(a)droneaud.fr> wrote:
Le mercredi 24 février 2010 à 15:47 +0100, Yann Droneaud a écrit :
Hi,
While trying to manage to fix warning about unused values, I've found a problem about some usages of ok() macro.
ok() macros is defined in include/wine/test.h as:
#define ok_(file, line) (winetest_set_location(file, line), 0) ? 0 : winetest_ok #define ok ok_(__FILE__, __LINE__)
Hopefully, this is only of limited use in wine test suite: find . -type d -name tests | xargs grep -r '[=\!][[:space:](]*ok[[:space:]]*(' returns only four cases:
In fact, it seems there's no more than those construct which use ok() return value.
Try :
find . -type d -and -name 'tests' | xargs grep -nr 'if[[:space:]]*([[:space:]]*\!\?[[:space:](]*ok[[:space:]]*(' find . -type d -and -name 'tests' | xargs grep -r '[=\!]\ +[[:space:](]*ok[[:space:]]*('
So I think it's a good opportunity to simplify ok() and let's it return void:
#define ok winetest_set_location(__FILE__, __LINE__), winetest_ok
Nice catch! Seems Alexandre fixed these issues: http://source.winehq.org/git/wine.git/?a=commitdiff;h=69ee0ad151b4ae14fa017d... http://source.winehq.org/git/wine.git/?a=commitdiff;h=fbbac38e4ed9fd95d5ab3d... http://source.winehq.org/git/wine.git/?a=commitdiff;h=2432b0f6b91e57e886dfe3... http://source.winehq.org/git/wine.git/?a=commitdiff;h=d5a54642f478a530cf7672... http://source.winehq.org/git/wine.git/?a=commitdiff;h=d279227538a32130c437ba... -- -Austin
participants (2)
-
Austin English -
Yann Droneaud