The following section illustrates various ways to test the return value of the function pi used
by rad2deg and deg2rad in converter.c shown below
double pi() {
return 3.14f;
}
double rad2deg(double rad) {
return 180*rad / pi();
}
double deg2rad(double deg) {
return deg * pi() / 180;
}
EXPECT, ALLOW will accept functions that returns float or doubles and all other testape
macros will accept either floating point values or integer values as arguments.
So it is possible to write a test like it is shown in sample242.1below
#define PI (4.0 * atan( 1.0 ))
double testape_validate_fp_accuracy() {
return 0.01;
}
void test_rad2deg(void) {
EXPECT ( pi );
ALLOW ( pi );
VALIDATE ( rad2deg(0), 0);
VALIDATE ( rad2deg(2*PI), 360);
VALIDATE_FP( deg2rad(0), 0);
VALIDATE_FP( deg2rad(360), 2*PI);
}
The first two validations will convert the floating point return value to integers before validating
them against the integer limits e,g, 0 == 0, and 360 == 360. The later two, will directly validate the
floating point return value from deg2rad against PI. e.g. 0.0f == 0.0f and 6.283185307f == 6.28f.
These validation will both pass, as they are accurate with 0.01f as indicated in the
testape_validate_fp_accuracy function.
It is also possible to use macros SIMULATE(function, value) and ALLOW_SIMULATE(function, value)
with floating point values. These macros will evaluate value twice each time the macro is used, as
the framework will save two versions of value. First version as an integer representation and second
version as a floating point representation. If function is a function returning a floting point, the
floating point version will be returned to the calling function and similar if function is a function
returning an integer value, the integer version will be used.
In sample252.1below, the floating point representation is used to mock the return
value from pi.
#define PI (4.0 * atan( 1.0 ))
void test_deg2rad(void) {
SIMULATE ( pi, PI );
SIMULATE ( pi, PI );
VALIDATE_FP( deg2rad(0), 0);
VALIDATE_FP( deg2rad(360), 2*PI);
}
Notice the absence of testape_validate_fp_accuracy and that the simulated value used are more
accurate than the actual implementaion of pi. Therfore both validation will pass with the
default accuracy of 0.00001f.
The double evaluation of value in the SIMUALTE macros, may cause cause problems if value parameter expands to a function for which its return value varies each time it is called. Make a local variable, if you have this problem.
testape
New is this release are support for floating point validations and function mocking. Also, MinGW has been added to the list of supported platforms.
moreTestApe forum is now hosted on Proboards. Support questions can be posted here or send directly on email. Due to ...
moreTestApe can now be used with MinGW GCC on windows. Also supported in this beta are floating point types in validations or when mocking functions
moreA small fix for webtty scripts, to allow the usage from Apple IPads. Tab on textarea to bring up IPad keyboard - you may have to scroll webpage beneath keyboard, in order to actually see what you're typing.
This release contains a new flexible mocking system with default mocks automatically generated for unresolved functions. Installation packages are available for GCC/Linux, GCC/CygWin as well Visual Studio 2009/Windows XP or Vista.
moreNew beta version is now available for download. This is the last beta before official release. The release supports an extensive mocking system.
moreThere is a change for the forum hosted on this site. The previous phpBB forum is closed for now. All forum threads will be migrated to a new simple blog. ...
more