Difference between revisions of "Scl test cclass"

From STRIDE Wiki
Jump to: navigation, search
(Examples)
(Notes)
 
(37 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
= The scl_test_cclass pragma =
 
= The scl_test_cclass pragma =
  
The scl_test_cclass pragma declares a "C" struct to captured as a test unit. Once captured, STRIDE will generate the appropriate code for executing the test methods in the class.
+
The ''scl_test_cclass'' pragma is one of the [[SCL_Pragmas#Test_Units|Test Unit]] pragmas. It declares a "C" language struct (class) to be captured as a test unit. Once captured, STRIDE will generate the appropriate code for executing test methods defined for this "C" Class. It is up to the user to specify actual test method code to be executed.
  
 
== Syntax ==
 
== Syntax ==
  
  #pragma scl_test_cclass(cclass-name, init-function-name)
+
  #pragma scl_test_cclass(cclass-name, init-function-name { , deinit-function-name })
  
 
{| border="1" cellspacing="0" cellpadding="10" style="align:left;"   
 
{| border="1" cellspacing="0" cellpadding="10" style="align:left;"   
| '''Parameters'''
+
| width="180" | '''Parameters'''
| '''Type'''
+
| width="60" | '''Type'''
 
| '''Description'''
 
| '''Description'''
 
|-
 
|-
 
| ''cclass-name''
 
| ''cclass-name''
| Object
+
| Identifier
| The name of the test struct (can be a class in C++) to be captured.
+
| The name of the test unit. This is must be the name of an existing struct in C/C++ or a class in C++.
 
|-
 
|-
 
| ''init-function-name''
 
| ''init-function-name''
| Object
+
| Identifier
| The initialization function name.
+
| The initialization function name. This is synonymous with a class constructor. There must be a prior user-declared function with this name. The first parameter must be a pointer to cclass-name. Additional parameters are left up to the user's implementation.
 +
|-
 +
| ''deinit-function-name (optional)''
 +
| Identifier
 +
| The deinitialization function name. This is synonymous with a class destructor. If declared, there must be a user-declared function with this name. The first parameter must be a pointer to cclass-name. Additional parameters are left up to the user's implementation.
 
|}
 
|}
  
 
== Notes ==
 
== Notes ==
* The test C class identified must:
+
* The cclass-name identified:
** Have a public constructor.
+
** may not appear as a specifier of a prior pragma.
** The constructor may have parameters, but they must all be POD type.
+
** must be a struct in C.
** Have one or more member functions that suitable as a test method. For a member function to be a test method it must:
+
** must be either a struct or class in C++.
*** be declared within the test class (method not declared, but inherited from a base class cannot be test methods)
+
** must be [http://en.wikipedia.org/wiki/Plain_Old_Data_Structures POD] type.
*** have a return type of bool, an integral type (signed or unsigned long, int, short, char) or void.
+
** must not be a template class.
*** have an empty parameter list. That is, declared as f() or f(void).
+
** must not be a nested class.
*** not be a templatized function
+
** must contain at least one member function pointer with a prototype that:
*** not be an overloaded operator
+
*** returns integral type: void, int, or bool (bool accepted only for C++).  
*** The class cannot be a pure virtual class
+
*** has a first parameter that is a pointer to cclass-name.
*** not be a static member.
+
 
** Cannot be a templated class.
+
* The init-function-name identified:
** Cannot be a nested class.
+
** must be declared prior to this pragma's declaration.
* This pragma can only work in STRIDE version 2.1 or later.
+
** must not have been used in any prior or subsequent SCL pragma.
* The host PC must also have a recent distribution of ActiveState Perl installed.
+
** must have its first parameter declared as a pointer to the identified cclass.
 +
** optionally if desired it may have additional parameters (they must all be of [http://en.wikipedia.org/wiki/Null-terminated_string C-string] and numeric types). For which concrete values could be specified when [[Stride_Runner#Input|running]] the test unit.
 +
 
 +
* The deinit-function-name:
 +
** is optional.
 +
** must be declared prior to this pragma's declaration if it appears in pragma.
 +
** must not have been used in any prior or subsequent SCL pragma.
 +
** must have its first parameter declared as a pointer to the identified class.
 +
 
 +
* Optionally if desired a set of [[scl_test_setup|setup]]/[[scl_test_teardown|teardown]] fixtures could be applied.
  
 
== Examples ==
 
== Examples ==
 +
<source lang=c>
 +
#include <srtest.h>
  
    #include <srtest.h>
+
typedef struct CClass_Basic_Simple {
    typedef struct CClass_Basic_Simple {
+
  int  (*pf_TestMethod)(struct CClass_Basic_Simple* pcc);
        int  (*pf_TestMethod)(struct CClass_Basic_Simple* pcc);
+
} CClass_Basic_Simple;
    } CClass_Basic_Simple;
+
 
    #ifdef __cplusplus
+
#ifdef __cplusplus
    extern "C" {
+
extern "C" {
    #endif
+
#endif
    void CClass_Basic_Simple_init(struct CClass_Basic_Simple* pcc);
+
void CClass_Basic_Simple_init(struct CClass_Basic_Simple* pcc);
    #ifdef __cplusplus
+
#ifdef __cplusplus
    }
+
}
    #endif
+
#endif
    #ifdef _SCL
+
 
    #pragma scl_test_cclass(CClass_Basic_Simple, CClass_Basic_Simple_init)
+
#ifdef _SCL
    #endif
+
#pragma scl_test_cclass(CClass_Basic_Simple, CClass_Basic_Simple_init)
 +
#endif
 +
</source>
  
 
== See Also ==
 
== See Also ==
* Refer to the [[Test_CClass_Sample]] page for more information on capturing and qualifying test "C" classes.
+
* Refer to the [[Test_CClass_Samples|Test "C" Class Samples]] page for more information on capturing and qualifying test "C" classes.
 
 
  
[[Category: SCL_Reference]]
+
[[Category: Test Units]]
 +
[[Category: SCL]]

Latest revision as of 01:14, 30 November 2014

The scl_test_cclass pragma

The scl_test_cclass pragma is one of the Test Unit pragmas. It declares a "C" language struct (class) to be captured as a test unit. Once captured, STRIDE will generate the appropriate code for executing test methods defined for this "C" Class. It is up to the user to specify actual test method code to be executed.

Syntax

#pragma scl_test_cclass(cclass-name, init-function-name { , deinit-function-name })
Parameters Type Description
cclass-name Identifier The name of the test unit. This is must be the name of an existing struct in C/C++ or a class in C++.
init-function-name Identifier The initialization function name. This is synonymous with a class constructor. There must be a prior user-declared function with this name. The first parameter must be a pointer to cclass-name. Additional parameters are left up to the user's implementation.
deinit-function-name (optional) Identifier The deinitialization function name. This is synonymous with a class destructor. If declared, there must be a user-declared function with this name. The first parameter must be a pointer to cclass-name. Additional parameters are left up to the user's implementation.

Notes

  • The cclass-name identified:
    • may not appear as a specifier of a prior pragma.
    • must be a struct in C.
    • must be either a struct or class in C++.
    • must be POD type.
    • must not be a template class.
    • must not be a nested class.
    • must contain at least one member function pointer with a prototype that:
      • returns integral type: void, int, or bool (bool accepted only for C++).
      • has a first parameter that is a pointer to cclass-name.
  • The init-function-name identified:
    • must be declared prior to this pragma's declaration.
    • must not have been used in any prior or subsequent SCL pragma.
    • must have its first parameter declared as a pointer to the identified cclass.
    • optionally if desired it may have additional parameters (they must all be of C-string and numeric types). For which concrete values could be specified when running the test unit.
  • The deinit-function-name:
    • is optional.
    • must be declared prior to this pragma's declaration if it appears in pragma.
    • must not have been used in any prior or subsequent SCL pragma.
    • must have its first parameter declared as a pointer to the identified class.
  • Optionally if desired a set of setup/teardown fixtures could be applied.

Examples

#include <srtest.h>

typedef struct CClass_Basic_Simple {
  int   (*pf_TestMethod)(struct CClass_Basic_Simple* pcc);
} CClass_Basic_Simple;

#ifdef __cplusplus
extern "C" {
#endif
void CClass_Basic_Simple_init(struct CClass_Basic_Simple* pcc);
#ifdef __cplusplus
}
#endif

#ifdef _SCL
#pragma scl_test_cclass(CClass_Basic_Simple, CClass_Basic_Simple_init)
#endif

See Also