Runtime Test Services: Difference between revisions

From STRIDE Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(53 intermediate revisions by 5 users not shown)
Line 1: Line 1:
== Runtime Test Services ==
__NOTOC__
The Runtime Test Services (declared in '''srtest.h''') are a set of APIs in the Stride Runtime that facilitate the writing of target based test code. These APIs make up an optional portion of the Stride Runtime and can be used to communicate additional information about tests to the host based reporting mechanism. These APIs also allow target test code to create additional test suites and test cases dynamically at runtime.


The Runtime Test Services (declared in srtest.h) are a set of APIs in the STRIDE Runtime that facilitate the writing of target based test code. These APIs make up an optional portion of the STRIDE Runtime and can be used to communicate additional information about tests to the host based reporting mechanism. These APIs also allow target test code to create additional test suites and test cases dynamically at runtime.  
There are two ways of accessing these APIs: through C-based functions, or through a C++ base class from which you may derive your C++ test class. These are discussed below in [[#C Test Functions|C Test Functions]], and [[#C++ Test Classes|C++ Test Classes]] sections below.


There are two ways of accessing these APIs: through C-based functions, or through a C++ base class from which you may derive your C++ test class. These are discussed below in [[#C Test Functions|C Test Functions]], and [[#C++ Test Classes|C++ Test Classes]] sections below.
= C Test Functions =


Refer to the [[Media:s2sSCLReferenceGuide.pdf|SCL Reference Guide]] or the [[Media:s2sRuntime.pdf|Runtime Developer's Guide]] for more detailed information about any of these APIs.
The following C APIs are provided:  


=== C Test Functions ===
*'''[[#srTestGetParam|srTestGetParam]]''': returns an input parameters value.


The following C APIs are provided:  
*'''[[#srTestSuiteAddCase|srTestSuiteAddCase]]''': creates an additional test case at runtime.
*'''[[#srTestSuiteAddAnnotation|srTestSuiteAddAnnotation]]''': creates a suite annotation at runtime.
*'''[[#srTestSuiteSetData|srTestSuiteSetData]]''': associates a custom name|value.


*'''[[#srTestSuiteAddSuite|srTestSuiteAddSuite]]''': creates an additional sub-suite at runtime.
*'''[[#srTestSuiteSetName|srTestSuiteSetName]]''': sets the name of the specified suite.
*'''[[#srTestSuiteSetDescription|srTestSuiteSetDescription]]''': sets the description of the specified suite.
*'''[[#srTestSuiteAddCase|srTestSuiteAddCase]]''': creates an additional test case at runtime.
*'''[[#srTestCaseSetName|srTestCaseSetName]]''': sets the name of the specified test case.
*'''[[#srTestCaseSetDescription|srTestCaseSetDescription]]''': sets the description of the specified test case.
*'''[[#srTestCaseAddComment|srTestCaseAddComment]]''': adds a comment to the specified test case.
*'''[[#srTestCaseSetStatus|srTestCaseSetStatus]]''': explicitly sets the status for the specified test case.
*'''[[#srTestCaseSetStatus|srTestCaseSetStatus]]''': explicitly sets the status for the specified test case.
*'''[[#srTestSuiteAddAnnotation|srTestSuiteAddAnnotation]]''': creates an annotation at runtime.  
*'''[[#srTestCaseAddAnnotation|srTestCaseAddAnnotation]]''': creates a test case annotation at runtime.  
*'''[[#srTestSuiteSetData|srTestSuiteSetData]]''': associates a custom name|value pair with the specified test case.
 
*'''[[#srTestAnnotationAddComment|srTestAnnotationAddComment]]''': adds a comment to the specified annotation.
*'''[[#srTestAnnotationAddComment|srTestAnnotationAddComment]]''': adds a comment to the specified annotation.




==== srTestSuiteAddSuite ====
== srTestGetParam ==
The srTestSuiteAddSuite() routine is used to add a new test suite to the specified test suite.
The srTestGetParam() function is used to get the value of a named parameter as a string.
<source lang=c>
<source lang=c>
srTestSuiteHandle_t srTestSuiteAddSuite(srTestSuiteHandle_t tParent, const srCHAR * szName)
srWORD srTestGetParam(const srCHAR * szName, srCHAR * szValue, srDWORD dwSize, const srCHAR * szDefValue);
</source>
</source>


{| border="1" cellspacing="0" cellpadding="10" style="align:left;"   
{| border="1" cellspacing="0" cellpadding="10" style="align:left;"   
Line 33: Line 32:
| '''Type'''
| '''Type'''
| '''Description'''
| '''Description'''
|-  
|-
| tParent
| szName
| Input
| Input
| Handle to the parent test suite to which new test suite is to be added. srTEST_SUITE_DEFAULT can be used for the default test suite.
| Pointer to a null-terminated string that represents the name of the parameter. Cannot be null.
|-
| szValue
| Output
| Pointer to a block of memory to store the value of the parameter with a maximum size of <i>dwSize</i> chars
|-
|-
| szName
| dwSize
| Input  
| Input  
| Pointer to a null-terminated string that represents the name of test suite. If null, the default host naming scheme will be used.
| Size in chars of the buffer pointed to by <i>szValue</i>
|-
| szDefValue
| Input (optional)
| Pointer to a null-terminated string that represents a default value in case the parameter is not specified. By setting this value to srNULL (or omitting it), you can use <i>srTestGetParam()</i> to test for the existence of a named parameter. If the named parameter doesn't exist, the function will return <i>srERR_HANDLE_INVALID</i>.
|}
|}
<br>
<br>
Line 47: Line 54:
| ''' Description'''
| ''' Description'''
|-
|-
|srTestSuiteHandle_t
| srOK
| Handle of the newly created test suite. srTEST_SUITE_INVALID indicates failure to create test suite.
| Success
|-
| srERR
| Null or empty szName string passed in.
|-
| srERR_HANDLE_INVALID
| The named parameter is not found and <i>szDefValue</i> is set to srNULL.
|}
|}


<source lang=c>
<source lang=c>
#include <srtest.h>
#include <srtest.h>


void tfsuite_addSuite(void)
#define MAX_VALUE_LEN 128
void tfsuite_getParam(void)
{
{
   srTestSuiteHandle_t subSuite =
   srCHAR szValue[MAX_VALUE_LEN] = {0};
   srTestSuiteAddSuite(srTEST_SUITE_DEFAULT, "tf Sub Suite");
 
   srWORD wRet = srTestGetParam("ParamName", szValue, MAX_VALUE_LEN, "default value");
}
}


#ifdef _SCL
#ifdef _SCL
#pragma scl_test_flist(“testfunc”, tfsuite_addSuite)
#pragma scl_test_flist("testfunc", tfsuite_getParam)
#endif
#endif
</source>
</source>


==== srTestSuiteSetName ====
 
The srTestSuiteSetName() routine is used to set the name of the specified test suite.
== srTestGetParamLong ==
The srTestGetParamLong() function is used to get the value of a named parameter as a long.
<source lang=c>
<source lang=c>
srWORD srTestSuiteSetName(srTestSuiteHandle_t tTestSuite, const srCHAR * szName)
srLONG srTestGetParamLong(const srCHAR * szName, srLONG lDefValue);
</source>
</source>


{| border="1" cellspacing="0" cellpadding="10" style="align:left;"   
{| border="1" cellspacing="0" cellpadding="10" style="align:left;"   
Line 76: Line 94:
| '''Description'''
| '''Description'''
|-
|-
| tTestSuite
| szName
| Input
| Input
| Handle to a test suite. srTEST_SUITE_DEFAULT can be used for the default test suite.
| Pointer to a null-terminated string that represents the name of the parameter.
|-
|-
| szName
| lDefValue
| Input  
| Input  
| Pointer to a null-terminated string representing the name of test suite. Cannot be null.
| Default value that is returned if the parameter is not found.
|}
|}
<br>
<br>
Line 89: Line 107:
| ''' Description'''
| ''' Description'''
|-
|-
| srOK
| srLONG
| Success
| Parameter value, or value specified by <i>lDefValue</i> if parameter isn't found.
|-
| srERR
| Null string passed in.
|-
| srTEST_ERR_HANDLE_INVALID
| Invalid handle passed in.
|-
| srTEST_WARN_STR_TRUNCATED
| String passed in was too large and was truncated.
|}
|}


<source lang=c>
<source lang=c>
#include <srtest.h>
#include <srtest.h>


void tfsuite_setName(void)
void tfsuite_getParam(void)
{
{
   srTestSuiteSetName(srTEST_SUITE_DEFAULT, "Setting name for default suite");
   srLONG lVal = srTestGetParamLong("ParamName", -1);
}
}


#ifdef _SCL
#ifdef _SCL
#pragma scl_test_flist(“testfunc”, tfsuite_setName)
#pragma scl_test_flist("testfunc", tfsuite_getParam)
#endif
#endif
</source>
</source>


==== srTestSuiteSetDescription ====
 
The srTestSuiteSetDescription() routine is used to set the description of the specified test suite.
== srTestGetParamDouble ==
The srTestGetParamDouble() function is used to get the value of a named parameter as a double.
<source lang=c>
<source lang=c>
srWORD srTestSuiteSetDescription(srTestSuiteHandle_t tTestSuite, const srCHAR * szDescr)
double srTestGetParamDouble(const srCHAR * szName, double dbDefValue);
</source>
</source>


{| border="1" cellspacing="0" cellpadding="10" style="align:left;"   
{| border="1" cellspacing="0" cellpadding="10" style="align:left;"   
Line 126: Line 138:
| '''Description'''
| '''Description'''
|-
|-
| tTestSuite
| szName
| Input
| Input
| Handle to a test suite. srTEST_SUITE_DEFAULT can be used for the default test suite.
| Pointer to a null-terminated string that represents the name of the parameter.
|-
|-
| szDescr
| dbDefValue
| Input  
| Input  
| Pointer to a null-terminated string representing the description of test suite. Cannot be null.
| Default value that is returned if the parameter is not found.
|}
|}
<br>
<br>
Line 139: Line 151:
| ''' Description'''
| ''' Description'''
|-
|-
| srOK
| double
| Success
| Parameter value, or value specified by <i>dbDefValue</i> if parameter isn't found.
|-
| srERR
| Null string passed in.
|-
| srTEST_ERR_HANDLE_INVALID
| Invalid handle passed in.
|-
| srTEST_WARN_STR_TRUNCATED
| String passed in was too large and was truncated.
|}
|}


