Commit 393ac30f authored by Alexander Wiebel's avatar Alexander Wiebel
Browse files

[CHANGE] removed optionhandler as it is not needed at the moment

parent c62acce8
......@@ -98,7 +98,7 @@ IF( NOT CMAKE_BUILD_TYPE STREQUAL "Static" )
ADD_SUBDIRECTORY( kernel )
ADD_SUBDIRECTORY( common )
ADD_SUBDIRECTORY( modules )
ADD_EXECUTABLE( walnut OpenWalnut.cpp utils/WOptionHandler.cpp )
ADD_EXECUTABLE( walnut OpenWalnut.cpp )
TARGET_LINK_LIBRARIES( walnut kernel dataHandler gui guiqt4 common ${Boost_LIBRARIES} )
ELSE( NOT CMAKE_BUILD_TYPE STREQUAL "Static" )
......
......@@ -52,7 +52,6 @@ WQt4Gui::~WQt4Gui()
* At the moment it seems reasonable that differnet GUIs might have
* different command line options, thus we implement their parsing
* in the GUI implemntation itself, i.e. here.
* TODO(wiebel): check whether WOptionHandler still exists and probably remove it after discussion in the community.
*/
boost::program_options::variables_map parseOptions( int argc, char** argv )
{
......
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#include <iostream>
#include "WOptionHandler.h"
WOptionHandler::WOptionHandler( int argc, char* argv[] )
: m_argc( argc ),
m_argv( argv ),
m_errorOccured( false ),
m_desc( "Allowed options" ),
m_map()
{
createOptions();
try
{
parseOptions();
}
catch( po::error error )
{
m_errorOccured = true;
std::cerr << "Error parsing command-line options: " << error.what() << std::endl;
std::cerr << "Try option: --help for more information." << std::endl;
}
}
void WOptionHandler::createOptions()
{
// This is not our CodingStandard, but this is a special overloaded operator()
m_desc.add_options()
( "help,h", "prints this help message" );
}
void WOptionHandler::parseOptions()
{
po::store( po::parse_command_line( m_argc, m_argv, m_desc ), m_map );
}
int WOptionHandler::takeActions() const
{
if( m_errorOccured )
{
return 1;
}
if( m_map.count( "help" ) )
{
std::cout << m_desc << std::endl;
return 0;
}
// this code is outdated. It will be removed/rewritten.
// WMainApplication app;
return 0;
// return app.runQT( m_argc, m_argv );
}
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WOPTIONHANDLER_H
#define WOPTIONHANDLER_H
#include <boost/program_options.hpp>
// TODO(all): why is that include here?
// #include "../gui/qt4/WMainApplication.h"
// since the namespace is far to big we use a shortcut here:
namespace po = boost::program_options;
/**
* Parses commandline options, print usage and issue other appropriate actions.
*/
class WOptionHandler
{
friend class WOptionHandlerTest;
public:
/**
* Initiate the handling of the commandline parameter given via argc and
* argv with the ProgramOptions library from boost.
*/
WOptionHandler( int argc, char* argv[] );
/**
* Evaluates the given options and initiate the appropriate actions.
*
* \return Exitcode for main()
*/
int takeActions() const;
protected:
private:
int m_argc;
char** m_argv;
bool m_errorOccured;
/**
* Stores the option definition such as type, name and description.
*/
po::options_description m_desc;
/**
* Stores the values for each option and provides access to them.
*/
po::variables_map m_map;
/**
* This is a good place to define more Options.
*/
void createOptions();
/**
* Triggers the process of option parsing done by boost program_options.
*/
void parseOptions();
};
#endif // WOPTIONHANDLER_H
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WOPTIONHANDLER_TEST_H
#define WOPTIONHANDLER_TEST_H
#include <string>
#include <cxxtest/TestSuite.h>
#include "../WOptionHandler.h"
/**
* Basic testing facilities for our OptionHandler.
*/
class WOptionHandlerTest : public CxxTest::TestSuite
{
public:
/**
* Even if invalid options are given the instantiation should not fail.
*/
void testInstantiation( void )
{
const int argc = 2;
char* arg[argc];
arg[1] = const_cast<char *>( "--thisoptiondoesnotexist" );
TS_ASSERT_THROWS_NOTHING( WOptionHandler th( argc, arg ) );
}
/**
* If there are incorrect options then:
* 1. the internal error flag should be set
* 2. takeActions() should return 1
*/
void testCorrectSetErrorFlag( void )
{
const int argc = 2;
char* arg[argc];
arg[1] = const_cast<char *>( "--thisoptiondoesnotexist" );
WOptionHandler th( argc, arg );
TS_ASSERT_EQUALS( th.m_errorOccured, true );
TS_ASSERT_EQUALS( th.takeActions(), 1 );
}
/**
* If there are incorrect options a meaningful error message should be
* written to std::cerr
*/
void testParsingUnkownOption( void )
{
const int argc = 2;
char* arg[argc];
arg[1] = const_cast<char *>( "--thisoptiondoesnotexist" );
WOptionHandler th( argc, arg );
TS_ASSERT_THROWS_EQUALS( th.parseOptions(), po::error &e, std::string( e.what() ),
"unknown option thisoptiondoesnotexist" );
}
/**
* Using the help option (for example) should result in:
* 1. printing help to stdout (which we cannot check here)
* 2. Return immediately (don't start GUI) with exit code 0
*/
void testValidHelpOption( void )
{
const int argc = 2;
char* arg[argc];
arg[1] = const_cast<char *>( "--help" );
WOptionHandler th( argc, arg );
TS_ASSERT_EQUALS( th.takeActions(), 0 );
}
/**
* TODO(math): use QTTestLib for checking the QT-start.
*
* We cannot check if WMainApplication::runQT starts and return properly since
* it won't return unless we close the Window. At this point we should
* introduce QTTestLib to simulate the closing. But this isn't also a good
* idea since there must not be a display to which the window may connect.
* (e.g. consider automated testing without an X display)
*/
};
#endif // WOPTIONHANDLER_TEST_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment