Skip to content

Commit

Permalink
Refs #10408 Unit test AlgorithmHintStrategy
Browse files Browse the repository at this point in the history
  • Loading branch information
Harry Jeffery committed Oct 24, 2014
1 parent 1cdc745 commit 1a4efa5
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 4 deletions.
10 changes: 6 additions & 4 deletions Code/Mantid/MantidQt/MantidWidgets/CMakeLists.txt
Expand Up @@ -115,6 +115,10 @@ set ( TEST_PY_FILES
test/MWRunFilesTest.py
)

set ( TEST_FILES
AlgorithmHintStrategyTest.h
)

find_package (Qt4 REQUIRED QtHelp QtWebKit QtNetwork QUIET)
include(${QT_USE_FILE})

Expand Down Expand Up @@ -143,12 +147,10 @@ target_link_libraries ( MantidWidgets MantidQtAPI QtPropertyBrowser
)

###########################################################################
# Unit tests setup
# Testing
###########################################################################

if ( PYUNITTEST_FOUND )
pyunittest_add_test (${CMAKE_CURRENT_SOURCE_DIR}/test MantidWidgetsTest ${TEST_PY_FILES} )
endif ()
add_subdirectory ( test )

###########################################################################
# Installation settings
Expand Down
@@ -0,0 +1,64 @@
#ifndef MANTID_MANTIDWIDGETS_ALGORITHMHINTSTRATEGYTEST_H
#define MANTID_MANTIDWIDGETS_ALGORITHMHINTSTRATEGYTEST_H

#include <cxxtest/TestSuite.h>
#include "MantidAPI/FrameworkManager.h"
#include "MantidAPI/AlgorithmManager.h"
#include "MantidQtMantidWidgets/HintStrategy.h"
#include "MantidQtMantidWidgets/AlgorithmHintStrategy.h"

using namespace MantidQt::MantidWidgets;
using namespace Mantid::API;

//=====================================================================================
// Functional tests
//=====================================================================================
class AlgorithmHintStrategyTest : public CxxTest::TestSuite
{
public:
// This pair of boilerplate methods prevent the suite being created statically
// This means the constructor isn't called when running other tests
static AlgorithmHintStrategyTest *createSuite() { return new AlgorithmHintStrategyTest(); }
static void destroySuite( AlgorithmHintStrategyTest *suite ) { delete suite; }

AlgorithmHintStrategyTest()
{
FrameworkManager::Instance();
m_propAlg = AlgorithmManager::Instance().create("PropertyAlgorithm");
//Expected hints for PropertyAlgorithm
m_propMap["IntValue"] = "";
m_propMap["DoubleValue"] = "";
m_propMap["BoolValue"] = "";
m_propMap["StringValue"] = "";
m_propMap["PositiveIntValue"] = "";
m_propMap["PositiveIntValue1"] = "";
m_propMap["IntArray"] = "";
m_propMap["DoubleArray"] = "";
m_propMap["StringArray"] = "";
}

void testCreateHints()
{
boost::scoped_ptr<HintStrategy> strategy(new AlgorithmHintStrategy(m_propAlg, std::set<std::string>()));
TS_ASSERT_EQUALS(m_propMap, strategy->createHints());
}

void testBlacklist()
{
std::set<std::string> blacklist;
blacklist.insert("DoubleValue");
blacklist.insert("IntArray");

boost::scoped_ptr<HintStrategy> strategy(new AlgorithmHintStrategy(m_propAlg, blacklist));
auto expected = m_propMap;
expected.erase("DoubleValue");
expected.erase("IntArray");
TS_ASSERT_EQUALS(expected, strategy->createHints());
}

protected:
IAlgorithm_sptr m_propAlg;
std::map<std::string,std::string> m_propMap;
};

#endif /*MANTID_MANTIDWIDGETS_ALGORITHMHINTSTRATEGYTEST_H */
16 changes: 16 additions & 0 deletions Code/Mantid/MantidQt/MantidWidgets/test/CMakeLists.txt
@@ -0,0 +1,16 @@
if ( PYUNITTEST_FOUND )
pyunittest_add_test (${CMAKE_CURRENT_SOURCE_DIR} MantidWidgetsTest ${TEST_PY_FILES} )
endif ()

if ( CXXTEST_FOUND )
include_directories ( SYSTEM ${CXXTEST_INCLUDE_DIR} ${GMOCK_INCLUDE_DIR} ${GTEST_INCLUDE_DIR} )

if ( GMOCK_FOUND AND GTEST_FOUND )
cxxtest_add_test ( MantidWidgetsTest ${TEST_FILES} ${GMOCK_TEST_FILES} )
target_link_libraries( MantidWidgetsTest MantidWidgets ${GMOCK_LIBRARIES} ${GTEST_LIBRARIES} )

# Add to the 'UnitTests' group in VS
set_property( TARGET MantidWidgetsTest PROPERTY FOLDER "UnitTests" )
endif ()

endif ()

0 comments on commit 1a4efa5

Please sign in to comment.