ProteoWizard
TabReaderTest.cpp
Go to the documentation of this file.
1 //
2 // $Id: TabReaderTest.cpp 4129 2012-11-20 00:05:37Z chambm $
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 using namespace pwiz::utility;
32 
33 ostream *os_ = NULL;
34 
35 void testDefaultTabHandler(const bfs::path& datafile)
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 }
64 
65 void testMSIHandler(const bfs::path& datafile)
66 {
67  TabReader tr;
68  MSIHandler mh;
69 
70  tr.setHandler(&mh);
71  tr.process(datafile.string().c_str());
72 }
73 
74 void runTests(const bfs::path& datapath)
75 {
76  testDefaultTabHandler(datapath / "TabTest.tab");
77  testMSIHandler(datapath / "MSITest.tab");
78 }
79 
80 int main(int argc, char** argv)
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 }