Runtime Test Services: Difference between revisions

From STRIDE Wiki
Jump to navigation Jump to search
Line 11: Line 11:
The following C APIs are provided:  
The following C APIs are provided:  


*'''[[#srTestSuiteSetName|srTestSuiteSetName]]''': sets the name of the specified suite.
*'''[[#srTestSuiteSetDescription|srTestSuiteSetDescription]]''': sets the description of the specified suite.
*'''[[#srTestSuiteAddSuite|srTestSuiteAddSuite]]''': creates an additional sub-suite at runtime<ref name=dynamic>
*'''[[#srTestSuiteAddSuite|srTestSuiteAddSuite]]''': creates an additional sub-suite at runtime<ref name=dynamic>
The use of these functions in the context of any test method will cause the STRIDE Test Unit framework to  
The use of these functions in the context of any test method will cause the STRIDE Test Unit framework to  
  '''delete''' the default test case that was created for the current test method since their use implies that dynamic test cases will be created. In addition, the use of the dynamic test case creation methods will cause the framework to interpret the '''srTEST_CASE_DEFAULT''' value as the most recently created test case.</ref>.  
  '''delete''' the default test case that was created for the current test method since their use implies that dynamic test cases will be created. In addition, the use of the dynamic test case creation methods will cause the framework to interpret the '''srTEST_CASE_DEFAULT''' value as the most recently created test case.</ref>.  
