QNI API

Parameters management

QNI parameters QNI_INT_IN, QNI_FLOAT_IN and QNI_CHAR_IN have one function: getvalue() to access to their values.
QNI parameters QNI_INT_INOUT, QNI_FLOAT_INOUT and QNI_CHAR_INOUT have two functions: getvalue() to access to their values and setvalue() to assign a new value:

int QNI_INT_IN::getvalue() const;
double QNI_FLOAT_IN::getvalue() const;
const char* QNI_CHAR_IN::getvalue() const;
int QNI_CHAR_IN::getlength() const;

int QNI_INT_INOUT::getvalue() const;
void QNI_INT_INOUT::setvalue(int iValue);

double QNI_FLOAT_INOUT::getvalue() const;
void QNI_FLOAT_INOUT::setvalue(double dValue);

const char* QNI_CHAR_INOUT::getvalue() const;
int QNI_CHAR_INOUT::getlength() const;
void QNI_CHAR_INOUT::setvalue(const char* pValue, int iValueLen);

Example:

QNI_FUNCTION(UseQNIFunctions, QNI_INT_IN iIn, QNI_INT_INOUT iInout,
                                                            QNI_CHAR_IN pIn, QNI_CHAR_INOUT pInout,
                                                            QNI_FLOAT_IN dIn, QNI_FLOAT_INOUT dInout)
{
    // Use the getvalue() function to retrieve parameter values.
    int i = iIn.getvalue();
    int j = iInout.getvalue();
    char* p = new char[pIn.getlength()+1];
    strcpy(p, pIn.getvalue());
    char* q = new char[pInout.getlength()+1];
    strcpy(q, pInout.getvalue());
    double d1 = dIn.getvalue();
    double d2 = dInout.getvalue();

    // Use the setvalue() function to assign new values to inout parameters
    iInout.setvalue(215);
    dInout.setvalue(3.14159);
    pInout.setvalue("something");

    delete [] p;
    delete [] q;


    return 1;
}


Associate custom data to virtual user

There are some cases in which we want to save some data between several calls to QNI functions. For example, if we write a function OpenFile to open a file, a function WriteFile to write to this file and a function CloseFile to close the file, we need to access the file descriptor opened by OpenFile in WriteFile and in CloseFile.
QNI provides three functions that help saving a context across function calls:
 

void QNI_SET_USER_DATA(const char* szId, void* pData);
void* QNI_GET_USER_DATA(const char* szId);
const char* QNI_GET_USER_ID();

void QNI_SET_USER_DATA(const char* szId, void* pData);

This function associates data to the current virtual user.
szId is an identifier of the data associated to current virtual user. This function can be called several times with different szId to save several data in the current virtual user.
pData is a pointer to the data to be saved in current virtual user.

void* QNI_GET_USER_DATA(const char* szId);

This function retrieves data associated to the current virtual user.
szId is the identifier of the data associated to current virtual user.

const char* QNI_GET_USER_ID();

This function returns the current virtual user unique id. This id looks like TaskGroupId-UserId (eg: 1-10, 4-2, ...).
 

Example:

C++ QNI source:

#include "QNI.h"

QNI_FUNCTION(OpenFile, QNI_VOID)
{
    FILE* pFileDesc = NULL;
    fopen_s(pFileDesc, QNI_GET_USER_ID(), "w+");

    // Save the file descriptor with identifier "File" in current user
    QNI_SET_USER_DATA("File", pFileDesc);

    return 1;
}

QNI_FUNCTION(WriteFile, QNI_CHAR_IN szMsg)
{
    // Retrieve the file descriptor from current user
    FILE* pFileDesc = (FILE*)QNI_GET_USER_DATA("File");

    fprintf(pFileDesc, "%s\n", szMsg.getvalue());

    return 1;
}

QNI_FUNCTION(CloseFile, QNI_VOID)
{
    // Retrieve the file descriptor from current user
    FILE* pFileDesc = (FILE*)QNI_GET_USER_DATA("File");

    fclose(pFileDesc, "%s\n", szMsg.getvalue());

    // Set the "File" data to NULL
    QNI_SET_USER_DATA("File", NULL);

    return 1;
}

AgileLoad Script:

    function extern "QNIExample" integer OpenFile();
    function extern "QNIExample" integer WriteFile(string szMsg);
    function extern "QNIExample" integer CloseFile();

BEGIN

    OpenFile();
    WriteFile("My First Message");
    WriteFile("My Second Message");
    CloseFile();

END





Go back to the Learning center:


Copyright © AgileLoad. All rights reserved.
Agile Load testing tool| Contact AgileLoad | Terms of Use | Sitemap