<source lang=c>
<source lang=c>
#include <srtest.h>
#include <srtest.h>
void tfsuite_setDescription(void)
 
void tfsuite_getParam(void)
{
{
   srTestSuiteSetDescription(srTEST_SUITE_DEFAULT,
   double dbVal = srTestGetParamDouble("ParamName", 0.5772156649);
                            "Setting description for default suite");
}
}


#ifdef _SCL
#ifdef _SCL
#pragma scl_test_flist(“testfunc”, tfsuite_setDescription)
#pragma scl_test_flist("testfunc", tfsuite_getParam)
#endif
#endif
</source>
</source>


==== srTestSuiteAddCase ====
 
== srTestSuiteAddCase ==
The srTestSuiteAddCase() routine is used to add a new test case to the specified test suite.
The srTestSuiteAddCase() routine is used to add a new test case to the specified test suite.
<source lang=c>
<source lang=c>
srTestCaseHandle_t srTestSuiteAddCase(srTestSuiteHandle_t tParent, const srCHAR * szName)
srTestCaseHandle_t srTestSuiteAddCase(const srCHAR * szName, const srCHAR * szDescr)
</source>
</source>


{| border="1" cellspacing="0" cellpadding="10" style="align:left;"   
{| border="1" cellspacing="0" cellpadding="10" style="align:left;"   
Line 175: Line 181:
| '''Type'''
| '''Type'''
| '''Description'''
| '''Description'''
|-
| tParent
| Input
| Handle to the parent test suite to which new test case is to be added. srTEST_SUITE_DEFAULT can be used for the default test suite.
|-
|-
| szName  
| szName  
| Input  
| Input  
| Pointer to a null-terminated string that represents the name of test case. If null, the default host naming scheme will be used.
| Pointer to a null-terminated string that represents the name of the new test case. If null, the default host naming scheme will be used.
|-
| szDescr
| Input
| Pointer to a null-terminated string representing the description of the new test case. If null, description will be empty.
|}
|}
<br>
<br>
Line 190: Line 196:
|-
|-
| srTestCaseHandle_t  
| srTestCaseHandle_t  
| Handle of the newly created test case. srTEST_CASE_INVALID indicates failure to create test case.
| Handle of the newly created test case. srTEST_CASE_INVALID indicates failure to create a test case.
|}
|}


<source lang=c>
<source lang=c>
#include <srtest.h>
#include <srtest.h>
#include <stdio.h>


void tfsuite_addCase(void)
void tfsuite_addCase(void)
Line 202: Line 210:
     char szName[25];
     char szName[25];
     sprintf(szName, "dynamic test case %d", count);
     sprintf(szName, "dynamic test case %d", count);
     srTestCaseHandle_t test = srTestSuiteAddCase(srTEST_SUITE_DEFAULT, szName);
     srTestCaseHandle_t test = srTestSuiteAddCase(szName, "this is a dynamic test case");
    srTEST_ADD_COMMENT_WITH_LOCATION(test, "this is a dynamic test case");
    srTestCaseSetStatus(test, srTEST_PASS, 0);  
   }
   }
}
}


#ifdef _SCL
#ifdef _SCL
#pragma scl_test_flist(“testfunc”, tfsuite_addCase)
#pragma scl_test_flist("testfunc", tfsuite_addCase)
#endif
#endif
</source>
</source>


==== srTestCaseSetName ====
 
The srTestCaseSetName() routine is used to set set the name of the specified test case.
== srTestSuiteAddAnnotation ==
The srTestSuiteAddAnnotation() routine is used to add a new annotation to the specified test suite.
<source lang=c>
<source lang=c>
srWORD srTestCaseSetName(srTestCaseHandle_t tTestCase, const srCHAR *szName)
srTestAnnotationHandle_t srTestSuiteAddAnnotation(srTestAnnotationLevel_e eLevel,
                                                  const srCHAR * szName,
                                                  const srCHAR * szFmtDescr, ...)
</source>
</source>


{| border="1" cellspacing="0" cellpadding="10" style="align:left;"   
{| border="1" cellspacing="0" cellpadding="10" style="align:left;"   
Line 223: Line 235:
| '''Description'''
| '''Description'''
|-
|-
| tTestCase
| eLevel
| Input
| Input  
| Handle to a test case. srTEST_CASE_DEFAULT can be used for the default test case.
| Annotation level.  
 
* srTEST_ANNOTATION_LEVEL_TRACE,
* srTEST_ANNOTATION_LEVEL_DEBUG,
* srTEST_ANNOTATION_LEVEL_INFO,
* srTEST_ANNOTATION_LEVEL_WARN,
* srTEST_ANNOTATION_LEVEL_ERROR,
* srTEST_ANNOTATION_LEVEL_FATAL
|-
|-
| szName  
| szName  
| Input  
| Input  
| Pointer to a null-terminated string representing the name of test case. Cannot be null.
| Pointer to a null-terminated string representing the name of the new annotation. If null, the default host naming scheme will be used.
|-
| szFmtDescr
| Input
| Pointer to a null-terminated string representing the description of the new annotation. Cannot be null.
|-
| ...
| Input (Optional)
| Variable argument list to format szFmtDescr.
|}
|}
<br>
<br>
Line 236: Line 263:
| ''' Description'''
| ''' Description'''
|-
|-
| srOK
| srTestAnnotationHandle_t
| Success
| Handle of the newly created test annotation. srTEST_ANNOTATION_INVALID indicates failure to create a test annotation.
|-
| srERR
| Null string passed in.
|-
| srTEST_ERR_HANDLE_INVALID
| Invalid handle passed in.
|-
| srTEST_WARN_STR_TRUNCATED
| String passed in was too large and was truncated.
|}
|}


<source lang=c>
<source lang=c>
#include <srtest.h>
#include <srtest.h>


void tfcase_setName(void)
void tfsuite_addAnnotation(void)  
{
{
   srTestCaseSetName(srTEST_CASE_DEFAULT, "Setting name for default case");
   for (int count = 0; count < 5; ++count)
  {
    char szName[25];
    sprintf(szName, "annotation %d", count);
    srTestAnnotationHandle_t annot =
                    srTestSuiteAddAnnotation(srTEST_ANNOTATION_LEVEL_ERROR,
                                              szName,
                                              "description of annotation");
  }
}
}


#ifdef _SCL
#ifdef _SCL
#pragma scl_test_flist(“testfunc”, tfcase_setName)
#pragma scl_test_flist("testfunc", tfsuite_addAnnotation)
#endif
#endif
</source>
</source>


==== srTestCaseSetDescription ====
 
The srTestCaseSetDescription() routine is used to set the description of the specified test case.
== srTestSuiteSetData ==
The srTestSuiteSetData() routine is used to associate a custom name|value pair with a test suite.
<source lang=c>
<source lang=c>
srWORD srTestCaseSetDescription(srTestCaseHandle_t tTestCase, const srCHAR * szDescr)
srWORD srTestSuiteSetData(const srCHAR * szName, const srCHAR * szFmtValue, ...)
</source>
</source>


{| border="1" cellspacing="0" cellpadding="10" style="align:left;"   
{| border="1" cellspacing="0" cellpadding="10" style="align:left;"   
Line 273: Line 302:
| '''Description'''
| '''Description'''
|-
|-
| tTestCase
| szName
| Input
| Input
| Handle to a test case. srTEST_CASE_DEFAULT can be used for the default test case.
| Pointer to a null-terminated string representing the name of the custom pair. Cannot be null.
|-
|-
| szDescr
| szFmtValue
| Input  
| Input  
| Pointer to a null-terminated string representing the description of test case. Cannot be null.
| Pointer to a null-terminated string representing the value of the custom pair. Cannot be null.
|-
| ...
| Input (Optional)
| Variable argument list to format szFmtValue.
|}
|}
<br>
<br>
Line 286: Line 319:
| ''' Description'''
| ''' Description'''
|-
|-
| srOK
| srWORD
| Success
| srOK on success, srERR_HANDLE_INVALID on invalid handle.
|-
| srERR
| Null string passed in.
|-
| srTEST_ERR_HANDLE_INVALID
| Invalid handle passed in.
|-
| srTEST_WARN_STR_TRUNCATED
| String passed in was too large and was truncated.
|}
|}


<source lang=c>
<source lang=c>
#include <srtest.h>
#include <srtest.h>


void tfcase_setDescription(void)
void tfcase_setData(void)
{
{
   srTestCaseSetDescription(srTEST_CASE_DEFAULT,
   srTestSuiteSetData("MyName", "my value");
                          "Setting description for default case");
}
}


#ifdef _SCL
#ifdef _SCL
#pragma scl_test_flist(“testfunc”, tfcase_setDescription)
#pragma scl_test_flist("testfunc", tfcase_setData)
#endif
#endif
</source>
</source>


==== srTestCaseAddComment ====
 
The srTestCaseAddComment() routine is used to add a comment (aka a log) to be reported with the specified test case.
== srTestCaseSetStatus ==
The srTestCaseSetStatus() routine is used to set the result of test case.
<source lang=c>
<source lang=c>
srWORD srTestCaseAddComment(srTestCaseHandle_t tTestCase, const srCHAR * szLabel, const srCHAR * szFmtComment, ...)
srWORD srTestCaseSetStatus(srTestCaseHandle_t tTestCase, srTestStatus_e eStatus, srDWORD dwDuration)
</source>
</source>


