This program tests some internal features of libdatrwxx and can serve as an example for using features like datrw::Subformat
#define LIBDATRWXXTESTS_VERSION \
"LIBDATRWXXTESTS V1.1 test internal features of the library"
#include <iostream>
#include <fstream>
#include <string>
#include <tfxx/commandline.h>
#include <aff/dump.h>
using std::cout;
using std::cerr;
using std::endl;
};
const std::string k,
const std::string d)
{
cout << " " << k << " is ";
{
cout << "NOT ";
}
cout << "set";
cout <<
" and has value " << f.
value(k, d) << endl;
double a,b;
f(k, d) >> a >> b;
cout << " reading two doubles from value: " << a << ", " << b;
cout << endl;
cout << " the given default value is " << d << endl;
}
{
cout << "input stream ";
if (flag)
{ cout << "provides"; }
else
{ cout << "doesn't provide"; }
cout << " " << type << " type data" << endl;
}
{
cout << " " << k << " is ";
{
cout << "NOT ";
}
cout << "set" << endl;
}
int main(
int iargc,
char* argv[])
{
char usage_text[]=
{
"usage: libdatrwxxtests [-format s] [-rtest type] [-int] [-single]\n"
" [-error[=n]]" "\n"
" [-v] [-skip] [-DEBUG] file [file ...]" "\n"
" or: libdatrwxxtests --help|-h" "\n"
};
char help_text[]=
{
"\n"
"-v verbose mode\n"
"-DEBUG activate debugging output\n"
"-format s test datrwxx::Subformat by passing format string s\n"
"-rtest type read files of type \"type\" and report content\n"
"-int use integer reading\n"
"-single use float reading\n"
"-skip skip traces\n"
"-error[=n] test error report mechanism (n=0: prints available tests)\n"
"file file to be read\n"
};
using namespace tfxx::cmdline;
static Declare options[]=
{
{"help",arg_no,"-"},
{"v",arg_no,"-"},
{"format",arg_yes,"-"},
{"rtest",arg_yes,"-"},
{"int",arg_no,"-"},
{"single",arg_no,"-"},
{"skip",arg_no,"-"},
{"DEBUG",arg_no,"-"},
{"error",arg_opt,"0"},
{NULL}
};
if (iargc<2)
{
cerr << usage_text << endl;
exit(0);
}
Commandline cmdline(iargc, argv, options);
if (cmdline.optset(0))
{
cerr << usage_text << endl;
cerr << help_text << endl;
exit(0);
}
opt.
debug=cmdline.optset(7);
{
cout << "Test format modifiers" << endl;
cout << "=====================" << endl;
cout << "data format ID: " << format << endl;
if (subformat.allarechecked())
{
cout << "All keys have been checked by the program." << endl;
}
else
{
}
cout << endl;
}
{
sff::FREE free;
sff::INFO info;
sff::SRCE srce;
sff::WID2 wid2;
cout <<
"Read input files of type: " << opt.
readtype << endl;
cout << "=========================" << endl;
while (cmdline.extra())
{
std::string filename=cmdline.next();
cout << endl;
cout << "read file " << filename << endl;
std::ifstream ifs(filename.c_str());
{
}
if (is.hasfree())
{
{
cout << "file FREE block:" << endl;
is >> free;
::sff::verbose(std::cout, free);
}
else
{
cout << "file has FREE block" << endl;
}
}
else
{
cout << "file has no FREE block" << endl;
}
if (is.hassrce())
{
{
cout << "file SRCE line:" << endl;
is >> srce;
::sff::verbose(std::cout, srce);
}
else
{
cout << "file has SRCE line" << endl;
}
}
else
{
cout << "file has no SRCE line" << endl;
}
while (!is.last())
{
{
is.skipseries();
}
else
{
{
if (is.providesi())
{
is >> iseries;
}
else
{
cout << "stream does not provide integer data" << endl;
is.skipseries();
}
}
{
if (is.providesf())
{
is >> fseries;
}
else
{
cout << "stream does not provide single data" << endl;
is.skipseries();
}
}
else
{
if (is.providesd())
{
is >> dseries;
}
else
{
cout << "stream does not provide double data" << endl;
is.skipseries();
}
}
}
if (is.hasfree())
{
{
cout << "trace FREE block:" << endl;
is >> free;
::sff::verbose(std::cout, free);
}
else
{
cout << "trace has FREE block" << endl;
}
}
else
{
cout << "trace has no FREE block" << endl;
}
if (is.hasinfo())
{
{
cout << "trace INFO line:" << endl;
is >> info;
::sff::verbose(std::cout, info);
}
else
{
cout << "trace has INFO line" << endl;
}
}
else
{
cout << "trace has no INFO line" << endl;
}
is >> wid2;
::sff::verbose(std::cout, wid2);
{
if (is.providesi())
{
{
DUMP( iseries );
}
else
{
cout << "read " << iseries.size() << " integer samples" << endl;
}
}
else
{
cout << "stream does not provide integer data" << endl;
}
}
{
if (is.providesf())
{
{
DUMP( fseries );
}
else
{
cout << "read " << fseries.size()
<< " single precision samples" << endl;
}
}
else
{
cout << "stream does not provide single precision data" << endl;
}
}
else
{
if (is.providesd())
{
{
DUMP( dseries );
}
else
{
cout << "read " << dseries.size()
<< " double precision samples" << endl;
}
}
else
{
cout << "stream does not provide double precision data" << endl;
}
}
if (is.last())
{
cout << "This was the last trace in file!" << endl;
}
}
}
}
{
cout << "Test error reports (formatting of messages)" << endl;
cout << "===========================================" << endl;
cout << endl;
{
cout << "available tests:" << endl;
cout << "1: non-fatal reports" << endl;
cout << "2: direct abort" << endl;
cout << "3: fatal/non-fatal assert (non-fatal version)" << endl;
cout << "4: fatal/non-fatal assert (fatal version)" << endl;
cout << "5: standard assertion" << endl;
}
{
cout << "report assert" << endl;
cout << "-------------" << endl;
" a condition to report\n"
"that the test fails.");
cout << "\nwarning" << endl;
cout << "-------" << endl;
DATRW_warning(
"main",
"This is a warning message from a specific" " function in the library.\n"
"The macro takes a multiline message output too.");
}
{
cout << "direct abort" << endl;
cout << "------------" << endl;
"A multi-line message my be passed too in this case.\n"
"Pass one of the non-specified values for the error\n"
"test to see the output for DATRW_illegal.");
}
{
cout << "fatal/non-fatal assert" << endl;
cout << "----------------------" << endl;
"This is a test of a fatal/non-fatal assert.\n"
"The error is made non-fatal, if the option"
"opt.nerrortest equals 3.\n"
}
{
cout << "standard assertion" << endl;
cout << "------------------" << endl;
"This type of error is emitted,"
" if an assertion is failed.\n"
"Several lines of explanation can be provided"
" to the user.\n"
"This can include the output of variables like "
}
else
{
cout <<
"no test selected by n=" << opt.
nerrortest << endl;
}
cout << "...program did not abort" << endl;
}
}