Commit 96f7aaaf authored by thomas.forbriger's avatar thomas.forbriger
Browse files

libdatrwxx [WP]: provide tests for error message module

parent 5dd2d131
......@@ -28,6 +28,7 @@
*
* REVISIONS and CHANGES
* - 06/09/2011 V1.0 Thomas Forbriger
* - 11/07/2016 V1.1 provide means to test error message output
*
* ============================================================================
* \example libdatrwxxtests.cc
......@@ -35,12 +36,13 @@
* serve as an example for using features like datrw::Subformat
*/
#define LIBDATRWXXTESTS_VERSION \
"LIBDATRWXXTESTS V1.0 test internal features of the library"
"LIBDATRWXXTESTS V1.1 test internal features of the library"
#include <iostream>
#include <fstream>
#include <string>
#include <tfxx/commandline.h>
#include <datrwxx/error.h>
#include <datrwxx/util.h>
#include <datrwxx/types.h>
#include <datrwxx/readany.h>
......@@ -55,8 +57,10 @@ using std::endl;
struct Options {
bool testformat, readint, readsingle, skipsamples, readtest;
bool testerror;
bool debug, verbose;
std::string formatstring, readtype;
int nerrortest; // select an error function to be tested
}; // struct Options
/*----------------------------------------------------------------------*/
......@@ -113,6 +117,7 @@ int main(int iargc, char* argv[])
{
LIBDATRWXXTESTS_VERSION "\n"
"usage: libdatrwxxtests [-format s] [-rtest type] [-int] [-single]\n"
" [-error[=n]]" "\n"
" [-v] [-skip] [-DEBUG] file [file ...]" "\n"
" or: libdatrwxxtests --help|-h" "\n"
};
......@@ -128,6 +133,7 @@ int main(int iargc, char* argv[])
"-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"
};
......@@ -151,6 +157,8 @@ int main(int iargc, char* argv[])
{"skip",arg_no,"-"},
// 7: debug output
{"DEBUG",arg_no,"-"},
// 8: skip samples
{"error",arg_opt,"0"},
{NULL}
};
......@@ -182,6 +190,8 @@ int main(int iargc, char* argv[])
opt.readsingle=cmdline.optset(5);
opt.skipsamples=cmdline.optset(6);
opt.debug=cmdline.optset(7);
opt.testerror=cmdline.optset(8);
opt.nerrortest=cmdline.int_arg(8);
/*======================================================================*/
......@@ -414,6 +424,57 @@ int main(int iargc, char* argv[])
} // while (!is.last())
} // while (cmdline.extra())
} // if (opt.readtest)
/*======================================================================*/
if (opt.testerror)
{
cout << "Test format modifiers" << endl;
cout << "=====================" << endl;
if (opt.nerrortest == 0)
{
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;
}
else if (opt.nerrortest == 1)
{
cout << "report assert" << endl;
cout << "-------------" << endl;
DATRW_report_assert(false, "message");
cout << "warning" << endl;
cout << "-------" << endl;
DATRW_warning("main", "message");
}
else if (opt.nerrortest == 2)
{
cout << "direct abort" << endl;
cout << "------------" << endl;
DATRW_abort("abort program intentionally");
}
else if ((opt.nerrortest == 3) || (opt.nerrortest == 4))
{
cout << "fatal/non-fatal assert" << endl;
cout << "----------------------" << endl;
DATRW_nonfatal_assert(opt.nerrortest==3, false,
"fatal/non-fatal assert");
}
else if (opt.nerrortest == 5)
{
cout << "standard assertion" << endl;
cout << "------------------" << endl;
DATRW_assert(false, "faild assertion");
}
else
{
cout << "no test selected by n=" << opt.nerrortest << endl;
DATRW_illegal;
}
cout << "...program did not abort" << endl;
} // if (opt.testerror)
}
/* ----- END OF libdatrwxxtests.cc ----- */
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment