/*
 * Project: MoleCuilder
 * Description: creates and alters molecular systems
 * Copyright (C)  2010-2012 University of Bonn. All rights reserved.
 * 
 *
 *   This file is part of MoleCuilder.
 *
 *    MoleCuilder is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 2 of the License, or
 *    (at your option) any later version.
 *
 *    MoleCuilder 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 General Public License
 *    along with MoleCuilder.  If not, see .
 */
/*
 * CommandLineParser_ActionRegistry_ConsistencyUnitTest.cpp
 *
 *  Created on: Nov 25, 2009
 *      Author: heber
 */
// include config.h
#ifdef HAVE_CONFIG_H
#include 
#endif
using namespace std;
#include 
#include 
#include 
#include "Actions/Action.hpp"
#include "Actions/ActionQueue.hpp"
#include "Actions/ActionTrait.hpp"
#include "UIElements/CommandLineUI/CommandLineParser.hpp"
#include "World.hpp"
#include "WorldTime.hpp"
#include "CommandLineParser_ActionRegistry_ConsistencyUnitTest.hpp"
using namespace MoleCuilder;
#ifdef HAVE_TESTRUNNER
#include "UnitTestMain.hpp"
#endif /*HAVE_TESTRUNNER*/
/********************************************** Test classes **************************************/
// Registers the fixture into the 'registry'
CPPUNIT_TEST_SUITE_REGISTRATION( CommandLineParser_ActionRegistry_ConsistencyTest );
void CommandLineParser_ActionRegistry_ConsistencyTest::setUp()
{
  CLP = CommandLineParser::getPointer();
};
void CommandLineParser_ActionRegistry_ConsistencyTest::tearDown()
{
  CommandLineParser::purgeInstance();
  ActionQueue::purgeInstance();
  // these come about because of the validators accessing them instantiated
  // by ActionRegistry. In ActionRegistryUnitTest we used stubs for them but
  // here we care whether default values are actually valid.
  World::purgeInstance();
  WorldTime::purgeInstance();
};
/** UnitTest for consistency.
 * Here, we check that for each desired menu, stored in the Actions and
 * accessible via the ActionRegistry, there is a boost::program_options
 * present in the CommandLineParser (this is not necessarily one-and-onto,
 * there might be more program_options maps).
 */
void CommandLineParser_ActionRegistry_ConsistencyTest::ConsistencyCheck()
{
  std::set  MenuNames_from_CommandLineParser;
  std::set  MenuNames_from_ActionRegistry;
  // go through all Actions and gather menu names
  ActionQueue &AQ = ActionQueue::getInstance();
  ActionQueue::ActionTokens_t tokens = AQ.getListOfActions();
  for (ActionQueue::ActionTokens_t::const_iterator iter = tokens.begin();
      iter != tokens.end(); ++iter) {
    const ActionTrait &CurrentTrait = AQ.getActionsTrait(*iter);
    const std::string &MenuName = CurrentTrait.getMenuName();
    MenuNames_from_ActionRegistry.insert(MenuName);
  }
  // go through all Command line menus and gather all option names
  for (CommandLineParser::CmdParserLookupMap::const_iterator iter = CLP->CmdParserLookup.begin();
      iter != CLP->CmdParserLookup.end();
      ++iter) {
    const std::string &MenuName = (iter->first);
    MenuNames_from_CommandLineParser.insert(MenuName);
  }
  for (std::set ::const_iterator ARiter = MenuNames_from_ActionRegistry.begin();
      ARiter != MenuNames_from_ActionRegistry.end();
      ++ARiter) {
    CPPUNIT_ASSERT_MESSAGE(*ARiter
        +" cannot be found in the CommandLineParser.\n"
        +"Have you added a program_options map to CommandLineParser for this menu?",
        MenuNames_from_CommandLineParser.count(*ARiter));
  }
};