xTitan
All Classes Functions Groups
Macros | Functions
Spy Library

Macros

#define spyInput   xtitan::detail::SpyInput(spyGetToken(this).toUtf8(),__FUNCTION__)
 Records function call. More...
 
#define spyCheck   xtitan::detail::SpyCheck(__FILE__,__LINE__)
 Creates synchronized check point. More...
 
#define spyAsyncCheck   xtitan::detail::SpyAsyncCheck(__FILE__,__LINE__)
 Creates asynchronized check point. More...
 

Functions

void spyRegisterObject (QObject *object, const QString &id)
 Register object for record/replay. More...
 
QString spyGetToken (QObject *object)
 Get ID of a registered object. More...
 
QObject * spyGetObject (const QString &token)
 Get a registered object by ID. More...
 
void spyTryTestAutomation ()
 Start record/replay. More...
 
bool spyIsTesting ()
 record/replay is start or not More...
 

Detailed Description

Macro Definition Documentation

#define spyAsyncCheck   xtitan::detail::SpyAsyncCheck(__FILE__,__LINE__)

Creates asynchronized check point.

See Also
spyCheck

Similar to spyCheck, except that check points can reorder. Because execution order may randomly interleave in multi-thread context, you must use this macro in concurrent functions.

To distinguish individual execution order in each threads, you must specify ID and precondition to each check points. ID should be a string. Use id() to specify ID, and pre() to specify precondition, for example:

void ConcurrentJob::run() {
int i = 0;
// some logic
spyAsyncCheck.id("id1") % i;
// some logic
spyAsyncCheck.id("id2").pre("id1") % i;
// some logic
spyAsyncCheck.id("id3").pre("id2") % i;
}
#define spyCheck   xtitan::detail::SpyCheck(__FILE__,__LINE__)

Creates synchronized check point.

See Also
spyAsyncCheck

This macro creates a synchronized check point, which can record variables or function results while recording, and compares their values in each replay. After replay, if check point sequence mismatched (either by reordering, missing or duplicating), then this replay was failed.

To use this macro record variables, simply put variables with operator %, but variable type must be one of

  • bool
  • int64_t
  • double
  • std::string
  • std::wstring

or any other types which can implicitly convert to these types.

For example:

void Job::doSomething() {
int i = 0;
// after some logic, you want to check variable i and member variable name
spyCheck % i % this->name;
}
#define spyInput   xtitan::detail::SpyInput(spyGetToken(this).toUtf8(),__FUNCTION__)

Records function call.

See Also
spyRegisterObject

This macro records function call, so that test driver can replay this function later. The function being recording MUST match following rules:

  1. This function is a Qt slot or Q_INVOKABLE decorated.
  2. The instance is registered by spyRegisterObject.
  3. This function is a public method (i.e. not private or protected).
  4. All parameters either are one of these types or can implicitly convert to these types:
    • bool
    • int64_t
    • double
    • std::string
    • std::wstring

To use this macro is quite simple, just put this macro in your function (generally at first line), and concat all parameters with operator %.

Following example explains how to use spyInput:

void Dialog::showResult(int code, const std::wstring & message) {
spyInput % code % message;
// regular code
}

Function Documentation

QObject* spyGetObject ( const QString &  token)

Get a registered object by ID.

Parameters
[in]token
Returns
object that ID is token
See Also
spyGetToken spyRegisterObject

This function can retrive object which registered by spyRegisterObject.

QString spyGetToken ( QObject *  object)

Get ID of a registered object.

Parameters
[in]object
Returns
ID of object
See Also
spyGetObject spyRegisterObject

This function can retrive ID which registered by spyRegisterObject.

bool spyIsTesting ( )

record/replay is start or not

Returns
true if started
See Also
spyTryTestAutomation
void spyRegisterObject ( QObject *  object,
const QString &  id 
)

Register object for record/replay.

Parameters
[in]objectobject being register
[in]idunique ID for this object
See Also
spyInput

If object is nullptr, or id is an empty string, this function does nothing.

Objects must register by this method first before they can be recording by spyInput. A common place for this function is inside a constructor.

void spyTryTestAutomation ( )

Start record/replay.

See Also
spyIsTesting

Without calling this function, record/replay won't start. Please call this function as early as possible, e.g. in the main function.