ProteoWizard
Classes | Functions | Variables
ReaderTest.cpp File Reference
#include "pwiz/utility/misc/unit.hpp"
#include "pwiz/utility/misc/Std.hpp"
#include "pwiz/utility/misc/Filesystem.hpp"
#include "Reader.hpp"
#include "examples.hpp"
#include "MSDataFile.hpp"
#include "pwiz/data/vendor_readers/ExtendedReaderList.hpp"
#include <cstring>

Go to the source code of this file.

Classes

class  Reader1
struct  Reader1::ReaderConfig
class  Reader2
struct  Reader2::ReaderConfig

Functions

void testGet ()
void testAccept ()
void testRead ()
void testIdentifyFileFormat ()
void test ()
int main (int argc, char *argv[])

Variables

ostream * os_ = 0

Function Documentation

void testGet ( )

Definition at line 128 of file ReaderTest.cpp.

References Reader2::ReaderConfig::color, pwiz::msdata::ReaderList::get(), os_, Reader2::readerConfig, and unit_assert.

{
if (os_) *os_ << "testGet()\n";
ReaderList readers;
readers.push_back(ReaderPtr(new Reader1));
readers.push_back(ReaderPtr(new Reader2));
unit_assert(readers.size() == 2);
Reader1* reader1 = readers.get<Reader1>();
unit_assert(reader1);
if (os_) *os_ << "reader1 config: " << reader1->readerConfig.name << endl;
unit_assert(reader1->readerConfig.name == "default");
reader1->readerConfig.name = "raw";
if (os_) *os_ << "reader1 config: " << reader1->readerConfig.name << endl;
unit_assert(reader1->readerConfig.name == "raw");
Reader2* reader2 = readers.get<Reader2>();
unit_assert(reader2);
if (os_) *os_ << "reader2 config: " << reader2->readerConfig.color << endl;
unit_assert(reader2->readerConfig.color == "orange");
reader2->readerConfig.color = "purple";
if (os_) *os_ << "reader2 config: " << reader2->readerConfig.color << endl;
unit_assert(reader2->readerConfig.color == "purple");
const ReaderList& const_readers = readers;
const Reader2* constReader2 = const_readers.get<Reader2>();
unit_assert(constReader2);
if (os_) *os_ << "constReader2 config: " << constReader2->readerConfig.color << endl;
if (os_) *os_ << endl;
}
void testAccept ( )

Definition at line 163 of file ReaderTest.cpp.

References pwiz::msdata::Reader::accept(), os_, and unit_assert.

{
if (os_) *os_ << "testAccept()\n";
ReaderList readers;
readers.push_back(ReaderPtr(new Reader1));
readers.push_back(ReaderPtr(new Reader2));
if (os_) *os_ << "accept 1:\n";
unit_assert(readers.accept("1", "head"));
if (os_) *os_ << "accept 2:\n";
unit_assert(readers.accept("2", "head"));
if (os_) *os_ << "accept 3:\n";
unit_assert(!readers.accept("3", "head"));
if (os_) *os_ << endl;
}
void testRead ( )

Definition at line 182 of file ReaderTest.cpp.

References pwiz::msdata::Reader::accept(), Reader1::ReaderConfig::done, Reader2::ReaderConfig::done, pwiz::msdata::ReaderList::get(), os_, pwiz::msdata::ReaderList::read(), Reader1::readerConfig, Reader2::readerConfig, and unit_assert.

{
if (os_) *os_ << "testRead()\n";
ReaderList readers;
readers.push_back(ReaderPtr(new Reader1));
readers.push_back(ReaderPtr(new Reader2));
MSData msd;
// note: composite pattern with accept/read will cause two calls
// to accept(); the alternative is to maintain state between accept()
// and read(), which opens possibility for misuse.
unit_assert(readers.get<Reader1>()->readerConfig.done == false);
if (readers.accept("1", "head"))
readers.read("1", "head", msd);
unit_assert(readers.get<Reader1>()->readerConfig.done == true);
readers.get<Reader1>()->readerConfig.done = false;
unit_assert(readers.get<Reader2>()->readerConfig.done == false);
if (readers.accept("2", "head"))
readers.read("2", "head", msd);
unit_assert(readers.get<Reader1>()->readerConfig.done == false);
unit_assert(readers.get<Reader2>()->readerConfig.done == true);
if (os_) *os_ << endl;
}
void testIdentifyFileFormat ( )

Definition at line 212 of file ReaderTest.cpp.

References pwiz::msdata::MSDataFile::WriteConfig::format, pwiz::msdata::identifyFileFormat(), pwiz::identdata::examples::initializeTiny(), MS_ABI_WIFF_file, MS_ISB_mzXML_file, MS_Mascot_MGF_file, MS_MS2_file, MS_mz5_file, MS_mzML_file, MS_Waters_raw_file, unit_assert_operator_equal, and write().

Referenced by test().

{
{ofstream fs("testSpectraDataFile.mzedML"); fs << "<?xml?><mzML>";}
unit_assert_operator_equal(MS_mzML_file, identifyFileFormat(readers, "testSpectraDataFile.mzedML"));
bfs::remove("testSpectraDataFile.mzedML");
{ofstream fs("testSpectraDataFile.mzedXML"); fs << "<?xml?><mzXML>";}
unit_assert_operator_equal(MS_ISB_mzXML_file, identifyFileFormat(readers, "testSpectraDataFile.mzedXML"));
bfs::remove("testSpectraDataFile.mzedXML");
{
MSData msd;
config.format = MSDataFile::Format_MZ5;
#ifndef WITHOUT_MZ5
MSDataFile::write(msd, "testSpectraDataFile.Mz5", config);
unit_assert_operator_equal(MS_mz5_file, identifyFileFormat(readers, "testSpectraDataFile.Mz5"));
#endif
}
bfs::remove("testSpectraDataFile.Mz5");
{ofstream fs("testSpectraDataFile.mGF"); fs << "MGF";}
unit_assert_operator_equal(MS_Mascot_MGF_file, identifyFileFormat(readers, "testSpectraDataFile.mGF"));
bfs::remove("testSpectraDataFile.mGF");
{ofstream fs("testSpectraDataFile.Ms2"); fs << "MS2";}
unit_assert_operator_equal(MS_MS2_file, identifyFileFormat(readers, "testSpectraDataFile.Ms2"));
bfs::remove("testSpectraDataFile.Ms2");
{ofstream fs("testSpectraDataFile.wiFF"); fs << "WIFF";}
unit_assert_operator_equal(MS_ABI_WIFF_file, identifyFileFormat(readers, "testSpectraDataFile.wiFF"));
bfs::remove("testSpectraDataFile.wiFF");
{ofstream fs("_FUNC42.DAT"); fs << "Life, the Universe, and Everything";}
bfs::remove("_FUNC42.DAT");
}
void test ( )
int main ( int  argc,
char *  argv[] 
)

Definition at line 264 of file ReaderTest.cpp.

References e(), os_, test(), TEST_EPILOG, TEST_FAILED, and TEST_PROLOG_EX.

{
TEST_PROLOG_EX(argc, argv, "_MSData")
try
{
if (argc==2 && !strcmp(argv[1],"-v")) os_ = &cout;
test();
}
catch (exception& e)
{
TEST_FAILED(e.what())
}
catch (...)
{
TEST_FAILED("Caught unknown exception.")
}
}

Variable Documentation

ostream* os_ = 0

Definition at line 39 of file ReaderTest.cpp.