*'''[[#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<ref name=dynamic/>.  
*'''[[#srTestSuiteAddCase|srTestSuiteAddCase]]''': creates an additional test case at runtime<ref name=dynamic/>.  
*'''[[#srTestSuiteAddAnnotation|srTestSuiteAddAnnotation]]''': creates a suite annotation at runtime.
*'''[[#srTestCaseSetName|srTestCaseSetName]]''': sets the name of the specified test case.  
*'''[[#srTestCaseSetName|srTestCaseSetName]]''': sets the name of the specified test case.  
*'''[[#srTestCaseSetDescription|srTestCaseSetDescription]]''': sets the description of the specified test case.  
*'''[[#srTestCaseSetDescription|srTestCaseSetDescription]]''': sets the description of the specified test case.  
*'''[[#srTestCaseSetStatus|srTestCaseSetStatus]]''': explicitly sets the status for the specified test case.
*'''[[#srTestCaseAddComment|srTestCaseAddComment]]''': adds a comment to 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.
*'''[[#srTestSuiteAddAnnotation|srTestSuiteAddAnnotation]]''': creates a suite annotation at runtime.
*'''[[#srTestCaseAddAnnotation|srTestCaseAddAnnotation]]''': creates a test case annotation at runtime.  
*'''[[#srTestCaseAddAnnotation|srTestCaseAddAnnotation]]''': creates a test case annotation at runtime.  
*'''[[#srTestAnnotationAddComment|srTestAnnotationAddComment]]''': adds a comment to the specified annotation.
*'''[[#srTestAnnotationAddComment|srTestAnnotationAddComment]]''': adds a comment to the specified annotation.


==== srTestSuiteAddSuite ====
The srTestSuiteAddSuite()<ref name=dynamic/> routine is used to add a new test suite to the specified test suite.
<source lang=c>
srTestSuiteHandle_t srTestSuiteAddSuite(srTestSuiteHandle_t tParent, const srCHAR * szName)
</source>
{| border="1" cellspacing="0" cellpadding="10" style="align:left;" 
| '''Parameters'''
| '''Type'''
| '''Description'''
|-
| tParent
| 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.
|-
| szName
| Input
| Pointer to a null-terminated string that represents the name of test suite. If null, the default host naming scheme will be used.
|}
<br>
{| border="1" cellspacing="0" cellpadding="10" style="align:left;"
| '''Return Value'''
| ''' Description'''
|-
|srTestSuiteHandle_t
| Handle of the newly created test suite. srTEST_SUITE_INVALID indicates failure to create test suite.
|}
<source lang=c>
#include <srtest.h>
void tfsuite_addSuite(void)
{
  srTestSuiteHandle_t subSuite =
  srTestSuiteAddSuite(srTEST_SUITE_DEFAULT, "tf Sub Suite");
}
#ifdef _SCL
#pragma scl_test_flist("testfunc", tfsuite_addSuite)
#endif
</source>


==== srTestSuiteSetName ====
==== srTestSuiteSetName ====
Line 165: Line 125:
#ifdef _SCL
#ifdef _SCL
#pragma scl_test_flist("testfunc", tfsuite_setDescription)
#pragma scl_test_flist("testfunc", tfsuite_setDescription)
#endif
</source>
==== srTestSuiteAddSuite ====
The srTestSuiteAddSuite()<ref name=dynamic/> routine is used to add a new test suite to the specified test suite.
<source lang=c>
srTestSuiteHandle_t srTestSuiteAddSuite(srTestSuiteHandle_t tParent, const srCHAR * szName)
</source>
{| border="1" cellspacing="0" cellpadding="10" style="align:left;" 
| '''Parameters'''
| '''Type'''
| '''Description'''
|-
| tParent
| 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.
|-
| szName
| Input
| Pointer to a null-terminated string that represents the name of test suite. If null, the default host naming scheme will be used.
|}
<br>
{| border="1" cellspacing="0" cellpadding="10" style="align:left;"
| '''Return Value'''
| ''' Description'''
|-
|srTestSuiteHandle_t
| Handle of the newly created test suite. srTEST_SUITE_INVALID indicates failure to create test suite.
|}
<source lang=c>
#include <srtest.h>
void tfsuite_addSuite(void)
{
  srTestSuiteHandle_t subSuite =
  srTestSuiteAddSuite(srTEST_SUITE_DEFAULT, "tf Sub Suite");
}
#ifdef _SCL
#pragma scl_test_flist("testfunc", tfsuite_addSuite)
#endif
#endif
</source>
</source>
Line 217: Line 219:
</source>
</source>


==== srTestCaseSetName ====
==== srTestSuiteAddAnnotation ====
The srTestCaseSetName() routine is used to set set the name of the specified test case.
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(rTestSuiteHandle_t tParent, srTestAnnotationLevel_e eLevel, const srCHAR * szName, const srCHAR * szDescr)
</source>
</source>


Line 228: Line 230:
| '''Description'''
| '''Description'''
|-
|-
| tTestCase
| tParent
| Input
| Input
| Handle to a test case. srTEST_CASE_DEFAULT can be used for the default test case.
| 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.
|-
| eLevel
| Input
| Annotation level. Cannot be empty.
|-
|-
| 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 that represents the name of annotation. If null, the default host naming scheme will be used.
|-
| szDescr
| Input
| Pointer to a null-terminated string representing the description of annotation. If null, description will be empty.
|}
|}
<br>
<br>
Line 241: Line 251:
| ''' Description'''
| ''' Description'''
|-
|-
| srOK
| srTestAnnotationHandle_t
| Success
| HHandle of the newly created annotation. srTEST_ANNOTATION_INVALID indicates failure to create 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.
|}
|}


Line 257: Line 258:
#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_SUITE_DEFAULT,
                                              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 ====
==== srTestCaseSetName ====
The srTestCaseSetDescription() routine is used to set the description of the specified test case.
The srTestCaseSetName() routine is used to set set the name of the specified test case.
<source lang=c>
<source lang=c>
srWORD srTestCaseSetDescription(srTestCaseHandle_t tTestCase, const srCHAR * szDescr)
srWORD srTestCaseSetName(srTestCaseHandle_t tTestCase, const srCHAR *szName)
</source>
</source>


Line 282: Line 292:
| 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.
|-
|-
| szDescr
| szName
| 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 name of test case. Cannot be null.
|}
|}
<br>
<br>
Line 307: Line 317:
#include <srtest.h>
#include <srtest.h>


