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

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 117 of file ReaderTest.cpp.

References pwiz::proteome::ReaderList::get(), os_, and unit_assert.

Referenced by test().

118 {
119  if (os_) *os_ << "testGet()\n";
120 
121  ReaderList readers;
122  readers.push_back(ReaderPtr(new Reader1));
123  readers.push_back(ReaderPtr(new Reader2));
124 
125  unit_assert(readers.size() == 2);
126 
127  Reader1* reader1 = readers.get<Reader1>();
128  unit_assert(reader1);
129 
130  Reader2* reader2 = readers.get<Reader2>();
131  unit_assert(reader2);
132 
133  if (os_) *os_ << endl;
134 }
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 137 of file ReaderTest.cpp.

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

Referenced by test().

138 {
139  if (os_) *os_ << "testAccept()\n";
140 
141  ReaderList readers;
142  readers.push_back(ReaderPtr(new Reader1));
143  readers.push_back(ReaderPtr(new Reader2));
144 
145  if (os_) *os_ << "accept 1:\n";
146  unit_assert(readers.accept("1", "head"));
147  if (os_) *os_ << "accept 2:\n";
148  unit_assert(readers.accept("2", "head"));
149  if (os_) *os_ << "accept 3:\n";
150  unit_assert(!readers.accept("3", "head"));
151 
152  if (os_) *os_ << endl;
153 }
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 156 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.

Referenced by test().

157 {
158  if (os_) *os_ << "testRead()\n";
159 
160  ReaderList readers;
161  readers.push_back(ReaderPtr(new Reader1));
162  readers.push_back(ReaderPtr(new Reader2));
163 
164  TraData td;
165 
166  // note: composite pattern with accept/read will cause two calls
167  // to accept(); the alternative is to maintain state between accept()
168  // and read(), which opens possibility for misuse.
169 
170  unit_assert(readers.get<Reader1>()->config.done == false);
171  if (readers.accept("1", "head"))
172  readers.read("1", "head", td);
173  unit_assert(readers.get<Reader1>()->config.done == true);
174 
175  readers.get<Reader1>()->config.done = false;
176  unit_assert(readers.get<Reader2>()->config.done == false);
177  if (readers.accept("2", "head"))
178  readers.read("2", "head", td);
179  unit_assert(readers.get<Reader1>()->config.done == false);
180  unit_assert(readers.get<Reader2>()->config.done == true);
181 
182  if (os_) *os_ << endl;
183 }
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 186 of file ReaderTest.cpp.

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

Referenced by main().

187 {
188  testGet();
189  testAccept();
190  testRead();
191 }
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 194 of file ReaderTest.cpp.

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

195 {
196  TEST_PROLOG_EX(argc, argv, "_IdentData")
197 
198  try
199  {
200  if (argc==2 && !strcmp(argv[1],"-v")) os_ = &cout;
201  test();
202  }
203  catch (exception& e)
204  {
205  TEST_FAILED(e.what())
206  }
207  catch (...)
208  {
209  TEST_FAILED("Caught unknown exception.")
210  }
211 
213 }
#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