ProteoWizard
TabReaderTest.cpp
Go to the documentation of this file.
1 //
2 // $Id: TabReaderTest.cpp 7297 2015-03-12 05:30:33Z paragmallick $
3 //
4 //
5 // Original author: Matt Chambers <matt.chambers .@. vanderbilt.edu>
6 //
7 // Copyright 2008 Vanderbilt University - Nashville, TN 37232
8 //
9 // Licensed under the Apache License, Version 2.0 (the "License");
10 // you may not use this file except in compliance with the License.
11 // You may obtain a copy of the License at
12 //
13 // http://www.apache.org/licenses/LICENSE-2.0
14 //
15 // Unless required by applicable law or agreed to in writing, software
16 // distributed under the License is distributed on an "AS IS" BASIS,
17 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 // See the License for the specific language governing permissions and
19 // limitations under the License.
20 //
21 
22 
23 #include "Std.hpp"
24 #include "TabReader.hpp"
25 #include "MSIHandler.hpp"
26 #include "unit.hpp"
28 #include <cstring>
29 
30 using namespace pwiz::util;
31 
32 ostream *os_ = NULL;
33 
34 void testDefaultTabHandler(const bfs::path& datafile)
35 {
36  const char* alphabet = "abcd";
37  const char* numbers = "1234";
38 
39  TabReader tr;
40  VectorTabHandler vth;
41 
42  tr.setHandler(&vth);
43  tr.process(datafile.string().c_str());
44 
46  cout << (* (*it).begin()) << endl;
47 
48  size_t y=0;
49  for (; it != vth.end(); it++)
50  {
51  size_t x=0;
52  for (vector<string>::const_iterator it2=(*it).begin(); it2!=(*it).end();it2++)
53  {
54  const char* value = (*it2).c_str();
55  unit_assert(value[0] == alphabet[x]);
56  unit_assert(value[1] == numbers[y]);
57  x++;
58  }
59  cerr << endl;
60  y++;
61  }
62 }
63 
64 void testMSIHandler(const bfs::path& datafile)
65 {
66  TabReader tr;
67  MSIHandler mh;
68 
69  tr.setHandler(&mh);
70  tr.process(datafile.string().c_str());
71 }
72 
73 void runTests(const bfs::path& datapath)
74 {
75  testDefaultTabHandler(datapath / "TabTest.tab");
76  testMSIHandler(datapath / "MSITest.tab");
77 }
78 
79 int main(int argc, char** argv)
80 {
81  TEST_PROLOG(argc, argv)
82 
83  try
84  {
85  bfs::path datapath = ".";
86 
87  for (int i=1; i<argc; i++)
88  {
89  if (!strcmp(argv[i],"-v"))
90  os_ = &cout;
91  else
92  // hack to allow running unit test from a different directory:
93  // Jamfile passes full path to specified input file.
94  // we want the path, so we can ignore filename
95  datapath = bfs::path(argv[i]).branch_path();
96  }
97  if (os_) *os_ << "TabReaderTest\n";
98  runTests(datapath);
99  }
100  catch (exception& e)
101  {
102  TEST_FAILED(e.what())
103  }
104  catch (...)
105  {
106  TEST_FAILED("Caught unknown exception.")
107  }
108 
110 }
std::vector< std::vector< std::string > >::const_iterator const_iterator
Definition: TabReader.hpp:94
int main(int argc, char **argv)
virtual bool process(const char *filename)
#define TEST_EPILOG
Definition: unit.hpp:182
ostream * os_
void testMSIHandler(const bfs::path &datafile)
void runTests(const bfs::path &datapath)
virtual const_iterator end() const
virtual const_iterator begin() const
void testDefaultTabHandler(const bfs::path &datafile)
virtual void setHandler(TabHandler *handler)
#define TEST_FAILED(x)
Definition: unit.hpp:176
#define TEST_PROLOG(argc, argv)
Definition: unit.hpp:174
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:85