void tfcase_setDescription(void)
void tfcase_setName(void)
{
{
   srTestCaseSetDescription(srTEST_CASE_DEFAULT,
   srTestCaseSetName(srTEST_CASE_DEFAULT, "Setting name for default case");
                          "Setting description for default case");
}
}


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


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


Line 333: Line 342:
| 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
| szDescr
| Input
| Pointer to a null-terminated string specifying the comment's label.
|-
| 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 description of test case. Cannot be null.
|-
| ...
| Input (Optional)
| Variable argument list to format the comment szFmtComment.
|}
|}
<br>
<br>
Line 366: Line 367:
#include <srtest.h>
#include <srtest.h>


void tfcase_addComment(void)
void tfcase_setDescription(void)
{
{
   srTestCaseAddComment(srTEST_CASE_DEFAULT, "Note",
   srTestCaseSetDescription(srTEST_CASE_DEFAULT,
                      "this comment should print %s", "A STRING");
                          "Setting description for default case");
}
}


#ifdef _SCL
#ifdef _SCL
#pragma scl_test_flist("testfunc", tfcase_addComment)
#pragma scl_test_flist("testfunc", tfcase_setDescription)
#endif
#endif
</source>
</source>
Line 482: Line 483:
</source>
</source>


==== srTestSuiteAddAnnotation ====
==== srTestCaseAddComment ====
The srTestSuiteAddAnnotation() routine is used to add a new annotation to the specified test suite.
The srTestCaseAddComment() routine is used to add a comment (aka a log) to be reported with the specified test case.
<source lang=c>
<source lang=c>
srTestAnnotationHandle_t srTestSuiteAddAnnotation(rTestSuiteHandle_t tParent, srTestAnnotationLevel_e eLevel, const srCHAR * szName, const srCHAR * szDescr)
srWORD srTestCaseAddComment(srTestCaseHandle_t tTestCase, const srCHAR * szLabel, const srCHAR * szFmtComment, ...)
</source>
</source>


