Commit in lcio/src/cpp/src/TESTS on MAIN
test_example.cc+57added 1.1
tutil.h+44added 1.1
+101
2 added files
added template for creating small LCIO tests

lcio/src/cpp/src/TESTS
test_example.cc added at 1.1
diff -N test_example.cc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ test_example.cc	4 Jun 2008 17:32:23 -0000	1.1
@@ -0,0 +1,57 @@
+////////////////////////////////////////
+// example for LCIO tests
+////////////////////////////////////////
+
+#include "tutil.h"
+#include "lcio.h"
+
+#include "EVENT/LCIO.h"
+#include "IO/LCWriter.h"
+#include "IMPL/LCEventImpl.h" 
+#include "IMPL/LCCollectionVec.h"
+
+#include <iostream>
+
+using namespace std ;
+using namespace lcio ;
+
+// replace mytest with the name of your test
+const static string testname="mytest";
+
+//=============================================================================
+
+int main(int argc, char** argv ){
+    
+    // this should be the first line in your test
+    TEST MYTEST=TEST( testname, std::cout );
+    
+    // write your test here
+    for( int i=0; i<3; i++){
+        MYTEST.LOG( "this is just a test..." );
+    }
+
+    //if( true ){
+    if( false ){
+        // force test program to fail in this way:
+        MYTEST.FAILED( "oops, something went wrong..." );
+    }
+
+    // example with a try&catch fail condition:
+    //
+    ///////////////////////////////////////////////////////////////////////
+    //LCReader* lcReader = LCFactory::getInstance()->createLCReader() ;
+    //try{
+    //    lcReader->open( "blub.slcio" ) ;
+    //}
+    //catch( Exception &e ){
+    //    MYTEST.FAILED( e.what() );
+    //}
+    //lcReader->close();
+    //delete lcReader;
+    ///////////////////////////////////////////////////////////////////////
+
+    return 0;
+}
+
+//=============================================================================
+

lcio/src/cpp/src/TESTS
tutil.h added at 1.1
diff -N tutil.h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tutil.h	4 Jun 2008 17:32:23 -0000	1.1
@@ -0,0 +1,44 @@
+#include <iostream>
+//#include <cstring>
+#include <sstream>
+
+class TEST{
+
+public:
+
+    TEST( const std::string& tname, std::ostream& stream=std::cout ): _testname(tname), _out(stream){
+        _out << std::endl << "[" << _testname << "] ";
+        _out << "TEST_BEGIN ******************************" << std::endl << std::endl;
+    }
+
+    ~TEST(){
+        _out << std::endl << "[" << _testname << "] ";
+        _out << "TEST_PASSED ******************************" << std::endl << std::endl;
+    }
+
+    void LOG( const std::string& msg ){
+        _out << "[" << _testname << "] LOG: " << msg << std::endl;
+    }
+
+    void FAILED( const std::string& msg ){
+        
+        std::stringstream errmsg;
+        errmsg << std::endl;
+        errmsg << "[" << _testname << "] TEST_FAILED ############################################" << std::endl;
+        errmsg << "[" << _testname << "] TEST_ERROR: " << msg << std::endl;
+        errmsg << "[" << _testname << "] TEST_FAILED ############################################" << std::endl;
+        errmsg << std::endl;
+
+        _out << errmsg.str();
+
+        // also send error to stderr
+        std::cerr << errmsg.str();
+
+        // abort program
+        exit(1);
+    }
+
+private:
+    std::string _testname;
+    std::ostream& _out;
+};
CVSspam 0.2.8