Mantid
Loading...
Searching...
No Matches
MockAlgorithm.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8
9#include <cxxtest/TestSuite.h>
10#include <gmock/gmock.h>
11
13#include "MantidJson/Json.h"
15
17
18using namespace Mantid::API;
19using namespace testing;
20
22
23class MockAlgorithm : public IAlgorithm {
24public:
25 MOCK_CONST_METHOD0(name, const std::string());
27 MOCK_CONST_METHOD0(summary, const std::string());
28 MOCK_CONST_METHOD0(category, const std::string());
29 MOCK_CONST_METHOD0(categories, const std::vector<std::string>());
31 MOCK_CONST_METHOD0(seeAlso, const std::vector<std::string>());
32 MOCK_CONST_METHOD0(aliasDeprecated, const std::string());
33 MOCK_CONST_METHOD0(alias, const std::string());
34 MOCK_CONST_METHOD0(helpURL, const std::string());
35
37 MOCK_CONST_METHOD0(workspaceMethodOn, const std::vector<std::string>());
39
41
43 MOCK_METHOD0(validateInputs, std::map<std::string, std::string>());
47
50
53
59
60 MOCK_METHOD1(setChild, void(const bool));
63 MOCK_METHOD1(setRethrows, void(const bool));
64
65 MOCK_CONST_METHOD1(addObserver, void(const Poco::AbstractObserver &));
66 MOCK_CONST_METHOD1(removeObserver, void(const Poco::AbstractObserver &));
67
68 MOCK_METHOD1(setLogging, void(const bool));
70 MOCK_METHOD1(setLoggingOffset, void(const int));
74
77
79 MOCK_CONST_METHOD0(toJson, ::Json::Value());
80
81 // IPropertyManager methods
86 MOCK_METHOD2(removeProperty, void(const std::string &, const bool));
87 MOCK_METHOD1(takeProperty, std::unique_ptr<Mantid::Kernel::Property>(const size_t));
89
90 MOCK_METHOD2(setPropertiesWithString, void(const std::string &, const std::unordered_set<std::string> &));
91 MOCK_METHOD3(setProperties, void(const std::string &, const std::unordered_set<std::string> &, bool));
92 MOCK_METHOD3(setProperties, void(const ::Json::Value &, const std::unordered_set<std::string> &, bool));
93
94 MOCK_METHOD2(setPropertyValue, void(const std::string &, const std::string &));
95 MOCK_METHOD2(setPropertyValueFromJson, void(const std::string &, const Json::Value &));
96 MOCK_METHOD2(setPropertyOrdinal, void(const int &, const std::string &));
97
98 MOCK_CONST_METHOD1(existsProperty, bool(const std::string &));
101 MOCK_CONST_METHOD1(getPropertyValue, std::string(const std::string &));
102 MOCK_CONST_METHOD0(getProperties, const std::vector<Mantid::Kernel::Property *> &());
103 MOCK_METHOD((std::vector<std::string>), getDeclaredPropertyNames, (), (const, noexcept));
104 MOCK_CONST_METHOD1(asString, std::string(bool));
105 MOCK_CONST_METHOD1(asJson, ::Json::Value(bool));
106
107 MOCK_METHOD2(declareProperty, void(std::unique_ptr<Mantid::Kernel::Property>, const std::string &));
108 MOCK_METHOD2(declareOrReplaceProperty, void(std::unique_ptr<Mantid::Kernel::Property>, const std::string &));
109
110 // Methods to help when testing
111 template <typename T> void expectGetProperty(std::string const &propertyName, PropertyWithValue<T> *prop) {
112 EXPECT_CALL(*this, getPointerToProperty(propertyName)).WillOnce(Return(prop));
113 EXPECT_CALL(*this, getProperty(propertyName)).WillOnce(Return(TypedValue(*this, propertyName)));
114 }
115};
116
#define GNU_DIAG_ON_SUGGEST_OVERRIDE
#define GNU_DIAG_OFF_SUGGEST_OVERRIDE
IAlgorithm is the interface implemented by the Algorithm base class.
Definition IAlgorithm.h:45
virtual const std::string workspaceMethodInputProperty() const =0
Returns the name of the input workspace property used by the calling object.
virtual std::string toString() const =0
Serialize an algorithm.
virtual ::Json::Value toJson() const =0
Serialize an algorithm as Json.
virtual Poco::ActiveResult< bool > executeAsync()=0
Asynchronous execution of the algorithm.
virtual bool isExecuted() const =0
Check whether the algorithm has been executed sucessfully.
virtual bool isInitialized() const =0
Check whether the algorithm is initialized properly.
virtual const std::string alias() const =0
function to return any aliases of the algorithm.
virtual void removeObserver(const Poco::AbstractObserver &observer) const =0
Remove an observer.
virtual bool isChild() const =0
To query whether algorithm is a child. Default to false.
virtual int version() const =0
function to return a version of the algorithm, must be overridden in all algorithms
virtual const std::string aliasDeprecated() const =0
Expiration date (in ISO8601 format) for the algorithm aliases. Empty if no expiration date.
virtual const std::string categorySeparator() const =0
Function to return the separator token for the category string.
virtual const std::string helpURL() const =0
function to return an optional URL for documentation.
virtual void setChildStartProgress(const double startProgress) const =0
setting the child start progress
virtual const std::vector< std::string > categories() const =0
Function to return all of the categories that contain this algorithm.
virtual bool isLogging() const =0
returns the status of logging, True = enabled
virtual ExecutionState executionState() const =0
Gets the current execution state.
virtual const std::vector< std::string > seeAlso() const =0
Function to return all of the seeAlso algorithms related to this algorithm.
virtual bool isRunning() const =0
True if the algorithm is running.
virtual const std::string category() const =0
function to return a category of the algorithm.
virtual bool isReadyForGarbageCollection() const =0
True if the algorithm is ready for garbage collection.
virtual void setChild(const bool isChild)=0
To set whether algorithm is a child.
virtual const std::string workspaceMethodName() const =0
virtual void executeAsChildAlg()=0
Execute as a Child Algorithm, with try/catch.
virtual const std::vector< std::string > workspaceMethodOn() const =0
Returns a set of class names that will have the method attached.
virtual bool getAlgStartupLogging() const =0
get the state of Logging of start and end messages
virtual const std::string summary() const =0
function returns a summary message that will be displayed in the default GUI, and in the help.
virtual void enableHistoryRecordingForChild(const bool on)=0
If true history will be recorded for a child.
virtual bool getAlwaysStoreInADS() const =0
To query whether the output is stored in the analysis data service.
virtual void setLogging(const bool value)=0
Logging can be disabled by passing a value of false.
virtual void cancel()=0
Raises the cancel flag.
virtual void setLoggingOffset(const int value)=0
gets the logging priority offset
virtual void setAlwaysStoreInADS(const bool doStore)=0
Set whether we always store the output in the analysis data service.
virtual void setRethrows(const bool rethrow)=0
To query whether an algorithm should rethrow exceptions when executing.
virtual void setAlgStartupLogging(const bool enabled)=0
disable Logging of start and end messages
virtual const std::string name() const =0
function to return a name of the algorithm, must be overridden in all algorithms
virtual bool execute()=0
System execution.
virtual void setChildEndProgress(const double endProgress) const =0
setting the child end progress
virtual void addObserver(const Poco::AbstractObserver &observer) const =0
Add an observer for a notification.
virtual int getLoggingOffset() const =0
returns the logging priority offset
virtual std::map< std::string, std::string > validateInputs()=0
Method checking errors on ALL the inputs, before execution.
virtual AlgorithmID getAlgorithmID() const =0
Algorithm ID.
virtual ResultState resultState() const =0
Gets the currnet result State.
virtual void initialize()=0
Initialization method invoked by the framework.
virtual void clear()=0
Clears all properties under management.
virtual Property * getPointerToPropertyOrdinal(const int &index) const =0
Get a property by an index.
virtual void setPropertyValue(const std::string &name, const std::string &value)=0
Sets property value from a string.
virtual bool validateProperties() const =0
Validates all the properties in the collection.
virtual ::Json::Value asJson(bool withDefaultValues=false) const =0
Return the property manager serialized as a json object.
virtual bool existsProperty(const std::string &name) const =0
Checks whether the named property is already in the list of managed property.
virtual void setPropertyOrdinal(const int &index, const std::string &value)=0
Set the value of a property by an index.
virtual void setPropertiesWithString(const std::string &propertiesString, const std::unordered_set< std::string > &ignoreProperties=std::unordered_set< std::string >())=0
Sets all the declared properties from a string.
virtual void removeProperty(const std::string &name, const bool delproperty=true)=0
Removes the property from management.
virtual std::string asString(bool withDefaultValues=false) const =0
Return the property manager serialized as a string.
virtual void declareProperty(std::unique_ptr< Property > p, const std::string &doc="")=0
Function to declare properties (i.e. store them)
virtual void declareOrReplaceProperty(std::unique_ptr< Property > p, const std::string &doc="")=0
Function to declare properties (i.e. store them)
virtual Property * getPointerToProperty(const std::string &name) const =0
Get a pointer to property by name.
virtual std::vector< std::string > getDeclaredPropertyNames() const noexcept=0
Get the list of managed property names.
virtual TypedValue getProperty(const std::string &name) const =0
Get the value of a property.
virtual void setProperties(const std::string &propertiesJson, const std::unordered_set< std::string > &ignoreProperties=std::unordered_set< std::string >(), bool createMissing=false)=0
Sets all properties from a string.
virtual std::string getPropertyValue(const std::string &name) const =0
Get the value of a property as a string.
virtual size_t propertyCount() const =0
Returns the number of properties under management.
virtual std::unique_ptr< Property > takeProperty(const size_t index)=0
Removes the property from management and returns a pointer to it.
virtual const std::vector< Property * > & getProperties() const =0
Get the list of managed properties.
virtual void setPropertyValueFromJson(const std::string &name, const Json::Value &value)=0
Sets property value from a Json::Value.
The concrete, templated class for properties.
Base class for properties.
Definition Property.h:94
MOCK_CONST_METHOD0(workspaceMethodInputProperty, const std::string())
MOCK_CONST_METHOD1(setChildStartProgress, void(const double))
MOCK_METHOD0(clear, void())
MOCK_CONST_METHOD1(asString, std::string(bool))
MOCK_CONST_METHOD0(isInitialized, bool())
void expectGetProperty(std::string const &propertyName, PropertyWithValue< T > *prop)
MOCK_METHOD0(initialize, void())
MOCK_CONST_METHOD0(isRunning, bool())
MOCK_CONST_METHOD1(getPointerToPropertyOrdinal, Mantid::Kernel::Property *(const int &))
MOCK_CONST_METHOD1(existsProperty, bool(const std::string &))
MOCK_METHOD((std::vector< std::string >), getDeclaredPropertyNames,(),(const, noexcept))
MOCK_METHOD1(setLoggingOffset, void(const int))
MOCK_CONST_METHOD0(seeAlso, const std::vector< std::string >())
MOCK_CONST_METHOD0(workspaceMethodOn, const std::vector< std::string >())
MOCK_METHOD1(setAlgStartupLogging, void(const bool))
MOCK_CONST_METHOD0(isReadyForGarbageCollection, bool())
MOCK_CONST_METHOD0(version, int())
MOCK_CONST_METHOD0(workspaceMethodName, const std::string())
MOCK_METHOD0(executeAsChildAlg, void())
MOCK_METHOD2(declareOrReplaceProperty, void(std::unique_ptr< Mantid::Kernel::Property >, const std::string &))
MOCK_CONST_METHOD0(categories, const std::vector< std::string >())
MOCK_CONST_METHOD0(isLogging, bool())
MOCK_METHOD2(setPropertyValueFromJson, void(const std::string &, const Json::Value &))
MOCK_CONST_METHOD0(category, const std::string())
MOCK_CONST_METHOD0(executionState, ExecutionState())
MOCK_METHOD1(setLogging, void(const bool))
MOCK_CONST_METHOD1(getPointerToProperty, Mantid::Kernel::Property *(const std::string &))
MOCK_METHOD2(setPropertyOrdinal, void(const int &, const std::string &))
MOCK_METHOD0(executeAsync, Poco::ActiveResult< bool >())
MOCK_METHOD2(setPropertiesWithString, void(const std::string &, const std::unordered_set< std::string > &))
MOCK_CONST_METHOD0(summary, const std::string())
MOCK_METHOD3(setProperties, void(const ::Json::Value &, const std::unordered_set< std::string > &, bool))
MOCK_CONST_METHOD0(toJson, ::Json::Value())
MOCK_METHOD2(removeProperty, void(const std::string &, const bool))
MOCK_CONST_METHOD0(isExecuted, bool())
MOCK_METHOD2(setPropertyValue, void(const std::string &, const std::string &))
MOCK_CONST_METHOD0(getLoggingOffset, int())
MOCK_CONST_METHOD0(alias, const std::string())
MOCK_CONST_METHOD0(getAlwaysStoreInADS, bool())
MOCK_CONST_METHOD0(name, const std::string())
MOCK_CONST_METHOD0(categorySeparator, const std::string())
MOCK_CONST_METHOD1(removeObserver, void(const Poco::AbstractObserver &))
MOCK_CONST_METHOD1(getPropertyValue, std::string(const std::string &))
MOCK_CONST_METHOD0(resultState, ResultState())
MOCK_METHOD1(takeProperty, std::unique_ptr< Mantid::Kernel::Property >(const size_t))
MOCK_METHOD0(execute, bool())
MOCK_CONST_METHOD0(toString, std::string())
MOCK_METHOD0(resetProperties, void())
MOCK_METHOD1(enableHistoryRecordingForChild, void(const bool))
MOCK_CONST_METHOD0(helpURL, const std::string())
MOCK_CONST_METHOD0(aliasDeprecated, const std::string())
MOCK_METHOD1(setAlwaysStoreInADS, void(const bool))
MOCK_CONST_METHOD0(isChild, bool())
MOCK_METHOD0(validateInputs, std::map< std::string, std::string >())
MOCK_CONST_METHOD0(getAlgStartupLogging, bool())
MOCK_METHOD1(setChild, void(const bool))
MOCK_CONST_METHOD0(propertyCount, size_t())
MOCK_CONST_METHOD1(getProperty, TypedValue(const std::string &))
MOCK_METHOD1(setRethrows, void(const bool))
MOCK_CONST_METHOD0(getAlgorithmID, AlgorithmID())
MOCK_CONST_METHOD0(validateProperties, bool())
MOCK_CONST_METHOD1(addObserver, void(const Poco::AbstractObserver &))
MOCK_METHOD2(declareProperty, void(std::unique_ptr< Mantid::Kernel::Property >, const std::string &))
MOCK_CONST_METHOD1(asJson, ::Json::Value(bool))
MOCK_METHOD0(cancel, void())
MOCK_CONST_METHOD0(getProperties, const std::vector< Mantid::Kernel::Property * > &())
MOCK_CONST_METHOD1(setChildEndProgress, void(const double))
MOCK_METHOD3(setProperties, void(const std::string &, const std::unordered_set< std::string > &, bool))
ResultState
The validity of the results of the algorithm object.
Definition IAlgorithm.h:33
ExecutionState
The current state of the algorithm object.
Definition IAlgorithm.h:31
void * AlgorithmID
As we have multiple interfaces to the same logical algorithm we need a way of uniquely identifying ma...
Definition IAlgorithm.h:28
Utility class that enables the getProperty() method to effectively be templated on the return type.