classPiiOperationTest
#include <PiiOperationTest.h>
A class that makes it easier to write unit tests for operations.
Inherits QObject
Description
PiiOperationTest attaches probes to the outputs of an operation to be tested. A derived class can then selectively connect inputs of the operation and send arbitrary data to the input sockets.
A typical unit test for an operation is as follows:
// In TestMyOperation.h #include <PiiOperationTest.h> class TestMyOperation : public PiiOperationTest { Q_OBJECT private slots: void initTestCase(); void process(); }; // In main.cc #include "TestMyOperation.h" #include <QtTest> void TestMyOperation::initTestCase() { QVERIFY(createOperation("myplugin", "TestMyOperation")); } void TestMyOperation::process() { // No inputs connected -> should fail QVERIFY(start(ExpectFail)); // Set properties QVERIFY(operation()->setProperty("property", "value")); // Connect inputs connectAllInputs(); // Try to start again QVERIFY(start()); // Send object(s) QVERIFY(sendObject("input", 1)); // Verify outputs QCOMPARE(outputValue("output", 0), 1); } QTEST_MAIN(TestMyOperation)
Public types
|
enum
|
{ ExpectSuccess, ExpectFail }
Failure handling types in start(). |
Protected Slots
|
virtual void
|
( )
Clears all collected output values by calling clearAllOutputValues(). |
Signals
|
void
|
Emitted whenever an object is emitted through any of the output sockets. |
Constructors and destructor
|
( )
|
|
Protected member functions
|
void
|
Clears all stored output values. |
|
void
|
Clears the output value stored into the named output. |
|
void
|
( )
Makes all inputs of the internal operation connected. |
|
bool
|
Makes the named input connected. |
|
bool
|
(
Creates the operation to be tested. |
|
void
|
Disconnects all input sockets in the internal operation. |
|
void
|
Disconnects the named input. |
|
bool
|
( )
A utility function that checks if any output has an object. |
|
bool
|
Returns |
|
( )
Returns a pointer to the operation being tested. |
|
|
( )
Returns the names of outputs that have received output. |
|
|
template<class T>
T
|
Checks that the named output has an object and that its type
matches |
|
Returns the last received value in the named output socket. |
|
|
( )
|
|
|
bool
|
Sends an object to the named input. |
|
bool
|
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Automatically converts const char* to QString. |
|
template<class T>
bool
|
Sends an object to the named input. |
|
void
|
Sets the operatito be tested. |
|
bool
|
Starts the tester. |
|
bool
|
( )
Stops the execution of the operation. |
Enumeration details
-
enum FailMode
Failure handling types in start().
Function details
-
PiiOperationTest
()[protected] -
~PiiOperationTest
() -
void clearAllOutputValues
()[protected]Clears all stored output values.
-
Clears the output value stored into the named output.
-
void connectAllInputs
()[protected]Makes all inputs of the internal operation connected.
-
Makes the named input connected.
This function connects the named input into an output socket that is not attached to any operation.
-
bool createOperation
(- const char * plugin
- const char * operation
[protected]Creates the operation to be tested.
Parameters
- plugin
-
the name of the plug-in that contains the operation
- operation
-
the name of the operation to test
Returns
trueif the plug-in was successfully loaded and the operation was successfully created,falseotherwise -
void disconnectAllInputs
()[protected]Disconnects all input sockets in the internal operation.
-
Disconnects the named input.
-
bool hasOutputValue
()[protected]A utility function that checks if any output has an object.
-
Returns
trueif the named output contains a stored output value andfalseotherwise. -
Returns a pointer to the operation being tested.
-
Returns the names of outputs that have received output.
-
Checks that the named output has an object and that its type matches
T.If both of these hold, return the value of the object. Otherwise return
defaultValue. -
Returns the last received value in the named output socket.
-
Sends an object to the named input.
Parameters
- name
-
the name of the input socket to which the object is to be sent
- value
-
the object to be sent
Returns
trueif the object was successfully sent,falseotherwise -
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Automatically converts const char* to QString.
-
Sends an object to the named input.
The function automatically converts the object to a PiiVariant.
Parameters
- name
-
the name of the input socket to which the object is to be sent
- value
-
the value of the object
Returns
trueif the object was successfully sent,falseotherwise -
Sets the operatito be tested.
This function can be used if the operation is not in a plug-in.
-
Starts the tester.
If the
modeflag isExpectSuccess, this function ensures that the tester was successfully started. IfmodeisExpectFail, it ensures that the startup fails.ExpectFailis useful when one needs to check that the operation correctly identifies unconnected inputs, missing configuration etc. One needs to stop the tester (stop()) once the test is finished.Returns
trueif themode== ExpectSuccess and the operation was successfully started, or ifmode== ExpectFail and the start-up fails, andfalseotherwise. -
bool stop
()[protected]Stops the execution of the operation.
This function calls PiiOperation::interrupt() on the internal operation. Returns
trueif the operation finished within a second,falseotherwise. -
virtual void cleanup
()[protected, virtual, slot]Clears all collected output values by calling clearAllOutputValues().
This function will be called by Qt's test system after each test function.
-
void deleteOutput
()[slot] -
void deleteProbe
()[slot] -
void emitObject
()[slot]
Add a note
Not a single note added yet. Be the first, add yours.