Into

Modules

Documentation

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
(
  • const char * plugin
  • const char * operation
)

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 true if the named output contains a stored output value and false otherwise.

Returns a pointer to the operation being tested.

Returns the names of outputs that have received output.

template<class T>
T
(
  • const QString & name
  • const T & defaultValue
)

Checks that the named output has an object and that its type matches T.

( )

Returns the last received value in the named output socket.

bool
( )

Sends an object to the named input.

bool
(
  • const QString & name
  • const char * value
)

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.

  • void clearOutputValue

    ( )
    [protected]

    Clears the output value stored into the named output.

  • void connectAllInputs

    ()
    [protected]

    Makes all inputs of the internal operation connected.

  • bool connectInput

    ( )
    [protected]

    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

    true if the plug-in was successfully loaded and the operation was successfully created, false otherwise

  • void disconnectAllInputs

    ()
    [protected]

    Disconnects all input sockets in the internal operation.

  • void disconnectInput

    ( )
    [protected]

    Disconnects the named input.

  • bool hasOutputValue

    ()
    [protected]

    A utility function that checks if any output has an object.

  • bool hasOutputValue

    ( )
    [protected]

    Returns true if the named output contains a stored output value and false otherwise.

  • PiiOperation * operation

    ()
    [protected]

    Returns a pointer to the operation being tested.

  • QStringList outputsWithData

    ()
    [protected]

    Returns the names of outputs that have received output.

  • template<class T>

    T outputValue

    (
    • const QString & name
    • const T & defaultValue
    )
    [protected]

    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.

  • PiiVariant outputValue

    ( )
    [protected]

    Returns the last received value in the named output socket.

  • bool sendObject

    ( )
    [protected]

    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

    true if the object was successfully sent, false otherwise

  • bool sendObject

    (
    • const QString & name
    • const char * value
    )
    [protected]

    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 sendObject

    ( )
    [inline, protected]

    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

    true if the object was successfully sent, false otherwise

  • void setOperation

    ( )
    [protected]

    Sets the operatito be tested.

    This function can be used if the operation is not in a plug-in.

  • bool start

    ( )
    [protected]

    Starts the tester.

    If the mode flag is ExpectSuccess, this function ensures that the tester was successfully started. If mode is ExpectFail, it ensures that the startup fails. ExpectFail is 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

    true if the mode == ExpectSuccess and the operation was successfully started, or if mode == ExpectFail and the start-up fails, and false otherwise.

  • bool stop

    ()
    [protected]

    Stops the execution of the operation.

    This function calls PiiOperation::interrupt() on the internal operation. Returns true if the operation finished within a second, false otherwise.

  • void objectReceived

    ( )
    [signal]

    Emitted whenever an object is emitted through any of the output sockets.

    See also
  • 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]
Notes (0)

Add a note

Not a single note added yet. Be the first, add yours.