ProteoWizard
Classes | Functions | Variables
ReaderTest.cpp File Reference
#include "Reader.hpp"
#include "pwiz/utility/misc/unit.hpp"
#include "pwiz/utility/misc/Std.hpp"

Go to the source code of this file.

Classes

class  Reader1
struct  Reader1::Config
class  Reader2
struct  Reader2::Config

Functions

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

Variables

ostream * os_ = 0

Function Documentation

void testGet ( )

Definition at line 99 of file ReaderTest.cpp.

References Reader2::Config::color, Reader2::config, pwiz::proteome::ReaderList::get(), os_, 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->config.name << endl;
unit_assert(reader1->config.name == "default");
reader1->config.name = "raw";
if (os_) *os_ << "reader1 config: " << reader1->config.name << endl;
unit_assert(reader1->config.name == "raw");
Reader2* reader2 = readers.get<Reader2>();
unit_assert(reader2);
if (os_) *os_ << "reader2 config: " << reader2->config.color << endl;
unit_assert(reader2->config.color == "orange");
reader2->config.color = "purple";
if (os_) *os_ << "reader2 config: " << reader2->config.color << endl;
unit_assert(reader2->config.color == "purple");
const ReaderList& const_readers = readers;
const Reader2* constReader2 = const_readers.get<Reader2>();
unit_assert(constReader2);
if (os_) *os_ << "constReader2 config: " << constReader2->config.color << endl;
if (os_) *os_ << endl;
}
void testAccept ( )

Definition at line 134 of file ReaderTest.cpp.

References pwiz::proteome::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", shared_ptr<istream>()));
if (os_) *os_ << "accept 2:\n";
unit_assert(readers.accept("2", shared_ptr<istream>()));
if (os_) *os_ << "accept 3:\n";
unit_assert(!readers.accept("3", shared_ptr<istream>()));
if (os_) *os_ << endl;
}
void testRead ( )

Definition at line 153 of file ReaderTest.cpp.

References pwiz::proteome::Reader::accept(), Reader1::config, Reader2::config, Reader1::Config::done, Reader2::Config::done, pwiz::proteome::ReaderList::get(), os_, pwiz::proteome::ReaderList::read(), and unit_assert.

{
if (os_) *os_ << "testRead()\n";
ReaderList readers;
readers.push_back(ReaderPtr(new Reader1));
readers.push_back(ReaderPtr(new Reader2));
// 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>()->config.done == false);
if (readers.accept("1", shared_ptr<istream>()))
readers.read("1", shared_ptr<istream>(), pd);
unit_assert(readers.get<Reader1>()->config.done == true);
readers.get<Reader1>()->config.done = false;
unit_assert(readers.get<Reader2>()->config.done == false);
if (readers.accept("2", shared_ptr<istream>()))
readers.read("2", shared_ptr<istream>(), pd);
unit_assert(readers.get<Reader1>()->config.done == false);
unit_assert(readers.get<Reader2>()->config.done == true);
if (os_) *os_ << endl;
}
void test ( )

Definition at line 183 of file ReaderTest.cpp.

References testAccept(), testGet(), and testRead().

int main ( int  argc,
char *  argv[] 
)

Definition at line 191 of file ReaderTest.cpp.

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

{
TEST_PROLOG_EX(argc, argv, "_ProteomeData")
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 32 of file ReaderTest.cpp.