MOAB: Mesh Oriented datABase
(version 5.4.1)
|
00001 /* ***************************************************************** 00002 MESQUITE -- The Mesh Quality Improvement Toolkit 00003 00004 Copyright 2004 Sandia Corporation and Argonne National 00005 Laboratory. Under the terms of Contract DE-AC04-94AL85000 00006 with Sandia Corporation, the U.S. Government retains certain 00007 rights in this software. 00008 00009 This library is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU Lesser General Public 00011 License as published by the Free Software Foundation; either 00012 version 2.1 of the License, or (at your option) any later version. 00013 00014 This library is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public License 00020 (lgpl.txt) along with this library; if not, write to the Free Software 00021 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00022 00023 diachin2@llnl.gov, djmelan@sandia.gov, mbrewer@sandia.gov, 00024 pknupp@sandia.gov, tleurent@mcs.anl.gov, tmunson@mcs.anl.gov 00025 00026 ***************************************************************** */ 00027 #include <cppunit/extensions/TestFactoryRegistry.h> 00028 #include <cppunit/ui/text/TestRunner.h> 00029 #include <cppunit/Outputter.h> 00030 #include <cppunit/TestResultCollector.h> 00031 #include <cppunit/TestFailure.h> 00032 #include <cppunit/Test.h> 00033 #include <cassert> 00034 #include <cstdio> 00035 #include <cstring> 00036 #include <cstdlib> 00037 00038 #include <vector> 00039 #include <iostream> 00040 using namespace std; 00041 00042 #include "MsqFPE.hpp" 00043 00044 class CPPUNIT_API SummaryOutput : public CppUnit::Outputter 00045 { 00046 public: 00047 SummaryOutput( FILE* file, CppUnit::TestResultCollector* result ) : file_( file ), results_( result ) {} 00048 void write(); 00049 00050 private: 00051 FILE* file_; 00052 CppUnit::TestResultCollector* results_; 00053 }; 00054 00055 int main( int argc, char** argv ) 00056 { 00057 CppUnit::Test* test; 00058 vector< CppUnit::Test* > test_list; 00059 CppUnit::TextUi::TestRunner runner; 00060 int firsttest = 1; 00061 bool list = false; 00062 MBMesquite::MsqFPE trap_fpe( true ); 00063 00064 // Check for command line arguments 00065 if( argc > 2 && !strcmp( argv[1], "-s" ) ) 00066 { 00067 FILE* file = fopen( argv[2], "w" ); 00068 if( !file ) 00069 { 00070 perror( argv[2] ); 00071 exit( 1 ); 00072 } 00073 runner.setOutputter( new SummaryOutput( file, &runner.result() ) ); 00074 firsttest += 2; 00075 } 00076 else if( argc > 1 && !strcmp( argv[1], "-l" ) ) 00077 { 00078 ++firsttest; 00079 list = true; 00080 } 00081 00082 // If the user requested a specific test... 00083 if( argc > firsttest ) 00084 { 00085 while( argc > firsttest ) 00086 { 00087 argc--; 00088 CppUnit::TestFactoryRegistry& registry = CppUnit::TestFactoryRegistry::getRegistry( argv[argc] ); 00089 test = registry.makeTest(); 00090 if( !test->countTestCases() ) 00091 { 00092 std::cerr << argv[argc] << ": does not match any test or group" << std::endl; 00093 return 1; 00094 } 00095 test_list.push_back( test ); 00096 } 00097 } 00098 // Otherwise do Unit and Regression suites 00099 else 00100 { 00101 test = CppUnit::TestFactoryRegistry::getRegistry( "Unit" ).makeTest(); 00102 test_list.push_back( test ); 00103 test = CppUnit::TestFactoryRegistry::getRegistry( "Regression" ).makeTest(); 00104 test_list.push_back( test ); 00105 } 00106 00107 // If user just wants list of tests 00108 if( list ) 00109 { 00110 for( vector< CppUnit::Test* >::iterator i = test_list.begin(); i != test_list.end(); ++i ) 00111 { 00112 CppUnit::TestSuite* suite = dynamic_cast< CppUnit::TestSuite* >( *i ); 00113 if( !suite ) 00114 { 00115 cout << ( *i )->getName() << endl; 00116 continue; 00117 } 00118 const vector< CppUnit::Test* >& list = suite->getTests(); 00119 for( vector< CppUnit::Test* >::const_iterator j = list.begin(); j != list.end(); ++j ) 00120 cout << ( *j )->getName() << endl; 00121 } 00122 } 00123 // Otherwise run the tests 00124 else 00125 { 00126 for( vector< CppUnit::Test* >::iterator i = test_list.begin(); i != test_list.end(); ++i ) 00127 runner.addTest( *i ); 00128 return !runner.run(); 00129 } 00130 00131 // Return 0 if there were no errors 00132 return 0; 00133 } 00134 00135 void SummaryOutput::write() 00136 { 00137 CppUnit::TestResultCollector::TestFailures fails = results_->failures(); 00138 CppUnit::TestResultCollector::Tests tests = results_->tests(); 00139 00140 CppUnit::TestResultCollector::TestFailures::const_iterator f_iter = fails.begin(); 00141 CppUnit::TestResultCollector::Tests::const_iterator t_iter; 00142 00143 fprintf( file_, "****Tests Run:\n" ); 00144 for( t_iter = tests.begin(); t_iter != tests.end(); ++t_iter ) 00145 fprintf( file_, "%s\n", ( *t_iter )->getName().c_str() ); 00146 00147 fprintf( file_, "****Tests Failed:\n" ); 00148 for( f_iter = fails.begin(); f_iter != fails.end(); ++f_iter ) 00149 fprintf( file_, "%s\n", ( *f_iter )->failedTestName().c_str() ); 00150 }