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