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

§ testGet()

void testGet ( )

Definition at line 99 of file ReaderTest.cpp.

References Reader2::Config::color, Reader2::config, pwiz::proteome::ReaderList::get(), os_, and unit_assert.

100 {
101  if (os_) *os_ << "testGet()\n";
102 
103  ReaderList readers;
104  readers.push_back(ReaderPtr(new Reader1));
105  readers.push_back(ReaderPtr(new Reader2));
106 
107  unit_assert(readers.size() == 2);
108 
109  Reader1* reader1 = readers.get<Reader1>();
110  unit_assert(reader1);
111  if (os_) *os_ << "reader1 config: " << reader1->config.name << endl;
112  unit_assert(reader1->config.name == "default");
113  reader1->config.name = "raw";
114  if (os_) *os_ << "reader1 config: " << reader1->config.name << endl;
115  unit_assert(reader1->config.name == "raw");
116 
117  Reader2* reader2 = readers.get<Reader2>();
118  unit_assert(reader2);
119  if (os_) *os_ << "reader2 config: " << reader2->config.color << endl;
120  unit_assert(reader2->config.color == "orange");
121  reader2->config.color = "purple";
122  if (os_) *os_ << "reader2 config: " << reader2->config.color << endl;
123  unit_assert(reader2->config.color == "purple");
124 
125  const ReaderList& const_readers = readers;
126  const Reader2* constReader2 = const_readers.get<Reader2>();
127  unit_assert(constReader2);
128  if (os_) *os_ << "constReader2 config: " << constReader2->config.color << endl;
129 
130  if (os_) *os_ << endl;
131 }
Config config
Definition: ReaderTest.cpp:87
ostream * os_
Definition: ReaderTest.cpp:34
Reader container (composite pattern).
Definition: Reader.hpp:98
reader_type * get()
returns pointer to Reader of the specified type
Definition: Reader.hpp:134
boost::shared_ptr< Reader > ReaderPtr
Definition: Reader.hpp:110
#define unit_assert(x)
Definition: unit.hpp:85

§ testAccept()

void testAccept ( )

Definition at line 134 of file ReaderTest.cpp.

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

135 {
136  if (os_) *os_ << "testAccept()\n";
137 
138  ReaderList readers;
139  readers.push_back(ReaderPtr(new Reader1));
140  readers.push_back(ReaderPtr(new Reader2));
141 
142  if (os_) *os_ << "accept 1:\n";
143  unit_assert(readers.accept("1", shared_ptr<istream>()));
144  if (os_) *os_ << "accept 2:\n";
145  unit_assert(readers.accept("2", shared_ptr<istream>()));
146  if (os_) *os_ << "accept 3:\n";
147  unit_assert(!readers.accept("3", shared_ptr<istream>()));
148 
149  if (os_) *os_ << endl;
150 }
bool accept(const std::string &uri, boost::shared_ptr< std::istream > uriStreamPtr) const
return true iff Reader recognizes the file as one it should handle
Definition: Reader.hpp:44
ostream * os_
Definition: ReaderTest.cpp:34
Reader container (composite pattern).
Definition: Reader.hpp:98
boost::shared_ptr< Reader > ReaderPtr
Definition: Reader.hpp:110
#define unit_assert(x)
Definition: unit.hpp:85

§ testRead()

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.

154 {
155  if (os_) *os_ << "testRead()\n";
156 
157  ReaderList readers;
158  readers.push_back(ReaderPtr(new Reader1));
159  readers.push_back(ReaderPtr(new Reader2));
160 
161  ProteomeData pd;
162 
163  // note: composite pattern with accept/read will cause two calls
164  // to accept(); the alternative is to maintain state between accept()
165  // and read(), which opens possibility for misuse.
166 
167  unit_assert(readers.get<Reader1>()->config.done == false);
168  if (readers.accept("1", shared_ptr<istream>()))
169  readers.read("1", shared_ptr<istream>(), pd);
170  unit_assert(readers.get<Reader1>()->config.done == true);
171 
172  readers.get<Reader1>()->config.done = false;
173  unit_assert(readers.get<Reader2>()->config.done == false);
174  if (readers.accept("2", shared_ptr<istream>()))
175  readers.read("2", shared_ptr<istream>(), pd);
176  unit_assert(readers.get<Reader1>()->config.done == false);
177  unit_assert(readers.get<Reader2>()->config.done == true);
178 
179  if (os_) *os_ << endl;
180 }
virtual void read(const std::string &uri, ProteomeData &result) const
delegates to first child that identifies
Config config
Definition: ReaderTest.cpp:87
bool accept(const std::string &uri, boost::shared_ptr< std::istream > uriStreamPtr) const
return true iff Reader recognizes the file as one it should handle
Definition: Reader.hpp:44
Config config
Definition: ReaderTest.cpp:47
ostream * os_
Definition: ReaderTest.cpp:34
Reader container (composite pattern).
Definition: Reader.hpp:98
reader_type * get()
returns pointer to Reader of the specified type
Definition: Reader.hpp:134
boost::shared_ptr< Reader > ReaderPtr
Definition: Reader.hpp:110
#define unit_assert(x)
Definition: unit.hpp:85

§ test()

void test ( )

Definition at line 183 of file ReaderTest.cpp.

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

184 {
185  testGet();
186  testAccept();
187  testRead();
188 }
void testGet()
Definition: ReaderTest.cpp:117
void testAccept()
Definition: ReaderTest.cpp:137
void testRead()
Definition: ReaderTest.cpp:156

§ main()

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

Definition at line 191 of file ReaderTest.cpp.

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

192 {
193  TEST_PROLOG_EX(argc, argv, "_ProteomeData")
194 
195  try
196  {
197  if (argc==2 && !strcmp(argv[1],"-v")) os_ = &cout;
198  test();
199  }
200  catch (exception& e)
201  {
202  TEST_FAILED(e.what())
203  }
204  catch (...)
205  {
206  TEST_FAILED("Caught unknown exception.")
207  }
208 
210 }
#define TEST_EPILOG
Definition: unit.hpp:182
void test()
Definition: ReaderTest.cpp:186
ostream * os_
Definition: ReaderTest.cpp:34
#define TEST_PROLOG_EX(argc, argv, suffix)
Definition: unit.hpp:157
#define TEST_FAILED(x)
Definition: unit.hpp:176

Variable Documentation

§ os_

ostream* os_ = 0

Definition at line 32 of file ReaderTest.cpp.