Line 493: Line 494:
| '''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
| szLabel
| Input  
| Input
| Annotation level. Cannot be empty.
| Pointer to a null-terminated string specifying the comment's label.
|-
|-
| szName
| szFmtComment
| 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, which can be formatted, representing the comment. 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 the comment szFmtComment.
|}
|}
<br>
<br>
Line 514: Line 515:
| ''' Description'''
| ''' Description'''
|-
|-
| srTestAnnotationHandle_t
| srOK
| HHandle of the newly created annotation. srTEST_ANNOTATION_INVALID indicates failure to create annotation.
| Success
|-
| 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.
|}
|}


Line 521: Line 531:
#include <srtest.h>
#include <srtest.h>


void tfsuite_addAnnotation(void)  
void tfcase_addComment(void)
{
{
   for (int count = 0; count < 5; ++count)
   srTestCaseAddComment(srTEST_CASE_DEFAULT, "Note",
  {
                      "this comment should print %s", "A STRING");
    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_addComment)
#endif
#endif
</source>
</source>
Line 680: Line 682:
The srTest class provides the folowing methods:
The srTest class provides the folowing methods:


===== method AddSuite =====
===== method SetName =====
The AddSuite<ref name=dynamic/> method is used to add a new test suite.
The SetName method is used to set the name of test suite.
<source lang=cpp>
<source lang=cpp>
srTestSuite AddSuite(const srCHAR * szName = srNULL)
srWORD SetName(const srCHAR * szName)
</source>
</source>


Line 691: Line 693:
| '''Description'''
| '''Description'''
|-  
|-  
|szName  
| szName  
| 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 null-terminated string representing the name of test suite. Cannot be empty.
|}
|}
<br>
<br>
Line 700: Line 702:
| ''' Description'''
| ''' Description'''
|-
|-
| srTestSuite
| srOK
| Newly created test suite class.
| Success
|-
| 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.
|}
|}


Line 710: Line 721:
{
{
public:
public:
   void suiteAddSuite()
   void suiteSetName()
   {
   {
     stride::srTestSuite suite = testSuite.AddSuite("tc Sub Suite");
     testSuite.SetName("Setting name for suite");
   }
   }
};
};
Line 721: Line 732:
</source>
</source>


===== method SetName =====
===== method SetDescription =====
The SetName method is used to set the name of test suite.
The SetDescription method is used to set the description of test suite.
<source lang=cpp>
<source lang=cpp>
srWORD SetName(const srCHAR * szName)
srWORD SetDescription(const srCHAR * szDescr)
</source>
</source>


Line 732: Line 743:
| '''Description'''
| '''Description'''
|-  
|-  
| szName
| szDescr
| Input  
| Input  
| Pointer to null-terminated string representing the name of test suite. Cannot be empty.
| Pointer to null-terminated string representing the description of test suite. Cannot be empty.
|}
|}
<br>
<br>
Line 746: Line 757:
| srERR  
| srERR  
| Null string passed in.
| Null string passed in.
|-
|-  
| srTEST_ERR_HANDLE_INVALID  
| srTEST_ERR_HANDLE_INVALID  
| Invalid handle passed in.
| Invalid handle passed in.
Line 760: Line 771:
{
{
public:
public:
   void suiteSetName()
   void suiteSetDescription()
   {
   {
     testSuite.SetName("Setting name for suite");
     testSuite.SetDescription("Setting description for suite");
   }
   }
};
};
Line 771: Line 782:
</source>
</source>


===== method SetDescription =====
===== method AddSuite =====
The SetDescription method is used to set the description of test suite.
The AddSuite<ref name=dynamic/> method is used to add a new test suite.
<source lang=cpp>
<source lang=cpp>
srWORD SetDescription(const srCHAR * szDescr)
srTestSuite AddSuite(const srCHAR * szName = srNULL)
</source>
</source>


Line 782: Line 793:
| '''Description'''
| '''Description'''
|-  
|-  
| szDescr
|szName
| Input  
| Input (Optional)
| Pointer to null-terminated string representing the description of test suite. Cannot be empty.
| Pointer to null-terminated string that represents the name of test suite. If empty, the default host naming scheme will be used.
|}
|}
<br>
<br>
Line 791: Line 802:
| ''' Description'''
| ''' Description'''
|-
|-
| srOK
| srTestSuite
| Success
| Newly created test suite class.
|-
| 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.
|}
|}


Line 810: Line 812:
{
{
public:
public:
   void suiteSetDescription()
   void suiteAddSuite()
   {
   {
     testSuite.SetDescription("Setting description for suite");
     stride::srTestSuite suite = testSuite.AddSuite("tc Sub Suite");
   }
   }
};
};
Line 1,035: Line 1,037:
</source>
</source>


===== method AddComment =====
===== method SetStatus =====
The AddComment method is used to add a comment to test case.
The SetStatus method is used to set the result of the default test case.
<source lang=cpp>
<source lang=cpp>
srWORD AddComment(const srCHAR * szFmtComment, ...)
srWORD SetStatus(srTestStatus_e eStatus, srDWORD dwDuration = 0)
</source>
</source>


Line 1,046: Line 1,048:
| '''Description'''
| '''Description'''
|-  
|-  
| szFmtComment
| eStatus
| Input  
| Input  
| Pointer to null-terminated string, which can be formatted, representing the comment. 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'''
|-
|-
| ...
| dwDuration
| Input (Optional)
| Input (Optional)
| Variable argument list to format the comment szFmtComment.
| The duration of the test in clock ticks. The default is 0.
|}
|}
<br>
<br>
Line 1,061: Line 1,068:
| srOK  
| srOK  
| Success
| Success
|-
| srERR
| Null string passed in.
|-
|-
| srTEST_ERR_HANDLE_INVALID  
| srTEST_ERR_HANDLE_INVALID  
| Invalid handle passed in.
| Invalid handle.
|-
| srTEST_WARN_STR_TRUNCATED
| String passed in was too large and was truncated.
|}
|}