{| border="1" cellspacing="0" cellpadding="10" style="align:left;"   
{| border="1" cellspacing="0" cellpadding="10" style="align:left;"   
Line 328: Line 354:
| Handle to a test case. srTEST_CASE_DEFAULT can be used for the default test case.
| Handle to a test case. srTEST_CASE_DEFAULT can be used for the default test case.
|-
|-
| szLabel
| eStatus
| Input
| Input  
| Pointer to a null-terminated string specifying the comment's label.
| Result of the test. Possible values are:
* '''srTEST_FAIL'''
* '''srTEST_PASS'''
* '''srTEST_NOTINUSE'''
* '''srTEST_INPROGRESS'''
* '''srTEST_DONE''' - applicable to dynamic cases - sets the status to '''pass''' unless already set to '''fail''' or '''not-in-use'''
|-
|-
| szFmtComment
| dwDuration
| Input  
| Input  
| Pointer to a null-terminated string, which can be formatted, representing the comment. Cannot be null.
| The duration of the test in clock ticks. Using "0" allows the Stride Runtime (Intercept Module) to set the time automatically.
|-
| ...
| Input (Optional)
| Variable argument list to format the comment szFmtComment.
|}
|}
<br>
<br>
Line 345: Line 372:
| ''' Description'''
| ''' Description'''
|-
|-
| srOK
| srWORD
| Success
| srOK on success, srERR_HANDLE_INVALID on invalid handle.
|-
| srERR
| Null string passed in.
|-
| srTEST_ERR_HANDLE_INVALID
| Invalid handle passed in.
|-
| srTEST_WARN_STR_TRUNCATED
| String passed in was too large and was truncated.
|}
|}


<source lang=c>
<source lang=c>
#include <srtest.h>
#include <srtest.h>


void tfcase_addComment(void)
void tfcase_setStatus(void)
{
{
   srTestCaseAddComment(srTEST_CASE_DEFAULT, "Note",
   srTestCaseSetStatus(srTEST_CASE_DEFAULT, srTEST_PASS, 0);
                      "this comment should print %s", "A STRING");
}
}


#ifdef _SCL
#ifdef _SCL
#pragma scl_test_flist(“testfunc”, tfcase_addComment)
#pragma scl_test_flist("testfunc", tfcase_setStatus)
#endif
#endif
</source>
</source>


==== srTestCaseSetStatus ====
 
The srTestCaseSetStatus() routine is used to set the result of test case.
== srTestCaseSetStatusEx ==
The srTestCaseSetStatusEx() routine is used to set the result of test case and allow specification of an extendedFailureCode.
<source lang=c>
<source lang=c>
srWORD srTestCaseSetStatus(srTestCaseHandle_t tTestCase, srTestStatus_e eStatus, srDWORD dwDuration)
srWORD srTestCaseSetStatus(srTestCaseHandle_t tTestCase, srTestStatus_e eStatus, srDWORD dwDuration, srLONG lExtendedFailureCode)
</source>
</source>


{| border="1" cellspacing="0" cellpadding="10" style="align:left;"   
{| border="1" cellspacing="0" cellpadding="10" style="align:left;"   
Line 393: Line 413:
| dwDuration  
| dwDuration  
| Input  
| Input  
| The duration of the test in clock ticks. Using “0” allows the STRIDE Runtime (Intercept Module) to set the time automatically.
| The duration of the test in clock ticks. Using "0" allows the Stride Runtime (Intercept Module) to set the time automatically.
|-
| lExtendedFailureCode
| Input
| The Stride framework uses the extendedFailureCode to capture the numeric results of test method when the test method fails via a numeric (non-void, nonbool) return type.
|}
|}
<br>
<br>
Line 400: Line 424:
| ''' Description'''
| ''' Description'''
|-
|-
| srOK
| srWORD
| Success
| srOK on success, srERR_HANDLE_INVALID on invalid handle.
|-
| srTEST_ERR_HANDLE_INVALID
| Invalid handle passed in.
|}
|}


<source lang=c>
<source lang=c>
#include <srtest.h>
#include <srtest.h>


void tfcase_setStatus(void)
void tfcase_setStatusEx(void)
{
{
   srTestCaseSetStatus(srTEST_CASE_DEFAULT, srTEST_PASS, 0);
   srTestCaseSetStatusEx(srTEST_CASE_DEFAULT, srTEST_FAIL, 0, -5);
}
}


#ifdef _SCL
#ifdef _SCL
#pragma scl_test_flist(“testfunc”, tfcase_setStatus)
#pragma scl_test_flist("testfunc", tfcase_setStatusEx)
#endif
#endif
</source>
</source>


==== srTestCaseSetStatusEx ====
 
The srTestCaseSetStatusEx() routine is used to set the result of test case and allow specification of an extendedFailureCode.
== srTestCaseAddAnnotation ==
The srTestCaseAddAnnotation() routine is used to add a new annotation to the specified test case.
<source lang=c>
<source lang=c>
srWORD srTestCaseSetStatus(srTestCaseHandle_t tTestCase, srTestStatus_e eStatus, srDWORD dwDuration, srLONG lExtendedFailureCode)
srTestAnnotationHandle_t srTestCaseAddAnnotation(rTestCaseHandle_t tTestCase, srTestAnnotationLevel_e eLevel, const srCHAR * szName, const srCHAR * szFmtDescr, ...)
</source>
</source>


{| border="1" cellspacing="0" cellpadding="10" style="align:left;"   
{| border="1" cellspacing="0" cellpadding="10" style="align:left;"   
Line 433: Line 457:
| tTestCase  
| tTestCase  
| Input
| Input
| Handle to a test case. srTEST_CASE_DEFAULT can be used for the default test case.
| Handle to the parent test case to which new test annotation is to be added. srTEST_CASE_DEFAULT can be used for the default test case.
|-
| eLevel
| Input
| Annotation level.
 
* srTEST_ANNOTATION_LEVEL_TRACE,
* srTEST_ANNOTATION_LEVEL_DEBUG,
* srTEST_ANNOTATION_LEVEL_INFO,
* srTEST_ANNOTATION_LEVEL_WARN,
* srTEST_ANNOTATION_LEVEL_ERROR,
* srTEST_ANNOTATION_LEVEL_FATAL
|-
|-
| eStatus
| szName
| Input  
| Input  
| Result of the test. dwDuration Input The duration of the test in clock ticks. Using “0” allows the STRIDE Runtime (Intercept Module) to set the time automatically.
| Pointer to a null-terminated string representing the name of the new annotation. If null, the default host naming scheme will be used.
|-
|-
| lExtendedFailureCode
| szFmtDescr
| Input  
| Input  
| The Stride framework uses the extendedFailureCode to capture the numeric results of test method when the test method fails via a numeric (non-void, nonbool) return type.
| Pointer to a null-terminated string representing the description of the new annotation. Cannot be null.
|-
| ...
| Input (Optional)
| Variable argument list to format szFmtDescr.
|}
|}
<br>
<br>
Line 448: Line 487:
| ''' Description'''
| ''' Description'''
|-
|-
| srOK
| srTestAnnotationHandle_t
| Success
| Handle of the newly created test annotation. srTEST_ANNOTATION_INVALID indicates failure to create a test annotation.
|-
| srTEST_ERR_HANDLE_INVALID
| Invalid handle passed in.
|}
|}


<source lang=c>
<source lang=c>
#include <srtest.h>
#include <srtest.h>


void tfcase_setStatusEx(void)
void tfcase_addAnnotation(void)  
{
{
   srTestCaseSetStatusEx(srTEST_CASE_DEFAULT, srTEST_FAIL, 0, -5);
   for (int count = 0; count < 5; ++count)
  {
    char szName[25];
    sprintf(szName, "annotation %d", count);
    srTestAnnotationHandle_t annot =
                    srTestCaseAddAnnotation(srTEST_CASE_DEFAULT,
                                            srTEST_ANNOTATION_LEVEL_ERROR,
                                            szName,
                                            "description of annotation");
  }
}
}


#ifdef _SCL
#ifdef _SCL
#pragma scl_test_flist(“testfunc”, tfcase_setStatusEx)
#pragma scl_test_flist("testfunc", tfcase_addAnnotation)
#endif
#endif
</source>
</source>


==== srTestSuiteAddAnnotation ====
 
The srTestSuiteAddAnnotation() routine is used to add a new annotation to the specified test suite.
== srTestCaseSetData ==
The srTestCaseSetData() routine is used to associate a custom name|value pair with a test case.
<source lang=c>
<source lang=c>
srTestAnnotationHandle_t srTestSuiteAddAnnotation(rTestSuiteHandle_t tParent, srTestAnnotationLevel_e eLevel, const srCHAR * szName, const srCHAR * szDescr)
srWORD srTestCaseSetData(srTestCaseHandle_t tTestCase, const srCHAR * szName, const srCHAR * szFmtValue, ...);
</source>
</source>


{| border="1" cellspacing="0" cellpadding="10" style="align:left;"   
{| border="1" cellspacing="0" cellpadding="10" style="align:left;"   
Line 479: Line 527:
| '''Description'''
| '''Description'''
|-
|-
| tParent
| tTestCase
| Input
| Input
| Handle to the parent test suite to which new annotation is to be added. srTEST_SUITE_DEFAULT can be used for the default test suite.
| Handle to a test case. srTEST_CASE_DEFAULT can be used for the default test case.
|-
|-
| eLevel
| szName
| Input  
| Input
| Annotation level. Cannot be empty.
| Pointer to a null-terminated string representing the name of the custom pair. Cannot be null.
|-
|-
| szName
| szFmtValue
| Input  
| Input  
| Pointer to a null-terminated string that represents the name of annotation. If null, the default host naming scheme will be used.
| Pointer to a null-terminated string representing the value of the custom pair. Cannot be null.
|-
|-
| szDescr
| ...
| Input  
| Input (Optional)
| Pointer to a null-terminated string representing the description of annotation. If null, description will be empty.
| Variable argument list to format szFmtValue.
|}
|}
<br>
<br>
Line 500: Line 548:
| ''' Description'''
| ''' Description'''
|-
|-
| srTestAnnotationHandle_t
| srWORD
| HHandle of the newly created annotation. srTEST_ANNOTATION_INVALID indicates failure to create annotation.
| srOK on success, srERR_HANDLE_INVALID on invalid handle.
|}
|}


