/* * open output file * Input : nothing but uses global fname * Output : nothing but fname contain the name of the out file now * * Guess the name of the outfile thanks to the input one and try to open it * In case of succes returns YES and output is the handle of the opened file * else returns NO * */ int openout (void) { outfname (fname); if ((output = fopen (fname, "w")) == NULL) { pl ("Open failure : "); pl (fname); pl ("\n"); return (NO); } kill_line (); return (YES); }
void CInfiniteMediatorTest::testSkipSome() { tearDown(); int nToSkip=4; std::string proto("file://"); std::string infname("./run-0000-00.evt"); std::string outfname("./copy-run-0000-00.evt"); std::string modeloutfname("./model-skip-run-0000-00.evt"); // Generate the file to compare against that we manually skipped over setUpSkipTestFile(nToSkip, proto+infname, modeloutfname); try { URL uri(proto+infname); m_source = new CFileDataSource(uri, std::vector<uint16_t>()); m_sink = new CFileDataSink(outfname); m_mediator = new CInfiniteMediator(0,0,0); m_mediator->setDataSource(m_source); m_mediator->setDataSink(m_sink); m_mediator->setFilter(new CTransparentFilter); m_mediator->setSkipCount(nToSkip); m_mediator->mainLoop(); // kill all of the sinks and sources tearDown(); // set up defaults so that we don't segfault at tearDown setUp(); } catch (CException& exc) { std::stringstream errmsg; errmsg << "Caught exception:" << exc.ReasonText(); CPPUNIT_FAIL(errmsg.str().c_str()); } catch (int errcode) { std::stringstream errmsg; errmsg << "Caught integer " << errcode; CPPUNIT_FAIL(errmsg.str().c_str()); } catch (std::string errmsg) { CPPUNIT_FAIL(errmsg.c_str()); } CPPUNIT_ASSERT( filesEqual(modeloutfname,outfname) ); // cleanup remove(outfname.c_str()); remove(modeloutfname.c_str()); }
void CInfiniteMediatorTest::testFilterReturnsNULL() { tearDown(); // Set up the mediator std::string proto("file://"); std::string infname("./run-0000-00.evt"); std::string outfname("./copy2-run-0000-00.evt"); // std::ifstream ifile (infname.c_str()); // std::ofstream ofile (outfname.c_str()); // m_source = new CIStreamDataSource(ifile); // m_sink = new COStreamDataSink(ofile); try { URL uri(proto+infname); m_source = new CFileDataSource(uri, std::vector<uint16_t>()); m_sink = new CFileDataSink(outfname); m_filter = new CNullFilter; m_mediator = new CInfiniteMediator(0,0,0); m_mediator->setDataSource(m_source); m_mediator->setDataSink(m_sink); m_mediator->setFilter(m_filter); m_mediator->mainLoop(); // kill all of the sinks and sources tearDown(); // set up defaults so that we don't segfault at tearDown setUp(); } catch (CException& exc) { std::stringstream errmsg; errmsg << "Caught exception:" << exc.ReasonText(); CPPUNIT_FAIL(errmsg.str().c_str()); } catch (int errcode) { std::stringstream errmsg; errmsg << "Caught integer " << errcode; CPPUNIT_FAIL(errmsg.str().c_str()); } catch (std::string errmsg) { CPPUNIT_FAIL(errmsg.c_str()); } struct stat st; stat(outfname.c_str(), &st); CPPUNIT_ASSERT_EQUAL( 0, int(st.st_size) ); remove(outfname.c_str()); }
void CInfiniteMediatorTest::testProcessSome() { tearDown(); int nToProcess=11; std::string proto("file://"); std::string infname("./run-0000-00.evt"); std::string outfname("./copy-run-0000-00.evt"); try { URL uri(proto+infname); m_source = new CFileDataSource(uri, std::vector<uint16_t>()); m_sink = new CFileDataSink(outfname); m_filter = new CTestFilter; m_mediator = new CInfiniteMediator(0,0,0); m_mediator->setDataSource(m_source); m_mediator->setDataSink(m_sink); m_mediator->setFilter(m_filter); m_mediator->setProcessCount(nToProcess); m_mediator->mainLoop(); CPPUNIT_ASSERT_EQUAL(nToProcess, static_cast<CTestFilter*>(m_filter)->getNProcessed()); // kill all of the sinks and sources tearDown(); // set up defaults so that we don't segfault at tearDown setUp(); } catch (CException& exc) { std::stringstream errmsg; errmsg << "Caught exception:" << exc.ReasonText(); CPPUNIT_FAIL(errmsg.str().c_str()); } catch (int errcode) { std::stringstream errmsg; errmsg << "Caught integer " << errcode; CPPUNIT_FAIL(errmsg.str().c_str()); } catch (std::string errmsg) { CPPUNIT_FAIL(errmsg.c_str()); } remove(outfname.c_str()); }
void CInfiniteMediatorTest::testSkipNone() { tearDown(); // This should have no effect on any default behavior // We will simply test this as the TransparentMainLoop m_mediator = new CInfiniteMediator(0,0,0); m_mediator->setSkipCount(0); std::string proto("file://"); std::string infname("./run-0000-00.evt"); std::string outfname("./copy-run-0000-00.evt"); try { URL uri(proto+infname); m_source = new CFileDataSource(uri, std::vector<uint16_t>()); m_sink = new CFileDataSink(outfname); m_mediator->setDataSource(m_source); m_mediator->setDataSink(m_sink); m_mediator->setFilter(new CTransparentFilter); m_mediator->mainLoop(); // kill all of the sinks and sources tearDown(); // set up defaults so that we don't segfault at tearDown setUp(); } catch (CException& exc) { std::stringstream errmsg; errmsg << "Caught exception:" << exc.ReasonText(); CPPUNIT_FAIL(errmsg.str().c_str()); } catch (int errcode) { std::stringstream errmsg; errmsg << "Caught integer " << errcode; CPPUNIT_FAIL(errmsg.str().c_str()); } catch (std::string errmsg) { CPPUNIT_FAIL(errmsg.c_str()); } CPPUNIT_ASSERT( filesEqual(infname,outfname) ); remove(outfname.c_str()); }