psana/test/InputIterTest.cpp

Go to the documentation of this file.
00001 //--------------------------------------------------------------------------
00002 // File and Version Information:
00003 //      $Id: InputIterTest.cpp 7715 2014-02-28 03:30:21Z salnikov@SLAC.STANFORD.EDU $
00004 //
00005 // Description:
00006 //      Test suite case for the InputIterTest.
00007 //
00008 //------------------------------------------------------------------------
00009 
00010 //---------------
00011 // C++ Headers --
00012 //---------------
00013 #include <boost/make_shared.hpp>
00014 #include <algorithm>
00015 #include <iterator>
00016 #include <iostream>
00017 
00018 //-------------------------------
00019 // Collaborating Class Headers --
00020 //-------------------------------
00021 #include "psana/InputIter.h"
00022 #include "psana/InputModule.h"
00023 #include "PSEnv/Env.h"
00024 
00025 using namespace psana ;
00026 
00027 #define BOOST_TEST_MODULE InputIterTest
00028 #include <boost/test/included/unit_test.hpp>
00029 
00030 /**
00031  * Simple test suite for class InputIter.
00032  * See http://www.boost.org/doc/libs/1_36_0/libs/test/doc/html/index.html
00033  */
00034 
00035 namespace {
00036 
00037 // Implementation of the InputModulle which generates sequences of events
00038 class TestInputModule: public InputModule {
00039 public:
00040   
00041   TestInputModule(const InputModule::Status states[], int nstates) : InputModule("TestInputModule")
00042   {
00043     std::copy(states, states+nstates, std::back_inserter(m_states));
00044   }
00045   
00046   virtual void beginJob(Event& evt, Env& env) {}
00047 
00048   virtual Status event(Event& evt, Env& env) {
00049     InputModule::Status state = InputModule::Stop;
00050     if (not m_states.empty()) {
00051       state = m_states.front();
00052       m_states.pop_front();
00053     }
00054     return state;
00055   }
00056   
00057   virtual void endJob(Event& evt, Env& env) {}
00058 
00059 private:
00060   
00061   std::deque<psana::InputModule::Status> m_states;  
00062 };
00063 
00064 struct Fixture {
00065   
00066   Fixture(const InputModule::Status states[], int nstates, InputIter::EventType expected[], unsigned nexpected) 
00067   {
00068     boost::shared_ptr<AliasMap> amap = boost::make_shared<AliasMap>();
00069     boost::shared_ptr<PSEnv::IExpNameProvider> expNameProvider;
00070     boost::shared_ptr<PSEnv::Env> env = boost::make_shared<PSEnv::Env>("", expNameProvider, "", amap, 0);
00071     boost::shared_ptr<InputModule> input = boost::make_shared<TestInputModule>(states, nstates);
00072     iter = boost::make_shared<InputIter>(input, env);
00073     std::copy(expected, expected+nexpected, std::back_inserter(exp));
00074 
00075   }
00076   
00077   std::vector<InputIter::EventType> readAll() 
00078   {
00079     std::vector<InputIter::EventType> result;
00080     InputIter::value_type val;
00081     do {
00082       val = iter->next();
00083       result.push_back(val.first);
00084     } while (val.first != InputIter::None);
00085     return result;
00086   }
00087 
00088   bool checkResult()
00089   {
00090     std::vector<InputIter::EventType> res = readAll();
00091     
00092     std::cout << "expected: ";
00093     std::copy(exp.begin(), exp.end(), std::ostream_iterator<InputIter::EventType>(std::cout, " "));
00094     std::cout << "\n";
00095     std::cout << "result  : ";
00096     std::copy(res.begin(), res.end(), std::ostream_iterator<InputIter::EventType>(std::cout, " "));
00097     std::cout << "\n";
00098 
00099     return res == exp;
00100   }
00101 
00102   boost::shared_ptr<InputIter> iter;
00103   std::vector<InputIter::EventType> exp;
00104 };
00105 
00106 
00107 }
00108 
00109 
00110 // ==============================================================
00111 
00112 BOOST_AUTO_TEST_CASE( test_1 )
00113 {
00114   InputModule::Status states[] = {
00115       InputModule::BeginRun,
00116       InputModule::BeginCalibCycle,
00117       InputModule::DoEvent,
00118       InputModule::DoEvent,
00119       InputModule::EndCalibCycle,
00120       InputModule::EndRun,
00121   };
00122   InputIter::EventType expected[] = {
00123       InputIter::BeginJob,
00124       InputIter::BeginRun,
00125       InputIter::BeginCalibCycle,
00126       InputIter::Event,
00127       InputIter::Event,
00128       InputIter::EndCalibCycle,
00129       InputIter::EndRun,
00130       InputIter::EndJob,
00131       InputIter::None,
00132   };
00133   
00134   Fixture f(states, sizeof states/sizeof states[0], expected, sizeof expected/sizeof expected[0]);
00135   BOOST_CHECK(f.checkResult());
00136 }
00137 
00138 // ==============================================================
00139 
00140 BOOST_AUTO_TEST_CASE( test_2 )
00141 {
00142   InputModule::Status states[] = {
00143       InputModule::BeginRun,
00144       InputModule::Skip,
00145       InputModule::BeginCalibCycle,
00146       InputModule::Skip,
00147       InputModule::DoEvent,
00148       InputModule::Skip,
00149       InputModule::DoEvent,
00150       InputModule::Skip,
00151       InputModule::EndCalibCycle,
00152       InputModule::Skip,
00153       InputModule::EndRun,
00154   };
00155   InputIter::EventType expected[] = {
00156       InputIter::BeginJob,
00157       InputIter::BeginRun,
00158       InputIter::BeginCalibCycle,
00159       InputIter::Event,
00160       InputIter::Event,
00161       InputIter::EndCalibCycle,
00162       InputIter::EndRun,
00163       InputIter::EndJob,
00164       InputIter::None,
00165   };
00166   
00167   
00168   Fixture f(states, sizeof states/sizeof states[0], expected, sizeof expected/sizeof expected[0]);
00169   BOOST_CHECK(f.checkResult());
00170 }
00171 
00172 // ==============================================================
00173 
00174 BOOST_AUTO_TEST_CASE( test_3 )
00175 {
00176   InputModule::Status states[] = {
00177       InputModule::BeginRun,
00178       InputModule::BeginCalibCycle,
00179       InputModule::DoEvent,
00180       InputModule::DoEvent,
00181       InputModule::EndCalibCycle,
00182       InputModule::BeginCalibCycle,
00183       InputModule::DoEvent,
00184       InputModule::DoEvent,
00185       InputModule::EndCalibCycle,
00186       InputModule::EndRun,
00187   };
00188   InputIter::EventType expected[] = {
00189       InputIter::BeginJob,
00190       InputIter::BeginRun,
00191       InputIter::BeginCalibCycle,
00192       InputIter::Event,
00193       InputIter::Event,
00194       InputIter::EndCalibCycle,
00195       InputIter::BeginCalibCycle,
00196       InputIter::Event,
00197       InputIter::Event,
00198       InputIter::EndCalibCycle,
00199       InputIter::EndRun,
00200       InputIter::EndJob,
00201       InputIter::None,
00202   };
00203   
00204   Fixture f(states, sizeof states/sizeof states[0], expected, sizeof expected/sizeof expected[0]);
00205   BOOST_CHECK(f.checkResult());
00206 }
00207 
00208 // ==============================================================
00209 
00210 BOOST_AUTO_TEST_CASE( test_4 )
00211 {
00212   InputModule::Status states[] = {
00213       InputModule::BeginRun,
00214       InputModule::BeginCalibCycle,
00215       InputModule::DoEvent,
00216       InputModule::DoEvent,
00217       InputModule::EndCalibCycle,
00218       InputModule::EndRun,
00219       InputModule::BeginRun,
00220       InputModule::BeginCalibCycle,
00221       InputModule::DoEvent,
00222       InputModule::DoEvent,
00223       InputModule::EndCalibCycle,
00224       InputModule::EndRun,
00225   };
00226   InputIter::EventType expected[] = {
00227       InputIter::BeginJob,
00228       InputIter::BeginRun,
00229       InputIter::BeginCalibCycle,
00230       InputIter::Event,
00231       InputIter::Event,
00232       InputIter::EndCalibCycle,
00233       InputIter::EndRun,
00234       InputIter::BeginRun,
00235       InputIter::BeginCalibCycle,
00236       InputIter::Event,
00237       InputIter::Event,
00238       InputIter::EndCalibCycle,
00239       InputIter::EndRun,
00240       InputIter::EndJob,
00241       InputIter::None,
00242   };
00243   
00244   Fixture f(states, sizeof states/sizeof states[0], expected, sizeof expected/sizeof expected[0]);
00245   BOOST_CHECK(f.checkResult());
00246 }
00247 
00248 // ==============================================================
00249 
00250 BOOST_AUTO_TEST_CASE( test_5 )
00251 {
00252   InputModule::Status states[] = {
00253       InputModule::BeginRun,
00254       InputModule::BeginCalibCycle,
00255       InputModule::DoEvent,
00256       InputModule::DoEvent,
00257 //      InputModule::EndCalibCycle,
00258 //      InputModule::EndRun,
00259       InputModule::BeginRun,
00260       InputModule::BeginCalibCycle,
00261       InputModule::DoEvent,
00262       InputModule::DoEvent,
00263       InputModule::EndCalibCycle,
00264       InputModule::EndRun,
00265   };
00266   InputIter::EventType expected[] = {
00267       InputIter::BeginJob,
00268       InputIter::BeginRun,
00269       InputIter::BeginCalibCycle,
00270       InputIter::Event,
00271       InputIter::Event,
00272       InputIter::EndCalibCycle,
00273       InputIter::EndRun,
00274       InputIter::BeginRun,
00275       InputIter::BeginCalibCycle,
00276       InputIter::Event,
00277       InputIter::Event,
00278       InputIter::EndCalibCycle,
00279       InputIter::EndRun,
00280       InputIter::EndJob,
00281       InputIter::None,
00282   };
00283   
00284   Fixture f(states, sizeof states/sizeof states[0], expected, sizeof expected/sizeof expected[0]);
00285   BOOST_CHECK(f.checkResult());
00286 }
00287 
00288 // ==============================================================
00289 
00290 BOOST_AUTO_TEST_CASE( test_6 )
00291 {
00292   InputModule::Status states[] = {
00293       InputModule::BeginRun,
00294       InputModule::BeginCalibCycle,
00295       InputModule::DoEvent,
00296       InputModule::DoEvent,
00297 //      InputModule::EndCalibCycle,
00298 //      InputModule::EndRun,
00299   };
00300   InputIter::EventType expected[] = {
00301       InputIter::BeginJob,
00302       InputIter::BeginRun,
00303       InputIter::BeginCalibCycle,
00304       InputIter::Event,
00305       InputIter::Event,
00306       InputIter::EndCalibCycle,
00307       InputIter::EndRun,
00308       InputIter::EndJob,
00309       InputIter::None,
00310   };
00311   
00312   Fixture f(states, sizeof states/sizeof states[0], expected, sizeof expected/sizeof expected[0]);
00313   BOOST_CHECK(f.checkResult());
00314 }
00315 
00316 // ==============================================================
00317 
00318 BOOST_AUTO_TEST_CASE( test_7 )
00319 {
00320   InputModule::Status states[] = {
00321 //      InputModule::BeginRun,
00322 //      InputModule::BeginCalibCycle,
00323       InputModule::DoEvent,
00324       InputModule::DoEvent,
00325       InputModule::EndCalibCycle,
00326       InputModule::EndRun,
00327   };
00328   InputIter::EventType expected[] = {
00329       InputIter::BeginJob,
00330       InputIter::BeginRun,
00331       InputIter::BeginCalibCycle,
00332       InputIter::Event,
00333       InputIter::Event,
00334       InputIter::EndCalibCycle,
00335       InputIter::EndRun,
00336       InputIter::EndJob,
00337       InputIter::None,
00338   };
00339   
00340   Fixture f(states, sizeof states/sizeof states[0], expected, sizeof expected/sizeof expected[0]);
00341   BOOST_CHECK(f.checkResult());
00342 }
00343 
00344 // ==============================================================
00345 
00346 BOOST_AUTO_TEST_CASE( test_8 )
00347 {
00348   InputModule::Status states[] = {
00349       InputModule::BeginRun,
00350       InputModule::BeginCalibCycle,
00351       InputModule::DoEvent,
00352       InputModule::EndCalibCycle,
00353       InputModule::BeginRun,
00354       InputModule::DoEvent,
00355       InputModule::EndCalibCycle,
00356       InputModule::EndRun,
00357   };
00358   InputIter::EventType expected[] = {
00359       InputIter::BeginJob,
00360       InputIter::BeginRun,
00361       InputIter::BeginCalibCycle,
00362       InputIter::Event,
00363       InputIter::EndCalibCycle,
00364       InputIter::EndRun,
00365       InputIter::BeginRun,
00366       InputIter::BeginCalibCycle,
00367       InputIter::Event,
00368       InputIter::EndCalibCycle,
00369       InputIter::EndRun,
00370       InputIter::EndJob,
00371       InputIter::None,
00372   };
00373   
00374   Fixture f(states, sizeof states/sizeof states[0], expected, sizeof expected/sizeof expected[0]);
00375   BOOST_CHECK(f.checkResult());
00376 }
00377 
00378 // ==============================================================
00379 

Generated on 19 Dec 2016 for PSANAclasses by  doxygen 1.4.7