OpenMS  2.7.0
Functions | Variables
OpenMS::Internal::ClassTest Namespace Reference

Namespace for class tests. More...

Functions

bool validate (const std::vector< std::string > &file_names)
 Validates the given files against the XML schema (if available) More...
 
std::string tmpFileName (const std::string &file, int line)
 Creates a temporary file name from the test name and the line. More...
 
bool isRealType (float)
 This overload returns true; float is a floating point type. More...
 
bool isRealType (double)
 This overload returns true; double is a floating point type. More...
 
bool isRealType (long double)
 This overload returns true; long double is a floating point type. More...
 
bool isRealType (const ParamValue &)
 This overload returns true; ParamValue will be converted to double by TEST_REAL_SIMILAR. More...
 
bool isRealType (const DataValue &)
 This overload returns true; DataValue will be converted to double by TEST_REAL_SIMILAR. More...
 
template<typename T >
bool isRealType (const T &)
 This catch-all template returns false; it will be instantiated for non-floating point types. More...
 
void testRealSimilar (const char *file, int line, long double number_1, const char *number_1_stringified, bool number_1_is_realtype, Int number_1_written_digits, long double number_2, const char *number_2_stringified, bool, Int number_2_written_digits)
 Compare floating point numbers using absdiff_max_allowed and ratio_max_allowed. More...
 
bool isRealSimilar (long double number_1, long double number_2)
 used by testRealSimilar() More...
 
void testStringSimilar (const char *file, int line, const std::string &string_1, const char *string_1_stringified, const std::string &string_2, const char *string_2_stringified)
 Compare strings using absdiff_max_allowed and ratio_max_allowed. More...
 
void testStringEqual (const char *file, int line, const std::string &string_1, const char *string_1_stringified, const std::string &string_2, const char *string_2_stringified)
 used by TEST_STRING_EQUAL More...
 
bool isFileSimilar (const std::string &filename_1, const std::string &filename_2)
 Compare files using absdiff_max_allowed and ratio_max_allowed. More...
 
void initialNewline ()
 make sure we have a newline before results from first subtest More...
 
void printWithPrefix (const std::string &text, const int marked=-1)
 print the text, each line gets a prefix, the marked line number gets a special prefix More...
 
void mainInit (const char *version, const char *class_name, int argc, const char *argv0)
 Set up some classtest variables as obtained from the 'START_TEST' macro and check that no additional arguments were passed to the test executable. More...
 
void filesEqual (int line, const char *filename, const char *templatename, const char *filename_stringified, const char *templatename_stringified)
 Test if two files are exactly equal (used in TEST_FILE_EQUAL macro) More...
 
void removeTempFiles ()
 removed all temporary files created with the NEW_TMP_FILE macro More...
 
void setWhitelist (const char *const, const int line, const std::string &whitelist)
 set the whitelist_ More...
 
template<typename T1 , typename T2 >
void testEqual (const char *, int line, const T1 &expression_1, const char *expression_1_stringified, const T2 &expression_2, const char *expression_2_stringified)
 
template<typename T1 , typename T2 >
void testNotEqual (const char *, int line, const T1 &expression_1, const char *expression_1_stringified, const T2 &expression_2, const char *expression_2_stringified)
 

Variables

double ratio_max_allowed
 Maximum ratio of numbers allowed, see TOLERANCE_RELATIVE. More...
 
double ratio_max
 Maximum ratio of numbers observed so far, see TOLERANCE_RELATIVE. More...
 
double ratio
 Recent ratio of numbers, see TOLERANCE_RELATIVE. More...
 
double absdiff_max_allowed
 Maximum absolute difference of numbers allowed, see TOLERANCE_ABSOLUTE. More...
 
double absdiff_max
 Maximum difference of numbers observed so far, see TOLERANCE_ABSOLUTE. More...
 
double absdiff
 Recent absolute difference of numbers, see TOLERANCE_ABSOLUTE. More...
 
int line_num_1_max
 
int line_num_2_max
 
int verbose
 Verbosity level ( "-v" is 1 and "-V" is 2 ) More...
 
bool all_tests
 Status of the whole test. More...
 
bool test
 Status of the current subsection. More...
 
bool this_test
 Status of last elementary test. More...
 
int exception
 (Used by various macros. Indicates a rough category of the exception being caught.) More...
 
std::string exception_name
 (Used by various macros. Stores the "name" of the exception, if applicable.) More...
 
std::string exception_message
 (Used by various macros. Stores the "message" of the exception, if applicable.) More...
 
std::string test_name
 Name of current subsection. More...
 
int start_section_line
 Line where current subsection started. More...
 
int test_line
 Line of current elementary test. More...
 
const char * version_string
 Version string supplied with START_TEST. More...
 
std::vector< std::string > tmp_file_list
 List of tmp file names (these will be cleaned up, see NEW_TMP_FILE) More...
 
std::vector< UIntfailed_lines_list
 List of all failed lines for summary at the end of the test. More...
 