<source lang=c>
<source lang=c>
#include <srtest.h>
#include <srtest.h>


void tfsuite_addAnnotation(void)  
void tfcase_setData(void)
{
{
   for (int count = 0; count < 5; ++count)
   srTestCaseSetData(srTEST_CASE_DEFAULT, "MyName", "my value");
  {
    char szName[25];
    sprintf(szName, "annotation %d", count);
    srTestAnnotationHandle_t annot =
                    srTestSuiteAddAnnotation(srTEST_SUITE_DEFAULT,
                                              srTEST_ANNOTATION_LEVEL_ERROR,
                                              szName,
                                              "description of annotation");
  }
}
}


#ifdef _SCL
#ifdef _SCL
#pragma scl_test_flist(“testfunc”, tfsuite_addAnnotation)
#pragma scl_test_flist("testfunc", tfcase_setData)
#endif
#endif
</source>
</source>


==== srTestAnnotationAddComment ====
 
The srTestAnnotationAddComment() routine is used to add a comment (aka a log) to be reported with the specified annotation.
== srTestAnnotationAddComment ==
The srTestAnnotationAddComment() routine is used to add a comment (aka a log) to a test annotation.
<source lang=c>
<source lang=c>
srWORD srTestAnnotationAddComment(srTestAnnotationHandle_t tTestAnnotation, const srCHAR * szLabel, const srCHAR * szFmtComment, ...)
srWORD srTestAnnotationAddComment(srTestAnnotationHandle_t tTestAnnotation, const srCHAR * szLabel, const srCHAR * szFmtComment, ...)
</source>
</source>


{| border="1" cellspacing="0" cellpadding="10" style="align:left;"   
{| border="1" cellspacing="0" cellpadding="10" style="align:left;"   
Line 539: Line 581:
| tTestAnnotation
| tTestAnnotation
| Input
| Input
| Handle to an annotation created using srTestSuiteAddAnnotation.
| Handle to a test annotation.
|-
|-
| szLabel
| szLabel
Line 547: Line 589:
| szFmtComment  
| szFmtComment  
| Input  
| Input  
| Pointer to a null-terminated string, which can be formatted, representing the comment. Cannot be null.
| Pointer to a null-terminated string representing the new comment. Cannot be null.
|-
|-
| ...  
| ...  
| Input (Optional)
| Input (Optional)
| Variable argument list to format the comment szFmtComment.
| Variable argument list to format szFmtComment.
|}
|}
<br>
<br>
Line 558: Line 600:
| ''' Description'''
| ''' Description'''
|-
|-
| srOK
| srWORD
| Success
| srOK on success, srERR on null string or invalid formatted string, srERR_HANDLE_INVALID on invalid handle, srERR_STR_TRUNCATED on truncated string.
|-
| srERR  
| Null string passed in.
|-
| srTEST_ERR_HANDLE_INVALID
| Invalid handle passed in.
|-
| srTEST_WARN_STR_TRUNCATED
| String passed in was too large and was truncated.
|}
|}


<source lang=c>
<source lang=c>
Line 577: Line 611:
{
{
   srTestAnnotationHandle_t annot =  
   srTestAnnotationHandle_t annot =  
                           srTestSuiteAddAnnotation(srTEST_SUITE_DEFAULT,
                           srTestSuiteAddAnnotation(srTEST_ANNOTATION_LEVEL_ERROR,
                                                    srTEST_ANNOTATION_LEVEL_ERROR,
                                                     "annot",
                                                     “annot”,
                                                     "annot description");
                                                     “annot description”);
   srTestAnnotationAddComment(annot,
   srTestAnnotationAddComment(annot,
                             srNULL,
                             srNULL,
Line 587: Line 620:


#ifdef _SCL
#ifdef _SCL
#pragma scl_test_flist(“testfunc”, tfsuiteAnnotation_addComment)
#pragma scl_test_flist("testfunc", tfsuiteAnnotation_addComment)
#endif
#endif
</source>
</source>


=== C++ Test Classes ===
 
= C++ Test Classes =
The Runtime Test Services C APIs work equally well from C test functions and C++ test classes. If, however, you are using C++ it might be more convinient for you to derive your C++ test classes from the Runtime Test Services C++ base class, ''srTest''. That way you will have access to a set of simpler to use C++ classes.  
The Runtime Test Services C APIs work equally well from C test functions and C++ test classes. If, however, you are using C++ it might be more convinient for you to derive your C++ test classes from the Runtime Test Services C++ base class, ''srTest''. That way you will have access to a set of simpler to use C++ classes.  


The following C++ classes are provided:  
The following C++ classes are provided:  
* '''[[#class srTest|class srTest]]''' - base test class
* '''[[#class srTest|class srTest]]''' - base test class
* '''[[#class srTestSuite|class srTestSuite]]''' - represents a test suite
* '''[[#class srTestCase|class srTestCase]]''' - represents a test case
* '''[[#class srTestCase|class srTestCase]]''' - represents a test case
* '''[[#class srTestAnnotation|class srTestAnnotation]]''' - represents a test annotation
* '''[[#class srTestAnnotation|class srTestAnnotation]]''' - represents a test annotation


==== class srTest ====
The srTest class provides two Member Objects:
*''testSuite'' of class srTestSuite
*''testCase''of class srTestCase


==== class srTestSuite ====
== class srTest ==
The srTest class provides the folowing methods:
The srTest class provides one member object ''testCase'' of [[#class srTestCase|class srTestCase]] and the folowing methods:


===== method AddSuite =====
 
The AddSuite method is used to add a new test suite.
=== method GetParam ===
This overload of the GetParam() method is used to get the value of a named parameter as a string.
<source lang=cpp>
<source lang=cpp>
srTestSuite AddSuite(const srCHAR * szName = srNULL)
static srWORD GetParam(const srCHAR * name, srCHAR * value, srDWORD size, const srCHAR * defval = srNULL)
</source>
</source>


{| border="1" cellspacing="0" cellpadding="10" style="align:left;"   
{| border="1" cellspacing="0" cellpadding="10" style="align:left;"   
Line 618: Line 649:
| '''Type'''
| '''Type'''
| '''Description'''
| '''Description'''
|-  
|-
|szName
| name
| Input (Optional)
| Input
| Pointer to null-terminated string that represents the name of test suite. If empty, the default host naming scheme will be used.
| Pointer to a null-terminated string that represents the name of the parameter. Cannot be null.
|-
| value
| Output
| Pointer to a block of memory to store the value of the parameter with a maximum size of <i>size</i> chars
|-
| size
| Input
| Size in chars of the buffer pointed to by <i>value</i>
|-
| defvalue
| Input (optional)  
| Pointer to a null-terminated string that represents a default value in case the parameter is not specified. By setting this value to srNULL (or omitting it), you can use <i>GetParam()</i> to test for the existence of a named parameter. If the named parameter doesn't exist, the function will return <i>srERR_HANDLE_INVALID</i>.
|}
|}
<br>
<br>
Line 628: Line 671:
| ''' Description'''
| ''' Description'''
|-
|-
| srTestSuite
| srWORD
| Newly created test suite class.
| srOK on success, error otherwise.
|}
|}


<source lang=cpp>
<source lang=cpp>
Line 638: Line 682:
{
{
public:
public:
   void suiteAddSuite()
   void getParam()
   {
   {
     stride::srTestSuite suite = testSuite.AddSuite("tc Sub Suite");
     GetParam("ParamName", szValue, MAX_VALUE_LEN, "default value");
   }
   }
};
};
Line 649: Line 693:
</source>
</source>


===== method SetName =====
 
The SetName method is used to set the name of test suite.
=== method GetParam ===
This overload of the GetParam() method is used to get the value of a named parameter as a long.
<source lang=cpp>
<source lang=cpp>
srWORD SetName(const srCHAR * szName)
static long GetParam(const srCHAR * name, srLONG defval = 0)
</source>
</source>


{| border="1" cellspacing="0" cellpadding="10" style="align:left;"   
{| border="1" cellspacing="0" cellpadding="10" style="align:left;"   
Line 659: Line 705:
| '''Type'''
| '''Type'''
| '''Description'''
| '''Description'''
|-  
|-
| szName
| name
| Input
| Pointer to a null-terminated string that represents the name of the parameter.
|-
| defvalue
| Input  
| Input  
| Pointer to null-terminated string representing the name of test suite. Cannot be empty.
| Default value that is returned if the parameter is not found.
|}
|}
<br>
<br>
Line 669: Line 719:
| ''' Description'''
| ''' Description'''
|-
|-
| srOK
| srLONG
| Success
| Parameter value, or value specified by <i>defvalue</i> if parameter isn't found.
|-
| srERR
| Null string passed in.
|-
| srTEST_ERR_HANDLE_INVALID
| Invalid handle passed in.
|-
| srTEST_WARN_STR_TRUNCATED
| String passed in was too large and was truncated.
|}
|}


<source lang=cpp>
<source lang=cpp>
Line 688: Line 730:
{
{
public:
public:
   void suiteSetName()
   void getParam()
   {
   {
     testSuite.SetName("Setting name for suite");
     srLONG lValue = GetParam("ParamName", -1);
   }
   }
};
};
Line 696: Line 738:
#ifdef _SCL
#ifdef _SCL
#pragma scl_test_class(srtest_class)
#pragma scl_test_class(srtest_class)
#endif
#endif</source>
</source>
 


===== method SetDescription =====
=== method GetParam ===
The SetDescription method is used to set the description of test suite.
This overload of the GetParam() method is used to get the value of a named parameter as a double.
<source lang=cpp>
<source lang=cpp>
srWORD SetDescription(const srCHAR * szDescr)
static double GetParam(const srCHAR * name, const double& defval)
</source>
</source>


{| border="1" cellspacing="0" cellpadding="10" style="align:left;"   
{| border="1" cellspacing="0" cellpadding="10" style="align:left;"   
Line 709: Line 752:
| '''Type'''
| '''Type'''
| '''Description'''
| '''Description'''
|-  
|-
| szDescr
| name
| Input
| Pointer to a null-terminated string that represents the name of the parameter.
|-
| defvalue
| Input  
| Input  
| Pointer to null-terminated string representing the description of test suite. Cannot be empty.
| Default value that is returned if the parameter is not found.
|}
|}
<br>
<br>
Line 719: Line 766:
| ''' Description'''
| ''' Description'''
|-
|-
| srOK
| double
| Success
| Parameter value, or value specified by <i>defvalue</i> if parameter isn't found.
|-
| srERR
| Null string passed in.
|-
| srTEST_ERR_HANDLE_INVALID
| Invalid handle passed in.
|-
| srTEST_WARN_STR_TRUNCATED
| String passed in was too large and was truncated.
|}
|}


