Skip to content

Commit

Permalink
created new tester class to contain all the test functions
Browse files Browse the repository at this point in the history
the definition is in the new test_ibcp.h header file
the constructor is given the command line arguments, which are parsed
access functions check for errors and if test arguments were specified
the run function runs the test, which now handles initialization
main function modified to only handle arguments using new tester class
header change comments were removed from test_ibcp.cpp
  • Loading branch information
thunder422 committed Nov 22, 2012
1 parent c0c027c commit f70cf1f
Show file tree
Hide file tree
Showing 4 changed files with 230 additions and 293 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Expand Up @@ -135,6 +135,7 @@ set(ibcp_HEADERS
ibcp.h
parser.h
table.h
test_ibcp.h
token.h
translator.h
)
Expand Down
43 changes: 12 additions & 31 deletions main.cpp
Expand Up @@ -23,17 +23,12 @@
// 2010-03-13 initial version

#include <QtGui/QApplication>
#include <QFile>
#include <QFileInfo>
#include <QTextStream>
#include <QTimer>

#include "ibcp.h"
#include "ibcp_config.h" // for cmake
#include "token.h"
#include "table.h"
#include "parser.h"
#include "translator.h"
#include "test_ibcp.h"


void printGplHeader(QTextStream &cout, const QString &name)
Expand All @@ -45,9 +40,6 @@ void printGplHeader(QTextStream &cout, const QString &name)
<< "redistribute it under certain conditions." << endl << endl;
}

// Program Name and Length less extension
// TODO this needs to be put into a class somewhere)
QString programName;

// function to print version number
bool ibcpVersion(QTextStream &cout, const QString &name, QStringList &args)
Expand All @@ -62,17 +54,14 @@ bool ibcpVersion(QTextStream &cout, const QString &name, QStringList &args)
}


// prototype for test function
bool ibcpTest(QTextStream &cout, Translator &translator, QStringList &args);

int main(int argc, char *argv[])
{
QApplication app(argc, argv);

QStringList args = app.arguments();

// get base file name of program from first argument
programName = QFileInfo(args.at(0)).baseName();
QString programName = QFileInfo(args.at(0)).baseName();

// setup standard output stream
QFile output;
Expand All @@ -81,32 +70,24 @@ int main(int argc, char *argv[])

if (!ibcpVersion(cout, programName, args))
{
printGplHeader(cout, programName);

Token::initialize();

QStringList errors = Table::create();
if (!errors.isEmpty())
Tester tester(args);
if (tester.hasError())
{
int n = 0;
foreach (QString error, errors)
{
qWarning("%s", qPrintable(QObject::tr("Error #%1: %2").arg(++n)
.arg(error)));
}
qFatal("%s", qPrintable(QObject::tr("Program aborting!")));
qWarning("%s", qPrintable(tester.errorMessage()));
}
cout << "Table initialization successful." << endl;

Translator translator(Table::instance());

if (!ibcpTest(cout, translator, args))
else if (!tester.hasOption())
{
qWarning("%s: %s -v -t <%s>|-tp|-te|-tt",
qPrintable(QObject::tr("usage")), qPrintable(programName),
qPrintable(QObject::tr("test_file")));
}
else if (!tester.run(cout))
{
qWarning("%s", qPrintable(tester.errorMessage()));
}
}

// force quit once event processing loop is started
QTimer::singleShot(0, &app, SLOT(quit()));
return app.exec();
}
Expand Down

0 comments on commit f70cf1f

Please sign in to comment.