Protocol Implementation > Implementing Test Run > Code the API Functions > Declare the Functions |
The API Functions are called from a script in the C language. They require a header file and a C invocation implementation. The Visual Studio add-in creates the required header file, .h. Declare all the API functions in the header.
Define a function in the <protocol ID>.cpp file. For example, for protocol TinyFTP, add code to TinyFTP.cpp:
TinyFTP_action1 Definition
TinyFTP.cpp |
Copy Code
|
---|---|
#include "TinyFTP.h" #include <stdarg.h> #include <ProtocolExtension.h> TinyFTP_API int TinyFTP_action1(char* param1, ...) { int result = LR_PASS; // create an instance of the API function class (a step) Action1Method step(param1); // Create the variable argument list. va_list vaList; va_start(vaList, param1); // run the step result = step.Run("StepName", vaList); // release the variable argument list. va_end(vaList); // return LR_PASS if step ran successfully, LR_FAIL otherwise return result; } |
Declare the function in the <protocol ID>.h file. For example, for protocol TinyFTP, add code to TinyFTP.h:
TinyFTP_action1 Declaration
TinyFTP.h |
Copy Code
|
---|---|
TinyFTP_API int TinyFTP_action1(char* param1, ...); |
Declare the function in settings.lrapi. For example:
TinyFTP_action1 Declaration
settings.lrapi |
Copy Code
|
---|---|
<?xml version="1.0" encoding="iso-8859-1"?> <LrpApi> <Function Name="TinyFTP_action1" Signature="int TinyFTP_action1(char* param1, ...)" ReturnType="int" Description="This is a sample function for the TinyFTP protocol" Image="TinyFTP_16x16_action1"> <Parameters> <Parameter Name="param1" Type="char*" /> </Parameters> </Function> </LrpApi> |