<source lang=cpp>
<source lang=cpp>
Line 738: Line 777:
{
{
public:
public:
   void suiteSetDescription()
   void getParam()
   {
   {
     testSuite.SetDescription("Setting description for suite");
     double dbVal = GetParam("ParamName",  0.5772156649);
   }
   }
};
};
Line 746: Line 785:
#ifdef _SCL
#ifdef _SCL
#pragma scl_test_class(srtest_class)
#pragma scl_test_class(srtest_class)
#endif
#endif</source>
</source>
 


===== method AddCase =====
=== method AddCase ===
The AddCase method is used to add a new test case to test suite.
The AddCase method is used to add a new test case to the test suite.
<source lang=cpp>
<source lang=cpp>
srTestCase AddCase(const srCHAR * szName = srNULL)
srTestCase AddCase(const srCHAR * name, const srCHAR * descr = srNULL)
</source>
</source>


{| border="1" cellspacing="0" cellpadding="10" style="align:left;"   
{| border="1" cellspacing="0" cellpadding="10" style="align:left;"   
Line 760: Line 800:
| '''Description'''
| '''Description'''
|-  
|-  
| szName
| name
| Input
| Pointer to null-terminated string that represents the name of the new test case. If empty, the default host naming scheme will be used.
|-
| descr
| Input (Optional)
| Input (Optional)
| Pointer to null-terminated string that represents the name of test case. If empty, the default host naming scheme will be used.
| Pointer to null-terminated string representing the description of the new test case. If empty, description will be blank.
|}
|}
<br>
<br>
Line 770: Line 814:
|-
|-
| srTestCase  
| srTestCase  
| Newly created test case class.
| Newly created test case instance.
|}
|}
<br>
<br>
Line 788: Line 832:
       std::stringstream strm;
       std::stringstream strm;
       strm << prefix << count;
       strm << prefix << count;
       stride::srTestCase tc = testSuite.AddCase(strm.str().c_str());
       stride::srTestCase tc = AddCase(strm.str().c_str());
      tc.AddComment("this is a dynamic test case");
       tc.SetStatus(srTEST_PASS);
       tc.SetStatus(srTEST_PASS);
     }
     }
Line 800: Line 843:
</source>
</source>


===== method AddAnnotation =====
 
The AddAnnotation method is used to add a new annotation to test suite.
=== method AddAnnotation ===
The AddAnnotation method is used to add a new test annotation to the test suite.
<source lang=cpp>
<source lang=cpp>
srTestAnnoation AddAnnotation(srTestAnnotationLevel_e eLevel, const srCHAR * szName = srNULL, const srCHAR * szDescr = srNULL)
srTestAnnotation AddAnnotation(srTestAnnotationLevel_e level, const srCHAR * name, const srCHAR * descr, ...)
</source>
</source>


{| border="1" cellspacing="0" cellpadding="10" style="align:left;"   
{| border="1" cellspacing="0" cellpadding="10" style="align:left;"   
Line 811: Line 856:
| '''Description'''
| '''Description'''
|-  
|-  
| eLevel
| level
| Input
| Input
| Annotation level. Cannot be empty.
| Annotation level.  
 
* srTEST_ANNOTATION_LEVEL_TRACE,
* srTEST_ANNOTATION_LEVEL_DEBUG,
* srTEST_ANNOTATION_LEVEL_INFO,
* srTEST_ANNOTATION_LEVEL_WARN,
* srTEST_ANNOTATION_LEVEL_ERROR,
* srTEST_ANNOTATION_LEVEL_FATAL
|-  
|-  
| szName
| name
| Input (Optional)
| Input  
| Pointer to null-terminated string that represents the name of annotation. If empty, the default host naming scheme will be used.
| Pointer to null-terminated string that represents the name of the new annotation. If empty, the default host naming scheme will be used.
|-  
|-  
| szDescr
| descr
| Input (Optional)
| Input  
| Pointer to null-terminated string that represents the description of annotation. If empty, the description will be blank.
| Pointer to null-terminated string representing the description of the new annotation. Cannot be null.
|}
|}
<br>
<br>
Line 829: Line 881:
|-
|-
| srTestAnnotation
| srTestAnnotation
| Newly created annotation class.
| Newly created annotation instance.
|}
|}


<source lang=cpp>
<source lang=cpp>
Line 847: Line 900:
       strmName << "annotation " << count;
       strmName << "annotation " << count;
       strmDescr << "description of annotation " << count;
       strmDescr << "description of annotation " << count;
       stride::srTestAnnotation ta =  
       stride::srTestAnnotation ta = AddAnnotation(srTEST_ANNOTATION_LEVEL_INFO,
                testSuite.AddAnnotation(srTEST_ANNOTATION_LEVEL_INFO,
                                                  strmName.str().c_str(),
                                        strmName.str().c_str(),
                                                  strmDescr.str().c_str());
                                        strmDescr.str().c_str());
     }
     }
   }
   }
Line 860: Line 912:
</source>
</source>


==== class srTestCase ====
The srTestCase class provides the following methods:


===== method SetName =====
=== method SetData ===
The SetName method is used to set the name of test case.
The SetData method is used to associate a custom name|value pair with the test suite.
<source lang=cpp>
<source lang=cpp>
srWORD SetName(const srCHAR * szName)
srWORD SetData(const srCHAR * name, const srCHAR * value, ...)
</source>
</source>


{| border="1" cellspacing="0" cellpadding="10" style="align:left;"   
{| border="1" cellspacing="0" cellpadding="10" style="align:left;"   
Line 874: Line 925:
| '''Description'''
| '''Description'''
|-  
|-  
| szName
| name
| Input  
| Input
| Pointer to null-terminated string representing the name of test case. Cannot be empty.
| Pointer to a null-terminated string representing the name of the custom pair. Cannot be null.
|-
| value
| Input
| Pointer to a null-terminated string representing the value of the custom pair. Cannot be null.
|}
|}
<br>
<br>
Line 883: Line 938:
| ''' Description'''
| ''' Description'''
|-
|-
| srOK
| srWORD
| Success
| srOK on success, srERR_HANDLE_INVALID on invalid handle.
|-
| srERR
| Null string passed in.
|-
| srTEST_ERR_HANDLE_INVALID
| Invalid handle passed in.
|-
| srTEST_WARN_STR_TRUNCATED
| String passed in was too large and was truncated.
|}
|}
 
<br>
'''Example'''
<source lang=cpp>
<source lang=cpp>
#include <srtest.h>
#include <srtest.h>
#include <sstream>


class srtest_class : public stride::srTest
class srtest_class : public stride::srTest
{
{
public:
public:
   void caseSetName()
   void suiteSetData()
   {
   {
    testCase.SetName("Setting name for case");
      SetData("MyName", "my value");
   }
   }
};
};
Line 913: Line 961:
</source>
</source>


===== method SetDescription =====
 
The SetDescription method is used to set the description of test case.
== class srTestCase ==
The srTestCase class provides the following methods:
 
=== method SetStatus ===
The SetStatus method is used to set the result of the default test case.
<source lang=cpp>
<source lang=cpp>
srWORD SetDescription(const srCHAR * szDescr)
srWORD SetStatus(srTestStatus_e status, srDWORD duration = 0)
</source>
</source>


{| border="1" cellspacing="0" cellpadding="10" style="align:left;"   
{| border="1" cellspacing="0" cellpadding="10" style="align:left;"   
Line 924: Line 977:
| '''Description'''
| '''Description'''
|-  
|-  
| szDescr
| status
| Input  
| Input  
| Pointer to null-terminated string representing the description of test case. Cannot be empty.
| Result of the test. Possible values are:
* '''srTEST_FAIL'''
* '''srTEST_PASS'''
* '''srTEST_NOTINUSE'''
* '''srTEST_INPROGRESS'''
* '''srTEST_DONE''' - applicable to dynamic cases - sets the status to '''pass''' unless already set to '''fail''' or '''not-in-use'''
|-
| duration
| Input (Optional)
| The duration of the test in clock ticks. The default is 0.
|}
|}
<br>
<br>
Line 933: Line 995:
| ''' Description'''
| ''' Description'''
|-
|-
| srOK
| srWORD
| Success
| srOK on success, srERR_HANDLE_INVALID on invalid handle.
|-
| srERR
| Null string passed in.
|-
| srTEST_ERR_HANDLE_INVALID
| Invalid handle passed in.
|-
| srTEST_WARN_STR_TRUNCATED
| String passed in was too large and was truncated.
|}
|}


<source lang=cpp>
<source lang=cpp>
Line 952: Line 1,006:
{
{
public:
public:
   void caseSetDescription()
   void caseSetStatus()
   {
   {
     testCase.SetDescription("Setting description for case");
     testCase.SetStatus(srTEST_NOTINUSE);
   }
   }
};
};
Line 963: Line 1,017:
</source>
</source>


===== method AddComment =====
 
