ProteoWizard
TabReaderTest.cpp
Go to the documentation of this file.
1//
2// $Id$
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
30using namespace pwiz::util;
31
32ostream *os_ = NULL;
33
34void testDefaultTabHandler(const bfs::path& datafile)
35{
36 const char* alphabet = "abcd";
37 const char* numbers = "1234";
38
39 TabReader tr;
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
64void 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
73void runTests(const bfs::path& datapath)
74{
75 testDefaultTabHandler(datapath / "TabTest.tab");
76 testMSIHandler(datapath / "MSITest.tab");
77}
78
79int 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}
KernelTraitsBase< Kernel >::space_type::abscissa_type x
KernelTraitsBase< Kernel >::space_type::ordinate_type y
int main(int argc, char **argv)
void testMSIHandler(const bfs::path &datafile)
void testDefaultTabHandler(const bfs::path &datafile)
void runTests(const bfs::path &datapath)
ostream * os_
virtual void setHandler(TabHandler *handler)
virtual bool process(const char *filename)
virtual const_iterator begin() const
virtual const_iterator end() const
std::vector< std::vector< std::string > >::const_iterator const_iterator
Definition TabReader.hpp:94
#define unit_assert(x)
Definition unit.hpp:85
#define TEST_EPILOG
Definition unit.hpp:183
#define TEST_FAILED(x)
Definition unit.hpp:177
#define TEST_PROLOG(argc, argv)
Definition unit.hpp:175