std::ifstream infile
 Questionable file tested by TEST_FILE_EQUAL. More...
 
std::ifstream templatefile
 Template (correct) file used by TEST_FILE_EQUAL. More...
 
bool equal_files
 (A variable used by TEST_FILE_EQUAL) More...
 
char line_buffer [65536]
 (A buffer for one line from a file. Used by TEST_FILE_EQUAL.) More...
 
int test_count
 Counter for the number of elementary tests within the current subsection. More...
 
std::string add_message
 See ADD_MESSAGE. More...
 
std::string fuzzy_message
 Last message from a fuzzy comparison. Written by isRealSimilar(), testStringSimilar(), isFileSimilar(). Read by TEST_REAL_SIMILAR, TEST_STRING_SIMILAR, TEST_FILE_SIMILAR;. More...
 
bool newline
 (Flags whether a new line is in place, depending on context and verbosity setting. Used by initialNewline() and some macros.) More...
 

Detailed Description

Namespace for class tests.

Function Documentation

◆ filesEqual()

void OpenMS::Internal::ClassTest::filesEqual ( int  line,
const char *  filename,
const char *  templatename,
const char *  filename_stringified,
const char *  templatename_stringified 
)

Test if two files are exactly equal (used in TEST_FILE_EQUAL macro)

Parameters
lineThe line where the macro was called (for reporting)
filenameThe temp file
templatenameThe ground truth file
filename_stringifiedThe expression used as the first macro argument
templatename_stringifiedThe expression used as the second macro argument

◆ initialNewline()

void OpenMS::Internal::ClassTest::initialNewline ( )

make sure we have a newline before results from first subtest

Referenced by testEqual(), and testNotEqual().

◆ isFileSimilar()

bool isFileSimilar ( const std::string &  filename_1,
const std::string &  filename_2 
)

Compare files using absdiff_max_allowed and ratio_max_allowed.

Side effects: Updates absdiff, ratio, fuzzy_message, line_num_1_max and line_num_2_max.

◆ isRealSimilar()

bool OpenMS::Internal::ClassTest::isRealSimilar ( long double  number_1,
long double  number_2 
)

◆ isRealType() [1/6]

bool OpenMS::Internal::ClassTest::isRealType ( const DataValue )
inline

This overload returns true; DataValue will be converted to double by TEST_REAL_SIMILAR.

◆ isRealType() [2/6]

bool OpenMS::Internal::ClassTest::isRealType ( const ParamValue )
inline

This overload returns true; ParamValue will be converted to double by TEST_REAL_SIMILAR.

◆ isRealType() [3/6]

bool OpenMS::Internal::ClassTest::isRealType ( const T &  )
inline

This catch-all template returns false; it will be instantiated for non-floating point types.

◆ isRealType() [4/6]

bool OpenMS::Internal::ClassTest::isRealType ( double  )
inline

This overload returns true; double is a floating point type.

◆ isRealType() [5/6]

bool OpenMS::Internal::ClassTest::isRealType ( float  )
inline

This overload returns true; float is a floating point type.

◆ isRealType() [6/6]

bool OpenMS::Internal::ClassTest::isRealType ( long double  )
inline

This overload returns true; long double is a floating point type.

◆ mainInit()

void OpenMS::Internal::ClassTest::mainInit ( const char *  version,
const char *  class_name,
int  argc,
const char *  argv0 
)

Set up some classtest variables as obtained from the 'START_TEST' macro and check that no additional arguments were passed to the test executable.

Parameters
versionA version string, obtained from 'START_TEST(FuzzyStringComparator, "<VERSION>")'
class_nameThe class under test (used for error messages etc), obtained from 'START_TEST(FuzzyStringComparator, "<VERSION>")'
argcThe number of arguments to the main() function of the class test (must be 1; test will quit otherwise)
argv0Name of the executable (for debug output)

◆ printWithPrefix()

void OpenMS::Internal::ClassTest::printWithPrefix ( const std::string &  text,
const int  marked = -1 
)

print the text, each line gets a prefix, the marked line number gets a special prefix

◆ removeTempFiles()

void OpenMS::Internal::ClassTest::removeTempFiles ( )

removed all temporary files created with the NEW_TMP_FILE macro

◆ setWhitelist()

void OpenMS::Internal::ClassTest::setWhitelist ( const char * const  ,
const int  line,
const std::string &  whitelist 
)

set the whitelist_

◆ testEqual()

void OpenMS::Internal::ClassTest::testEqual ( const char *  ,
int  line,
const T1 &  expression_1,
const char *  expression_1_stringified,
const T2 &  expression_2,
const char *  expression_2_stringified 
)

◆ testNotEqual()

void OpenMS::Internal::ClassTest::testNotEqual ( const char *  ,
int  line,
const T1 &  expression_1,
const char *  expression_1_stringified,
const T2 &  expression_2,
const char *  expression_2_stringified 
)

◆ testRealSimilar()