The AddComment method is used to add a comment to test case.
=== method AddAnnotation ===
The AddAnnotation method is used to add a new test annotation to the test case.
<source lang=cpp>
<source lang=cpp>
srWORD AddComment(const srCHAR * szFmtComment, ...)
srTestAnnotation AddAnnotation(srTestAnnotationLevel_e level, const srCHAR * name, const srCHAR * descr, ...)
</source>
</source>


{| border="1" cellspacing="0" cellpadding="10" style="align:left;"   
{| border="1" cellspacing="0" cellpadding="10" style="align:left;"   
Line 974: Line 1,030:
| '''Description'''
| '''Description'''
|-  
|-  
| szFmtComment
| level
| Input  
| Input
| Pointer to null-terminated string, which can be formatted, representing the comment. Cannot be empty.
| Annotation level.
|-
 
| ...
* srTEST_ANNOTATION_LEVEL_TRACE,
| Input (Optional)
* srTEST_ANNOTATION_LEVEL_DEBUG,
| Variable argument list to format the comment szFmtComment.
* srTEST_ANNOTATION_LEVEL_INFO,
* srTEST_ANNOTATION_LEVEL_WARN,
* srTEST_ANNOTATION_LEVEL_ERROR,
* srTEST_ANNOTATION_LEVEL_FATAL
|-
| name
| Input
| Pointer to null-terminated string that represents the name of the new annotation. If null, the default host naming scheme will be used.
|-  
| descr
| Input
| Pointer to null-terminated string representing the description of the new annotation. Cannot be null.
|}
|}
<br>
<br>
Line 987: Line 1,054:
| ''' Description'''
| ''' Description'''
|-
|-
| srOK
| srTestAnnotation
| Success
| Newly created annotation instance.
|-
| srERR
| Null string passed in.
|-
| srTEST_ERR_HANDLE_INVALID
| Invalid handle passed in.
|-
| srTEST_WARN_STR_TRUNCATED
| String passed in was too large and was truncated.
|}
|}


<source lang=cpp>
<source lang=cpp>
#include <srtest.h>
#include <srtest.h>
#include <sstream>


class srtest_class : public stride::srTest
class srtest_class : public stride::srTest
{
{
public:
public:
   void caseAddComment()
   void caseAddAnnotation()
   {
   {
     testCase.AddComment("this comment should print %s", "A STRING");
     for (int count = 0; count < 5; ++count)
    {
      std::stringstream strmName;
      std::stringstream strmDescr;
      strmName << "annotation " << count;
      strmDescr << "description of annotation " << count;
      stride::srTestAnnotation ta =
                testCase.AddAnnotation(srTEST_ANNOTATION_LEVEL_INFO,
                                        strmName.str().c_str(),
                                        strmDescr.str().c_str());
    }
   }
   }
};
};
Line 1,017: Line 1,087:
</source>
</source>


===== method SetStatus =====
 
The SetStatus method is used to set the result of the default test case.
=== method SetData ===
The SetData method is used to associate a custom name|value pair with the test case.
<source lang=cpp>
<source lang=cpp>
srWORD SetStatus(srTestStatus_e eStatus, srDWORD dwDuration = 0)
srWORD SetData(const srCHAR * name, const srCHAR * value, ...)
</source>
</source>


{| border="1" cellspacing="0" cellpadding="10" style="align:left;"   
{| border="1" cellspacing="0" cellpadding="10" style="align:left;"   
Line 1,028: Line 1,100:
| '''Description'''
| '''Description'''
|-  
|-  
| eStatus
| name
| Input
| Pointer to a null-terminated string representing the name of the custom pair. Cannot be null.
|-
| value
| Input  
| Input  
| Result of the test.
| Pointer to a null-terminated string representing the value of the custom pair. Cannot be null.
|-
| dwDuration
| Input (Optional)
| The duration of the test in clock ticks. The default is 0.
|}
|}
<br>
<br>
Line 1,041: Line 1,113:
| ''' Description'''
| ''' Description'''
|-
|-
| srOK
| srWORD
| Success
| srOK on success, srERR_HANDLE_INVALID on invalid handle.
|-
| srTEST_ERR_HANDLE_INVALID
| Invalid handle.
|}
|}


<source lang=cpp>
<source lang=cpp>
Line 1,054: Line 1,124:
{
{
public:
public:
   void caseSetStatus()
   void caseSetData()
   {
   {
     testCase.SetStatus(srTEST_INPROGRESS, 0);
     testCase.SetData("MyName", "my value");
   }
   }
};
};
Line 1,065: Line 1,135:
</source>
</source>


==== class srTestAnnotation ====
 
== class srTestAnnotation ==
The srTestAnnotation class provides the following methods:
The srTestAnnotation class provides the following methods:


===== method AddComment =====
 
The AddComment method is used to add a comment to an annotation created under a test suite.
=== method AddComment ===
The AddComment method is used to add a comment to the test annotation.
<source lang=cpp>
<source lang=cpp>
srWORD AddComment(const srCHAR * szLabel, const srCHAR * szFmtComment, ...)
srWORD AddComment(const srCHAR * label, const srCHAR * comment, ...)
</source>
</source>


{| border="1" cellspacing="0" cellpadding="10" style="align:left;"   
{| border="1" cellspacing="0" cellpadding="10" style="align:left;"   
Line 1,079: Line 1,152:
| '''Description'''
| '''Description'''
|-  
|-  
| szLabel
| label
| Input  
| Input  
| Pointer to null-terminated string for the label. If null, the default label will be applied.
| Pointer to null-terminated string for the label. If null, the default label will be applied.
|-  
|-  
| szFmtComment
| comment
| Input  
| Input  
| Pointer to null-terminated string, which can be formatted, representing the comment. Cannot be empty.
| Pointer to null-terminated string representing the new comment. Cannot be empty.
|-
| ...
| Input (Optional)
| Variable argument list to format the comment szFmtComment.
|}
|}
<br>
<br>
Line 1,096: Line 1,165:
| ''' Description'''
| ''' Description'''
|-
|-
| srOK
| srWORD
| Success
| srOK on success, srERR on null string or invalid formatted string, srERR_HANDLE_INVALID on invalid handle, srERR_STR_TRUNCATED on truncated string.
|-
| srERR  
| Null string passed in.
|-
| srTEST_ERR_HANDLE_INVALID
| Invalid handle passed in.
|-
| srTEST_WARN_STR_TRUNCATED
| String passed in was too large and was truncated.
|}
|}


<source lang=cpp>
<source lang=cpp>

Latest revision as of 19:54, 7 July 2015

The Runtime Test Services (declared in srtest.h) are a set of APIs in the Stride Runtime that facilitate the writing of target based test code. These APIs make up an optional portion of the Stride Runtime and can be used to communicate additional information about tests to the host based reporting mechanism. These APIs also allow target test code to create additional test suites and test cases dynamically at runtime.

There are two ways of accessing these APIs: through C-based functions, or through a C++ base class from which you may derive your C++ test class. These are discussed below in C Test Functions, and C++ Test Classes sections below.

C Test Functions

The following C APIs are provided:


srTestGetParam

The srTestGetParam() function is used to get the value of a named parameter as a string.

srWORD srTestGetParam(const srCHAR * szName, srCHAR * szValue, srDWORD dwSize, const srCHAR * szDefValue);


Parameters Type Description
szName Input Pointer to a null-terminated string that represents the name of the parameter. Cannot be null.
szValue Output Pointer to a block of memory to store the value of the parameter with a maximum size of dwSize chars
dwSize Input Size in chars of the buffer pointed to by szValue
szDefValue Input (optional) Pointer to a null-terminated string that represents a default value in case the parameter is not specified. By setting this value to srNULL (or omitting it), you can use srTestGetParam() to test for the existence of a named parameter. If the named parameter doesn't exist, the function will return srERR_HANDLE_INVALID.


Return Value Description
srOK Success
srERR Null or empty szName string passed in.
srERR_HANDLE_INVALID The named parameter is not found and szDefValue is set to srNULL.


#include <srtest.h>

#define MAX_VALUE_LEN 128
void tfsuite_getParam(void)
{
  srCHAR szValue[MAX_VALUE_LEN] = {0};

  srWORD wRet = srTestGetParam("ParamName", szValue, MAX_VALUE_LEN, "default value");
}

#ifdef _SCL
#pragma scl_test_flist("testfunc", tfsuite_getParam)
#endif


srTestGetParamLong

The srTestGetParamLong() function is used to get the value of a named parameter as a long.

srLONG srTestGetParamLong(const srCHAR * szName, srLONG lDefValue);


Parameters Type Description
szName Input Pointer to a null-terminated string that represents the name of the parameter.
lDefValue Input Default value that is returned if the parameter is not found.


Return Value Description
srLONG Parameter value, or value specified by lDefValue if parameter isn't found.


#include <srtest.h>

void tfsuite_getParam(void)
{
  srLONG lVal = srTestGetParamLong("ParamName", -1);
}

#ifdef _SCL
#pragma scl_test_flist("testfunc", tfsuite_getParam)
#endif


srTestGetParamDouble

The srTestGetParamDouble() function is used to get the value of a named parameter as a double.

double srTestGetParamDouble(const srCHAR * szName, double dbDefValue);


Parameters Type Description
szName Input Pointer to a null-terminated string that represents the name of the parameter.
dbDefValue Input Default value that is returned if the parameter is not found.


Return Value Description
double Parameter value, or value specified by dbDefValue if parameter isn't found.


#include <srtest.h>

void tfsuite_getParam(void)
{
  double dbVal = srTestGetParamDouble("ParamName", 0.5772156649);
}

#ifdef _SCL
#pragma scl_test_flist("testfunc", tfsuite_getParam)
#endif


srTestSuiteAddCase

The srTestSuiteAddCase() routine is used to add a new test case to the specified test suite.

srTestCaseHandle_t srTestSuiteAddCase(const srCHAR * szName, const srCHAR * szDescr)


