MOAB: Mesh Oriented datABase
(version 5.4.1)
|
Public Member Functions | |
FileTokenizerTest () | |
void | setUp () |
void | tearDown () |
FILE * | make_file () |
void | token_test () |
void | line_number_test () |
void | newline_test () |
void | match_one_test () |
void | match_multiple_test () |
void | double_test () |
void | long_test () |
void | boolean_test () |
void | unget_test () |
Static Public Member Functions | |
static int | count_newlines (const char *str) |
Private Member Functions | |
CPPUNIT_TEST_SUITE (FileTokenizerTest) | |
CPPUNIT_TEST (token_test) | |
CPPUNIT_TEST (line_number_test) | |
CPPUNIT_TEST (newline_test) | |
CPPUNIT_TEST (match_one_test) | |
CPPUNIT_TEST (match_multiple_test) | |
CPPUNIT_TEST (double_test) | |
CPPUNIT_TEST (long_test) | |
CPPUNIT_TEST (boolean_test) | |
CPPUNIT_TEST (unget_test) | |
CPPUNIT_TEST_SUITE_END () |
Definition at line 27 of file FileTokenizerTest.cpp.
FileTokenizerTest::FileTokenizerTest | ( | ) | [inline] |
Definition at line 43 of file FileTokenizerTest.cpp.
{}
void FileTokenizerTest::boolean_test | ( | ) | [inline] |
Definition at line 264 of file FileTokenizerTest.cpp.
References booleans, MBMesquite::MsqError::clear(), CPPUNIT_ASSERT, MBMesquite::ft, MBMesquite::FileTokenizer::get_booleans(), make_file(), tokens, and value().
{ MsqPrintError err( cout ); FileTokenizer ft( make_file() ); for( int i = 0; tokens[i]; ++i ) { bool value; ft.get_booleans( 1, &value, err ); if( booleans[i] ) { CPPUNIT_ASSERT( !err ); CPPUNIT_ASSERT( value == !!atoi( tokens[i] ) ); } else { CPPUNIT_ASSERT( err ); err.clear(); } } }
static int FileTokenizerTest::count_newlines | ( | const char * | str | ) | [inline, static] |
Definition at line 103 of file FileTokenizerTest.cpp.
Referenced by line_number_test(), and newline_test().
{ int result = 0; for( ; *str; ++str ) if( *str == '\n' ) ++result; return result; }
FileTokenizerTest::CPPUNIT_TEST | ( | token_test | ) | [private] |
FileTokenizerTest::CPPUNIT_TEST | ( | line_number_test | ) | [private] |
FileTokenizerTest::CPPUNIT_TEST | ( | newline_test | ) | [private] |
FileTokenizerTest::CPPUNIT_TEST | ( | match_one_test | ) | [private] |
FileTokenizerTest::CPPUNIT_TEST | ( | match_multiple_test | ) | [private] |
FileTokenizerTest::CPPUNIT_TEST | ( | double_test | ) | [private] |
FileTokenizerTest::CPPUNIT_TEST | ( | long_test | ) | [private] |
FileTokenizerTest::CPPUNIT_TEST | ( | boolean_test | ) | [private] |
FileTokenizerTest::CPPUNIT_TEST | ( | unget_test | ) | [private] |
FileTokenizerTest::CPPUNIT_TEST_SUITE | ( | FileTokenizerTest | ) | [private] |
FileTokenizerTest::CPPUNIT_TEST_SUITE_END | ( | ) | [private] |
void FileTokenizerTest::double_test | ( | ) | [inline] |
Definition at line 220 of file FileTokenizerTest.cpp.
References MBMesquite::MsqError::clear(), CPPUNIT_ASSERT, doubles, MBMesquite::ft, MBMesquite::FileTokenizer::get_doubles(), make_file(), tokens, and value().
{ MsqPrintError err( cout ); FileTokenizer ft( make_file() ); for( int i = 0; tokens[i]; ++i ) { double value; ft.get_doubles( 1, &value, err ); if( doubles[i] ) { CPPUNIT_ASSERT( !err ); CPPUNIT_ASSERT( value == strtod( tokens[i], 0 ) ); } else { CPPUNIT_ASSERT( err ); err.clear(); } } }
void FileTokenizerTest::line_number_test | ( | ) | [inline] |
Definition at line 111 of file FileTokenizerTest.cpp.
References count_newlines(), CPPUNIT_ASSERT, MBMesquite::ft, MBMesquite::FileTokenizer::get_string(), MBMesquite::FileTokenizer::line_number(), make_file(), and spaces.
{ MsqPrintError err( cout ); const char* token; FileTokenizer ft( make_file() ); int lineno = 1; token = ft.get_string( err ); CPPUNIT_ASSERT( token ); CPPUNIT_ASSERT( !err ); for( const char* const* s_iter = spaces; *s_iter; ++s_iter ) { token = ft.get_string( err ); CPPUNIT_ASSERT( token ); CPPUNIT_ASSERT( !err ); lineno += count_newlines( *s_iter ); CPPUNIT_ASSERT( ft.line_number() == lineno ); } }
void FileTokenizerTest::long_test | ( | ) | [inline] |
Definition at line 242 of file FileTokenizerTest.cpp.
References MBMesquite::MsqError::clear(), CPPUNIT_ASSERT, MBMesquite::ft, MBMesquite::FileTokenizer::get_long_ints(), longs, make_file(), tokens, and value().
{ MsqPrintError err( cout ); FileTokenizer ft( make_file() ); for( int i = 0; tokens[i]; ++i ) { long value; ft.get_long_ints( 1, &value, err ); if( longs[i] ) { CPPUNIT_ASSERT( !err ); CPPUNIT_ASSERT( value == strtol( tokens[i], 0, 0 ) ); } else { CPPUNIT_ASSERT( err ); err.clear(); } } }
FILE* FileTokenizerTest::make_file | ( | ) | [inline] |
Definition at line 49 of file FileTokenizerTest.cpp.
References buffer, CPPUNIT_ASSERT, spaces, and tokens.
Referenced by boolean_test(), double_test(), line_number_test(), long_test(), match_multiple_test(), match_one_test(), newline_test(), token_test(), and unget_test().
{ #ifdef WIN32 char name1[L_tmpnam_s]; errno_t err = tmpnam_s( name1, L_tmpnam_s ); // Get the current working directory: char* buffer; buffer = _getcwd( NULL, 0 ); std::string full_path( buffer ); std::string temp_name( name1 ); full_path = full_path + temp_name; FILE* file = fopen( full_path.c_str(), "w+" ); #else FILE* file = tmpfile(); #endif CPPUNIT_ASSERT( !!file ); const char* const* t_iter = tokens; const char* const* s_iter = spaces; fputs( *t_iter, file ); ++t_iter; while( *t_iter ) { fputs( *s_iter, file ); ++s_iter; fputs( *t_iter, file ); ++t_iter; } rewind( file ); return file; }
void FileTokenizerTest::match_multiple_test | ( | ) | [inline] |
Definition at line 190 of file FileTokenizerTest.cpp.
References MBMesquite::MsqError::clear(), CPPUNIT_ASSERT, MBMesquite::ft, make_file(), MBMesquite::FileTokenizer::match_token(), and tokens.
{ MsqPrintError err( cout ); const char* const* t_iter = tokens; FileTokenizer ft( make_file() ); int result; const char* const test1[] = { *t_iter, "Mesquite", "x", 0 }; result = ft.match_token( test1, err ); CPPUNIT_ASSERT( result == 1 && !err ); ++t_iter; const char* const test2[] = { "x", "y", *t_iter, 0 }; result = ft.match_token( test2, err ); CPPUNIT_ASSERT( result == 3 && !err ); ++t_iter; const char* const test3[] = { *t_iter, 0 }; result = ft.match_token( test3, err ); CPPUNIT_ASSERT( result == 1 && !err ); ++t_iter; const char* const test4[] = { "Mesquite", "Mesh", 0 }; result = ft.match_token( test4, err ); CPPUNIT_ASSERT( result == 0 && err ); err.clear(); ++t_iter; }
void FileTokenizerTest::match_one_test | ( | ) | [inline] |
Definition at line 165 of file FileTokenizerTest.cpp.
References b, MBMesquite::MsqError::clear(), CPPUNIT_ASSERT, MBMesquite::ft, make_file(), MBMesquite::FileTokenizer::match_token(), and tokens.
{ MsqPrintError err( cout ); const char* const* t_iter; bool b; FileTokenizer ft( make_file() ); for( t_iter = tokens; *t_iter; ++t_iter ) { b = ft.match_token( *t_iter, err ); CPPUNIT_ASSERT( b && !err ); } FileTokenizer ft2( make_file() ); b = ft2.match_token( "", err ); CPPUNIT_ASSERT( !b && err ); err.clear(); b = ft2.match_token( "Mesquite", err ); CPPUNIT_ASSERT( !b && err ); err.clear(); }
void FileTokenizerTest::newline_test | ( | ) | [inline] |
Definition at line 134 of file FileTokenizerTest.cpp.
References b, MBMesquite::MsqError::clear(), count_newlines(), CPPUNIT_ASSERT, MBMesquite::ft, MBMesquite::FileTokenizer::get_newline(), MBMesquite::FileTokenizer::get_string(), make_file(), and spaces.
{ MsqPrintError err( cout ); const char* token; FileTokenizer ft( make_file() ); token = ft.get_string( err ); CPPUNIT_ASSERT( token ); CPPUNIT_ASSERT( !err ); for( const char* const* s_iter = spaces; *s_iter; ++s_iter ) { int count = count_newlines( *s_iter ); bool b; while( count-- ) { b = ft.get_newline( err ); CPPUNIT_ASSERT( b && !err ); } b = ft.get_newline( err ); CPPUNIT_ASSERT( !b && err ); err.clear(); token = ft.get_string( err ); CPPUNIT_ASSERT( token ); CPPUNIT_ASSERT( !err ); } }
void FileTokenizerTest::setUp | ( | ) | [inline] |
Definition at line 45 of file FileTokenizerTest.cpp.
{}
void FileTokenizerTest::tearDown | ( | ) | [inline] |
Definition at line 47 of file FileTokenizerTest.cpp.
{}
void FileTokenizerTest::token_test | ( | ) | [inline] |
Definition at line 82 of file FileTokenizerTest.cpp.
References MBMesquite::MsqError::clear(), CPPUNIT_ASSERT, MBMesquite::FileTokenizer::eof(), MBMesquite::ft, MBMesquite::FileTokenizer::get_string(), make_file(), and tokens.
{ MsqPrintError err( cout ); const char* token; FileTokenizer ft( make_file() ); for( const char* const* t_iter = tokens; *t_iter; ++t_iter ) { token = ft.get_string( err ); CPPUNIT_ASSERT( token ); CPPUNIT_ASSERT( !err ); CPPUNIT_ASSERT( !strcmp( *t_iter, token ) ); } token = ft.get_string( err ); CPPUNIT_ASSERT( !token ); CPPUNIT_ASSERT( ft.eof() ); err.clear(); }
void FileTokenizerTest::unget_test | ( | ) | [inline] |
Definition at line 286 of file FileTokenizerTest.cpp.
References CPPUNIT_ASSERT, MBMesquite::ft, MBMesquite::FileTokenizer::get_string(), make_file(), tokens, and MBMesquite::FileTokenizer::unget_token().
{ MsqPrintError err( cout ); FileTokenizer ft( make_file() ); const char* const* t_iter = tokens; const char* token = ft.get_string( err ); CPPUNIT_ASSERT( !err ); CPPUNIT_ASSERT( !strcmp( token, *t_iter ) ); ft.unget_token(); token = ft.get_string( err ); CPPUNIT_ASSERT( !err ); CPPUNIT_ASSERT( !strcmp( token, *t_iter ) ); ++t_iter; token = ft.get_string( err ); CPPUNIT_ASSERT( !err ); CPPUNIT_ASSERT( !strcmp( token, *t_iter ) ); ++t_iter; token = ft.get_string( err ); CPPUNIT_ASSERT( !err ); CPPUNIT_ASSERT( !strcmp( token, *t_iter ) ); ft.unget_token(); token = ft.get_string( err ); CPPUNIT_ASSERT( !err ); CPPUNIT_ASSERT( !strcmp( token, *t_iter ) ); }