[Echempp-devel] Experiment/Experiment/test ExperimentTest.cpp, NONE, 1.1
Status: Beta
Brought to you by:
berndspeiser
|
From: beeblbrox <bee...@us...> - 2007-04-06 10:13:43
|
Update of /cvsroot/echempp/Experiment/Experiment/test In directory sc8-pr-cvs5.sourceforge.net:/tmp/cvs-serv13546/test Added Files: ExperimentTest.cpp Log Message: Initial version. So far only minor checks for construction + serialization. --- NEW FILE: ExperimentTest.cpp --- // Boost includes #include <boost/test/unit_test.hpp> using namespace boost::unit_test; #include <boost/archive/text_oarchive.hpp> #include <boost/archive/text_iarchive.hpp> #include <boost/archive/xml_iarchive.hpp> #include <boost/archive/xml_oarchive.hpp> // local includes #include "../Experiment.hpp" using namespace experiment; // Note: Compile and link with: // g++ -o ExperimentTest ExperimentTest.cpp -lboost_unit_test_framework // TODO: Enter this in Makefile.am void test_creation_destruction() { Experiment *ep; ep = new experiment::MyAction(Dynamic,Real); delete ep; ep = new Observation(Dynamic,Real); delete ep; // ep = new Collection(); // delete ep; ep = new Homogeneous(); delete ep; // ep = new Sequential(); // delete ep; // ep = new Simultaneous(); // delete ep; } void test_serialization() { const Experiment *cep; { // Action serialization experiment::MyAction *act; act = new experiment::MyAction(Dynamic, Real); std::ofstream ofs_txt("/tmp/action.txt"); boost::archive::text_oarchive oa_txt(ofs_txt); std::ofstream ofs_xml("/tmp/action.xml"); boost::archive::xml_oarchive oa_xml(ofs_xml); const experiment::MyAction a(Dynamic, Real); cep = act; // oa_txt << *cep; oa_txt << a; oa_xml << BOOST_SERIALIZATION_NVP(a); ofs_txt.close(); ofs_xml.close(); } // Homogeneous serialization Homogeneous hg; hg.add(new experiment::MyAction(Dynamic,Real)); hg.add(new Observation(Dynamic,Real)); hg.add(new experiment::MyAction(Dynamic,Real)); std::ofstream ofs_txt("/tmp/exp.txt"); boost::archive::text_oarchive oa_txt(ofs_txt); std::ofstream ofs_xml("/tmp/exp.xml"); boost::archive::xml_oarchive oa_xml(ofs_xml); //cep = hg; const Homogeneous& hgc = hg; oa_txt << hgc; oa_xml << BOOST_SERIALIZATION_NVP(hgc); // oa_xml << BOOST_SERIALIZATION_NVP(*cep); ofs_txt.close(); ofs_xml.close(); std::ifstream ifs_txt("/tmp/exp.txt"); boost::archive::text_iarchive ia_txt(ifs_txt); Homogeneous hg2; ia_txt >> hg2; ifs_txt.close(); } test_suite* init_unit_test_suite( int argc, char * argv[] ) { test_suite* test= BOOST_TEST_SUITE( "Experiment unit test" ); test->add( BOOST_TEST_CASE( &test_creation_destruction ) ); test->add( BOOST_TEST_CASE( &test_serialization ) ); // test->add( BOOST_TEST_CASE( &infinite_loop ), 0, /* timeout */ 2 ); return test; } |