Parameters Type Description
szName Input Pointer to a null-terminated string that represents the name of the new test case. If null, the default host naming scheme will be used.
szDescr Input Pointer to a null-terminated string representing the description of the new test case. If null, description will be empty.


Return Value Description
srTestCaseHandle_t Handle of the newly created test case. srTEST_CASE_INVALID indicates failure to create a test case.


#include <srtest.h>
#include <stdio.h>

void tfsuite_addCase(void)
{
  for (int count = 0; count < 5; ++count)
  {
    char szName[25];
    sprintf(szName, "dynamic test case %d", count);
    srTestCaseHandle_t test = srTestSuiteAddCase(szName, "this is a dynamic test case");
    srTestCaseSetStatus(test, srTEST_PASS, 0); 
  }
}

#ifdef _SCL
#pragma scl_test_flist("testfunc", tfsuite_addCase)
#endif


srTestSuiteAddAnnotation

The srTestSuiteAddAnnotation() routine is used to add a new annotation to the specified test suite.

srTestAnnotationHandle_t srTestSuiteAddAnnotation(srTestAnnotationLevel_e eLevel,
                                                  const srCHAR * szName, 
                                                  const srCHAR * szFmtDescr, ...)


Parameters Type Description
eLevel Input Annotation level.
  • srTEST_ANNOTATION_LEVEL_TRACE,
  • srTEST_ANNOTATION_LEVEL_DEBUG,
  • srTEST_ANNOTATION_LEVEL_INFO,
  • srTEST_ANNOTATION_LEVEL_WARN,
  • srTEST_ANNOTATION_LEVEL_ERROR,
  • srTEST_ANNOTATION_LEVEL_FATAL
szName Input Pointer to a null-terminated string representing the name of the new annotation. If null, the default host naming scheme will be used.
szFmtDescr Input Pointer to a null-terminated string representing the description of the new annotation. Cannot be null.
... Input (Optional) Variable argument list to format szFmtDescr.


Return Value Description
srTestAnnotationHandle_t Handle of the newly created test annotation. srTEST_ANNOTATION_INVALID indicates failure to create a test annotation.


#include <srtest.h>

void tfsuite_addAnnotation(void) 
{
  for (int count = 0; count < 5; ++count)
  {
    char szName[25];
    sprintf(szName, "annotation %d", count);
    srTestAnnotationHandle_t annot = 
                     srTestSuiteAddAnnotation(srTEST_ANNOTATION_LEVEL_ERROR,
                                              szName,
                                              "description of annotation");
  }
}

#ifdef _SCL
#pragma scl_test_flist("testfunc", tfsuite_addAnnotation)
#endif


srTestSuiteSetData

The srTestSuiteSetData() routine is used to associate a custom name|value pair with a test suite.

srWORD srTestSuiteSetData(const srCHAR * szName, const srCHAR * szFmtValue, ...)


Parameters Type Description
szName Input Pointer to a null-terminated string representing the name of the custom pair. Cannot be null.
szFmtValue Input Pointer to a null-terminated string representing the value of the custom pair. Cannot be null.
... Input (Optional) Variable argument list to format szFmtValue.


Return Value Description
srWORD srOK on success, srERR_HANDLE_INVALID on invalid handle.


#include <srtest.h>

void tfcase_setData(void)
{
  srTestSuiteSetData("MyName", "my value");
}

#ifdef _SCL
#pragma scl_test_flist("testfunc", tfcase_setData)
#endif


srTestCaseSetStatus

The srTestCaseSetStatus() routine is used to set the result of test case.

srWORD srTestCaseSetStatus(srTestCaseHandle_t tTestCase, srTestStatus_e eStatus, srDWORD dwDuration)


Parameters Type Description
tTestCase Input Handle to a test case. srTEST_CASE_DEFAULT can be used for the default test case.
eStatus Input Result of the test. Possible values are:
  • srTEST_FAIL
  • srTEST_PASS
  • srTEST_NOTINUSE
  • srTEST_INPROGRESS
  • srTEST_DONE - applicable to dynamic cases - sets the status to pass unless already set to fail or not-in-use
dwDuration Input The duration of the test in clock ticks. Using "0" allows the Stride Runtime (Intercept Module) to set the time automatically.


Return Value Description
srWORD srOK on success, srERR_HANDLE_INVALID on invalid handle.


#include <srtest.h>

void tfcase_setStatus(void)
{
  srTestCaseSetStatus(srTEST_CASE_DEFAULT, srTEST_PASS, 0);
}

#ifdef _SCL
#pragma scl_test_flist("testfunc", tfcase_setStatus)
#endif


srTestCaseSetStatusEx

The srTestCaseSetStatusEx() routine is used to set the result of test case and allow specification of an extendedFailureCode.

srWORD srTestCaseSetStatus(srTestCaseHandle_t tTestCase, srTestStatus_e eStatus, srDWORD dwDuration, srLONG lExtendedFailureCode)


Parameters Type Description
tTestCase Input Handle to a test case. srTEST_CASE_DEFAULT can be used for the default test case.
eStatus Input Result of the test.
dwDuration Input The duration of the test in clock ticks. Using "0" allows the Stride Runtime (Intercept Module) to set the time automatically.
lExtendedFailureCode Input The Stride framework uses the extendedFailureCode to capture the numeric results of test method when the test method fails via a numeric (non-void, nonbool) return type.


Return Value Description
srWORD srOK on success, srERR_HANDLE_INVALID on invalid handle.


#include <srtest.h>

void tfcase_setStatusEx(void)
{
  srTestCaseSetStatusEx(srTEST_CASE_DEFAULT, srTEST_FAIL, 0, -5);
}

#ifdef _SCL
#pragma scl_test_flist("testfunc", tfcase_setStatusEx)
#endif


srTestCaseAddAnnotation

The srTestCaseAddAnnotation() routine is used to add a new annotation to the specified test case.

srTestAnnotationHandle_t srTestCaseAddAnnotation(rTestCaseHandle_t tTestCase, srTestAnnotationLevel_e eLevel, const srCHAR * szName, const srCHAR * szFmtDescr, ...)


Parameters Type Description
tTestCase Input Handle to the parent test case to which new test annotation is to be added. srTEST_CASE_DEFAULT can be used for the default test case.
eLevel Input Annotation level.
  • srTEST_ANNOTATION_LEVEL_TRACE,
  • srTEST_ANNOTATION_LEVEL_DEBUG,
  • srTEST_ANNOTATION_LEVEL_INFO,
  • srTEST_ANNOTATION_LEVEL_WARN,
  • srTEST_ANNOTATION_LEVEL_ERROR,
  • srTEST_ANNOTATION_LEVEL_FATAL
szName Input Pointer to a null-terminated string representing the name of the new annotation. If null, the default host naming scheme will be used.
szFmtDescr Input Pointer to a null-terminated string representing the description of the new annotation. Cannot be null.
... Input (Optional) Variable argument list to format szFmtDescr.


Return Value Description
srTestAnnotationHandle_t Handle of the newly created test annotation. srTEST_ANNOTATION_INVALID indicates failure to create a test annotation.


#include <srtest.h>

void tfcase_addAnnotation(void) 
{
  for (int count = 0; count < 5; ++count)
  {
    char szName[25];
    sprintf(szName, "annotation %d", count);
    srTestAnnotationHandle_t annot = 
                     srTestCaseAddAnnotation(srTEST_CASE_DEFAULT,
                                             srTEST_ANNOTATION_LEVEL_ERROR,
                                             szName,
                                             "description of annotation");
  }
}

#ifdef _SCL
#pragma scl_test_flist("testfunc", tfcase_addAnnotation)
#endif


srTestCaseSetData

The srTestCaseSetData() routine is used to associate a custom name|value pair with a test case.

srWORD srTestCaseSetData(srTestCaseHandle_t tTestCase, const srCHAR * szName, const srCHAR * szFmtValue, ...);


Parameters Type Description
tTestCase Input Handle to a test case. srTEST_CASE_DEFAULT can be used for the default test case.
szName Input Pointer to a null-terminated string representing the name of the custom pair. Cannot be null.
szFmtValue Input Pointer to a null-terminated string representing the value of the custom pair. Cannot be null.
... Input (Optional) Variable argument list to format szFmtValue.


Return Value Description
srWORD srOK on success, srERR_HANDLE_INVALID on invalid handle.


#include <srtest.h>

void tfcase_setData(void)
{
  srTestCaseSetData(srTEST_CASE_DEFAULT, "MyName", "my value");
}

#ifdef _SCL
#pragma scl_test_flist("testfunc", tfcase_setData)
#endif


srTestAnnotationAddComment

The srTestAnnotationAddComment() routine is used to add a comment (aka a log) to a test annotation.

srWORD srTestAnnotationAddComment(srTestAnnotationHandle_t tTestAnnotation, const srCHAR * szLabel, const srCHAR * szFmtComment, ...)


Parameters Type Description
tTestAnnotation Input Handle to a test annotation.
szLabel Input Pointer to a null-terminated string for the label. If null, the default label will be applied.
szFmtComment Input Pointer to a null-terminated string representing the new comment. Cannot be null.
... Input (Optional) Variable argument list to format szFmtComment.


Return Value Description
srWORD srOK on success, srERR on null string or invalid formatted string, srERR_HANDLE_INVALID on invalid handle, srERR_STR_TRUNCATED on truncated string.


#include <srtest.h>

void tfsuiteAnnotation_addComment(void) 
{
  srTestAnnotationHandle_t annot = 
                           srTestSuiteAddAnnotation(srTEST_ANNOTATION_LEVEL_ERROR,
                                                    "annot",
                                                    "annot description");
  srTestAnnotationAddComment(annot,
                             srNULL,
                             "this comment should print %s", "A STRING");
}

#ifdef _SCL
#pragma scl_test_flist("testfunc", tfsuiteAnnotation_addComment)
#endif


C++ Test Classes

