Prev Next run.cpp

Run Test of All the Library Routines

Syntax
example/adolc/run
example/cppad/run
example/fadbad/run

Description
These programs will test libf2c_adolc.a, libf2c_cppad.a, and libf2c_fadbad.a respectively. If all the test succeed, they will print
 
	All the tests passed.
and return the value zero (no error). Otherwise they will print
 
	At least one test failed.
and return a non-zero value (error).

Source Code
The source code for these programs follows below. Note that the definition of integer and doublereal, in the prototypes for the Fortran functions, depends on the preprocessor symbols (see prototype ).
 

// system include files used for I/O
# include <iostream>

// define the types integer and doublereal
# include <f2cad/f2cad.hpp>

// ../add2lib.sh uses this comment for extern command 
extern test_result dbesks(void);
extern test_result dbskes(void);
extern test_result d9knus(void);
extern test_result d9lgmc(void);
extern test_result dgamma(void);
extern test_result dint(void);
extern test_result dcsevl(void);
extern test_result dgamlm(void);
extern test_result initds(void);
extern test_result idamax(void);
extern test_result daxpy(void);
extern test_result ddot(void);
extern test_result dgefa(void);
extern test_result dgesl(void);
extern test_result dscal(void);

// xerror is a special case
extern void xerror(void);

// function that runs one test
bool run(test_result test_fun(void), const char *name)
{
	bool ok = true;
	switch( test_fun() )
	{
		case test_none:
		std::cout << "None: " << name << std::endl;
		break;

		case test_pass:
		std::cout << "Pass: " << name << std::endl;
		break;

		case test_fail:
		std::cout << "Fail: " << name << std::endl;
		ok = false;
		break;
	}

	return ok;
}

// main program that runs all the examples
int main(void)
{	bool ok = true;
	using std::cout;
	using std::endl;

	// ../add2lib.sh uses this comment for run command 
	ok &= run( dbesks , "dbesks" );
	ok &= run( dbskes , "dbskes" );
	ok &= run( d9knus , "d9knus" );
	ok &= run( d9lgmc , "d9lgmc" );
	ok &= run( dgamma , "dgamma" );
	ok &= run( dint , "dint" );
	ok &= run( dcsevl , "dcsevl" );
	ok &= run( dgamlm , "dgamlm" );
	ok &= run( initds , "initds" );
	ok &= run( idamax , "idamax" );
	ok &= run( daxpy  , "daxpy"  );
	ok &= run( ddot   , "ddot"   );
	ok &= run( dgefa  , "dgefa"  );
	ok &= run( dgesl  , "dgesl"  );
	ok &= run( daxpy  , "dscal"  );

	if( ok )
		cout << endl << "Pass: None of the tests above failed." << endl;
	else	cout << endl << "Fail: At least one test above failed." << endl;
	cout << "      The next two lines should be identical:" << endl;

	// xerror is a special case because it is not checked automatically
	// and must be checked by eye.
	cout << "Pass: xerror" << endl;
	xerror();
	cout << endl;

	if( ok )
		return 0;
	return 1;
}

Input File: example/run.cpp