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.

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}
Reader container (composite pattern).
Definition Reader.hpp:100
reader_type * get()
returns pointer to Reader of the specified type
Definition Reader.hpp:134
boost::shared_ptr< Reader > ReaderPtr
Definition Reader.hpp:89
ostream * os_
#define unit_assert(x)
Definition unit.hpp:85

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

Referenced by test().

◆ testAccept()

void testAccept ( )

Definition at line 137 of file ReaderTest.cpp.

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

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

Referenced by test().

◆ testRead()

void testRead ( )

Definition at line 156 of file ReaderTest.cpp.

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}
Config config
Config config
virtual void read(const std::string &uri, ProteomeData &result) const
delegates to first child that identifies

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().

◆ test()

void test ( )

Definition at line 186 of file ReaderTest.cpp.

187{
188 testGet();
189 testAccept();
190 testRead();
191}
void testRead()
void testAccept()
void testGet()

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

Referenced by main().

◆ main()

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

Definition at line 194 of file ReaderTest.cpp.

195{
196 TEST_PROLOG_EX(argc, argv, "_TraData")
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}
void test()
#define TEST_PROLOG_EX(argc, argv, suffix)
Definition unit.hpp:157
#define TEST_EPILOG
Definition unit.hpp:183
#define TEST_FAILED(x)
Definition unit.hpp:177

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

Variable Documentation

◆ os_

ostream* os_ = 0