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

Go to the source code of this file.

Classes

struct  SimpleAnalyzer
 
struct  SimpleProgressCallback
 
struct  CancelProgressCallback
 

Functions

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

Variables

ostream * os_ = 0
 

Function Documentation

◆ test()

void test ( )

Definition at line 109 of file MSDataAnalyzerTest.cpp.

110 {
111  if (os_) *os_ << "test()\n";
112 
113  // set up analyzers
114 
115  MSDataAnalyzerContainer analyzers;
116  analyzers.push_back(MSDataAnalyzerPtr(new SimpleAnalyzer(23))); // request index 23
117  analyzers.push_back(MSDataAnalyzerPtr(new SimpleAnalyzer(17))); // request index 17
118 
119  unit_assert(analyzers.size() == 2);
120  for (MSDataAnalyzerContainer::const_iterator it=analyzers.begin(); it!=analyzers.end(); ++it)
121  {
122  const SimpleAnalyzer& anal = dynamic_cast<const SimpleAnalyzer&>(**it);
123  unit_assert(!anal.opened);
124  unit_assert(anal.updateCount == 0);
125  unit_assert(!anal.closed);
126  }
127 
128  // instantiate MSData object
129 
130  MSData dummy;
132  const int spectrumCount = 30;
133  for (int i=0; i<spectrumCount; i++)
134  {
135  sl->spectra.push_back(SpectrumPtr(new Spectrum));
136  sl->spectra.back()->index = i;
137  }
138  dummy.run.spectrumListPtr = sl;
139 
140  // run driver
141 
142  MSDataAnalyzerDriver driver(analyzers);
143  SimpleProgressCallback callback;
144  MSDataAnalyzerDriver::Status status = driver.analyze(dummy, &callback);
145 
147 
148  for (MSDataAnalyzerContainer::const_iterator it=analyzers.begin(); it!=analyzers.end(); ++it)
149  {
150  const SimpleAnalyzer& anal = dynamic_cast<const SimpleAnalyzer&>(**it);
151  unit_assert(anal.opened);
152  unit_assert(anal.updateCount == 1);
153  unit_assert(anal.closed);
154  }
155 
156  unit_assert(callback.count == spectrumCount/callback.iterationsPerCallback() + 1);
157 
158  // run driver again with cancel callback
159 
160  if (os_) *os_ << "testing cancel callback:\n";
161 
162  CancelProgressCallback cancelCallback;
163  status = driver.analyze(dummy, &cancelCallback);
164 
165  unit_assert(status == MSDataAnalyzerDriver::Status_Cancel);
166 
167  if (os_) *os_ << "cancelled!\n";
168 
169  for (MSDataAnalyzerContainer::const_iterator it=analyzers.begin(); it!=analyzers.end(); ++it)
170  {
171  const SimpleAnalyzer& anal = dynamic_cast<const SimpleAnalyzer&>(**it);
172  unit_assert(anal.opened);
173  unit_assert(anal.updateCount == 0);
174  unit_assert(!anal.closed);
175  }
176 
177  unit_assert(cancelCallback.count == 2);
178 }

References anal(), pwiz::analysis::MSDataAnalyzerDriver::analyze(), SimpleProgressCallback::count, CancelProgressCallback::count, SimpleProgressCallback::iterationsPerCallback(), os_, pwiz::msdata::MSData::run, pwiz::msdata::Run::spectrumListPtr, Status_Ok, and unit_assert.

Referenced by main().

◆ main()

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

Definition at line 181 of file MSDataAnalyzerTest.cpp.

182 {
183  TEST_PROLOG(argc, argv)
184 
185  try
186  {
187  if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
188  test();
189  }
190  catch (exception& e)
191  {
192  TEST_FAILED(e.what())
193  }
194  catch (...)
195  {
196  TEST_FAILED("Caught unknown exception.")
197  }
198 
200 }

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

Variable Documentation

◆ os_

ostream* os_ = 0
pwiz::analysis::MSDataAnalyzerDriver
event generator for MSDataAnalyzer
Definition: MSDataAnalyzer.hpp:158
pwiz::msdata::Spectrum
The structure that captures the generation of a peak list (including the underlying acquisitions)
Definition: MSData.hpp:506
SimpleProgressCallback::iterationsPerCallback
virtual size_t iterationsPerCallback() const
Definition: MSDataAnalyzerTest.cpp:81
CancelProgressCallback
Definition: MSDataAnalyzerTest.cpp:93
pwiz::msdata::MSData::run
Run run
a run in mzML should correspond to a single, consecutive and coherent set of scans on an instrument.
Definition: MSData.hpp:886
pwiz::analysis::MSDataAnalyzerPtr
boost::shared_ptr< MSDataAnalyzer > MSDataAnalyzerPtr
Definition: MSDataAnalyzer.hpp:108
SimpleAnalyzer
Definition: MSDataAnalyzerTest.cpp:38
test
void test()
Definition: MSDataAnalyzerTest.cpp:109
TEST_EPILOG
#define TEST_EPILOG
Definition: unit.hpp:183
anal
const char * anal(const CVParam &cvParam)
Definition: SpectrumIteratorTest.cpp:79
pwiz::msdata::SpectrumPtr
boost::shared_ptr< Spectrum > SpectrumPtr
Definition: MSData.hpp:573
pwiz::msdata::SpectrumListSimple
Simple writeable in-memory implementation of SpectrumList.
Definition: MSData.hpp:717
pwiz::msdata::Run::spectrumListPtr
SpectrumListPtr spectrumListPtr
all mass spectra and the acquisitions underlying them are described and attached here....
Definition: MSData.hpp:827
TEST_FAILED
#define TEST_FAILED(x)
Definition: unit.hpp:177
TEST_PROLOG
#define TEST_PROLOG(argc, argv)
Definition: unit.hpp:175
SimpleProgressCallback
Definition: MSDataAnalyzerTest.cpp:76
pwiz::msdata::MSData
This is the root element of ProteoWizard; it represents the mzML element, defined as: intended to cap...
Definition: MSData.hpp:850
Status_Ok
Status_Ok
Definition: MSDataAnalyzer.hpp:164
unit_assert
#define unit_assert(x)
Definition: unit.hpp:85
pwiz::analysis::MSDataAnalyzerContainer
container of MSDataAnalyzer (composite pattern)
Definition: MSDataAnalyzer.hpp:136
CancelProgressCallback::count
size_t count
Definition: MSDataAnalyzerTest.cpp:94
SimpleProgressCallback::count
size_t count
Definition: MSDataAnalyzerTest.cpp:77
os_
ostream * os_
Definition: MSDataAnalyzerTest.cpp:34
pwiz::msdata::SpectrumListSimplePtr
boost::shared_ptr< SpectrumListSimple > SpectrumListSimplePtr
Definition: MSData.hpp:731