Difference between revisions of "Scl test class"

From STRIDE Wiki
Jump to: navigation, search
(Notes)
(Notes)
 
(15 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
= The scl_test_class pragma =
 
= The scl_test_class pragma =
  
The scl_test_class pragma is one of the [[SCL_Pragmas#Test_Units|Test Unit]] pragmas. It declares a test class as captured. Once captured, STRIDE will generate the appropriate code for executing the test methods in the class.
+
The ''scl_test_class'' pragma is one of the [[SCL_Pragmas#Test_Units|Test Unit]] pragmas. It declares a test class as captured. Once captured, the STRIDE compiler will generate the appropriate code in the Intercept Module (IM) for instantiating the class and executing its test methods.
  
 
== Syntax ==
 
== Syntax ==
Line 13: Line 13:
 
|-
 
|-
 
| ''class-name''
 
| ''class-name''
| String
+
| Identifier
| The name of the test class to be captured. Once captured, STRIDE will generate the appropriate code for executing the test methods in the class.
+
| The name of the test unit. This is must be the name of an existing C++ class or a struct.
 
|}
 
|}
  
 
== Notes ==
 
== Notes ==
 
* This pragma requires the compilation language to be C++. If the compilation language is not C++ and this pragma is encountered, then an error is issued and this pragma is ignored.
 
* This pragma requires the compilation language to be C++. If the compilation language is not C++ and this pragma is encountered, then an error is issued and this pragma is ignored.
* The test class identified must:
+
 
** Have a public constructor.
+
* The test class identified:
** The constructor may have parameters, but they must all be [http://en.wikipedia.org/wiki/Plain_Old_Data_Structures POD] type.
+
** must have single public constructor - default or explicit.
** Have one or more member functions that suitable as a test method. For a member function to be a test method it must:
+
** must not be a templated class
*** be declared within the test class (method not declared, but inherited from a base class cannot be test methods)
+
** must not be a nested class
*** have a return type of bool, an integral type (signed or unsigned long, int, short, char) or void.
+
** must not be a pure virtual class
*** have an empty parameter list. That is, declared as f() or f(void).
+
** must have one or more member functions that is suitable as a test method. For a member function to be a test method it:
*** not be a templatized function
+
*** must be declared within the test class (a method that is inherited from a base class cannot be a test method)
*** not be an overloaded operator
+
*** must be declared with public access
*** The class cannot be a pure virtual class
+
*** must have a return type of bool, an integral type (signed or unsigned long, int, short, char) or void.
*** not be a static member.
+
*** must have an empty parameter list - declared as f() or f(void).
** Cannot be a templated class.
+
*** must not be a templatized function
** Cannot be a nested class.
+
*** must not be an overloaded operator
* This pragma can only work in STRIDE version 2.1 or later.
+
*** must not be a static member.
* The host PC must also have a recent distribution of ActiveState Perl installed.
+
 
 +
* Optionally if desired a set of [[scl_test_setup|setup]]/[[scl_test_teardown|teardown]] fixtures could be applied.
 +
 
 +
* Optionally if desired the public constructor may have arguments (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.
  
 
== Examples ==
 
== Examples ==
Line 39: Line 42:
 
#include <srtest.h>
 
#include <srtest.h>
  
class RuntimeServices_dynamic {
+
class RuntimeServices_dynamic  
 +
{
 
public:
 
public:
  void dynamic(void);
 
   
 
 
   // Declaring a constructor for an scl_test_class is optional, but
 
   // Declaring a constructor for an scl_test_class is optional, but
   // if a constructor is declared all parameters must be of plain old data (POD) type.
+
   // if a constructor is declared all arguments must be of plain old data (POD) type.
  // An scl_test_class-specified class may only have one explicit public constructor.
+
   RuntimeServices_dynamic(int i, const char* s);
  // Declaration of this constructor results in IM synthesization of a function
+
 
  // that initializes the test unit. The constructor parameters become parameters of
+
  void dynamic();
  // the synthesized test unit.
 
   RuntimeServices_dynamic(int i, int j, int k);
 
 
};
 
};
 
      
 
      
Line 58: Line 58:
  
 
== See Also ==
 
== See Also ==
* Refer to the [[Test Class Sample]] page for more information on capturing and qualifying test classes.
+
* Refer to the [[Test Class Samples]] page for more information on capturing and qualifying test classes.
  
 
[[Category: Test Units]]
 
[[Category: Test Units]]
 
[[Category: SCL]]
 
[[Category: SCL]]

Latest revision as of 00:57, 30 November 2014

The scl_test_class pragma

The scl_test_class pragma is one of the Test Unit pragmas. It declares a test class as captured. Once captured, the STRIDE compiler will generate the appropriate code in the Intercept Module (IM) for instantiating the class and executing its test methods.

Syntax

#pragma scl_test_class(class-name)
Parameters Type Description
class-name Identifier The name of the test unit. This is must be the name of an existing C++ class or a struct.

Notes

  • This pragma requires the compilation language to be C++. If the compilation language is not C++ and this pragma is encountered, then an error is issued and this pragma is ignored.
  • The test class identified:
    • must have single public constructor - default or explicit.
    • must not be a templated class
    • must not be a nested class
    • must not be a pure virtual class
    • must have one or more member functions that is suitable as a test method. For a member function to be a test method it:
      • must be declared within the test class (a method that is inherited from a base class cannot be a test method)
      • must be declared with public access
      • must have a return type of bool, an integral type (signed or unsigned long, int, short, char) or void.
      • must have an empty parameter list - declared as f() or f(void).
      • must not be a templatized function
      • must not be an overloaded operator
      • must not be a static member.
  • Optionally if desired a set of setup/teardown fixtures could be applied.
  • Optionally if desired the public constructor may have arguments (they must all be of C-string and numeric types). For which concrete values could be specified when running the test unit.

Examples

#include <srtest.h>

class RuntimeServices_dynamic 
{
public:
  // Declaring a constructor for an scl_test_class is optional, but
  // if a constructor is declared all arguments must be of plain old data (POD) type.
  RuntimeServices_dynamic(int i, const char* s);

  void dynamic();
};
    
#ifdef _SCL
#pragma scl_test_class(RuntimeServices_dynamic)
#endif

See Also

  • Refer to the Test Class Samples page for more information on capturing and qualifying test classes.