Line 1,078: Line 1,079:
{
{
public:
public:
   void caseAddComment()
   void caseSetStatus()
   {
   {
     testCase.AddComment("this comment should print %s", "A STRING");
     testCase.SetStatus(srTEST_NOTINUSE, 0);
   }
   }
};
};
Line 1,089: Line 1,090:
</source>
</source>


===== method SetStatus =====
===== method AddComment =====
The SetStatus method is used to set the result of the default test case.
The AddComment method is used to add a comment to test case.
<source lang=cpp>
<source lang=cpp>
srWORD SetStatus(srTestStatus_e eStatus, srDWORD dwDuration = 0)
srWORD AddComment(const srCHAR * szFmtComment, ...)
</source>
</source>


Line 1,100: Line 1,101:
| '''Description'''
| '''Description'''
|-  
|-  
| eStatus
| szFmtComment
| Input  
| Input  
| Result of the test. Possible values are:
| Pointer to null-terminated string, which can be formatted, representing the comment. Cannot be empty.
* '''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 (Optional)
| Input (Optional)
| The duration of the test in clock ticks. The default is 0.
| Variable argument list to format the comment szFmtComment.
|}
|}
<br>
<br>
Line 1,120: Line 1,116:
| srOK  
| srOK  
| Success
| Success
|-
| srERR
| Null string passed in.
|-
|-
| srTEST_ERR_HANDLE_INVALID  
| srTEST_ERR_HANDLE_INVALID  
| Invalid handle.
| Invalid handle passed in.
|-
| srTEST_WARN_STR_TRUNCATED
| String passed in was too large and was truncated.
|}
|}


Line 1,131: Line 1,133:
{
{
public:
public:
   void caseSetStatus()
   void caseAddComment()
   {
   {
     testCase.SetStatus(srTEST_NOTINUSE, 0);
     testCase.AddComment("this comment should print %s", "A STRING");
   }
   }
};
};

Revision as of 19:29, 13 June 2011

Runtime Test Services

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.

Refer to the SCL Reference Guide or the Runtime Developer's Guide for more detailed information about any of these APIs.

C Test Functions

The following C APIs are provided:


srTestSuiteSetName

The srTestSuiteSetName() routine is used to set the name of the specified test suite.

srWORD srTestSuiteSetName(srTestSuiteHandle_t tTestSuite, const srCHAR * szName)
Parameters Type Description
tTestSuite Input Handle to a test suite. srTEST_SUITE_DEFAULT can be used for the default test suite.
szName Input Pointer to a null-terminated string representing the name of test suite. Cannot be null.


Return Value Description
srOK Success
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.
#include <srtest.h>

void tfsuite_setName(void)
{
  srTestSuiteSetName(srTEST_SUITE_DEFAULT, "Setting name for default suite");
}

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

srTestSuiteSetDescription

The srTestSuiteSetDescription() routine is used to set the description of the specified test suite.

srWORD srTestSuiteSetDescription(srTestSuiteHandle_t tTestSuite, const srCHAR * szDescr)
Parameters Type Description
tTestSuite Input Handle to a test suite. srTEST_SUITE_DEFAULT can be used for the default test suite.
szDescr Input Pointer to a null-terminated string representing the description of test suite. Cannot be null.


Return Value Description
srOK Success
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.
#include <srtest.h>
void tfsuite_setDescription(void)
{
  srTestSuiteSetDescription(srTEST_SUITE_DEFAULT,
                            "Setting description for default suite");
}

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

srTestSuiteAddSuite

The srTestSuiteAddSuite()[1] routine is used to add a new test suite to the specified test suite.

srTestSuiteHandle_t srTestSuiteAddSuite(srTestSuiteHandle_t tParent, const srCHAR * szName)
Parameters Type Description
tParent 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.
szName Input Pointer to a null-terminated string that represents the name of test suite. If null, the default host naming scheme will be used.


Return Value Description
srTestSuiteHandle_t Handle of the newly created test suite. srTEST_SUITE_INVALID indicates failure to create test suite.
#include <srtest.h>

void tfsuite_addSuite(void)
{
  srTestSuiteHandle_t subSuite =
  srTestSuiteAddSuite(srTEST_SUITE_DEFAULT, "tf Sub Suite");
}

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

srTestSuiteAddCase

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

srTestCaseHandle_t srTestSuiteAddCase(srTestSuiteHandle_t tParent, const srCHAR * szName)
Parameters Type 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 Input Pointer to a null-terminated string that represents the name of test case. If null, the default host naming scheme will be used.


Return Value Description
srTestCaseHandle_t Handle of the newly created test case. srTEST_CASE_INVALID indicates failure to create 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(srTEST_SUITE_DEFAULT, szName);
    srTEST_ADD_COMMENT_WITH_LOCATION(test, srNULL, "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(rTestSuiteHandle_t tParent, srTestAnnotationLevel_e eLevel, const srCHAR * szName, const srCHAR * szDescr)
Parameters Type Description
tParent 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.
eLevel Input Annotation level. Cannot be empty.
szName Input Pointer to a null-terminated string that represents the name of annotation. If null, the default host naming scheme will be used.
szDescr Input Pointer to a null-terminated string representing the description of annotation. If null, description will be empty.


Return Value Description
srTestAnnotationHandle_t HHandle of the newly created annotation. srTEST_ANNOTATION_INVALID indicates failure to create 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_SUITE_DEFAULT,
                                              srTEST_ANNOTATION_LEVEL_ERROR,
                                              szName,
                                              "description of annotation");
  }
}

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

srTestCaseSetName

The srTestCaseSetName() routine is used to set set the name of the specified test case.

srWORD srTestCaseSetName(srTestCaseHandle_t tTestCase, const srCHAR *szName)
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 test case. Cannot be null.


Return Value Description
srOK Success
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.
#include <srtest.h>

void tfcase_setName(void)
{
  srTestCaseSetName(srTEST_CASE_DEFAULT, "Setting name for default case");
}

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

srTestCaseSetDescription

The srTestCaseSetDescription() routine is used to set the description of the specified test case.

srWORD srTestCaseSetDescription(srTestCaseHandle_t tTestCase, const srCHAR * szDescr)
Parameters Type Description
tTestCase Input Handle to a test case. srTEST_CASE_DEFAULT can be used for the default test case.
szDescr Input Pointer to a null-terminated string representing the description of test case. Cannot be null.


Return Value Description
srOK Success
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.
#include <srtest.h>

void tfcase_setDescription(void)
{
  srTestCaseSetDescription(srTEST_CASE_DEFAULT,
                           "Setting description for default case");
}

#ifdef _SCL
#pragma scl_test_flist("testfunc", tfcase_setDescription)
#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
srOK Success
srTEST_ERR_HANDLE_INVALID Invalid handle passed in.
#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
srOK Success
srTEST_ERR_HANDLE_INVALID Invalid handle passed in.
#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

srTestCaseAddComment

The srTestCaseAddComment() routine is used to add a comment (aka a log) to be reported with the specified test case.

srWORD srTestCaseAddComment(srTestCaseHandle_t tTestCase, const srCHAR * szLabel, const srCHAR * szFmtComment, ...)
Parameters Type Description
tTestCase Input Handle to a test case. srTEST_CASE_DEFAULT can be used for the default test case.
szLabel Input Pointer to a null-terminated string specifying the comment's label.
szFmtComment Input Pointer to a null-terminated string, which can be formatted, representing the comment. Cannot be null.
... Input (Optional) Variable argument list to format the comment szFmtComment.


Return Value Description
srOK Success
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.
#include <srtest.h>

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

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

srTestCaseAddAnnotation

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

srTestAnnotationHandle_t srTestCaseAddAnnotation(rTestCaseHandle_t tParent, srTestAnnotationLevel_e eLevel, const srCHAR * szName, const srCHAR * szDescr)
Parameters Type Description
tParent Input Handle to the parent test case to which new annotation is to be added. srTEST_CASE_DEFAULT can be used for the default test case.
eLevel Input Annotation level. Cannot be empty.
szName Input Pointer to a null-terminated string that represents the name of annotation. If null, the default host naming scheme will be used.
szDescr Input Pointer to a null-terminated string representing the description of annotation. If null, description will be empty.


Return Value Description
srTestAnnotationHandle_t HHandle of the newly created annotation. srTEST_ANNOTATION_INVALID indicates failure to create 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

srTestAnnotationAddComment

The srTestAnnotationAddComment() routine is used to add a comment (aka a log) to be reported with the specified annotation.

srWORD srTestAnnotationAddComment(srTestAnnotationHandle_t tTestAnnotation, const srCHAR * szLabel, const srCHAR * szFmtComment, ...)
Parameters Type Description
tTestAnnotation Input Handle to an annotation created using srTestSuiteAddAnnotation.
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, which can be formatted, representing the comment. Cannot be null.
... Input (Optional) Variable argument list to format the comment szFmtComment.


Return Value Description
srOK Success
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.
#include <srtest.h>

void tfsuiteAnnotation_addComment(void) 
{
  srTestAnnotationHandle_t annot = 
                           srTestSuiteAddAnnotation(srTEST_SUITE_DEFAULT,
                                                    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 two Member Objects:

  • testSuite of class srTestSuite
  • testCase of class srTestCase

class srTestSuite

The srTest class provides the folowing methods:

method SetName

The SetName method is used to set the name of test suite.

srWORD SetName(const srCHAR * szName)
Parameters Type Description
szName Input Pointer to null-terminated string representing the name of test suite. Cannot be empty.


Return Value Description
srOK Success
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.
#include <srtest.h>

class srtest_class : public stride::srTest
{
public:
  void suiteSetName()
  {
    testSuite.SetName("Setting name for suite");
  }
};

#ifdef _SCL
#pragma scl_test_class(srtest_class)
#endif
method SetDescription

The SetDescription method is used to set the description of test suite.

srWORD SetDescription(const srCHAR * szDescr)
Parameters Type Description
szDescr Input Pointer to null-terminated string representing the description of test suite. Cannot be empty.


Return Value Description
srOK Success
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.
#include <srtest.h>

class srtest_class : public stride::srTest
{
public:
  void suiteSetDescription()
  {
    testSuite.SetDescription("Setting description for suite");
  }
};

#ifdef _SCL
#pragma scl_test_class(srtest_class)
#endif
method AddSuite

The AddSuite[1] method is used to add a new test suite.

srTestSuite AddSuite(const srCHAR * szName = srNULL)
Parameters Type Description
szName Input (Optional) Pointer to null-terminated string that represents the name of test suite. If empty, the default host naming scheme will be used.


Return Value Description
srTestSuite Newly created test suite class.
#include <srtest.h>

class srtest_class : public stride::srTest
{
public:
  void suiteAddSuite()
  {
    stride::srTestSuite suite = testSuite.AddSuite("tc Sub Suite");
  }
};

#ifdef _SCL
#pragma scl_test_class(srtest_class)
#endif
method AddCase

The AddCase[1] method is used to add a new test case to test suite.

srTestCase AddCase(const srCHAR * szName = srNULL)
Parameters Type Description
szName Input (Optional) Pointer to null-terminated string that represents the name of test case. If empty, the default host naming scheme will be used.


Return Value Description
srTestCase Newly created test case class.


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 = testSuite.AddCase(strm.str().c_str());
      tc.AddComment("this is a dynamic test case");
      tc.SetStatus(srTEST_PASS);
    }
  }
};

#ifdef _SCL
#pragma scl_test_class(srtest_class)
#endif
method AddAnnotation

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

srTestAnnotation AddAnnotation(srTestAnnotationLevel_e eLevel, const srCHAR * szName = srNULL, const srCHAR * szDescr = srNULL)
Parameters Type Description
eLevel Input Annotation level. Cannot be empty.
szName Input (Optional) Pointer to null-terminated string that represents the name of annotation. If empty, the default host naming scheme will be used.
szDescr Input (Optional) Pointer to null-terminated string that represents the description of annotation. If empty, the description will be blank.


Return Value Description
srTestAnnotation Newly created annotation class.
#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 = 
                 testSuite.AddAnnotation(srTEST_ANNOTATION_LEVEL_INFO,
                                         strmName.str().c_str(),
                                         strmDescr.str().c_str());
    }
  }
};

#ifdef _SCL
#pragma scl_test_class(srtest_class)
#endif

class srTestCase

The srTestCase class provides the following methods:

method SetName

The SetName method is used to set the name of test case.

srWORD SetName(const srCHAR * szName)
Parameters Type Description
szName Input Pointer to null-terminated string representing the name of test case. Cannot be empty.


Return Value Description
srOK Success
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.
#include <srtest.h>

class srtest_class : public stride::srTest
{
public:
  void caseSetName()
  {
    testCase.SetName("Setting name for case");
  }
};

#ifdef _SCL
#pragma scl_test_class(srtest_class)
#endif
method SetDescription

The SetDescription method is used to set the description of test case.

srWORD SetDescription(const srCHAR * szDescr)
Parameters Type Description
szDescr Input Pointer to null-terminated string representing the description of test case. Cannot be empty.


Return Value Description
srOK Success
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.
#include <srtest.h>

class srtest_class : public stride::srTest
{
public:
  void caseSetDescription()
  {
    testCase.SetDescription("Setting description for case");
  }
};

#ifdef _SCL
#pragma scl_test_class(srtest_class)
#endif
method SetStatus

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

srWORD SetStatus(srTestStatus_e eStatus, srDWORD dwDuration = 0)
Parameters Type Description
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 (Optional) The duration of the test in clock ticks. The default is 0.


Return Value Description
srOK Success
srTEST_ERR_HANDLE_INVALID Invalid handle.
#include <srtest.h>

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

#ifdef _SCL
#pragma scl_test_class(srtest_class)
#endif
method AddComment

The AddComment method is used to add a comment to test case.

srWORD AddComment(const srCHAR * szFmtComment, ...)
Parameters Type Description
szFmtComment Input Pointer to null-terminated string, which can be formatted, representing the comment. Cannot be empty.
... Input (Optional) Variable argument list to format the comment szFmtComment.


Return Value Description
srOK Success
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.
#include <srtest.h>

class srtest_class : public stride::srTest
{
public:
  void caseAddComment()
  {
    testCase.AddComment("this comment should print %s", "A STRING");
  }
};

#ifdef _SCL
#pragma scl_test_class(srtest_class)
#endif
method AddAnnotation

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

srTestAnnotation AddAnnotation(srTestAnnotationLevel_e eLevel, const srCHAR * szName = srNULL, const srCHAR * szDescr = srNULL)
Parameters Type Description
eLevel Input Annotation level. Cannot be empty.
szName Input (Optional) Pointer to null-terminated string that represents the name of annotation. If empty, the default host naming scheme will be used.
szDescr Input (Optional) Pointer to null-terminated string that represents the description of annotation. If empty, the description will be blank.


Return Value Description
srTestAnnotation Newly created annotation class.
#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

class srTestAnnotation

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.

srWORD AddComment(const srCHAR * szLabel, const srCHAR * szFmtComment, ...)
Parameters Type Description
szLabel Input Pointer to null-terminated string for the label. If null, the default label will be applied.
szFmtComment Input Pointer to null-terminated string, which can be formatted, representing the comment. Cannot be empty.
... Input (Optional) Variable argument list to format the comment szFmtComment.


Return Value Description
srOK Success
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.
#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

Notes

  1. 1.0 1.1 1.2 1.3 1.4 1.5 The use of these functions in the context of any test method will cause the STRIDE Test Unit framework to delete the default test case that was created for the current test method since their use implies that dynamic test cases will be created. In addition, the use of the dynamic test case creation methods will cause the framework to interpret the srTEST_CASE_DEFAULT value as the most recently created test case.