ProteoWizard
Functions | Variables
TabReaderTest.cpp File Reference
#include "Std.hpp"
#include "TabReader.hpp"
#include "MSIHandler.hpp"
#include "unit.hpp"
#include "pwiz/utility/misc/Filesystem.hpp"
#include <cstring>

Go to the source code of this file.

Functions

void testDefaultTabHandler (const bfs::path &datafile)
 
void testMSIHandler (const bfs::path &datafile)
 
void runTests (const bfs::path &datapath)
 
int main (int argc, char **argv)
 

Variables

ostream * os_ = NULL
 

Function Documentation

void testDefaultTabHandler ( const bfs::path &  datafile)

Definition at line 35 of file TabReaderTest.cpp.

References pwiz::utility::VectorTabHandler::begin(), pwiz::utility::VectorTabHandler::end(), pwiz::utility::TabReader::process(), pwiz::utility::TabReader::setHandler(), unit_assert, pwiz::msdata::id::value(), x, and y.

Referenced by runTests().

36 {
37  const char* alphabet = "abcd";
38  const char* numbers = "1234";
39 
40  TabReader tr;
41  VectorTabHandler vth;
42 
43  tr.setHandler(&vth);
44  tr.process(datafile.string().c_str());
45 
47  cout << (* (*it).begin()) << endl;
48 
49  size_t y=0;
50  for (; it != vth.end(); it++)
51  {
52  size_t x=0;
53  for (vector<string>::const_iterator it2=(*it).begin(); it2!=(*it).end();it2++)
54  {
55  const char* value = (*it2).c_str();
56  unit_assert(value[0] == alphabet[x]);
57  unit_assert(value[1] == numbers[y]);
58  x++;
59  }
60  cerr << endl;
61  y++;
62  }
63 }
virtual void setHandler(TabHandler *handler)
std::vector< std::vector< std::string > >::const_iterator const_iterator
Definition: TabReader.hpp:94
virtual const_iterator end() const
virtual bool process(const char *filename)
virtual const_iterator begin() const
KernelTraitsBase< Kernel >::space_type::abscissa_type x
PWIZ_API_DECL std::string value(const std::string &id, const std::string &name)
convenience function to extract a named value from an id string
KernelTraitsBase< Kernel >::space_type::ordinate_type y
#define unit_assert(x)
Definition: unit.hpp:82
void testMSIHandler ( const bfs::path &  datafile)

Definition at line 65 of file TabReaderTest.cpp.

References pwiz::utility::TabReader::process(), and pwiz::utility::TabReader::setHandler().

Referenced by runTests().

66 {
67  TabReader tr;
68  MSIHandler mh;
69 
70  tr.setHandler(&mh);
71  tr.process(datafile.string().c_str());
72 }
virtual void setHandler(TabHandler *handler)
virtual bool process(const char *filename)
void runTests ( const bfs::path &  datapath)

Definition at line 74 of file TabReaderTest.cpp.

References testDefaultTabHandler(), and testMSIHandler().

75 {
76  testDefaultTabHandler(datapath / "TabTest.tab");
77  testMSIHandler(datapath / "MSITest.tab");
78 }
void testMSIHandler(const bfs::path &datafile)
void testDefaultTabHandler(const bfs::path &datafile)
int main ( int  argc,
char **  argv 
)

Definition at line 80 of file TabReaderTest.cpp.

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

81 {
82  TEST_PROLOG(argc, argv)
83 
84  try
85  {
86  bfs::path datapath = ".";
87 
88  for (int i=1; i<argc; i++)
89  {
90  if (!strcmp(argv[i],"-v"))
91  os_ = &cout;
92  else
93  // hack to allow running unit test from a different directory:
94  // Jamfile passes full path to specified input file.
95  // we want the path, so we can ignore filename
96  datapath = bfs::path(argv[i]).branch_path();
97  }
98  if (os_) *os_ << "TabReaderTest\n";
99  runTests(datapath);
100  }
101  catch (exception& e)
102  {
103  TEST_FAILED(e.what())
104  }
105  catch (...)
106  {
107  TEST_FAILED("Caught unknown exception.")
108  }
109 
111 }
void runTests(const bfs::path &datadir)
ostream * os_
#define TEST_EPILOG
Definition: unit.hpp:166
#define TEST_FAILED(x)
Definition: unit.hpp:160
#define TEST_PROLOG(argc, argv)
Definition: unit.hpp:158

Variable Documentation

ostream* os_ = NULL

Definition at line 33 of file TabReaderTest.cpp.