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
|
/***************************************************************************
* Copyright (C) 2007 by Dominik Seichter *
* domseichter@web.de *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Library General Public License as *
* published by the Free Software Foundation; either version 2 of the *
* License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <cppunit/CompilerOutputter.h>
#include <cppunit/XmlOutputter.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/ui/text/TestRunner.h>
#include <iostream>
#include <podofo.h>
void show_help()
{
std::cout << "podofo-test" << std::endl << std::endl;
std::cout << "Supported commandline switches:" << std::endl;
std::cout << "\t --help\t So this help message." << std::endl;
std::cout << "\t --selftest\t Output in compiler compatible format." << std::endl;
std::cout << "\t --test [name]\t Run only the test case [name]." << std::endl;
std::cout << std::endl;
}
int main(int argc, char* argv[])
{
// Get the top level suite from the registry
CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
// Adds the test to the list of test to run
CppUnit::TextUi::TestRunner runner;
runner.addTest( suite );
// check some commandline arguments
std::string sTestName = "";
bool bSelfTest = false;
if( argc > 1 )
{
for(int i=1;i<argc;i++)
{
std::string argument(argv[i]);
if( argument=="--help" || argument=="-help")
{
show_help();
return 0;
}
else if(argument=="--selftest" || argument=="-selftest")
{
bSelfTest = true;
}
else if((argument=="--test" || argument=="-test") && i+1 < argc)
{
if( i == argc - 1 )
{
show_help();
return 0;
}
i++;
sTestName = argv[i];
}
}
}
if( bSelfTest )
{
// Change the default outputter to a compiler error format outputter
runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
std::cerr ) );
}
else
{
// Change the default outputter to a xml format outputter
// The test runner owns the new outputter.
CppUnit::XmlOutputter *xmlOutputter = new
CppUnit::XmlOutputter( &runner.result(), std::cerr ) ;
runner.setOutputter(xmlOutputter);
}
// Enable PoDoFo debugging and logging
PoDoFo::PdfError::EnableLogging( true );
PoDoFo::PdfError::EnableDebug( true );
// Run the tests.
bool wasSucessful = runner.run( sTestName );
// Return error code 1 if the one of test failed.
return wasSucessful ? 0 : 1;
}
|