void OpenMS::Internal::ClassTest::testRealSimilar ( const char *  file,
int  line,
long double  number_1,
const char *  number_1_stringified,
bool  number_1_is_realtype,
Int  number_1_written_digits,
long double  number_2,
const char *  number_2_stringified,
bool  ,
Int  number_2_written_digits 
)

Compare floating point numbers using absdiff_max_allowed and ratio_max_allowed.

Side effects: Updates fuzzy_message.

◆ testStringEqual()

void OpenMS::Internal::ClassTest::testStringEqual ( const char *  file,
int  line,
const std::string &  string_1,
const char *  string_1_stringified,
const std::string &  string_2,
const char *  string_2_stringified 
)

used by TEST_STRING_EQUAL

◆ testStringSimilar()

void testStringSimilar ( const char *  file,
int  line,
const std::string &  string_1,
const char *  string_1_stringified,
const std::string &  string_2,
const char *  string_2_stringified 
)

Compare strings using absdiff_max_allowed and ratio_max_allowed.

This is called by the TEST_STRING_SIMILAR macro.

Side effects: Updates absdiff, ratio, fuzzy_message, line_num_1_max and line_num_2_max.

◆ tmpFileName()

std::string OpenMS::Internal::ClassTest::tmpFileName ( const std::string &  file,
int  line 
)

Creates a temporary file name from the test name and the line.

◆ validate()

bool OpenMS::Internal::ClassTest::validate ( const std::vector< std::string > &  file_names)

Validates the given files against the XML schema (if available)

Returns
If all files passed the validation

Variable Documentation

◆ absdiff

double absdiff
extern

Recent absolute difference of numbers, see TOLERANCE_ABSOLUTE.

◆ absdiff_max

double absdiff_max
extern

Maximum difference of numbers observed so far, see TOLERANCE_ABSOLUTE.

◆ absdiff_max_allowed

double absdiff_max_allowed
extern

Maximum absolute difference of numbers allowed, see TOLERANCE_ABSOLUTE.

◆ add_message

std::string add_message
extern

◆ all_tests

bool all_tests
extern

Status of the whole test.

◆ equal_files

bool equal_files
extern

(A variable used by TEST_FILE_EQUAL)

◆ exception

int exception
extern

(Used by various macros. Indicates a rough category of the exception being caught.)

◆ exception_message

std::string exception_message
extern

(Used by various macros. Stores the "message" of the exception, if applicable.)

◆ exception_name

std::string exception_name
extern

(Used by various macros. Stores the "name" of the exception, if applicable.)

◆ failed_lines_list

std::vector<UInt> failed_lines_list
extern

List of all failed lines for summary at the end of the test.

Referenced by testEqual(), and testNotEqual().

◆ fuzzy_message

std::string fuzzy_message
extern

Last message from a fuzzy comparison. Written by isRealSimilar(), testStringSimilar(), isFileSimilar(). Read by TEST_REAL_SIMILAR, TEST_STRING_SIMILAR, TEST_FILE_SIMILAR;.

◆ infile

std::ifstream infile
extern

Questionable file tested by TEST_FILE_EQUAL.

◆ line_buffer

char line_buffer[65536]
extern

(A buffer for one line from a file. Used by TEST_FILE_EQUAL.)

◆ line_num_1_max

int line_num_1_max
extern

◆ line_num_2_max

int line_num_2_max
extern

◆ newline

bool newline
extern

(Flags whether a new line is in place, depending on context and verbosity setting. Used by initialNewline() and some macros.)

◆ ratio

double ratio
extern

Recent ratio of numbers, see TOLERANCE_RELATIVE.

◆ ratio_max

double ratio_max
extern

Maximum ratio of numbers observed so far, see TOLERANCE_RELATIVE.

◆ ratio_max_allowed

double ratio_max_allowed
extern

Maximum ratio of numbers allowed, see TOLERANCE_RELATIVE.

◆ start_section_line

int start_section_line
extern

Line where current subsection started.

◆ templatefile

std::ifstream templatefile
extern

Template (correct) file used by TEST_FILE_EQUAL.

◆ test

bool test
extern

Status of the current subsection.

Referenced by testEqual(), and testNotEqual().

◆ test_count

int test_count
extern

Counter for the number of elementary tests within the current subsection.

Referenced by testEqual(), and testNotEqual().

◆ test_line

int test_line
extern

Line of current elementary test.

Referenced by testEqual(), and testNotEqual().

◆ test_name

std::string test_name
extern

Name of current subsection.

◆ this_test

bool this_test
extern

Status of last elementary test.

Referenced by testEqual(), and testNotEqual().

◆ tmp_file_list

std::vector<std::string> tmp_file_list
extern

List of tmp file names (these will be cleaned up, see NEW_TMP_FILE)

◆ verbose

int verbose
extern

Verbosity level ( "-v" is 1 and "-V" is 2 )

◆ version_string

const char* version_string
extern

Version string supplied with START_TEST.