The Runtime Test Services C APIs work equally well from C test functions and C++ test classes. If, however, you are using C++ it might be more convinient for you to derive your C++ test classes from the Runtime Test Services C++ base class, srTest. That way you will have access to a set of simpler to use C++ classes.

The following C++ classes are provided:


class srTest

The srTest class provides one member object testCase of class srTestCase and the folowing methods:


method GetParam

This overload of the GetParam() method is used to get the value of a named parameter as a string.

static srWORD GetParam(const srCHAR * name, srCHAR * value, srDWORD size, const srCHAR * defval = srNULL)


Parameters Type Description
name Input Pointer to a null-terminated string that represents the name of the parameter. Cannot be null.
value Output Pointer to a block of memory to store the value of the parameter with a maximum size of size chars
size Input Size in chars of the buffer pointed to by value
defvalue Input (optional) Pointer to a null-terminated string that represents a default value in case the parameter is not specified. By setting this value to srNULL (or omitting it), you can use GetParam() to test for the existence of a named parameter. If the named parameter doesn't exist, the function will return srERR_HANDLE_INVALID.


Return Value Description
srWORD srOK on success, error otherwise.


#include <srtest.h>

class srtest_class : public stride::srTest
{
public:
  void getParam()
  {
    GetParam("ParamName", szValue, MAX_VALUE_LEN, "default value");
  }
};

#ifdef _SCL
#pragma scl_test_class(srtest_class)
#endif


method GetParam

This overload of the GetParam() method is used to get the value of a named parameter as a long.

static long GetParam(const srCHAR * name, srLONG defval = 0)


Parameters Type Description
name Input Pointer to a null-terminated string that represents the name of the parameter.
defvalue Input Default value that is returned if the parameter is not found.


Return Value Description
srLONG Parameter value, or value specified by defvalue if parameter isn't found.


#include <srtest.h>

class srtest_class : public stride::srTest
{
public:
  void getParam()
  {
    srLONG lValue = GetParam("ParamName", -1);
  }
};

#ifdef _SCL
#pragma scl_test_class(srtest_class)
#endif


method GetParam

This overload of the GetParam() method is used to get the value of a named parameter as a double.

static double GetParam(const srCHAR * name, const double& defval)


Parameters Type Description
name Input Pointer to a null-terminated string that represents the name of the parameter.
defvalue Input Default value that is returned if the parameter is not found.


Return Value Description
double Parameter value, or value specified by defvalue if parameter isn't found.


#include <srtest.h>

class srtest_class : public stride::srTest
{
public:
  void getParam()
  {
    double dbVal = GetParam("ParamName",  0.5772156649);
  }
};

#ifdef _SCL
#pragma scl_test_class(srtest_class)
#endif


method AddCase

The AddCase method is used to add a new test case to the test suite.

srTestCase AddCase(const srCHAR * name, const srCHAR * descr = srNULL)


Parameters Type Description
name Input Pointer to null-terminated string that represents the name of the new test case. If empty, the default host naming scheme will be used.
descr Input (Optional) Pointer to null-terminated string representing the description of the new test case. If empty, description will be blank.


Return Value Description
srTestCase Newly created test case instance.


Example

#include <srtest.h>
#include <sstream>

class srtest_class : public stride::srTest
{
public:
  void suiteAddSuite()
  {
    const std::string prefix("dynamic test case ");
    for (int count = 0; count < 5; ++count)
    {
      std::stringstream strm;
      strm << prefix << count;
      stride::srTestCase tc = AddCase(strm.str().c_str());
      tc.SetStatus(srTEST_PASS);
    }
  }
};

#ifdef _SCL
#pragma scl_test_class(srtest_class)
#endif


method AddAnnotation

The AddAnnotation method is used to add a new test annotation to the test suite.

srTestAnnotation AddAnnotation(srTestAnnotationLevel_e level, const srCHAR * name, const srCHAR * descr, ...)


Parameters Type Description
level Input Annotation level.
  • srTEST_ANNOTATION_LEVEL_TRACE,
  • srTEST_ANNOTATION_LEVEL_DEBUG,
  • srTEST_ANNOTATION_LEVEL_INFO,
  • srTEST_ANNOTATION_LEVEL_WARN,
  • srTEST_ANNOTATION_LEVEL_ERROR,
  • srTEST_ANNOTATION_LEVEL_FATAL
name Input Pointer to null-terminated string that represents the name of the new annotation. If empty, the default host naming scheme will be used.
descr Input Pointer to null-terminated string representing the description of the new annotation. Cannot be null.


Return Value Description
srTestAnnotation Newly created annotation instance.


#include <srtest.h>
#include <sstream>

class srtest_class : public stride::srTest
{
public:
  void suiteAddAnnotation()
  {
    for (int count = 0; count < 5; ++count)
    {
      std::stringstream strmName;
      std::stringstream strmDescr;
      strmName << "annotation " << count;
      strmDescr << "description of annotation " << count;
      stride::srTestAnnotation ta = AddAnnotation(srTEST_ANNOTATION_LEVEL_INFO,
                                                  strmName.str().c_str(),
                                                  strmDescr.str().c_str());
    }
  }
};

#ifdef _SCL
#pragma scl_test_class(srtest_class)
#endif


method SetData

The SetData method is used to associate a custom name|value pair with the test suite.

srWORD SetData(const srCHAR * name, const srCHAR * value, ...)


Parameters Type Description
name Input Pointer to a null-terminated string representing the name of the custom pair. Cannot be null.
value Input Pointer to a null-terminated string representing the value of the custom pair. Cannot be null.


Return Value Description
srWORD srOK on success, srERR_HANDLE_INVALID on invalid handle.


Example

#include <srtest.h>
#include <sstream>

class srtest_class : public stride::srTest
{
public:
  void suiteSetData()
  {
      SetData("MyName", "my value");
  }
};

#ifdef _SCL
#pragma scl_test_class(srtest_class)
#endif


class srTestCase

The srTestCase class provides the following methods:

method SetStatus

The SetStatus method is used to set the result of the default test case.

srWORD SetStatus(srTestStatus_e status, srDWORD duration = 0)


Parameters Type Description
status Input Result of the test. Possible values are:
  • srTEST_FAIL
  • srTEST_PASS
  • srTEST_NOTINUSE
  • srTEST_INPROGRESS
  • srTEST_DONE - applicable to dynamic cases - sets the status to pass unless already set to fail or not-in-use
duration Input (Optional) The duration of the test in clock ticks. The default is 0.


Return Value Description
srWORD srOK on success, srERR_HANDLE_INVALID on invalid handle.


#include <srtest.h>

class srtest_class : public stride::srTest
{
public:
  void caseSetStatus()
  {
    testCase.SetStatus(srTEST_NOTINUSE);
  }
};

#ifdef _SCL
#pragma scl_test_class(srtest_class)
#endif


method AddAnnotation

The AddAnnotation method is used to add a new test annotation to the test case.

srTestAnnotation AddAnnotation(srTestAnnotationLevel_e level, const srCHAR * name, const srCHAR * descr, ...)


Parameters Type Description
level Input Annotation level.
  • srTEST_ANNOTATION_LEVEL_TRACE,
  • srTEST_ANNOTATION_LEVEL_DEBUG,
  • srTEST_ANNOTATION_LEVEL_INFO,
  • srTEST_ANNOTATION_LEVEL_WARN,
  • srTEST_ANNOTATION_LEVEL_ERROR,
  • srTEST_ANNOTATION_LEVEL_FATAL
name Input Pointer to null-terminated string that represents the name of the new annotation. If null, the default host naming scheme will be used.
descr Input Pointer to null-terminated string representing the description of the new annotation. Cannot be null.


Return Value Description
srTestAnnotation Newly created annotation instance.


#include <srtest.h>
#include <sstream>

class srtest_class : public stride::srTest
{
public:
  void caseAddAnnotation()
  {
    for (int count = 0; count < 5; ++count)
    {
      std::stringstream strmName;
      std::stringstream strmDescr;
      strmName << "annotation " << count;
      strmDescr << "description of annotation " << count;
      stride::srTestAnnotation ta = 
                 testCase.AddAnnotation(srTEST_ANNOTATION_LEVEL_INFO,
                                         strmName.str().c_str(),
                                         strmDescr.str().c_str());
    }
  }
};

#ifdef _SCL
#pragma scl_test_class(srtest_class)
#endif


method SetData

The SetData method is used to associate a custom name|value pair with the test case.

srWORD SetData(const srCHAR * name, const srCHAR * value, ...)


Parameters Type Description
name Input Pointer to a null-terminated string representing the name of the custom pair. Cannot be null.
value Input Pointer to a null-terminated string representing the value of the custom pair. Cannot be null.


Return Value Description
srWORD srOK on success, srERR_HANDLE_INVALID on invalid handle.


#include <srtest.h>

class srtest_class : public stride::srTest
{
public:
  void caseSetData()
  {
    testCase.SetData("MyName", "my value");
  }
};

#ifdef _SCL
#pragma scl_test_class(srtest_class)
#endif


class srTestAnnotation

The srTestAnnotation class provides the following methods:


method AddComment

The AddComment method is used to add a comment to the test annotation.

srWORD AddComment(const srCHAR * label, const srCHAR * comment, ...)


Parameters Type Description
label Input Pointer to null-terminated string for the label. If null, the default label will be applied.
comment Input Pointer to null-terminated string representing the new comment. Cannot be empty.


Return Value Description
srWORD srOK on success, srERR on null string or invalid formatted string, srERR_HANDLE_INVALID on invalid handle, srERR_STR_TRUNCATED on truncated string.


#include <srtest.h>

class srtest_class : public stride::srTest
{
public:
  void suiteAnnotationAddComment()
  {
    stride::srTestAnnotation ta = 
                 testSuite.AddAnnotation(srTEST_ANNOTATION_LEVEL_INFO,
                                         "annot",
                                         "annot description");
    ta.AddComment("this comment on annotation should print %s", "A STRING");
  }
};

#ifdef _SCL
#pragma scl_test_class(srtest_class)
#endif