Test Macros Sample: Difference between revisions

From STRIDE Wiki
Jump to navigation Jump to search
No edit summary
 
(11 intermediate revisions by 4 users not shown)
Line 1: Line 1:
==Introduction==
==Introduction==
The Test Macros Samples are part of the [[Test_Unit_Samples|STRIDE Test Unit Samples]].
== Building and Running the Samples ==
Please refer to the section appropriate for your target build environment:


*[[Building and Running Test Unit Samples Under Windows| Windows Off-Target]]  
These examples cover simple uses of each of the [[Test Macros]]. The names of the test methods contain either ''Pass'' or ''Fail''. All methods containing ''Fail'' illustrates uses of test macros that result in failures. Methods containing ''Pass'' illustrate passing uses. While these examples use [[Test_Units#Test__Unit_Packaging| Test Class packaging]], these macros works basically the same within c compilation units.


*[[Building and Running Test Unit Samples Under Linux|Linux]]
==Tests Description==


*[[Building and Running Test Unit Samples Under WinMobile|WinMobile]]
===Bool===


==Sample Test Macros==
This example demonstrates uses of the [[Test Macros#Boolean_Macros|''srEXPECT_TRUE()'' and ''srEXPECT_FALSE()'']] test class macros.


Once you have built the target application and executed the tests it contains, you can take time to peruse the test macros source and the corresponding results that each produces.  This section provides a brief description for each.
===Comparison===


''NOTE:'' For all C++ test versions, each of the example test classes is grouped in the ''Basic'' namespace.  This is for organizational purposes only -- it is '''not''' a general requirement that test classes be placed into namespaces.  
This example demonstrates uses of the [[Test Macros#Comparison_Macros|''srEXPECT_EQ()'', ''srEXPECT_NE()'', ''srEXPECT_GT()'', ''srEXPECT_GE()'', ''srEXPECT_LT()'' and ''srEXPECT_LE()'']] macros.  


===Basic Examples===
===CString===


These examples cover simple uses of each of the macro families. The names of the test methods contain either ''Pass'' or ''Fail''. All methods containing ''Fail'' illustrates uses of test macros that result in failures. Methods containing ''Pass'' illustrate passing uses.  
This example demonstrates use of the C-string (zero terminated character sequence) macros [[Test Macros#C_String_Comparison_Macros|''srEXPECT_STREQ()'', ''srEXPECT_STRNE(''), ''srEXPECT_STRCASEEQ()'' and ''srEXPECT_STRCASENE()'']].  


====01_01_Basic_ExpectBool====
===FloatingPointComparison===


This example demonstrates uses of the [[Test_Units#Boolean_Macros|''srEXPECT_TRUE()'' and ''srEXPECT_FALSE()'']] test class macros.  
This example demonstrates use of the macro used to test equality (or near equality) of floating point values [[Test Macros#Floating_Point_Comparison_Macros|''srEXPECT_NEAR()'']].


====01_02_Basic_Comparison====
===Predicates===


This example demonstrates uses of the [[Test_Units#Comparison_Macros|''srEXPECT_EQ()'', ''srEXPECT_NE()'', ''srEXPECT_GT()'', ''srEXPECT_GE()'', ''srEXPECT_LT()'' and ''srEXPECT_LE()'']] macros.  
This example demonstrates use of the predicate based macros [[Test Macros#Predicate_Macros|''srEXPECT_PRED<n>()'']].


====01_03_Basic_CString====
===Note===
TBD


This example demonstrates use of the C-string (zero terminated character sequence) macros [[Test_Units#C_String_Comparison_Macros|''srEXPECT_STREQ()'', ''srEXPECT_STRNE(''), ''srEXPECT_STRCASEEQ()'' and ''srEXPECT_STRCASENE()'']].
===Assert===


====01_04_Basic_Exceptions====
This example illustrates the use of the [[Test Macros#General_Guidelines_for_Test_Macros|assertion macros]] (''srASSERT_xx'') which, in contrast to the [[Test Macros#General_Guidelines_for_Test_Macros|expectation macros]] (''srEXPECT_xx''), cause the rest of the test case code to be bypassed.


This example demonstrates use of the exception verification macros [[Test_Units#Exception_Macros|''srEXPECT_THROW()'', ''srEXPECT_THROW_ANY()'' and ''srEXPECT_NO_THROW()'']]. Note there is only C++ implementation for this test.
===ExitUnit===
TBD


====01_05_Basic_Predicates====
===ExitUnitFixture===
TBD


This example demonstrates use of the predicate based macros [[Test_Units#Predicate_Macros|''srEXPECT_PRED<n>()'']].
===ExitUnitConstructor===
TBD


====01_06_Basic_FloatingPt====
===Exceptions===


This example demonstrates use of the macro used to test equality (or near equality) of floating point values [[Test_Units#Floating_Point_Macros|''srEXPECT_NEAR()'']].
This example demonstrates use of the exception verification macros [[Test Macros#Exception_Macros|''srEXPECT_THROW()'', ''srEXPECT_THROW_ANY()'' and ''srEXPECT_NO_THROW()'']]. Note there is only C++ implementation for this test.


====01_07_Basic_Assert====
This example illustrates the use of the [[Test_Units#General_guidelines_for_all_macros|assertion macros]] (''srASSERT_xx'') which, in contrast to the [[Test_Units#General_guidelines_for_all_macros|expectation macros]] (''srEXPECT_xx''), cause the rest of the test case code to be bypassed.
====01_08_Basic_Log====
This example illustrates the use of the [[Test_Units#Log_Macros|logging macros]] (''srLOG_xx'').
==Test Macros Execution==
This sample demonstrates two different techniques for executing test macros.
===Command Line Execution===
Command line execution for test macros is done using the [[Test_Runners#TestUnitRun.pl|TestUnitRun utility]].  Here are several examples of specific syntax to execute test macros.  All of these commands can be invoked from a standard [http://en.wikipedia.org/wiki/Command_Prompt_(Windows) command shell] (or other shell of your choosing) and the arguments shown assume that the commands are executed with the sample's directory as the starting directory. You must have your TestMacros.exe application running in order for the runner to be able to initiate a connection to the target simulator. In addition, you should verify that your %STRIDE_DIR%\bin\transport.cfg file is using the TCP transport to connect to port 8000 (these are the default settings when the product is installed).
====Simple execution of all test units====
The following command executes all of the test units found in the STRIDE database you have previously generated.  For the purpose of this sample, since there is only one database, the -d parameter is not strictly needed, but it is shown here for completeness.
  TestUnitRun.pl -d TestMacros.sidb
This command executes all Test Units found in the database in descending alpha-numeric sort order.  Any Test Macros initialization arguments are given default values (typically zero or NULL).
When you run this command, you should see console output like:
  Attempting connection using [Sockets (S2)] transport ...
  Connected to device.
  Initializing STRIDE database objects...
  Done.
  Running Test Basic::Assert...
  Running Test Basic::CString...
  Running Test Basic::Comparison...
  Running Test Basic::Exceptions...
  Running Test Basic::ExpectBool...
  Running Test Basic::FloatingPt...
  Running Test Basic::Log...
  Running Test Basic::Predicates...
  Running Test Basic_Assert...
  Running Test Basic_CString...
  Running Test Basic_Comparison...
  Running Test Basic_ExpectBool...
  Running Test Basic_FloatingPt...
  Running Test Basic_Log...
  Running Test Basic_Predicates...
  Disconnected from device.
  Test Results saved to C:\STRIDE\Samples\TestUnits\TestMacros\TestMacros.xml
  Test Report saved to C:\STRIDE\Samples\TestUnits\TestMacros\TestMacros.html
  ***************************************************************************
  Results Summary
  ***************************************************************************
    Passed:              19
    Failed:              15
    In Progress:          0
    Not Applicable:      0
    ...in 15 suites.
  ***************************************************************************
===Workspace-based Execution===
TestMacros.ssw, a workspace in the TestMacros directory, demonstrates the use of script execution with Studio to manage test order and hierarchy.  This workspace was created using [[WorkspaceSetup.pl]].  The setup and teardown folders provide basic infrastructure scripts that start/stop the simulator application (TestMacros.exe) and to manage traceviews used for [[Runtime_Reference#Logging_Services|srPrint]] message collection.  The scripts that drive the testing are in the workspace '''test''' folder. What follows is a brief description for each.
====RunAll====
This folder contains a script, All.js, that iterates through the entire collection of test units and executes them one at a time. The order of execution will be in ascending alphabetical order (by name) since the [[AutoScript#ascript.TestUnits|ArrangeBy]] collection method was called.
====Run Individual====
This folder shows how to use individual scripts to execute test classes. Each script has the following form:
  ascript.TestUnits.Item('''TEST_MACRO_NAME''').Run();
The '''TEST_MACRO_NAME''' is the name of the scl_test_macro test to be run.  The order and hierarchy of each item may be changed via the Studio tree control by moving the item within the scripts and/or folders. The sample contains individual scripts for a few of the sample scl_test_macro tests - you are free to move, add, or delete any items as you experiment with the workspace.


[[Category: Samples]]
[[Category: Samples]]

Latest revision as of 23:49, 6 June 2011

Introduction

These examples cover simple uses of each of the Test Macros. The names of the test methods contain either Pass or Fail. All methods containing Fail illustrates uses of test macros that result in failures. Methods containing Pass illustrate passing uses. While these examples use Test Class packaging, these macros works basically the same within c compilation units.

Tests Description

Bool

This example demonstrates uses of the srEXPECT_TRUE() and srEXPECT_FALSE() test class macros.

Comparison

This example demonstrates uses of the srEXPECT_EQ(), srEXPECT_NE(), srEXPECT_GT(), srEXPECT_GE(), srEXPECT_LT() and srEXPECT_LE() macros.

CString

This example demonstrates use of the C-string (zero terminated character sequence) macros srEXPECT_STREQ(), srEXPECT_STRNE(), srEXPECT_STRCASEEQ() and srEXPECT_STRCASENE().

FloatingPointComparison

This example demonstrates use of the macro used to test equality (or near equality) of floating point values srEXPECT_NEAR().

Predicates

This example demonstrates use of the predicate based macros srEXPECT_PRED<n>().

Note

TBD

Assert

This example illustrates the use of the assertion macros (srASSERT_xx) which, in contrast to the expectation macros (srEXPECT_xx), cause the rest of the test case code to be bypassed.

ExitUnit

TBD

ExitUnitFixture

TBD

ExitUnitConstructor

TBD

Exceptions

This example demonstrates use of the exception verification macros srEXPECT_THROW(), srEXPECT_THROW_ANY() and srEXPECT_NO_THROW(). Note there is only C++ implementation for this test.