Vcast Interactive Tutorials PDF
Vcast Interactive Tutorials PDF
Vcast Interactive Tutorials PDF
Version 6.4
New editions of this guide incorporate all material added or changed since the previous edition.
Update packages may be used between editions. The manual printing date changes when a new
edition is printed. The contents and format of this manual are subject to change without notice.
Rev: cb0043d
© Copyright 2017, Vector Software, Inc. All rights reserved. No part of the material protected by
this copyright notice may be reproduced or utilized in any form or by any means, electronic or
mechanical, including photocopying, recording, or by any informational storage and retrieval
system, without written permission from the copyright owner.
This computer software and related documentation are provided with Restricted Rights. Use,
duplication or disclosure by the Government is subject to restrictions as set forth in the
governing Rights in Technical Data and Computer Software clause of
Vector Software reserves the right to make changes in specifications and other information
contained in this document without prior notice. Contact Vector Software to determine whether
such changes have been made.
2
Table of Contents
INSTALLATION 8
Introduction 9
Summary of the Installation Process 9
Platforms 9
Installing VectorCAST (UNIX) 9
Step 1: Install VectorCAST on License Server 10
Step 2: Request a License Key 10
Step 3: Install the License Key 11
Step 4: Start/Stop the License Server 12
Step 5: Install VectorCAST on Clients 12
Installing VectorCAST (64-bit Linux) 13
Step 1: Identify Missing Libraries 13
Step 2: Install Missing Libraries 14
Troubleshooting 15
Installing VectorCAST (Windows) 15
Step 1: Install VectorCAST 15
Existing Installed Instances Detected 17
Step 2: Request a License Key 19
Step 3: Install the License Key 20
Step 4: Start the License Server 21
Upgrading VectorCAST 23
Installing VectorCAST Automatically 24
INTRODUCTION 25
Starting VectorCAST 26
The Welcome Page 28
To Create the Tutorials Using the Welcome Page 29
Importing Examples into the Welcome Page 29
VectorCAST Overview 31
VectorCAST Automation 32
VectorCAST Components 32
VectorCAST/Cover Overview 33
Testing Overview 34
Key Terminology 34
Key Concepts 36
Tutorial Overview 38
Example Environments 38
After the Tutorials 39
3
C TUTORIALS 41
Introduction 42
Basic Tutorial 42
What You Will Accomplish 42
Preparing to Run the Tutorial 42
Building a Test Environment 43
Building Test Cases 58
Controlling Values Returned from Stubs 62
Adding Expected Results to the Test Case 64
Executing Test Cases 68
Generating Test Reports 70
Analyzing Code Coverage 71
Generating Coverage Reports 74
Using Stub-By-Function 76
Creating Regression Scripts 83
Tutorial Summary 84
Troubleshooting 84
Multiple UUT Tutorial 88
What You Will Accomplish 88
Building a Multiple UUT Environment 88
Building a Compound Test Case 91
Adding Test Iterations for Fuller Coverage 101
Adding Test Cases to a Compound Test 106
Exporting a Test Script 110
Tutorial Summary 110
Introduction 112
Basic Tutorial 112
What You Will Accomplish 112
Preparing to Run the Tutorial 112
Building an Executable Test Environment 113
Building Test Cases 129
Controlling Values Returned from Stubs 134
Adding Expected Results to the Test Case 136
Executing Test Cases 142
Instantiating a Class Instance 142
Generating Test Reports 145
Analyzing Code Coverage 146
Generating and Managing Coverage Reports 150
Using Stub-By-Function 152
Creating Regression Scripts 159
Tutorial Summary 160
Troubleshooting 160
Multiple UUT Tutorial 164
4
What You Will Accomplish 164
Building a Multi UUT Environment 165
Building a Compound Test Case 168
Adding Test Iterations for Fuller Coverage 180
Adding Test Cases to a Compound Test 185
Exporting a Test Script 189
Tutorial Summary 189
Introduction 191
Basic Tutorial 191
What You Will Accomplish 191
Preparing to Run the Tutorial 191
Building an Executable Test Environment 192
Building Test Cases 201
Controlling Values Returned from Stubs 206
Adding Expected Results to the Test Case 208
Executing Test Cases 212
Generating and Managing Test Reports 214
Analyzing Code Coverage 215
Generating and Managing Coverage Reports 218
Creating Regression Scripts 220
Tutorial Summary 222
Troubleshooting 222
Multiple UUT Tutorial 225
What You Will Accomplish 225
Building a Multi UUT Environment 226
Building a Compound Test Case 229
Adding Test Iterations for Fuller Coverage 239
Adding Test Cases to a Compound Test Case 243
Exporting a Test Script 247
Tutorial Summary 247
Whitebox Tutorial 248
What You Will Accomplish 249
Building a Whitebox Test Environment 249
Creating a Test Case for a Hidden Subprogram 254
Tutorial Summary 256
Introduction 258
C++ Cover Tutorial 258
What You Will Accomplish 258
Creating a VectorCAST/Cover Environment 259
Building the Tutorial Application 262
Executing the Instrumented Program 265
5
Adding Test Results 266
View the Aggregate Coverage Report 269
View the Management Report 270
Tutorial Summary 273
Ada Cover Tutorial 273
What You Will Accomplish 274
Creating a VectorCAST/Cover Environment 274
Building the Tutorial Application 278
Executing the Instrumented Program 281
Adding Test Results 282
View the Aggregate Coverage Report 284
View the Management Report 285
Tutorial Summary 288
Introduction 291
Integrating Lint 291
Preparing to Run the Tutorial 291
Build the Tutorial Environment 291
Using Lint to Analyze Source Code 293
Using VectorCAST/Lint’s MISRA Compliance Checking 296
Homework 299
Tutorial Summary 299
Integrating PRQA 300
Preparing to Run the Tutorial 300
Using QA•C++ to Analyze Source Code 300
Tutorial Summary 307
Introduction 309
How VectorCAST/Manage Works 309
Terminology 310
Creating a Manage Project 311
What You Will Accomplish 311
Preparing to Run the Tutorial 311
Setting Up the Source Files 311
Compile Source Code (Ada only) 313
Build the Environments 313
Using the Manage Project Wizard 313
The Project Tree 318
The Status Panel 319
Building and Executing the Environments 321
6
More About Data Sources 324
Modifying the Project 324
Tutorial Summary 330
Requirements 332
C 334
C++ 339
Ada 347
Build Settings 355
INDEX 361
7
Installation
INTRODUCTION 9
Introduction
The following sections will guide you through the process of installing the VectorCAST software and
obtaining a license key. During this process, you will need to fill out a Software License Key Request
form, which is available on the Vector Software Web site at http://www.vectorcast.com/services/license-
key-request.
VectorCAST uses FLEXlm™ as the license manager. A user guide for FLEXlm is shipped with
VectorCAST and can be found in the VectorCAST installation directory, under
docs/PDF/LicensingEndUserGuide.pdf.
Step 2: Use the Host Name and the Host ID of the License Server to request an evaluation or permanent
license key.
Step 5: Install the VectorCAST software on all clients and configure them to access the License Server.
These steps are described in detail below for your specific platforms.
Platforms
VectorCAST runs on the following platforms:
The License Server can be any platform (Steps 1-4); the VectorCAST client can be on any platform (Step
5).
The Vector Software website provides access to VectorCAST on all platforms. If you are installing
VectorCAST from the website, be sure you download the appropriate version for your platform.
Note: If your License Server is on a UNIX platform and your client is on a Windows platform,
you will need to follow the UNIX Installation Instructions for Steps 1-4 and the Windows
Installation Instructions for Step 5.
Note: If your organization already has a license key and you know its location, you can skip to
step 5.
INSTALLING VECTORCAST (UNIX) 10
With very large test environments, you might need to increase the process limit for STACKSIZE and for
DESCRIPTORS. For example:
cd /usr/local
mkdir vcast
chmod 755 vcast
cd vcast
3. Download the files from the Vector Software Web site. Enter:
gunzip vcast.platform.version.tar.gz
tar -xvf vcast.platform.version.tar.gz.
export VECTORCAST_DIR=/usr/local/vcast
Note: If you created a directory other than /usr/local/vcast as the installation directory, use
that path here.
$VECTORCAST_DIR/flexlm/lmutil hostid
lmutil - Copyright(c)1989-2015 Flexera Software LLC. All Rights Reserved.
The FLEXnet host ID of this machine is "f8b156b12ea3"
uname -a
Linux hostname ...
3. Use this information to fill out the License Key Request form (available on our web site at
http://www.vectorcast.com/services/license-key-request); then submit this form to Vector Software.
Save your license-key file (delivered as an e-mail attachment) to a location on the License Server.
The default location is /usr/local/flexlm/licenses/license.dat. VectorCAST looks
in this location for a license key first, by default.
If you save the license-key file to a different location, you must set the environment variable LM_
LICENSE_FILE to this location (use export or set).
For example, a typical license-key file looks like this:
In the example above, the name of the machine that is serving the license is birch, the HostID is
f8b156b12ea3, and the port is 7650. The path to the vector daemon is
/home/Users/flexlm/vector.
Modify the DAEMON line in the license-key file to point to the location of the vector vendor
daemon on the license server. For example,
$VECTORCAST_DIR/flexlm/lmgrd –c path_to_license_file
where path_to_license_file is usually /usr/local/flexlm/licenses/license.dat
$VECTORCAST_DIR/flexlm/lmutil lmstat
lmutil - Copyright (c) 1989-2015 Flexera Software LLC. All Rights Reserved.
Flexible License Manager status on Thu 10/15/2015 09:10
License server status: 1234@birch
License file(s) on birch: /home/USERS/licenses/birch.lic:
alder: license server UP (MASTER) v11.13.1
Vendor daemon status (on birch):
vector: UP v11.13.1
Note: If you are already using FLEXlm for VectorCAST and receive a new license, you will need
to replace the previous license with the new one and stop and re-start the license server.
For example, if the VectorCAST installation directory on the server is mounted on the client by way of
NFS, and the location is /share/vcast, you set VECTORCAST_DIR to point to that directory as follows:
export VECTORCAST_DIR=/share/vcast
You then set LM_LICENSE_FILE to port@server, where port is the port number in the VectorCAST
license file (the default port is 7650), and server is the Host Name of the License Server. For example:
export LM_LICENSE_FILE=7650@HostName
If your organization has more than one application using FLEXlm as the license manager, you may find it
easier to set the environment variable VECTOR_LICENSE_FILE instead of LM_LICENSE_FILE. Using
VECTOR_LICENSE_FILE enables FLEXlm to find the Vector vendor daemon quickly, without searching
through the list specified for LM_LICENSE_FILE.
When you have installed VectorCAST and your license key, we highly recommend that you select and
run the relevant Tutorials in this guide. These tutorials will quickly get you up and running using
VectorCAST’s powerful functionality to automate the entire testing process.
At minimum, the 32-bit libc.so.6 and auxiliary libraries (collectively referred to as C run time) must be
installed.
Such an error indicates that a dependency which enables you to run VectorCAST is missing from your
system. The remainder of this section covers how to resolve these dependencies.
Enter the following to get the absolute path of the 64-bit C run time:
Run one of the following commands to return the 64-bit package used to install the 64-bit C run time:
(Debian/Ubuntu)
dpkg -S /path/to/libc.so.6
INSTALLING VECTORCAST (64-BIT LINUX) 14
(Debian/Ubuntu)
sudo apt-get install <package>:i386
VectorCAST will attempt to run but will fail because there are other missing 32-bit libraries. Since the C
run time is available, a message should appear at invocation identifying which libraries are missing.
Note that after installing libc6 on your distribution, it is possible that lmgrd will not run. It is
recommended that you install the lsb package for your platform (lsb for Ubuntu, redhat-lsb for Red
Hat-based platforms) and then enter the following command:
ln -s /lib/ld-linux.so.2 /lib/ld-lsb.so.3
Packages may be installed via apt-get install <pkgname>.This section assumes that you have the
apt-get package installed.
Enter the following command to find the location of the 64-bit version of the library:
For our example, we will assume that our missing library is libXrender.so.1.
dpkg -S /usr/lib/x86_64-linux-gnu/libXrender.so.1
This will give us the 64-bit package, and the package name should come back as libxrender1:amd64.
The 32-bit package we want to install is libxrender1:i386.
This section assumes that the package management tool yum is provided.
Enter the following command to find the package containing the missing library:
For our example, we will assume that our missing library is libpng12.so.0, so we run the following
command:
Repo : @rhel-7-server-rpms
Matched from:
Filename : /usr/lib/libpng12.so.0
Troubleshooting
Error messages indicating that an appropriate hash method cannot be found are due to the VectorCAST
supplied library libssl.so.6, which is required by Python's _hashlib.so module.
This will identify the missing libraries. Follow the steps as outlined above to find out which packages
provide these libraries and install them. You may need to install more than one package.
To install VectorCAST on a Windows platform, first log onto the computer as Administrator, then
perform the following steps:
INSTALLING VECTORCAST (WINDOWS) 16
Note: The directory path you use must not include spaces. Also, the directory path must not
contain an instance of VectorCAST. If you wish to reuse a directory path, VectorCAST must
first be removed. See "Existing Installed Instances Detected" on page 17.
6. Click Next.
VectorCAST begins installing the licensed software.
7. When the files finish copying, VectorCAST looks for a license file. If a license is detected, go to
step 11. If no license is detected, the License Setup dialog appears:
8. Select either 'I will browse for an existing license file' or 'I know the name of my license server'.
If you do not have a license key yet, select 'I would like to request a license key'. This action opens
INSTALLING VECTORCAST (WINDOWS) 17
Enter the address of the FLEXlm license server. Enter this address in the format: port@server.
The default port on a Windows License Server is 27000; the default port on a UNIX License Server
is 7650.
10. Click Next.
11. Click the Finish button to complete the installation.
VectorCAST sets environment variable VECTORCAST_DIR to the installation directory you specified,
and the VECTOR_LICENSE_FILE environment variable to the port@server address you specified.
If you select Install a new instance of this application, follow the installation steps in the section above
to complete the new installation. You will be notified that VECTORCAST_DIR will be modified for the
new directory path. Click Yes to accept the change, or No and the VECTORCAST_DIR will be left
unchanged.
If you select Maintain or update the instance of this application selected below, click an instance in the
list to select the instance to be maintained or updated.
l Modify – this selection allows you to add or remove features for the selected program instance.
l Repair – this selection re-installs all the features for the selected program instance.
l Remove – this selection removes all installed features of the selected program instance.
1. From the Windows Start menu, select All Programs => VectorCAST => FLEXlm =>
LMTools.
INSTALLING VECTORCAST (WINDOWS) 20
1. Save the license-key file (delivered as an e-mail attachment) to a location on the License Server.
The default location is C:\FLEXlm\license.dat. VectorCAST looks in this location for a license
key first, by default.
If you save the license-key file to a different location, you must set the environment variable LM_
LICENSE_FILE to this location. (From the Control Panel, select System and Security => System
=> Advanced System Settings and select the Environment Variables button from the Advanced
tab on the System Properties dialog.
For example, a typical license-key file looks like this:
In this example, the Host name of the machine that is serving the license is hypatia, the HostID is
B8CA3AB69B62, and the license is being served from port 27000. The path to the vector daemon
is C:\VCAST\flexlm\vector.
2. If necessary, modify the DAEMON line in the license-key file to point to the location of the
vector.exe vendor daemon on the license server. For example:
1. From the Windows Start menu, select All Programs => VectorCAST => FLEXlm =>
LMTools.
INSTALLING VECTORCAST (WINDOWS) 22
The LMTools utility screen appears (refer to the screen shot in Step 2 below).
2. Click the Config Services tab. The following screen appears:
In the Service Name field, enter a new name, such as Vector License Server.
3. Use the Browse button associated with Path to the lmgrd.exe file to enter the full pathname
for lmgrd.exe.
By default, this file is located at C:\vcast\FLEXlm\.
If you installed VectorCAST in a different directory, use that path instead of C:\vcast.
4. Use the Browse button associated with Path to the license file to enter the full path name for
the VectorCAST license key (hostname.lic).
This file is located in the directory in which you stored it in "Step 3: Install the License Key"
on page 20.
5. In the Path to the debug log file field, enter the full pathname for a debug log file.
If this file does not exist, you must create it first.
6. Check the box preceding Use Services.
7. If you want the license server to start automatically when the server machine is rebooted, also
select Start Server at Power-Up.
8. Click the Save Service button (upper right), and confirm when asked.
9. Select the Start/Stop/Reread tab at the top of the screen:
UPGRADING VECTORCAST 23
Troubleshooting: If you experience any problems, please contact Technical Support at:
Phone: +1 401 398 7185
Email: support@vectorcast.com
For answers to frequently asked questions, and to access FLEXlm user help (the FlexNet License
Administration Guide), select:
Start => All Programs => VectorCAST => FLEXlm => Licensing User's Guide
Upgrading VectorCAST
Visit the download page of our web site at http://www.vectorcast.com/downloads to see if a new version
of VectorCAST has been released. By request, or if you have an outstanding problem report, your
organization is notified about new releases of VectorCAST. If you decide to upgrade your VectorCAST
installation, you should first determine if you will need to upgrade the FLEXnet licensing binaries.
l VectorCAST 5.1a and above requires that FLEXlm version 11.7 or above be used.
l VectorCAST 5.1h and above requires that FLEXlm version 11.9 or above be used.
l VectorCAST 6.4a and above requires that FLEXlm version 11.13.1 be used.
To determine the version of the FLEXlm license manager, enter in a Command Prompt:
Or, you can go to Windows Start => All Programs => VectorCAST => FLEXlm => LMTools and
select the Utilities tab. Browse for lmgrd.exe in the installation directory / FLEXlm directory. Click the
Find Version button to display the version number.
%VECTORCAST_DIR%\flexlm\lmutil lmstat
%VECTORCAST_DIR%\flexlm\lmutil lmdown -c path_to_old_license_file
3. Install the new version of VectorCAST, which will upgrade the FLEXlm binaries to version 11.13.1
(or greater).
4. Install the new license key (see"Step 3: Install the License Key" on page 20).
5. Restart the license server and check the status by entering:
%VECTORCAST_DIR%\flexlm\lmgrd –c path_to_new_license_file
%VECTORCAST_DIR%\flexlm\lmutil lmreread –c path_to_new_license_file
%VECTORCAST_DIR%\flexlm\lmutil lmstat
To instruct the VectorCAST installation program to install itself silently, follow these steps:
1. Run setup.exe -r from the command line to record the steps you want to use in a repeating fashion.
Note that the installation steps need to be repeatable, that is, you must install to the same directory
each time.
This process creates a file named setup.iss in the C:\Windows\system directory.
2. Move this file into the directory from which you install VectorCAST.
From then on, when you run setup.exe -s from the particular machine on which you want to install
VectorCAST, the installation process installs silently. It runs in the background, working its way
automatically through the prompts.
Introduction
STARTING VECTORCAST 26
Starting VectorCAST
Prior to starting VectorCAST, you should ensure that the VectorCAST is installed as specified by the
Windows or UNIX Installation instructions in Chapter 1 of VectorCAST Interactive Tutorials, and that
environment variable VECTORCAST_DIR is set to the installation directory.
UNIX
In UNIX or Cygwin, you start VectorCAST by entering:
$VECTORCAST_DIR/vcastqt
The compiler you are using must be included in your PATH environment variable. If it is not included,
modify your PATH environment variable with the set, setenv, or export command (as appropriate to your
shell), and then start VectorCAST from the same shell window.
Windows
In Windows, you can start VectorCAST from the Start menu or from a command line.
%VECTORCAST_DIR%\vcastqt
From the Windows Start menu, select Start => All Programs => VectorCAST => VectorCAST.
The compiler executables must be found in a directory specified on your PATH environment variable. You
can access your PATH environment variable by selecting the System icon on the Windows Control Panel.
If you start VectorCAST without specifying the location of the license file, a FLEXlm License Finder
dialog appears.
STARTING VECTORCAST 27
This dialog enables you to specify the path to the license file or the port@host from which the
VectorCAST license is served. When you click OK, the information entered is saved in the Windows
registry at location:
Note: If you do not want to modify the Windows registry, set the environment variable FLEXLM_
NO_CKOUT_INSTALL_LIC to 1.
If FLEXlm cannot find VECTOR_LICENSE_FILE in the Windows registry, it looks for LM_LICENSE_FILE.
If that is not defined in the registry, FLEXlm uses environment variables VECTOR_LICENSE_FILE and LM_
LICENSE_FILE, in that order.
Note: If you do not want FLEXlm to read the Windows registry to find the license file, set the
environment variable LM_APP_DISABLE_CACHE_READ to 1. Note that this environment variable
controls registry reading for all FLEXlm applications, not just VectorCAST.
To use one of the Microsoft Visual Studio compilers, select Start menu => All Programs =>
VectorCAST => VectorCAST for Visual Studio. Then select one of the compiler-version options under
VectorCAST for Visual Studio.
STARTING VECTORCAST 28
When you select a VectorCAST for Visual Studio option, the vcvars32.bat or vsvars32.bat file
automatically runs to ensure that the associated compiler is included in your PATH environment variable.
Select an example or tutorial and VectorCAST will automatically build the test environment, load the
example test cases and display an HTML overview of the tool features demonstrated in the example.
Note: Before starting the Manage Demo, you must build at least one C, C++ or ADA example.
This will provide a test environment for the Manage project.
Examples are imported from a .csv file as described below. For illustration the following file will be
created:
%VECTORCAST_DIR%\Examples\MyExamples.csv
STARTING VECTORCAST 30
This file contains a single line entry for each imported example.
l Column 1 specifies the language used for a VectorCAST environment or a dash (“-“) for a Manage
Project
l Ada
l C
l C++
l –
l Column 2 specifies the example type:
l UnitTest
l Cover
l Manage
l Column 3 specifies the relative path to the example’s .env or shell script. This path is relative to the
$VECTORCAST_DIR/Examples directory.
l Column 4 specifies a prefix to be appended to the README.html file (if one is available) when the
environment is built in %VECTORCAST_DIR\Examples\environments
l Column 5 specifies the category (Ada, C, C++, Cover or Manage) for the example and the name of
the example as it will appear on the Welcome page and in the Help => Environments context
menu.
l The format for this column is “CATEGORY -> NAME”.
After the changes are saved to MyExamples.csv, select Help => Import Examples … and using the file
chooser, select MyExamples.csv..
If the Welcome screen is currently open, close it. Open the Welcome screen by selecting Help =>
Welcome and then select Try out some Unit Testing Examples. The new example, called Example
Demo, appears as a choice in the C Examples column.
VECTORCAST OVERVIEW 31
Select Help => Example Environments => C, and the new “Example Demo” entry is available on the
context menu.
VectorCAST Overview
VectorCAST® is a suite of tools for automating the entire process associated with conducting unit and
integration testing:
VectorCAST Automation
You can use VectorCAST to conduct unit or integration testing on applications written in the C, C++, or
Ada programming languages. VectorCAST automates the following unit and integration test functions:
Three types of input data can affect the processing of a unit under test (UUT): (1) the input parameters to
the UUT; (2) the output parameters of dependent-unit subprograms (that is, the output of subprograms
invoked by the unit); and (3) global data objects. VectorCAST provides direct control over all three types
of data. It does this by automatically creating a unique test harness for each software unit to be tested.
VectorCAST Components
VectorCAST consists of four major functional components:
The Environment Builder parses the designated files and, from the information gathered, generates a
complete test harness.
Unlike a manually generated test harness, a VectorCAST test harness can be automatically regenerated
whenever changes are made to a UUT or stub included in the environment (for example, when a
subprogram is fully coded).
In addition, test cases can be added to an existing environment without any need for manual coding,
recompiling, etc.
Execution Manager
The Execution Manager invokes the test harness created by the Environment Builder, and executes the
test cases built by the Test Case Generator.
Report Generator
The Report Generator produces a variety of reports based on information maintained in every
environment database. This information includes:
VectorCAST/Cover Overview
VectorCAST/Cover is a code-coverage analysis tool that identifies which areas of an application have
been exercised by test executions. It supports Ada, C, and C++ modules in the same execution
environment, and supplements the unit coverage provided by VectorCAST/C++ and VectorCAST/Ada.
You can apply VectorCAST/Cover to particular parts of an application or to the entire application at
once. In addition, you can also import coverage data from VectorCAST, which includes a utility for
determining the coverage on one or more units.
VectorCAST/Cover adds instrumentation statements to the source files to be tested and analyzed. These
statements capture information about code coverage at the time of execution. You access this information
by generating reports based on a single execution or on multiple executions.
You can tailor the content and formatting of any coverage report to meet your specific needs.
Testing Overview
This section presents some terms and concepts you should be familiar with before you begin using the
VectorCAST tutorials.
Key Terminology
You should be familiar with the following terms before you begin using the tutorials:
Test Harness – A test harness is the executable program created when the test driver, the units under test,
and the dependent units or stubs of dependent units are linked together.
The test harness has three components:
TESTING OVERVIEW 35
Dependent Unit – A subprogram that contains a function called by a UUT, or data objects used by a
UUT. A dependent unit is either a C/C++ file that is included or an Ada package that is 'withed' by a
unit. Dependent units can be stubbed or used 'as is'.
Event – An event is a change in the flow of control that VectorCAST can monitor. Each of the following
is an event:
l A call from the test harness to a UUT
l A call from a UUT to a stubbed dependent in the test harness
l A return from a UUT to the test harness
Test Case – A collection of input and output data, defined with the purpose of exercising specific
software and verifying results. This data is commonly comprised of the formal input and output
parameters of the dependent subprograms, and input and output parameters of the subprogram under test.
The Test Data controls the execution of the unit under test as well as values for global objects visible in
the unit under test or stubbed subprograms.
Test Driver – VectorCAST generates the main program, or driver, necessary to exercise all visible
subprograms in all units under test. This consists of calls to each visible subprogram in a unit under test.
Search List (C/C++) / Parent Library (Ada) – The directory that contains the units under test and
dependent units. In C or C++ environments, the Search List can contain multiple directories; in Ada
environments, the Parent Library is a single directory in the hierarchy of libraries.
Prototype Stubbing – In C and C++ environments, VectorCAST can generate stubs of dependent units
using only the function’s declaration. If VectorCAST cannot find the function’s definition (the
implementation of the function) in any C/C++ source file in the Search List, then it creates a stub of the
function using the function declaration (from a header file). Prototype-stubs are grouped under the name
Stubbed Subprograms instead of under the name of a unit.
TESTING OVERVIEW 36
Stub by Function Units – Prior to VectorCAST version 5.0, only subprograms in dependent units of the
UUT were allowed to be stubbed. In fact, all subprograms in stubbed units had to be stubbed. In
VectorCAST 5.0, you have the choice of making a Unit Under Test "stub by function (SBF)." When a
UUT is made "SBF", this means that functions in the unit can be stubbed individually, while others in the
unit are not stubbed.
Testable Class – In C++ environments, a testable class is one that has any member function defined in a
UUT source file, or an inlined function defined in a header that is included by a UUT source file.
Key Concepts
You should be familiar with the following concepts before you begin using the tutorials:
Execution Closure – An execution closure consists of all the units required for an application to
successfully link. Figure 1 shows a closure consisting of a single UUT, three direct dependent units, and
several sub-dependents.
Stubbing Units in a Closure – When building a VectorCAST environment, you designate stubbing from
the top-most level of dependency downward to the bottom-most level in each branch.
In the closure illustrated in Figure 1, for example, dependents Dep Unit A, Dep Unit B, and Dep Unit C
would be the primary candidates for stubbing. If you were to leave one of these dependents unstubbed,
the dependents immediately under it would then become the primary candidates for stubbing, and so on
to the bottom of each branch.
Figure 2 shows the example closure after stubbing has been designated.
TESTING OVERVIEW 37
The scheme allows a flexibility spanning from testing a single unit in a standalone environment in which
every dependent is stubbed, to testing groups of units with only the dependents on the periphery (bottom)
of the closure stubbed.
Ignoring Units in a Closure (Ada only) – As mentioned above, normally when you choose not to stub a
unit, any dependents below this unit remain in the closure. In VectorCAST/Ada, however, you can
choose to leave a unit unstubbed but effectively remove all the downstream dependents from the list of
stub candidates; all downstream dependents will not be stubbed. You do this by directing
VectorCAST/Ada to ignore the unit.
Note: In Ada, ignoring dependents applies only to the dependents of the 'body' of the ignored
unit; it does not apply to the dependents of the 'spec'. The reason for this is that VectorCAST
needs to parse the dependents of the 'spec' in order to resolve types derived from the dependents.
This option is useful when you want to avoid doing any stubbing beyond a certain point. For example, in
Figure 3, suppose Unit C is an interface to a subsystem already tested. There is no need to stub beyond
Unit C. By directing VectorCAST to ignore Unit C, it will use this entire branch as if you had chosen not
to stub the units.
This option can in some cases dramatically reduce the time it takes for VectorCAST to build an
TUTORIAL OVERVIEW 38
environment.
Note: In choosing to ignore a unit, downstream dependents will not be ignored if these units are
brought into the closure through an alternate dependency.
Tutorial Overview
VectorCAST was designed to be analogous to the work you currently perform manually. This work
normally includes building the test code (stubs and drivers) to invoke the unit under test and simulate
dependent program interfaces, defining and building test cases to perform a particular function, executing
the test cases, and collecting data from the test case execution to build the necessary reports.
Tutorials are provided for each development language supported by VectorCAST, organized into chapters
by language (C, C++, and Ada). The first tutorial (Basic) in each chapter serves to introduce the most
commonly used commands; the second (Multiple UUT) demonstrates VectorCAST’s multiple-unit
support.
Tutorials are also provided for the VectorCAST/Cover tool, and for the VectorCAST build settings
repository.
The tutorials use the source files listed in Table 1. Source Files Used in the Tutorials. You will find the
complete contents of these files in "Tutorial Source Code Listings" on page 332.
All the source files listed above are included in the VectorCAST installation subdirectory named
Tutorial.
Example Environments
Example environments are included as part of the Welcome screen, see "To Create the Tutorials Using the
Welcome Page" on page 29.
Also included in the VectorCAST installation directory is a subdirectory (Examples) that contains
TUTORIAL OVERVIEW 39
environments that demonstrate, in the case of VectorCAST/C++ and VectorCAST/Ada, how these tools
handle certain language-specific concepts (inheritance and class, for example); and, in the case of
VectorCAST/Cover, the different types of coverage this tool supports (statement, branch, etc.).
The directory for each example contains a Readme file. This file describes the concept or feature being
demonstrated.
1. Start VectorCAST.
2. (Optional) Set the working directory to the directory containing the .env file you want to run.
For example, select File => Set Working Directory, and then
c:\vcast\Examples\cpp\inheritance. Click OK.
Note: In UNIX, copy the example files to a location on your local machine, and then
set the working directory to this location.
In the File Open dialog, ensure that the Look In field contains the correct subdirectory
(for example, inheritance).
7. Click Open.
An environment name (e.g., SHAPE) appears in the Environment Name field.
8. Click the Build button (bottom far right).
Note: If the Build button is not enabled, you will need to make corrections before you
can build your environment.
Once the environment is built, import the test script that is included in the example directory:
Test => Scripting => Import Script.
For each test case, click the Notes tab to learn what this test case is demonstrating. To access
the Notes tab, double-click on the name of the relevant test case in the Environment View.
9. Execute the test cases: Test => Execute Batch All.
l Using regression scripts to invoke VectorCAST functionality from CLICAST (Command Line
Interface to VectorCAST)
C Tutorials
INTRODUCTION 42
Introduction
The tutorials in this chapter demonstrate how to use VectorCAST/C++ to unit-test an application written
in the C programming language.
For a comprehensive explanation of the VectorCAST/C++ features, refer to the VectorCAST/C++ User’s
Guide.
The modules you will test in the first two tutorials are components of a simple order-management
application for restaurants. The source listings for this application are available in Appendix A, "Tutorial
Source Code Listings" on page 332. It is recommended that you at least scan through these listings before
proceeding with the tutorials.
You should run the tutorials in this chapter in the order presented.
You can stop a tutorial at any point and return later to where you left off. Each tutorial session is
automatically saved. To return to where you left off, simply restart VectorCAST and the use File
=> Recent Environments to reopen the tutorial environment.
Basic Tutorial
The Basic Tutorial will take you through the entire process of using VectorCAST/C++ to test a software
unit.
You can build the test environment and create the test cases simply and easily using the
Welcome Screen,"To Create the Tutorials Using the Welcome Page" on page 29.
Please be aware that this tutorial does not provide a comprehensive explanation of VectorCAST’s
features. To gain a complete understanding of VectorCAST, we recommend that you read
VectorCAST/C++ User’s Guide before attempting to test your own code.
Note: User entries and selections are represented in this tutorial in bold. For example: “Enter
Demo, then click OK”.
For efficiency, this tutorial assumes a working directory named vcast_tutorial located at the top level
in your file tree, and a sub-directory named C. You can, however, locate this directory any place you
want, and make the necessary translations in the text as you progress through the tutorial. Also for
efficiency, this tutorial assumes you will be running the tutorial in a Windows environment, using
Windows syntax for file paths and things specific to an operating system (Windows, Solaris, and UNIX).
Again, you should have no problems making the necessary translations.
The files you need to copy are located in the directory in which you installed VectorCAST. On
Windows, these files are located in %VECTORCAST_DIR%\Tutorial\c by default.
In Windows, enter:
C:\>mkdir vcast_tutorial\C
C:\>copy %VECTORCAST_DIR%\Tutorial\c vcast_tutorial\C
In UNIX, enter:
$ mkdir vcast_tutorial/C
$ cp $VECTORCAST_DIR/tutorial/cpp/* vcast_tutorial/C
You will:
The working directory contains the files you will use to build your test harness. For the purposes of this
tutorial, the working directory is vcast_tutorial\C
1. With the VectorCAST main window open, select File => Set Working Directory.
A browsing dialog appears.
2. Navigate to C:\vcast_tutorial\C ; click Choose.
BASIC TUTORIAL 44
The location and name of the working directory you specified appear at the lower right-hand corner
of the VectorCAST main window:
BASIC TUTORIAL 45
If the only type of environment licensed is C/C++, the Create New Environment wizard appears
when you click the New button.
2. Select C/C++ Environment .
The Choose Compiler page of the Create New Environment wizard appears:
Selecting a Compiler
You use the Choose Compiler page to specify a compiler. The compiler you specify must be included in
your PATH environment variable.
BASIC TUTORIAL 46
1. To access a list of compilers supported by VectorCAST, click the down arrow on the Compilers
button. Select a C compiler from the dropdown menu.
In this tutorial, you are building a C environment; therefore, you must select a C VectorCAST
compiler template. Most compiler templates have both C and C++ variants.
If you are planning to use VectorCAST with a target compiler, it is recommended you first
go through the tutorials using a Host version of your compiler. Once you are familiar with
the basic functionality of VectorCAST, refer to the VectorCAST/RSP User's Guide for
information specific to your target.
For example, if you are using the Visual C++ .NET 2003 compiler, you would select from the
cascading menus as shown here
After you select a compiler, VectorCAST fills in the Preprocessor command and Compile
command fields with the correct commands.
BASIC TUTORIAL 47
If VectorCAST cannot find these commands on your default path, it outlines the fields with a red
border. In this case, hover your cursor over either field and a tool tip will explain the problem;
then click Cancel, exit VectorCAST, and address the problem. (Most likely, the compiler you
specified is not included in your PATH environment variable.)
2. Click Next.
The Name the Environment page appears:
BASIC TUTORIAL 48
For the purposes of this tutorial, you will name your environment ‘tutorial’.
2. Click Next.
This page of the Wizard offers four choices for the method of testing to use. Depending on the testing
method, VectorCAST builds a different test harness. For the purposes of this tutorial, we will go with the
Traditional Unit Testing method.
3. Click Next.
The Build Options page opens. Click the checkbox next to “Whitebox.” Turning on whitebox ensures
you access to private and protected member variables in the source code units.
BASIC TUTORIAL 50
4. Click Next.
The Locate Source Files page opens:
BASIC TUTORIAL 51
1. Click the Add Search Directory button to display the Add Search Directory dialog.
The name of the working directory (C:/vcast_tutorial/C/) displays in the Look in field; the
content of this directory displays in the pane below. In this tutorial, you will be building your
environment in the same directory in which the source files are located. In practice, you might need
to navigate to a different directory.
2. Click Choose.
The Search directories pane on the Locate Source Files page displays the name of the source
directory. The icon at the left side of the search directory path indicates it is a Search directory,
so VectorCAST will search it for files that it needs as it is parsing the Unit Under Test.
3. Click Next.
BASIC TUTORIAL 52
You use the Choose UUTs & Stubs page to designate units as a UUT or stub and the method of stubbing.
The pane under Unit Names lists the units that VectorCAST found in the specified source directory. You
can select one or more of these units to be UUTs. For this tutorial, you will select only manager.
BASIC TUTORIAL 53
1. Click manager.c under Unit Names, and then click the move-right button; or simply double-click
manager.c. The name manager.c moves to the Units Under Test tab, and is displayed with the SBF
icon ( ) next to it. By default, the unit is a UUT with Stub-by-function enabled.
Three options are available under Stub dependencies for designating stubbing: All, None, or
Custom:
As indicated, VectorCAST defaults to stubbing all dependent units. You can override this setting
by selecting None or Custom. The Custom option allows you to select individual units for stubbing
by implementation or not stubbing.
BASIC TUTORIAL 54
A toggle button (Show Dependency View ) appears at the bottom of the Units Under Test
tab:
BASIC TUTORIAL 56
VectorCAST parses the units in the search directory, and finds that the unit database is a dependent of
the unit manager . It draws the hierarchy to represent this relationship between the units.
Database appears as a dependent to manager , and “stub (by prototype)” appears in the Type column for
database, to indicate that it is going to be stubbed using its prototype:
1. Click Next.
The Summary page appears:
This page allows you to check your test-environment specifications before you generate the test
harness.
VectorCAST has created an environment file named TUTORIAL.vce and a subdirectory named
TUTORIAL.
The Environment View shows that the current environment (TUTORIAL) has one UUT, named
manager, which has six subprograms: Add_Included_Dessert, Place_Order, Clear_Table, Get_
Check_Total, Add_Party_To_Waiting_List, and Get_Next_Party_To_Be_Seated
At this point, VectorCAST has built the complete test harness necessary to test the manager unit,
including:
l A test directory with all test-harness components compiled and linked.
l The test driver source code that can invoke all subprograms in the file (manager).
lThe stub source code for the dependent unit (database).
Note what was accomplished during environment creation:
l The unit under test was parsed. The dependent unit did not have to be parsed, because
its prototype was used to determine the parameter profile.
l The data-driven driver and stub source code were generated.
l The test code generated by VectorCAST was compiled and linked with the UUT to
form an executable test harness.
The harness that VectorCAST builds is data driven. This means that data sets can be built to stimulate
the different logic paths of the unit under test without ever having to re-compile the harness. You are
now ready to build test cases for the subprograms in the unit under test (manager).
BASIC TUTORIAL 58
The process of building test cases with VectorCAST is very simple. All the information is available by
means of a point-and-click interface. The idea is to create a set of data that will stimulate the unit under
test and cause it to execute a particular logic path. In its simplest form, a test case consists of values for
the formal parameters of a single subprogram within the unit under test. A more complex test case can
also contain values to be returned by a stubbed dependent, or values to be set into global data objects.
Test cases are constructed to stimulate individual subprograms. Each subprogram within a unit will have
its own series of test cases defined. The first step is to select a subprogram in the Environment View and
create a test case for it.
1. If a list of subprograms is not displayed under manager in the Environment View, click the
symbol preceding its name to display the list of subprograms.
2. Right-click Place_Order and select Insert Test Case from the popup menu:
Note: You can change the default name of a test case by right-clicking its name and
selecting Rename from the popup menu.
The following test case parameter tree appears in the Test Case Editor:
A tree item having branches is preceded by a plus symbol . To expand a tree item, simply click
the symbol.
4. Press Enter.
Table 2 is now the focus of your test case.
5. Double-click Table.
BASIC TUTORIAL 60
Notice that you can use this dialog to set simple scalar values, and also to build test cases for a
range of values or a list of values, or with user code.
6. Click Cancel to dismiss this dialog.
You will use it in the next tutorial.
Note: When you create a test case, the only subprogram displayed for the UUT is the
subprogram that this test case has been created for, in this case, Place_Order.
7. For this tutorial, assume now that someone is occupying seat 0 at table 2.
Enter 0 into the Input Values field for Seat, and then press Enter.
BASIC TUTORIAL 61
You will use this same technique to set values for all parameters. Although you can access all
parameters of visible subprograms of the unit under test, and of any stubbed unit, it is only
necessary to select those parameters that are relevant to the test you are running.
Non-scalar parameters (arrays and structures) are accessed using the same tree-expansion
technique that is used for units and subprograms. Parameter Order is a structure with five fields.
Each field is an enumeration type.
At this point, you could create separate test cases for the other seats at table 2 (as well as for the
other tables in the restaurant); however, for the purposes of this basic tutorial, one test case (one
order at one seat) is sufficient.
You have someone sitting in seat 0 at table 2; it’s time now to take an order.
Note: To clear a field, select the blank item at the top of the associated drop-down menu.
10. Save test case PLACE_ORDER.001: Either select File => Save from the main-menu bar or click the
Save button on the toolbar.
BASIC TUTORIAL 62
11. To access a test-case data listing, select Test => View => Test Case Data.
The Test Case Data Report for your test case appears in the Report Viewer.
12. In the Table of Contents section of this report, click Test Case Data.
The report jumps to the Test Case Data section.
At this point you could execute your test case as is, or you could add expected results for
comparing against actual results. Because the latter course is generally the more valuable, you will
now add expected results to your test case.
In this section, you will add expected results to the test case you created in the previous section:
1. Click the preceding Stubbed Subprograms; then click the preceding Get_Table_Record.
Then click the preceding return.
BASIC TUTORIAL 63
Note: If you encounter any problems, refer to the section titled Troubleshooting.
2. To initialize the data returned by Get_Table_Record, enter 0 into the Input Values fields for
Number_In_Party and Check_Total:
BASIC TUTORIAL 64
3. Press Enter.
The 0 value you entered for Check_Total becomes 0.0, because Check_Total is a floating-point
number.
You are now ready to enter expected values for comparing against the actual values returned by
Update_Table_Record.
You might want to make more room by closing up the Parameter trees for both Get_
Table_Record and manager.
In this section, you will add expected results to the test case you created in the previous section:
Note: Be sure you enter these values under Expected Values column, not into the Input
Values column.
BASIC TUTORIAL 65
3. Expand Order.
Order is an array whose index corresponds to the seat specified in the call to Place_Order.
Because we specified seat 0, we need to expand Order[0].
4. In the Input Values column, enter 0 next to <<Expand Indices: Size 4>>.
BASIC TUTORIAL 66
5. Press Enter.
The array element [0] in the array Order is expanded in the Parameter Tree, and the “0” is removed.
6. Expand the tree for Order[0].
7. For the Expected Value for Dessert, enter PIE. We expect Pie for dessert because Place_Order
calls Add_Included_Dessert, which sets the Dessert to Pie.
BASIC TUTORIAL 67
You now have a test case defined with input data and expected results.
The values entered into the Expected Values column for a stub are verified as they are passed into
the stub; the values entered into the Input Values column are passed out of the stub and back into
the test harness.
You must now save your data in order to make them a part of your test case.
When a test case has been modified and needs to be saved, a green icon ( ) appears to the left of
its name on a tab above the Test Case Editor
Table 1. Test Case Data
Test Case: "PLACE_ORDER.001"
File Name: "C-000001.DAT"
Input Test Data
UUT: manager.c
Subprogram: Place_Order
Table 2
Seat 0
Order
Soup ONION
Salad CAESAR
Entree STEAK
Beverage MIXED_DRINK
Stubbed Subprograms:
Unit: manager.c
BASIC TUTORIAL 68
Subprogram: Get_Table_Record
return
Number_In_Party 0
Check_Total 0.0
Expected Test Data
Stubbed Subprograms:
Unit: manager.c
Subprogram: Update_Table_Record
Data
Is_Occupied v_true
Number_In_Party 1
Order
[0]
Dessert PIE
Check_Total BETWEEN:12.0 AND:16.0
Test Case / Parameter Input User Code
Test Case / Parameter Expected User Code
Troubleshooting: If your test case Data report does not show any data in the section labeled Expected
Test Data, refer to the section titled Troubleshooting at the end of this tutorial.
10. To close this report, click the X on the Test Case Data tab. To close all reports, click on the X on
the Reports tab.
You have now created a test case named PLACE_ORDER.001 that includes expected results. You are
now ready to execute it.
1. To execute your test case, click PLACE_ORDER.001 in the Environment View, then click the
Execute button on the toolbar.
When processing completes, an execution report appears in the Report Viewer.
2. Click the green down-arrow on the toolbar, or scroll down the report until you come to a group
of table cells shaded in green.
BASIC TUTORIAL 69
The green shading and the term match here indicate that the expected values you specified were
matched by actual values. Your test passed!
Note: You can customize the appearance of this or any other VectorCAST report. To
customize a report, select Tools => Options; click the Report tab; then click the Format
sub-tab.
3. To print your Test Case Management Report, click the Print button on the toolbar , or select
File => Print from the main-menu bar.
4. To save your report into a file, select File => Save As.
BASIC TUTORIAL 71
When the Save As dialog box opens, enter tutorial_report.html for the file name, then click Save.
Note: You can open a saved report with any HTML browser (Internet Explorer, Mozilla,
Netscape, etc.).
The Units Under Test must be instrumented for the kind of coverage you want: Statement, Branch,
MC/DC, DO-178B Level A, DO-178B Level B, or DO-178B Level C. In this section, you will instrument
the source files in your environment for statement coverage:
1. To instrument the source files in your environment for statement coverage, select Coverage =>
Initialize => Statement.
The status bar on the bottom right of the VectorCAST main window now indicates that statement
coverage is active:
2. To execute an existing test case and generate a report, click PLACE_ORDER.001 in the
Environment View, then click the execute button ( ).
When coverage is enabled, VectorCAST keeps track of the lines or branches in the source code that
are traversed during execution. You can access a report on the results by way of clicking the
checkbox next to the test case name in Environment View.
3. To access the coverage report for your test case, click the green checkbox to the left of PLACE_
ORDER.001.
BASIC TUTORIAL 72
An annotated version of the manager source code appears in the Coverage Viewer:
Each set of repeating numbers in the first column marks a subprogram within manager. The
ascending numbers in the second column mark the executable statements within a subprogram. The
statements in green have been exercised; the statements in red have not been exercised; the
statements in black cannot be exercised, or are the continuation of previous statements.
Note the icons on the left-hand margin of the Coverage Viewer:
BASIC TUTORIAL 73
A circled minus-sign means the associated subprogram is fully expanded in the Coverage
Viewer, and can be collapsed. To collapse a subprogram (to its first line), double-click either the
circle or the first line of the subprogram.
Clicking the file symbol gives you immediate access to the associated source code.
The status bar (upper right) tells you the number and percentage of statements exercised.
4. Hover your mouse over Statements on the status bar.
A tool tip provides the exact number of lines covered; in this case, 12 of 40. (30%)
Note: VectorCAST’s animation feature allows you to view the step-by-step coverage of a
test case. This feature is described in the user guide accompanying your version of
VectorCAST.
The Metrics tab at the bottom of the Coverage Viewer displays a tabular summary of the coverage
achieved, on a per subprogram basis.
5. Click the Metrics tab:
This table tells you that subprogram Place_Order consists of 17 executable statements; that 10 of
these statements were exercised during the selected test; and that the complexity of the subprogram
is 5, meaning there are five distinct execution paths.
6. Click the Coverage tab to return to the previous view.
For each green line, you can identify the test case that most recently exercised it.
7. Hold your mouse over any green line in the Coverage Viewer.
BASIC TUTORIAL 74
A tool tip appears showing the name of the test case that exercised this line:
Note: If you had run multiple test cases with coverage enabled, and had multiple check
boxes selected in the Environment View, the tool tip would list all cases that provided
coverage for the selected line.
8. To access the test case that exercised a line, right-click on the line, then select the test case from the
popup menu that appears; in this example, select PLACE_ORDER.001:
You initialized the source code in your environment for coverage and executed the test cases. You can
now view the coverage information that was generated.
The Report Viewer displays a report showing the total coverage for all test cases executed on
manager. The associated source code displayed is color-coded to mark the exercised lines (green)
and the un-exercised lines (red):
2. Scroll down the report until you come to a table similar to the metrics table you accessed from the
Metrics tab.
BASIC TUTORIAL 76
3. To print the Aggregate Coverage Report, click the Print button on the toolbar , or select File
=> Print from the main-menu bar.
4. To save your report into a file, select File => Save As.
When the Save As dialog box opens, enter tutorial_coverage.html for the file name, then click the
Save button .
You can open your saved report with any HTML browser (Internet Explorer, Mozilla, Netscape,
etc.).
5. Choose File => Close All in preparation for the next section.
Using Stub-By-Function
In the last section, we tested the subprogram Place_Order using inputs of STEAK, CAESAR, and
MIXED_DRINK for the Order. During test execution, Place_Order calls the subprogram Add_
Included_Dessert, which checks for the combination of STEAK and CAESAR salad and MIXED_
DRINK. It finds them and sets the Dessert to Pie. However, we would like to test for the case when Add_
Included_Dessert doesn’t set the Dessert to Pie.
In this section, we will create a new test case which stubs the subprogram Add_Included_Dessert, so
that we can cause it to return something else for the Dessert, such as CAKE.
l Set the value of a parameter in the stubbed subprogram to the desired value, so that it is returned to
the test harness instead
l Export a test script to see how SBF is specified in a test script
1. In the Environment View, right-click the test case name “PLACE_ORDER.001” and choose
Duplicate Test Case.
Using drag-and-drop, you can duplicate a test case in another subprogram. Select the test
case, press Alt+Shift, drag-and-drop the test case on the destination subprogram. Only data
that applies to the parameters in the new subprogram are copied to the new test case.
3. Click the checkbox next to Add_Included_Dessert. The checkmark indicates that this subprogram
should be stubbed during test execution.
5. Press Enter.
BASIC TUTORIAL 79
The text in the cell changes to “<<alloc 1>>” and a structure Order[0] is displayed.
7. Set the Input Value for Dessert to CAKE. When the test executes, CAKE will be returned from
Add_Included_Dessert, instead of the non-stubbed return value, PIE.
BASIC TUTORIAL 80
8. Scroll to the end of the Parameter Tree and locate Update_Table_Record, which is part of Stubbed
Subprograms.
9. Change the Expected Value of the Dessert from PIE to CAKE.
10. To save the test case, click the Save button on the toolbar .
13. To access the coverage achieved for this test case, click the green checkbox to the left of PLACE_
ORDER.002.
An annotated version of the manager source code appears in the Coverage Viewer, showing the
aggregate coverage achieved by both test cases.
14. Uncheck the green checkbox next to PLACE_ORDER.001.
The line beginning with TEST.STUB indicates that Add_Included_Dessert should be stubbed during
this test’s execution. The TEST.VALUE line in bold specifies the Input Value that the stubbed
subprogram returns to the test harness during this test’s execution. This is possible only because manager
is a Stubbed-by-Function (SBF) type of UUT, as specified during environment build.
BASIC TUTORIAL 83
l A shell script (.bat file on Windows, .sh or .csh on UNIX) sets the options, builds the environment,
imports and executes the test cases, and generates reports
l A test script (.tst) defines test cases to be imported by the shell script.
l The environment script (.env) defines the settings for the environment, such as the UUT(s), which
UUTs are Stub-by-Function, what is the method of stubbing, and where are the search directories.
1. Select Environment => Create Regression Scripts....
The Create Regression Scripts dialog appears.
2. In the first edit box, click the Browse button and navigate to any directory you choose. For the
purposes of this tutorial, we will specify the working directory as the destination for the regression
scripts.
3. Click Create.
BASIC TUTORIAL 84
VectorCAST creates the three regression scripts in the location you specified.
Tutorial Summary
You have now completed the Basic Tutorial. You:
l Built a test environment named TUTORIAL for testing a UUT named manager
l Defined and executed a test case named PLACE_ORDER.001
l Viewed source coverage information
l Viewed the Test Case Management Report and the Aggregate Coverage Report for your test
environment
l Duplicated a test case
l Stubbed a function in the UUT during test execution
l Created regression scripts for this environment, which include the shell script, test script, and
environment script
Troubleshooting
Problem: Dependents are not stubbed
If you do not see Get_Table_Record (only <<GLOBAL>> and Table_Data, as shown below), then you
did not stub database.
BASIC TUTORIAL 85
As a result, the test harness is using the actual unit (database), which means you cannot specify any input
or expected values for subprogram Get_Table_Record.
To solve this problem, you can update the environment to change database from not stubbed to stub:
or
3. Click the radio button All under Stub dependencies to change database to be stubbed.
BASIC TUTORIAL 86
(Alternatively, you could have clicked Custom, then the toggle button and then cycled the
unit database until its type was stub (by prototype)).
4. Click Update.
The environment rebuilds; database is now stubbed.
When testing more than one UUT in an environment, it is typical that the units interact. VectorCAST’s
multiple UUT (multi UUT) feature enables you to do this.
In VectorCAST, there are two types of test cases: simple test cases and compound test cases. In the Basic
Tutorial, you created and used a simple test case, which corresponded to a single invocation of a UUT. A
compound test case is a collection of simple test cases that invokes a UUT in different contexts. The data
is persistent across these invocations. Data persistence is very important when doing integration testing.
This tutorial will take you through the steps of building a compound test case to test the interaction
between the unit manager and the unit database. The unit manager is a simple database in which actual
data is stored in data objects defined within the unit. You are guided through the steps of building a
compound test case to write data into this database. You then use the same compound test case to retrieve
data from the database to verify it.
It is recommended that you review the relevant source listings in Appendix A, "Tutorial Source Code
Listings" on page 332before proceeding.
l Build a multi UUT environment by updating the environment you built in the Basic Tutorial
l Add a test case to unit database
l Use the simple test cases to create a compound case
l Verify the data flow between UUTs manager and database
l Set processing iterations across ranges of input data
l Build and execute a compound test case
The test cases present in this environment were created on the basis of database being a stubbed
dependent of manager. However, in your new environment, you want database to be a second
UUT. No problem! As you will see in the next section, VectorCAST converts the values in a
stubbed unit to corresponding values in a stubbed-by-function unit.
MULTIPLE UUT TUTORIAL 89
This wizard is similar to the Create Environment wizard you used in the Basic Tutorial to create the
original environment. There are no red outlines because there are no errors or missing items of
information.
Note: Double-clicking a name in the Unit Names pane is a shortcut for selecting the name
and then clicking the right-arrow ( ).
Both database and manager are now listed as Units Under Test with Stub-by-function (SBF)
enabled:
4. Click Update.
MULTIPLE UUT TUTORIAL 91
5. As the environment updates to include two UUTs, a series of messages is displayed in the Message
window. A message appears confirming that the update has completed:
6. Click OK.
The environment is opened:
Note in the Environment View that database is now listed as a UUT, and also that it has two
subprograms: Get_Table_Record and Update_Table_Record.
Next, you will edit one of the test cases in Place_Order and create a simple database test case, and
then combine these two simple cases to create a compound case.
You create a compound test case by creating a separate test case for each subprogram to be included in
the test and then combining these test cases into a compound test case.
To create the simple test cases, you use the same procedure you used in the Basic Tutorial to create the
test case (PLACE_ORDER.001) that you deleted for the purposes of this tutorial.
l Turn off stubbing-by-function in the test case PLACE_ORDER.001. We want to call the real code
for the subprograms in the unit database in this tutorial.
l Create a simple test case for subprogram Get_Table_Record, which reads data from the database.
This test case will be used to verify that Place_Order is updating the database properly.
l Place these test cases into a compound test case
1. In the Environment View, expand manager into its subprograms, and then expand Place_Order
into its test cases.
2. Double-click PLACE_ORDER.001.
The test case PLACE_ORDER.001 displays in the Test Case Editor.
Note that after the Environment Update, the subprograms Get_Table_Record and Update_Table_
Record are stubbed (by-function). But because this is an integration test, we do not want these
subprograms stubbed in order to verify the “real” code for these subprograms.
3. Uncheck the checkbox next to Get_Table_Record under the <<SBF>> node.
4. Uncheck the checkbox next to Update_Table_Record as well.
MULTIPLE UUT TUTORIAL 93
The test case already sets the Entrée, Soup, Salad, and Beverage. This combination yields an
included dessert of Pie, so we will expect PIE when later verifying the Order.
5. Save the test case by clicking the Save button on the toolbar.
Because you will be making your test case part of a compound test case, and you only want to use
this test within a compound case, you need to designate it as Compound Only. Compound Only
test cases can only be executed from within a compound test. They cannot be executed individually
or as part of a batch.
In some cases, you will want to use simple test cases both individually and as part of a compound
case. In these instances, it is not necessary to apply the Compound Only attribute to the simple
cases.
6. Right-click PLACE_ORDER.001 and select Compound Only.
The test case typeface changes to italic, signifying that this test case has been designated
Compound Only.
1. In the Environment View, expand database into its subprograms (if not already expanded).
2. Right-click Get_Table_Record and select Insert Test Case.
MULTIPLE UUT TUTORIAL 94
3. Keeping with our example situation, enter 2 as the input value for Table.
Note: Be sure you enter this value into the Input Values column, not into the Expected
Values column. You will enter the expected values for this case in the next step.
Note: Make sure you enter these two values in their respective Expected Values fields.
MULTIPLE UUT TUTORIAL 95
5. Expand Order.
Order is an array of structures of size 4.
6. To view the array indices of Order, right-click on <<Expand Indices: Size 4>> and select Expand
All Array Indices.
MULTIPLE UUT TUTORIAL 96
In this example, you want to verify input values written to the application database. The data
consists of an order taken for seat 0 at table 2.
7. Expand Order[0].
Order[0] corresponds to seat 0. The expected values you specify for Order[0] must match the input
values you previously specified in PLACE_ORDER.001.
Important:If you use any other index, the expected results will not match.
8. Assign the following Expected Values to the appropriate fields of Order[0]:
Soup ONION
Salad CAESAR
Entree STEAK
Dessert PIE
Beverage MIXED_DRINK
Note: Make sure you enter these values into the Expected Values column:
MULTIPLE UUT TUTORIAL 97
9. Click to save.
Note: Order[1], Order[2], and Order[3] are not populated with data. Populating a single Order
record is sufficient to verify the operation of the two subprograms under test.
10. Right-click GET_TABLE_RECORD.001 in the Environment View, then select Compound Only.
You have two simple test cases designated Compound Only. The first (PLACE_ORDER.001) takes
a dinner order for table 2, seat 0. The order is then stored in the application database by means of
Place_Order calling Update_Table_Record. The second simple test case (GET_TABLE_
RECORD.001) retrieves data from the database for verification.
1. In the Environment View, right-click <<COMPOUND>> and select Insert Test Case.
A test case named <<COMPOUND>>.001 appears under <<COMPOUND>>, and is selected
(highlighted) by default.
2. Click and hold the cursor on PLACE_ORDER.001 in the Environment View; drag until the
symbol appears in the Test Case Editor; release.
An entry appears in the Test Case Editor (slot 1) as a member of test case <<COMPOUND>>.001.
3. Do the same with test case GET_TABLE_RECORD.001.
MULTIPLE UUT TUTORIAL 99
Your compound test case now has two slots: PLACE_ORDER.001, and GET_TABLE_
RECORD.001:
4. Click Save.
You are now ready to execute your compound test case.
5. In the Environment View, select <<COMPOUND>>.001, then click the Execute button on
the toolbar.
An execution report for the compound test case appears in the Report Viewer.
Note: If your compound test case fails, make sure PLACE_ORDER.001 uses parameter
values table 2, seat 0, and that GET_TABLE_RECORD.001 uses table 2 and the proper
expected values in Order[0].
In the Coverage Viewer, note that the statement assigning the value PIE to Order-> Dessert is green,
indicating that it was covered by test execution.
2. Select <<COMPOUND>>.001 in the Environment View and click the Execute button in the
toolbar.
3. Click the checkbox preceding <<COMPOUND>>.001 in the Environment View:
In the Coverage Viewer, the instances of the ‘(T)’ symbol indicate that two Place_Order branches
were covered: the first at the subprogram entry point; the second at the STEAK branch in the
switch statement.
VectorCAST allows you to build more complex tests by linking multiple simple test cases together.
This feature allows you to test threads of execution while maintaining the data common to the
various units and subprograms.
In this section, you will modify test case PLACE_ORDER.001 to iterate over the 4 seats at table 2 while
iterating over the four entrées. The net effect will be to assign a different entrée to each seat.
3. Double-click Entree.
MULTIPLE UUT TUTORIAL 102
Note: You can also enter a range of values by typing it directly into the appropriate Input
Values field, in the appropriate format.
7. Click OK.
8. Click Save.
You have now assigned input ranges to two parameters. By default, when two parameters are
assigned input ranges, they will iterate in parallel, which is what you want to occur in this case.
(There is a setting to make them iterate in combination.)
These two parameters will iterate with the following value pairs:
Seat = 0 Entree = Steak
Seat = 1 Entree = Chicken
Seat = 2 Entree = Lobster
Seat = 3 Entree = Pasta
Given this information, you can specify expected values in your compound test case for each seat.
9. Click the tab for test case GET_TABLE_RECORD.001 at the top of the Test Case Editor.
MULTIPLE UUT TUTORIAL 104
The parameter tree for GET_TABLE_RECORD.001 comes to the front. You need to edit this tree to
reflect the expected results for your compound test.
You now need to specify expected values for each of the other three seats at table 2.
10. You have already specified values for Order[0], so move on to Order[1].
11. Expand Order[1]. (If you have recently re-opened the TUTORIAL environment, then the unused
array elements have been collapsed. If Order[1] is not visible, simply right-click on <<Expand
Indices: Size 4>> and choose Expand All Array Indices.)
Order[1] maps to seat 1. Specify the following expected values for seat 1:
Soup ONION
Salad CAESAR
Entree CHICKEN
Dessert NO_DESSERT (see Note)
Beverage MIXED_DRINK
Note: For Order[1], Order[2], and Order[3], Place_Order calls Add_Included_Dessert with a
soup, salad, and entrée combination that does not qualify for Pie, so we expect NO_
DESSERT.
Note: Be sure you have populated the Expected Values column for Order, and not the Input
Values column.
MULTIPLE UUT TUTORIAL 105
You now have Order data for each seat at table 2. Note that these orders are identical in each case
except for the Entree and the Dessert. Only the Entree variable is needed to exercise each branch in
the switch statement.
You must now change the number of occupied seats at table 2 to reflect the current test case.
14. Scroll up to Number_In_Party and change the expected value to 4.
15. Click Save.
Note: The amount of instruction given in this section will be a little less than in the previous
sections.
1. Under the manager unit, insert a test case for Get_Check_Total and make the test case Compound
Only.
4. Save.
You can now add your new test case to the compound case.
5. Double-click <<COMPOUND>>.001 in the Environment View.
6. Click the Compound Tree tab at the bottom of the Test Case Editor.
The Test Case Editor displays the slots in test case <<COMPOUND>>.001.
7. Add test case GET_CHECK_TOTAL.001 to the compound by dragging and dropping it as the
last slot.
MULTIPLE UUT TUTORIAL 108
8. Save.
10. Click the green down-arrow on the toolbar, or scroll down the report until you come to the
green-shaded results section. You can see that the check total for table 2 was $54.
MULTIPLE UUT TUTORIAL 109
11. To view the coverage data, click the green checkbox preceding <<COMPOUND>>.001 in the
Environment View.
The Coverage Viewer opens.
Notice from the green coloring that by iterating over four entrées, you exercised four of the five
switch branches. Notice from the status bar that total branch coverage was 10 of 23, or 43%.
At this point, you might want to initialize a different type of coverage. In addition, you might want
to try adding a test case for Clear_Table (with Table also set at 2).
MULTIPLE UUT TUTORIAL 110
Tutorial Summary
This tutorial built on the environment you created in the Basic Tutorial. You changed one of the
dependent units from a smart stub into a UUT. You then added test cases to both units, and combined
these test cases into a Compound test case, which you used to test the data flow from manager to
database. When test cases are combined into a Compound test case, the data remains persistent between
them.
In sum, you:
l Built a multi UUT environment by updating the environment you built in the Basic Tutorial
l Turned off stubbing-by-function in the test case from manager
l Added a test case to database
l Used these simple test cases to create a compound case
l Verified the data flow between UUTs manager and database
l Set up range iterations for a scalar parameter and an enumeral
l Added a test case to an existing compound case
C++ Tutorials
INTRODUCTION 112
Introduction
The tutorials in this chapter demonstrate how to use VectorCAST/C++ to unit-test an application written
in the C++ programming language.
For a comprehensive explanation of the VectorCAST/C++ features, refer to the VectorCAST/C++ User’s
Guide.
The modules you will test in the first two tutorials are components of a simple order-management
application for restaurants. The source listings for this application are available in Appendix A, "Tutorial
Source Code Listings" on page 332. It is recommended that you at least scan through these listings before
proceeding with the tutorials.
You should run the tutorials in this chapter in the order presented.
You can stop a tutorial at any point and return later to where you left off. Each tutorial session is
automatically saved. To return to where you left off, simply restart VectorCAST and the use File
=> Recent Environments to reopen the tutorial environment.
Basic Tutorial
The Basic Tutorial will take you through the entire process of using VectorCAST/C++ to test a software
unit.
Note: User entries and selections are represented in this tutorial in bold. For example: “Enter
Demo, then click OK”.
For efficiency, this tutorial assumes a working directory named vcast_tutorial located at the top level
in your file tree, and a sub-directory named cpp. You can, however, locate this directory any place you
want, and make the necessary translations in the text as you progress through the tutorial. Also for
efficiency, this tutorial assumes you will be running the tutorial in a Windows environment, using
BASIC TUTORIAL 113
Windows syntax for file paths and things specific to an operating system (Windows, Solaris, and UNIX).
Again, you should have no problems making the necessary translations.
The files you need to copy are located in the directory in which you installed VectorCAST. In Windows,
these files are located in %VECTORCAST_DIR%\Tutorial\cpp by default.
In Windows, enter:
C:\>mkdir vcast_tutorial\CPP
C:\>copy %VECTORCAST_DIR%\Tutorial\cpp vcast_tutorial\CPP
In UNIX, enter:
$ mkdir vcast_tutorial/CPP
$ CP $VECTORCAST_DIR/TUTORIAL/CPP/* VCAST_TUTORIAL/CPP
You will:
1. With the VectorCAST main window open, select File => Set Working Directory.
A browsing dialog appears.
2. Navigate to C:\vcast_tutorial\CPP ; click Choose.
BASIC TUTORIAL 114
The location and name of the working directory you specified appear at the lower right-hand corner
of the VectorCAST main window:
BASIC TUTORIAL 115
If the only type of environment licensed is C/C++, the Create New Environment wizard appears
when you click the New button.
2. Select C/C++ Environment .
The Choose Compiler page of the Create New Environment wizard appears:
Selecting a compiler
You use the Choose Compiler page to specify a compiler. The compiler you specify must be included in
your PATH environment variable.
1. To access a list of compilers supported by VectorCAST, click the down arrow on the Compilers
button. Select a C++ compiler from the dropdown menu.
BASIC TUTORIAL 116
In this tutorial, you are building a C++ environment; therefore, you must select a C++ VectorCAST
compiler template. Most compiler templates have both C and C++ variants.
If you are planning to use VectorCAST with a target compiler, it is recommended you first
go through the tutorials using a Host version of your compiler. Once you are familiar with
the basic functionality of VectorCAST, refer to the VectorCAST/RSP User's Guide for
information specific to your target.
For example, if you are using the Visual C++ .NET 2003 (C++) compiler, you would select from
the cascading menus as shown here
After you select a compiler, VectorCAST fills in the Preprocessor command and Compile
command fields with the correct commands.
BASIC TUTORIAL 117
If VectorCAST cannot find these commands on your default path, it outlines the fields with a red
border. In this case, hover your cursor over either field and a tool tip will explain the problem;
then click Cancel, exit VectorCAST, and address the problem. (Most likely, the compiler you
specified is not included in your PATH environment variable.)
BASIC TUTORIAL 118
2. Click Next.
The Name the Environment page appears:
2. Click Next.
This page of the Wizard offers four choices for the method of testing to use. Depending on the testing
method, VectorCAST builds a different test harness. For the purposes of this tutorial, we will go with the
Traditional Unit Testing method.
3. Click Next.
The Build Options page opens. Click the checkbox next to “Whitebox.” Turning on whitebox ensures
you access to private and protected member variables in the source code units.
BASIC TUTORIAL 121
4. Click Next.
The Locate Source Files page opens:
BASIC TUTORIAL 122
1. Click the Add Search Directory button to display the Add Search Directory dialog.
The name of the working directory (C:/vcast_tutorial/CPP/) displays in the Look in field; the
content of this directory displays in the pane below. In this tutorial, you will be building your
environment in the same directory in which the source files are located. In practice, you might need
to navigate to a different directory.
2. Click Choose.
The Search directories pane on the Locate Source Files page displays the name of the source
directory. The icon at the left side of the search directory path indicates it is a Search directory,
so VectorCAST will search it for files that it needs as it is parsing the Unit Under Test.
3. Click Next.
BASIC TUTORIAL 123
The pane under Unit Names lists the units that VectorCAST found in the specified source directory. You
can select one or more of these units to be UUTs. For this tutorial, you will select only manager.
BASIC TUTORIAL 124
1. Click manager.cpp under Unit Names, and then click the move-right button; or simply double-click
manager.cpp. The name manager.cpp moves to the Units Under Test tab, and is displayed with the
SBF icon ( ) next to it. By default, the unit is a UUT with Stub-by-function enabled.
Three options are available under Stub dependencies for designating stubbing: All, None, or
Custom:
As indicated, VectorCAST defaults to stubbing all dependent units. You can override this setting
by selecting None or Custom. The Custom option allows you to select individual units for stubbing
by implementation or not stubbing.
A toggle button (Show Dependency View ) appears at the bottom of the Units Under Test
tab:
3. Click the Show Dependency View button.
BASIC TUTORIAL 126
VectorCAST parses the units in the search directory, and finds that the unit database is a dependent of
the unit manager . It draws the hierarchy to represent this relationship between the units.
Database appears as a dependent to manager , and “stub (by prototype)” appears in the Type column for
database, to indicate that it is going to be stubbed using its prototype:
This page allows you to check your test-environment specifications before you generate the test
harness.
VectorCAST has created an environment file named TUTORIAL.vce and a subdirectory named
TUTORIAL.
The Environment View shows that the current environment (TUTORIAL) has one UUT, named
manager, which has six subprograms: AddIncludedDessert, PlaceOrder, ClearTable, GetCheckTotal,
AddPartyToWaitingList and GetNextPartyToBeSeated. They are all in the class Manager.
At this point, VectorCAST has built the complete test harness necessary to test the manager unit,
including:
l A test directory with all test-harness components compiled and linked.
l The test driver source code that can invoke all subprograms in the file (manager).
lThe stub source code for the dependent unit (database).
Note what was accomplished during environment creation:
l The unit under test was parsed. The dependent unit did not have to be parsed, because
its prototype was used to determine the parameter profile.
l The data-driven driver and stub source code were generated.
l The test code generated by VectorCAST was compiled and linked with the UUT to
form an executable test harness.
The harness that VectorCAST builds is data driven. This means that data sets can be built to stimulate
the different logic paths of the unit under test without ever having to re-compile the harness. You are
now ready to build test cases for the subprograms in the unit under test (manager).
BASIC TUTORIAL 129
The process of building test cases with VectorCAST is very simple. All the information is available by
means of a point-and-click interface. The idea is to create a set of data that will stimulate the unit under
test and cause it to execute a particular logic path. In its simplest form, a test case consists of values for
the formal parameters of a single subprogram within the unit under test. A more complex test case can
also contain values to be returned by a stubbed dependent, or values to be set into global data objects.
Test cases are constructed to stimulate individual subprograms. Each subprogram within a unit will have
its own series of test cases defined. The first step is to select a subprogram in the Environment View and
create a test case for it.
1. If a list of subprograms is not displayed under manager in the Environment View, click the
symbol preceding its name to display the list of subprograms.
The prefix "(cl)Manager" indicates a member function of class Manager.
2. Right-click PlaceOrder and select Insert Test Case from the popup menu:
BASIC TUTORIAL 130
Note: You can change the default name of a test case by right-clicking its name and
selecting Rename from the popup menu.
The following test case parameter tree appears in the Test Case Editor:
A tree item having branches is preceded by a plus symbol . To expand a tree item, simply click
the symbol.
BASIC TUTORIAL 131
4. Press Enter.
Table 2 is now the focus of your test case.
5. Double-click Table.
The parameter dialog box appears:
Notice that you can use this dialog to set simple scalar values, and also to build test cases for a
range of values or a list of values, or with user code.
6. Click Cancel to dismiss this dialog.
BASIC TUTORIAL 132
Note: When you create a test case, the only subprogram displayed for the UUT is the
subprogram that this test case has been created for, in this case, PlaceOrder.
7. For this tutorial, assume now that someone is occupying seat 0 at table 2.
Enter 0 into the Input Values field for Seat, and then press Enter.
You will use this same technique to set values for all parameters. Although you can access all
parameters of visible subprograms of the unit under test, and of any stubbed unit, it is only
necessary to select those parameters that are relevant to the test you are running.
Non-scalar parameters (arrays and structures) are accessed using the same tree-expansion
technique that is used for units and subprograms. Parameter Order is a structure with five fields.
Each field is an enumeration type.
At this point, you could create separate test cases for the other seats at table 2 (as well as for the
other tables in the restaurant); however, for the purposes of this basic tutorial, one test case (one
order at one seat) is sufficient.
You have someone sitting in seat 0 at table 2; it’s time now to take an order.
Entree STEAK
Dessert (leave unspecified)
Beverage MIXED_DRINK
Note: To clear a field, select the blank item at the top of the associated drop-down menu.
10. Save test case PLACEORDER.001: Either select File => Save from the main-menu bar or click the
Save button on the toolbar.
11. To access a test-case data listing, select Test => View => Test Case Data.
The Test Case Data Report for your test case appears in the Report Viewer.
12. In the Table of Contents section of this report, click Test Case Data.
BASIC TUTORIAL 134
At this point you could execute your test case as is, or you could add expected results for
comparing against actual results. Because the latter course is generally the more valuable, you will
now add expected results to your test case.
In this section, you will add expected results to the test case you created in the previous section:
If the Database subprograms do not appear under Stubbed Subprograms, see the Troubleshooting
section.
Because Data is a pointer, VectorCAST allows you to allocate a single or multiple instances of the
data type that is pointed to.
5. Press Enter.
You are now ready to enter expected values for comparing against the actual values returned by
UpdateTableRecord.
You might want to make more room by closing up the Parameter trees for both
GetTableRecord and manager.
In this section, you will add expected results to the test case you created in the previous section:
Enable the checkboxes for both Input and Expected, and enter 1 for both.
BASIC TUTORIAL 138
Click OK.
A single element named Data[0] appears in the parameter tree:
Note: Be sure you enter these values under Expected Values column, not into the Input
Values column.
6. Expand Order.
Order is an array whose index corresponds to the seat specified in the call to PlaceOrder. Because
we specified seat 0, we need to expand Order[0].
7. In the Input Values column, enter 0 next to <<Expand Indices: Size 4>>.
8. Press Enter.
BASIC TUTORIAL 140
The array element [0] in the array Order is expanded in the Parameter Tree, and the “0” is removed.
9. Expand the tree for Order[0].
10. For the Expected Value for Dessert, enter Pies. We expect Pie for dessert because PlaceOrder calls
AddIncludedDessert, which sets Dessert to Pie.
You now have a test case defined with input data and expected results.
The values entered into the Expected Values column for a stub are verified as they are passed into
the stub; the values entered into the Input Values column are passed out of the stub and back into
the test harness.
You must now save your data in order to make them a part of your test case.
When a test case has been modified and needs to be saved, a green icon appears to the left of its
name on a tab along the top of the Test Case Editor:
11. To save your modifications, click the Save button on the toolbar .
BASIC TUTORIAL 141
12. To view the saved data, select Test => View => Test Case data, then click the link “Test Case
Data.”
Table 1. Test Case Data
Test Case: "(CL)MANAGER::PLACE_ORDER.001"
File Name: "C-000001.DAT"
Input Test Data
UUT: manager.cpp
Subprogram: Manager::PlaceOrder
Table 2
Seat 0
Order
Soup Onion
Salad Caesar
Entree Steak
Beverage MixedDrink
Stubbed Subprograms:
Unit: database.h
Subprogram: DataBase::GetTableRecord
Data
[0]
NumberInParty 0
CheckTotal 0
Expected Test Data
Stubbed Subprograms:
Unit: database.h
Subprogram: DataBase::UpdateTableRecord
Data
[0]
IsOccupied true
NumberInParty 1
Order
[0]
Dessert Pie
Check_Total BETWEEN:12 AND:16
Test Case / Parameter Input User Code
Test Case / Parameter Expected User Code
Troubleshooting: If your test case Data report does not show any data in the section labeled Expected
Test Data, refer to the section titled Troubleshooting at the end of this tutorial.
13. To close this report, click the X on the Test Case Data tab. To close all reports, click on the X on
the Reports tab.
BASIC TUTORIAL 142
You have created a test case named PLACEORDER.001 that includes expected results. You are now
ready to execute it.
Because manager.cpp is a simple tutorial source file, this warning is not a problem. However, in most
situations, member data would be accessed during the test execution, and so it is best to instantiate a
class instance.
1. Return to the test’s Parameter Tree by clicking the Parameter Tree tab along the bottom of the Test
Case Editor.
2. Expand the UUT, manager, then expand <<GLOBAL>>.
BASIC TUTORIAL 143
In a typical source code unit, there may be many class instances listed. To determine the class
instance that is associated with the subprogram under test, look for the yellow-shaded one.
3. Next to the yellow-shaded class instance, Manager Instance, click the Input Values column cell
containing <<choose a subclass>>, and select Manager from the drop-down list.
Note: Typical source code would have many subclasses to choose from in this drop-down
list.
4. Press Enter.
The subclass Manager is displayed.
BASIC TUTORIAL 144
When the source code defines only one constructor, it is selected by default. Under ordinary
circumstances, you would need to click the Input Values cell containing <<choose a constructor>>,
and select a constructor from the drop-down list.
Note: Typical source code would have many constructors to choose from in this drop-down
list.
The collapsed member variables are expanded, public as well as private because this environment is
a whitebox environment. For the purposes of this tutorial, it is not necessary to initialize member
variables here.
5. Save the test case by clicking the Save icon on the toolbar .
6. Execute the test case again by clicking the Execute icon on the toolbar .
Click the green down-arrow on the toolbar, or scroll down the report until you come to the
green-shaded results section.
The green shading and the term “match” here indicate that the expected values you specified were
matched by actual values. Your test passed!
7.
BASIC TUTORIAL 145
The Test Case Management Report for environment TUTORIAL appears in the Report Viewer:
Note: You can customize the appearance of this or any other VectorCAST report. To
customize a report, select Tools => Options; click the Report tab; then click the Format
sub-tab.
3. To print your Test Case Management Report, click the Print button on the toolbar , or select
File => Print from the main-menu bar.
4. To save your report into a file, select File => Save As.
When the Save As dialog box opens, enter tutorial_report.html for the file name, then click Save.
Note: You can open a saved report with any HTML browser (Internet Explorer, Mozilla,
Netscape, etc.).
The Units Under Test must be instrumented for the kind of coverage you want: Statement, Branch,
Statement + Branch, and Statement + MC/DC, and MC/DC. In this section, you will instrument the
source files in your environment for statement coverage:
1. To instrument the source files in your environment for statement coverage, select Coverage =>
Initialize => Statement.
BASIC TUTORIAL 147
The status bar on the bottom right of the VectorCAST main window now indicates that statement
coverage is active:
2. To execute an existing test case and generate a report, click PLACEORDER.001 in the
Environment View, then click the execute button ( ).
When coverage is enabled, VectorCAST keeps track of the lines or branches in the source code that
are traversed during execution. You can access a report on the results by way of clicking the
checkbox next to the test case name in Environment View.
3. To access the coverage report for your test case, click the green checkbox to the left of
PLACEORDER.001.
An annotated version of the manager source code appears in the Coverage Viewer:
BASIC TUTORIAL 148
Each set of repeating numbers in the first column marks a subprogram within manager. The
ascending numbers in the second column mark the executable statements within a subprogram. The
statements in green have been exercised; the statements in red have not been exercised; the
statements in black cannot be exercised, or are the continuation of previous statements.
An asterisk (*) indicates a covered statement. The blue arrow marks the current line. You can move
the current line by means of the up and down arrows on your keyboard, or by clicking on a line.
Note the icons on the left-hand margin of the Coverage Viewer:
A circled minus-sign means the associated subprogram is fully expanded in the Coverage
Viewer, and can be collapsed. To collapse a subprogram (to its first line), double-click either the
circle or the first line of the subprogram.
Clicking the file symbol gives you immediate access to the associated source code.
The status bar (upper right) tells you the number and percentage of statements exercised.
4. Hover your mouse over Statements on the status bar.
A tool tip provides the exact number of lines covered; in this case, 16 of 41 (39%).
Note: VectorCAST’s animation feature allows you to view the step-by-step coverage of a
test case. This feature is described in the user guide accompanying your version of
VectorCAST.
The Metrics tab at the bottom of the Coverage Viewer displays a tabular summary of the coverage
achieved, on a per subprogram basis.
5. Click the Metrics tab:
BASIC TUTORIAL 149
This table tells you that subprogram PlaceOrder consists of 18 executable statements; that 11 of
these statements were exercised during the selected test; and that the complexity of the subprogram
is 5, meaning there are five distinct execution paths.
6. Click the Coverage tab to return to the previous view.
For each green line, you can identify the test case that most recently exercised it.
7. Hold your mouse over any green line in the Coverage Viewer.
A tool tip appears showing the name of the test case that exercised this line:
Note: If you had run multiple test cases with coverage enabled, and had multiple check
boxes selected in the Environment View, the tool tip would list all cases that provided
coverage for the selected line.
8. To access the test case that exercised a line, right-click on the line, then select the test case from the
popup menu that appears; in this example, select PLACEORDER.001:
BASIC TUTORIAL 150
Note: You could also select Window => Coverage Viewers (Coverage Results for MANAGER).
The Report Viewer displays a report showing the total coverage for all test cases executed on
manager. The associated source code displayed is color-coded to mark the exercised lines (green)
and the un-exercised lines (red):
2. Scroll down the report until you come to a table similar to the metrics table you accessed from the
Metrics tab.
The partially exercised subprograms, PlaceOrder and AddIncludedDessert, are shown in yellow;
the other subprograms, all unexercised, are shown in red. If 100% coverage for a subprogram is
achieved, it shows in green:
BASIC TUTORIAL 152
3. To print the Aggregate Coverage Report, click the Print button on the toolbar , or select File
=> Print from the main-menu bar.
4. To save your report into a file, select File => Save As.
When the Save As dialog box opens, enter tutorial_coverage.html for the file name, then click the
Save button .
You can open your saved report with any HTML browser (Internet Explorer, Mozilla, Netscape,
etc.).
5. Choose File => Close All in preparation for the next section.
Using Stub-By-Function
In the last section, we tested the subprogram PlaceOrder using inputs of Steak, Caesar, and MixedDrink
for the Order. During test execution, PlaceOrder calls the subprogram AddIncludedDessert, which checks
for the combination of Steak and Caesar and MixedDrink. It finds them and sets the Dessert to Pie.
However, we would like to test for the case when AddIncludedDessert doesn’t set the Dessert to Pie.
In this section, we will create a new test case which stubs the subprogram AddIncludedDessert, so that
we can cause it to return something else for the Dessert, such as Cake.
Note: Using drag-and-drop, you can duplicate a test case in another subprogram. Select the
test case, press Alt+Shift, drag-and-drop the test case on the destination subprogram. Only
data that applies to the parameters in the new subprogram are copied to the new test case.
PlaceOrder. The subprograms in this list are available for stubbing in this test case.
3. Click the checkbox next to AddIncludedDessert. The checkmark indicates that this subprogram
should be stubbed during test execution.
5. Press Enter.
BASIC TUTORIAL 155
The text in the cell changes to “<<alloc 1>>” and a structure Order[0] is displayed.
7. Set the Input Value for Dessert to Cake. When the test executes, Cake will be returned from
AddIncludedDessert, instead of the non-stubbed return value, Pie.
BASIC TUTORIAL 156
8. Scroll to the end of the Parameter Tree and locate UpdateTableRecord, which is part of Stubbed
Subprograms.
9. Change the Expected Value of the Dessert from PIE to CAKE.
10. To save the test case, click the Save button on the toolbar .
13. To access the coverage achieved for this test case, click the green checkbox to the left of
PLACEORDER.002.
An annotated version of the manager source code appears in the Coverage Viewer, showing the
aggregate coverage achieved by both test cases.
14. Uncheck the green checkbox next to PLACEORDER.001.
In this test case, the subprogram AddIncludedDessert is not covered, as evidenced by statements 2
3 and 2 4 in red. The subprogram does not have coverage because it was stubbed during the
execution of PLACEORDER.002.
15. In the Environment View, select the test case PLACEORDER.002, then choose Test => Scripting
=> Export Script... .
The Select Script Filename dialog appears.
16. Give the test script a name, such as _CL_MANAGER__PLACEORDER.002.tst, and click Save.
17. To open the test script, choose File => Open, set the File type to “Script Files (*.env *.tst)” and
then select _CL_MANAGER__PLACEORDER_002.tst. Click Open.
BASIC TUTORIAL 158
The line beginning with TEST.STUB indicates that AddIncludedDessert should be stubbed during this
test’s execution. The TEST.VALUE line in bold specifies the Input Value that the stubbed subprogram
returns to the test harness during this test’s execution. This is possible only because manager is a
Stubbed-by-Function (SBF) type of UUT, as specified during environment build.
BASIC TUTORIAL 159
l A shell script (.bat file on Windows, .sh or .csh on UNIX) sets the options, builds the environment,
imports and executes the test cases, and generates reports
l A test script (.tst) defines test cases to be imported by the shell script.
l The environment script (.env) defines the settings for the environment, such as the UUT(s), which
UUTs are Stub-by-Function, what is the method of stubbing, and where are the search directories.
1. Select Environment => Create Regression Scripts....
The Create Regression Scripts dialog appears.
2. In the first edit box, click the Browse button and navigate to any directory you choose. For the
purposes of this tutorial, we will specify the working directory as the destination for the regression
scripts.
3. Click Create.
BASIC TUTORIAL 160
VectorCAST creates the three regression scripts in the location you specified.
Tutorial Summary
You have now completed the Basic Tutorial. You:
l Built a test environment named TUTORIAL for testing a UUT named manager
l Defined and executed a test case named PLACEORDER.001
l Viewed source coverage information
l Viewed the Test Case Management Report and the Aggregate Coverage Report for your test
environment
l Duplicated a test case
l Stubbed a function in the UUT during test execution
l Created regression scripts for this environment, which include the shell script, test script, and
environment script
Troubleshooting
Problem: Dependents are not stubbed
If you do not see GetTableRecord (only <<GLOBAL>> and TableData, as shown below), then you did
not stub database. As a result, the test harness is using the actual unit (database), which means you cannot
specify any input or expected values for subprogram GetTableRecord.
BASIC TUTORIAL 161
To solve this problem, you can update the environment to change database from not stubbed to stub:
or
3. Click the radio button All under Stub dependencies to change database to be stubbed.
BASIC TUTORIAL 162
(Alternatively, you could have clicked Custom, then the toggle button and then cycled the
unit database until its type was stub (by prototype)).
4. Click Update.
The environment rebuilds; database is now stubbed.
Input Test Data
UUT: manager.cpp
Subprogram: Manager::PlaceOrder
Table 2
Seat 0
Order
Soup Onion
Salad Caesar
BASIC TUTORIAL 163
Entree Steak
Dessert
Beverage MixedDrink
Stubbed Subprograms:
Unit: database.h
Subprogram: DataBase::GetTableRecord
Data
[0]
NumberInParty 0
CheckTotal 0
Subprogram:
DataBase::UpdateTableRecord
Data
[0]
IsOccupied true
NumberInParty 1
VARY FROM: 12.0000
CheckTotal To:16.0000
BY:1
Expected Test Data
When testing more than one UUT in an environment, it is typical that the units interact. VectorCAST’s
multiple UUT (multi UUT) feature enables you to do this.
In VectorCAST, there are two types of test cases: simple test cases and compound test cases. In the Basic
Tutorial, you created and used a simple test case, which corresponded to a single invocation of a UUT. A
compound test case is a collection of simple test cases that invokes a UUT in different contexts. The data
is persistent across these invocations. Data persistence is very important when doing integration testing.
This tutorial will take you through the steps of building a compound test case to test the interaction
between the unit manager and the unit database. The unit manager is a simple database in which actual
data is stored in data objects defined within the unit. You are guided through the steps of building a
compound test case to write data into this database. You then use the same compound test case to retrieve
data from the database to verify it.
It is recommended that you review the relevant source listings in Appendix A, "Tutorial Source Code
Listings" on page 332before proceeding.
l Build a multi UUT environment using the environment script from the Basic Tutorial as a starting
point
l Build a class constructor
l Add a test case to unit database
MULTIPLE UUT TUTORIAL 165
The “Choose Compiler” page is skipped because it has already been specified.
2. Click the Load button.
MULTIPLE UUT TUTORIAL 166
In the “Choose File” dialog, choose the file TUTORIAL.env and click Open.
The Wizard fills in with the settings from the environment script, TUTORIAL.env.
The name is outlined in red to indicate that it is not unique; there is already an environment of that
name.
3. Change the name of this environment to “TUTORIAL_MULTI.”
Note: Double-clicking a name in the Unit Names pane is a shortcut for selecting the name
and then clicking the right-arrow ( ).
Both database and manager are now listed as Units Under Test with Stub-by-Function (SBF) enabled:
6. Click Build.
7. As the environment builds to include two UUTs, a series of messages is displayed in the Message
MULTIPLE UUT TUTORIAL 168
window.
The environment is opened:
Note in the Environment View that database is now listed as a UUT, and also that it has several
subprograms, including GetTableRecord and UpdateTableRecord.
In the next section, you will create a simple database test case and a simple manager test case and then
combine these two simple cases to create a compound case.
You create a compound test case by creating a separate test case for each subprogram to be included in
the test and then combining these test cases into a compound test case.
To create the simple test cases, you use the same procedure you used in the Basic Tutorial to create the
test case (PLACEORDER.001) that you deleted for the purposes of this tutorial.
l Create a test case to create an instance of the database class which will be shared; a new
PLACEORDER.001 test case will create the instance of the manager class.
l Create and add input values to the test case PLACEORDER.001, just as you did in the Basic
Tutorial. This test case will place an order at a table in the restaurant.
MULTIPLE UUT TUTORIAL 169
l Create a simple test case for subprogram GetTableRecord, which reads data from the database. This test
case will be used to verify that PlaceOrder is updating the database properly.
l Combine these test cases into a compound test case
The yellow highlighting indicates the class that is associated with the subprogram under test. There
may be many classes defined in a unit, and the highlighting indicates which one you would want to
choose a subclass and constructor for.
A special case is the test case for a constructor itself. You don’t need to pick a subclass and
constructor, so it is dimmed. When VectorCAST executes the test case, the constructor is
automatically called, and the class is therefore automatically instantiated.
At this point you have constructed a class object for the DataBase class. When you build the
compound test case, this test case should be placed first, to “initialize” a class object so that all of
the methods of the class can be called within the context of the same class object.
Insert PLACEORDER.001
In this section, you will:
l Create and add Input Values to the test case PLACEORDER.001. This test case will place an order
at a table in the restaurant.
l Create a simple test case for the subprogram GetTableRecord, which retrieves data from the database.
This test case will be used to verify that PlaceOrder is updating the database properly.
l Place these test cases into a compound test case
MULTIPLE UUT TUTORIAL 170
1. In the Environment View, expand manager into its subprograms, and then expand (cl)
Manager::PlaceOrder into its subprograms.
2. Right-click PlaceOrder and choose Insert Test Case.
The test case PLACEORDER.001 displays in the Test Case Editor.
6. Scroll down and locate the subprogram (cl)Manager::PlaceOrder. Assign Input Values for Table
and Seat as you did in the Basic Tutorial:
Table 2
Seat 0
7. Expand Order.
8. Assign values to the Order parameters as indicated below.
The idea is to populate an Order record with a set of Input Values you will also use as expected
values for a retrieval operation involving GetTableRecord:
Soup ONION
Salad CAESAR
Entree STEAK
Dessert (leave unspecified)
Beverage MIXED_DRINK
These values translate into the following situation: Someone is occupying seat 0 at table 2, and has
ordered onion soup, a Caesar salad, a steak entrée, a mixed drink. This combination yields an
included dessert of Pie, so we will expect PIE when later verifying the Order.
9. Save the test case by clicking the Save button on the toolbar .
Because you will be making your test case part of a compound test case, and you only want to use
this test within a compound case, you need to designate it as Compound Only. Compound Only
test cases can only be executed from within a compound test. They cannot be executed individually
or as part of a batch.
In some cases, you will want to use simple test cases both individually and as part of a compound
MULTIPLE UUT TUTORIAL 172
case. In these instances, it is not necessary to apply the Compound Only attribute to the simple
cases.
10. Right-click (CL)MANAGER::PLACEORDER.001 and select Compound Only.
The test case typeface changes to italic, signifying that this test case has been designated
Compound Only.
1. In the Environment View, expand database into its subprograms (if not already expanded).
2. Right-click (cl)DataBase::GetTableRecord and select Insert Test Case.
The test case GETTABLERECORD.001 appears in the Test Case Editor:
We do not want to set the class instance in this test case, because doing so would overwrite the
class instantiated by the constructor test case.
3. Keeping with our example situation, enter 2 as the input value for Table.
Note: Make sure you enter the value into the Input Values column, and not into the
Expected Values column. You will enter the expected values for this case in the next step.
4. To allocate one element of the array Data, enter 1 in the Input Values column for Data, or double-
click Data.
MULTIPLE UUT TUTORIAL 173
One element named Data[0] appears, and the “1” is replaced with “<<alloc 1>>”.
5. Click the Expected Values column for Data and enter 1, to gain access to the structure.
The cell displays “<<access 1>>”.
Note: Make sure you enter these values in the Expected Values column.
8. Expand Order.
Order is an array of structures of size 4.
9. To view the array-indices of Order, right-click on <<Expand Indices: Size 4>> and select Expand
All Array Indices.
MULTIPLE UUT TUTORIAL 174
In this example, you want to verify input values written to the application database. The data
consists of an order taken for seat 0 at table 2.
10. Expand Order[0].
Order[0] corresponds to seat 0. The expected values you specify for Order[0] must match the input
values you previously specified in PLACEORDER.001.
Troubleshooting: Important: If you use any other index, the expected results will not match.
11. Assign the following Expected Values to the appropriate fields of Order[0]:
Soup Onion
Salad Caesar
Entree Steak
Dessert Pies
Beverage MixedDrink
Note: Make sure you enter these values into the Expected Values column. If the Expected
Values column is dimmed, then you forgot to “Click the Expected Values column for Data
and enter 1, to gain access to the structure.”
MULTIPLE UUT TUTORIAL 175
You now have three test cases built: The first, DATABASE.001, is the constructor for the DataBase
instance. We will use this test case in the Compound test case to create a common instance. The second
case (PLACEORDER.001) places a dinner order from seat 0 at table 2. This order is stored in the database
by way of PlaceOrder calling UpdateTableRecord. The third case (GETTABLERECORD.001)
retrieves the order from the database for verification.
You will now use these test cases to create a compound test case.
1. In the Environment View, right-click <<COMPOUND>> and select Insert Test Case.
A test case named <<COMPOUND>>.001 appears under <<COMPOUND>>, and is selected
(highlighted) by default.
2. Click and hold the cursor on (CL)DATABASE::DATABASE.001 in the Environment View. Drag
5. Save.
You are now ready to execute your compound test case.
6. In the Environment View, select <<COMPOUND>>.001, then click Execute Test on the
toolbar.
An execution report for the compound test case appears in the Report Viewer.
Note: If your compound test case fails, make sure PLACEORDER.001 uses parameter values
table 2, seat 0, and that GETTABLERECORD.001 uses table 2 and the proper expected
values in Order[0], and both <<alloc 1>> and <<access 1>>.
Note that the expected values you specified were matched against corresponding actual values,
verifying the data flow from manager to database.
The tab for database appears in the Coverage Viewer because this is the unit called in the first slot.
9. To view the coverage for the unit manager , right-click unit manager in the Environment View, and
choose View Coverage.
MULTIPLE UUT TUTORIAL 179
A tab for manager opens in the Coverage Viewer, scrolled to the beginning of the subprogram
PlaceOrder.
In the Coverage Viewer, note that the statement assigning the value Pie to Order-> Dessert is green,
indicating that it was covered by test execution.
2. Select <<COMPOUND>>.001 in the Environment View and click the Execute button in the
toolbar.
3. Click the checkbox preceding <<COMPOUND>>.001 in the Environment View:
4. Open the Coverage Viewer for the manager unit by right-clicking manager in the Environment
View and choosing View Coverage.
5. Scroll to the first covered line of PlaceOrder.
In the Coverage Viewer, the instances of the ‘(T)’ symbol indicate that two PlaceOrder branches
were covered: the first at the subprogram entry point; the second at the Steak branch in the switch
MULTIPLE UUT TUTORIAL 180
statement.
VectorCAST allows you to build more complex tests by linking multiple simple test cases together.
This feature allows you to test threads of execution while maintaining the data common to the
various units and subprograms.
In this section, you will modify test case PLACE_ORDER.001 to iterate over the 4 seats at table 2 while
iterating over the four entrées. The net effect will be to assign a different entrée to each seat.
Your entry changes to 0..3/1. The /1 indicates that the input value for Seat will iterate over its range
with a delta of 1. (It is possible to specify a delta other than 1.)
3. Double-click Entree.
A dialog appears for setting parameter specifications:
4. Click the Range Values tab, and then enable the Input fields by clicking the checkbox at the far
right:
MULTIPLE UUT TUTORIAL 182
6. Click OK.
MULTIPLE UUT TUTORIAL 183
7. Click Save.
You have now assigned input ranges to two parameters. By default, when two parameters are
assigned input ranges, they will iterate in parallel, which is what you want to occur in this case.
(There is a setting to make them iterate in combination.)
These two parameters will iterate with the following value pairs:
Seat = 0 Entree = Steak
Seat = 1 Entree = Chicken
Seat = 2 Entree = Lobster
Seat = 3 Entree = Pasta
Given this information, you can specify expected values in your compound test case for each seat.
8. Click the tab for test case GETTABLERECORD.001 at the top of the Test Case Editor.
The parameter tree for test case GETTABLERECORD.001 comes to the top. You need to edit this
tree to reflect the expected results for your compound test.
You now need to specify expected values for each of the other three seats at table 2.
9. You have already specified values for Order[0], so move on to Order[1].
10. Expand Order[1]. (If you have recently re-opened the TUTORIAL_MULTI environment, then the
unused array elements have been collapsed. If Order[1] is not visible, simply right-click on
<<Expand Indices: Size 4>> and choose Expand All Array Indices.)
11. Order[1] maps to seat 1. Specify the following expected values for seat 0:
Soup Onion
Salad Caesar
Entree Chicken
Dessert NoDessert (see Note)
Beverage MixedDrink
Note: For Order[1], Order[2], and Order[3], PlaceOrder calls AddIncludedDessert with a soup,
salad, and entrée combination that does not qualify for Pie, so we expect NoDessert.
Entree Lobster
Dessert NoDessert
Beverage MixedDrink
13. Expand Order[3].
Enter the following expected values for seat 3:
Soup Onion
Salad Caesar
Entree Pasta
Dessert NoDessert
Beverage MixedDrink
Note: Be sure you have populated the Expected Values column for Order, and not the Input
Values column.
You now have Order data for each seat at table 2. Note that these orders are identical in each case
except for the entrée and dessert. Only the Entree variable is needed to exercise each branch in the
switch statement.
You must now change the number of occupied seats at table 2 to reflect the current test case.
14. Scroll up to NumberInParty and change the expected value to 4.
15. Click Save.
16. Select <<COMPOUND>>.001 in the Environment View, then click theExecute button .
<<COMPOUND>>.001 turns green; an execution report for your compound test appears in the Test
Case Editor. Your test has passed.
MULTIPLE UUT TUTORIAL 185
17. Scroll down the report to view the green-coded results for each element of Order:
Note: The amount of instruction given in this section will be a little less than in the previous
sections.
1. Under the manager unit, insert a test case for (cl)Manager::GetCheckTotal, and make it Compound
Only.
MULTIPLE UUT TUTORIAL 186
You can now add your new test case to the compound case.
5. Double-click <<COMPOUND>>.001 in the Environment View.
MULTIPLE UUT TUTORIAL 187
6. Click the Compound Tree tab at the bottom of the Test Case Editor.
The Test Case Editor displays the slots in test case <<COMPOUND>>.001.
7. Add test case GETCHECKTOTAL.001 to the compound by dragging and dropping it as the last
slot.
GETCHECKTOTAL.001 displays as slot 4 in your compound test case:
8. Save.
10. Click the green down-arrow on the toolbar, or scroll down the report until you come to the
green-shaded results section. You can see that the check total for table 2 was $54.
11. To view the coverage data, click the green checkbox preceding <<COMPOUND>>.001 in the
Environment View.
MULTIPLE UUT TUTORIAL 188
12. Click the manager tab at the top of the Coverage Viewer to see the coverage for the unit manager.
Notice from the green coloring that by iterating over four entrées, you exercised four of the five
switch branches. Notice from the status bar that total branch coverage was 10 of 23, or 43%.
At this point, you might want to initialize a different type of coverage. In addition, you might want
to try adding a test case for ClearTable (with Table also set at 2).
MULTIPLE UUT TUTORIAL 189
Tutorial Summary
This tutorial built on the environment you created in the Basic Tutorial. You changed one of the
dependent units from a smart stub into a UUT. You then added test cases to both units, and combined
these test cases into a Compound test case, which you used to test the data flow from manager to
database. When test cases are combined into a Compound test case, the data remains persistent between
them.
In sum, you:
l Built a multi UUT environment using the environment script from the Basic Tutorial as a starting
point
l Built a class constructor
l Added a test case for the subprogram PlaceOrder in manager
l Added a test case for the subprogram GetTableRecord in database
l Used these simple test cases to create a compound case
l Verified the data flow between UUTs manager and database
l Set up range iterations for a scalar parameter and an enumeral
l Added a test case to an existing compound case
Ada Tutorials
INTRODUCTION 191
Introduction
The tutorials in this chapter demonstrate how to use VectorCAST/Ada to unit-test an application written
in the Ada programming language.
For a comprehensive explanation of the VectorCAST/Ada features, refer to the VectorCAST/Ada User’s
Guide.
The modules you will test in the first two tutorials are components of a simple order-management
application for restaurants. The source listings for this application are available in Appendix A, "Tutorial
Source Code Listings" on page 332. It is recommended that you at least scan through these listings before
proceeding with the tutorials.
You should run the tutorials in this chapter in the order presented.
You can stop a tutorial at any point and return later to where you left off. Each tutorial session is
automatically saved. To return to where you left off, simply restart VectorCAST and the use File
=> Recent Environments to reopen the tutorial environment.
Basic Tutorial
The Basic Tutorial introduces you to all the steps necessary to build a test environment, generate test
cases, produce reports, and verify code coverage.
Note: User entries and selections are represented in this tutorial in bold. For example: “Enter
Demo, then click OK”.
For efficiency, this tutorial assumes a working directory named vcast_tutorial located at the top level in
your file tree, and a sub-directory named ADA. You can, however, locate this directory any place you
want, and make the necessary translations in the text as you progress through the tutorial. Also for
efficiency, this tutorial assumes you will be running the tutorial in a Windows environment, using
Windows syntax for file paths and things specific to an operating system (Windows, Solaris, and UNIX).
Again, you should have no problems making the necessary translations.
The files you need to copy are located in the directory in which you installed VectorCAST. On
BASIC TUTORIAL 192
In Windows, enter:
$ cp $VECTORCAST_DIR/Tutorial/ada/* vcast_tutorial/ADA
In a Windows or shell window, change directory to the directory into which you copied the tutorial files,
and then compile the Ada files using a compiler included in your PATH environment variable.
For example, to use the Green Hills Ada compiler, you would type:
You will:
1. With the VectorCAST main window open, select File => Set Working Directory.
A browsing dialog appears.
2. Navigate to C:\vcast_tutorial\ADA ; click Choose.
The location and name of the working directory you specified appear at the lower right-hand corner
of the VectorCAST main window:
BASIC TUTORIAL 194
1. Choose File => Set Product Mode => Ada Host Environment
2. Choose Tools => Options.
3. In the Option dialog, click the Builder tab.
4. Uncheck the option “GNAT version 5 or greater”
5. Click OK.
If the only type of environment licensed is Ada, the Create New Environment wizard appears when
you click the New button.
If you are planning to use VectorCAST with a target compiler, it is recommended you first
go through the tutorials using a Host version of your compiler. Once you are familiar with
the basic functionality of VectorCAST, refer to the VectorCAST/RSP User’s Guide for
information specific to your target.
The Choose Compiler page of the Create New Environment wizard appears:
Specifying a compiler
You use the Choose Compiler page to specify a compiler. The compiler you specify must be included in
your PATH environment variable.
1. To access a list of Ada compilers supported by VectorCAST, click the down-arrow at the far right of
the Compilation system field (bordered in red).
2. Select an Ada compiler from the drop-down menu that appears.
BASIC TUTORIAL 196
When you select a compiler, the red border disappears from the Compilation system field:
3. Click Next.
The Name the Environment page appears:
2. Click Next.
3. We’ll be initializing coverage later in the tutorial; for now, just click Next.
BASIC TUTORIAL 198
Note: The text on this page depends on the compiler you selected.
1. Click the Browse button on the Locate Source Files page to display the Choose Directory
dialog:
In this tutorial, you are building your environment in the same location in which the source files to
be tested are located. In practice, you might need to navigate to a different directory.
2. Click Choose.
BASIC TUTORIAL 199
3. Click Next.
The Choose UUTs & Stubs page appears:
The pane under Unit Names lists the units that VectorCAST found in the specified source directory. You
can select one or more of these units to be UUTs. For this tutorial, you will select only MANAGER.
1. Click MANAGER under Unit Names, and then click the move-right button; or simply double-click
MANAGER. The name The name MANAGER appears under UUT in the Units column:
Three options are available under Stub dependencies for designating stubbing: All, None, or
Custom:
As indicated, VectorCAST defaults to stubbing all dependent units. You can override this setting
by selecting None or Custom or by telling VectorCAST to ignore all dependent units. The Custom
option allows you to select individual subprograms for stubbing.
See VectorCAST/Ada User's Guide for information on using the STUB and IGNORE
nodes in conjunction with the Stub dependencies settings.
For the purposes of this tutorial you will accept the default setting (All).
2. Click Next
The User Code appears. The User Code page is optional and not needed for this tutorial.
BASIC TUTORIAL 200
This page allows you to check your test-environment specifications before you generate the test
harness.
1. Click the Build button to compile your test-environment specifications you generate the test
harness.
BASIC TUTORIAL 201
VectorCAST has created an environment file named TUTORIAL.vce and a subdirectory named
TUTORIAL.
The Environment View shows that the current environment (TUTORIAL) has one UUT, named
MANAGER, which has six subprograms:
At this point, VectorCAST has built the complete test harness necessary to test the MANAGER unit,
including:
l A test directory with all test-harness components compiled and linked.
l The test driver source code that can invoke all subprograms in the file (MANAGER).
lThe stub source code for the dependent unit (DATABASE).
Note what was accomplished during environment creation:
l The unit under test was parsed. The dependent unit did not have to be parsed, because
its prototype was used to determine the parameter profile.
l The data-driven driver and stub source code were generated.
l The test code generated by VectorCAST was compiled and linked with the UUT to
form an executable test harness.
The harness that VectorCAST builds is data driven. This means that data sets can be built to stimulate
the different logic paths of the unit under test without ever having to re-compile the harness. You are
now ready to build test cases for the subprograms in the unit under test ( MANAGER).
The process of building test cases with VectorCAST is very simple. All the information is available by
means of a point-and-click interface. The idea is to create a set of data that will stimulate the unit under
test and cause it to execute a particular logic path. In its simplest form, a test case consists of values for
the formal parameters of a single subprogram within the unit under test. A more complex test case can
also contain values to be returned by a stubbed dependent, or values to be set into global data objects.
Test cases are constructed to stimulate individual subprograms. Each subprogram within a unit will have
its own series of test cases defined. The first step is to select a subprogram in the Environment View and
create a test case for it.
1. If a list of subprograms is not displayed under manager in the Environment View, click the
symbol preceding its name to display the list of subprograms.
Note: You can change the default name of a test case by right-clicking its name and
selecting Rename from the popup menu.
The following test case parameter tree appears in the Test Case Editor:
A tree item having branches is preceded by a plus symbol . To expand a tree item, simply click
the symbol.
4. Press Enter.
Table 2 is now the focus of your test case.
5. Double-click Table.
BASIC TUTORIAL 204
Notice that you can use this dialog to set simple scalar values, and also to build test cases for a
range of values or a list of values, or with user code.
6. Click Cancel to dismiss this dialog.
You will use it in the next tutorial.
Note: When you create a test case, the only subprogram displayed for the UUT is the
subprogram that this test case has been created for, in this case, PLACE_ORDER.
7. For this tutorial, assume now that someone is occupying seat 1 at table 2.
Enter 1 into the Input Values field for Seat, and then press Enter.
BASIC TUTORIAL 205
You will use this same technique to set values for all parameters. Although you can access all
parameters of visible subprograms of the unit under test, and of any stubbed unit, it is only
necessary to select those parameters that are relevant to the test you are running.
Non-scalar parameters (arrays and structures) are accessed using the same tree-expansion
technique that is used for units and subprograms. Parameter Order is a structure with five fields.
Each field is an enumeration type.
At this point, you could create separate test cases for the other seats at table 2 (as well as for the
other tables in the restaurant); however, for the purposes of this basic tutorial, one test case (one
order at one seat) is sufficient.
You have someone sitting in seat 1 at table 2; it’s time now to take an order.
Note: To clear a field, select the blank item at the top of the associated drop-down menu.
BASIC TUTORIAL 206
10. Save test case PLACE_ORDER.001: Either select File => Save from the main-menu bar or click the
Save button on the toolbar.
11. To access a test-case data listing, select Test => View => Test Case Data.
The Test Case Data Report for your test case appears in the Report Viewer.
12. In the Table of Contents section of this report, click Test Case Data.
The report jumps to the Test Case Data section.
At this point you could execute your test case as is, or you could add expected results for
comparing against actual results. Because the latter course is generally the more valuable, you will
now add expected results to your test case.
VectorCAST provides you with a simple way to define expected results for each test case. You can add
expected results at the time you set input values or at a later time. As a test case is executed, the expected
results are compared against actual results to determine whether the test case passed or failed.
In this section, you will add expected results to the test case you created in the previous section:
1. Click the preceding DATABASE; then click the preceding GET_TABLE_RECORD. Then
click the preceding DATA.
BASIC TUTORIAL 207
Note: If you encounter any problems, refer to the section titled Troubleshooting.
You can now enter expected values for NUMBER_IN_PARTY and CHECK_TOTAL. Before you
do this, however, you need to initialize the data returned by GET_TABLE_RECORD.
2. To initialize the data returned by GET_TABLE_RECORD, enter 0 into the Input Values fields for
NUMBER_IN_PARTY and CHECK_TOTAL
You are now ready to enter expected values for comparing against the actual values returned by
UPDATE_TABLE_RECORD.
You might want to make more room by closing up the Parameter trees for both GET_
TABLE_RECORD and manager.
BASIC TUTORIAL 208
In this section, you will add expected results to the test case you created in the previous section:
Note: Be sure you enter your values into the Expected Values column, and not into the
Input Values column.
3. Expand ORDER
ORDER is an array whose index corresponds to the seat specified in the call to PLACE_ORDER.
Because we specified seat 1, we need to expand ORDER(1).
BASIC TUTORIAL 210
4. In the Input Values column, enter 1 next to <<Expand Indices: Size 4>>.
5. Press Enter.
The array element (1) in the array ORDER is expanded in the Parameter Tree, and the “1” is removed.
6. Expand the tree for ORDER(1).
7. For the Expected Value for Dessert, enter PIE. We expect Pie for dessert because PLACE_ORDER
calls ADD_INCLUDED_DESSERT, which sets the DESSERT to PIE.
BASIC TUTORIAL 211
You now have a test case defined with input data and expected results.
The values entered into the Expected Values column for a stub are verified as they are passed into
the stub; the values entered into the Input Values column are passed out of the stub and back into
the test harness.
You must now save your data in order to make them a part of your test case.
When a test case has been modified and needs to be saved, a green icon ( ) appears to the left of
its name on a tab above the Test Case Editor
Table 1. Test Case Data
Test Case: "PLACE_ORDER.001"
File Name: "C-000001.DAT"
Input Test Data
UUT: MANAGER
Subprogram: PLACE_ORDER
TABLE (in ) 2
SEAT (in ) 1
ORDER (in out)
SOUP ONION
SALAD CAESAR
ENTREE STEAK
BEVERAGE MIXED_DRINK
Stubbed Unit: DATABASE
Subprogram: GET_TABLE_RECORD
BASIC TUTORIAL 212
DATA ( out)
NUMBER_IN_PARTY 0
CHECK_TOTAL 0
Expected Test Data
Stubbed Unit: DATABASE
Subprogram: UPDATE_TABLE_RECORD
DATA (in )
IS_OCCUPIED TRUE
NUMBER_IN_PARTY 1
ORDER
(1)
DESSERT PIE
CHECK_TOTAL BETWEEN:12.0 AND:16.0
Test Case / Parameter Input User Code
Test Case / Parameter Expected User Code
Troubleshooting: If your test case Data report does not show any data in the section labeled Expected
Test Data, refer to the section titled Troubleshooting at the end of this tutorial.
10. To close this report, click the X on the Test Case Data tab. To close all reports, click on the X on
the Reports tab.
You have now created a test case named PLACE_ORDER.001 that includes expected results. You are
now ready to execute it.
1. To execute your test case, click PLACE_ORDER.001 in the Environment View, then click the
Execute button on the toolbar.
BASIC TUTORIAL 213
2. Click the green down-arrow on the toolbar, or scroll down the report until you come to a group
of table cells shaded in green.
The green shading and the term match here indicate that the expected values you specified were
matched by actual values. Your test passed!
BASIC TUTORIAL 214
The Test Case Management Report for environment TUTORIAL appears in the Report Viewer:
Note: You can customize the appearance of this or any other VectorCAST report. To
customize a report, select Tools => Options; click the Report tab; then click the Format
sub-tab.
3. To print your Test Case Management Report, click the Print button on the toolbar , or select
File => Print from the main-menu bar.
4. To save your report into a file, select File => Save As.
When the Save As dialog box opens, enter tutorial_report.html for the file name, then click Save.
Note: You can open a saved report with any HTML browser (Internet Explorer, Mozilla,
Netscape, etc.).
The Units Under Test must be instrumented for the kind of coverage you want: Statement, Branch,
MC/DC, DO-178B Level A, DO-178B Level B, or DO-178B Level C. In this section, you will instrument
the source files in your environment for statement coverage:
BASIC TUTORIAL 216
1. To instrument the source files in your environment for statement coverage, select Coverage =>
Initialize => Statement.
The status bar on the bottom right of the VectorCAST main window now indicates that statement
coverage is active:
2. To execute an existing test case and generate a report, click PLACE_ORDER.001 in the
Environment View, then click the execute button ( ).
When coverage is enabled, VectorCAST keeps track of the lines or branches in the source code that
are traversed during execution. You can access a report on the results by way of clicking the
checkbox next to the test case name in Environment View.
3. To access the coverage report for your test case, click the green checkbox to the left of PLACE_
ORDER.001.
An annotated version of the MANAGER source code appears in the Coverage Viewer:
Each set of repeating numbers in the first column marks a subprogram within MANAGER. The
ascending numbers in the second column mark the executable statements within a subprogram. The
statements in green have been exercised; the statements in red have not been exercised; the
statements in black cannot be exercised, or are the continuation of previous statements.
An asterisk (*) indicates a covered statement. The blue arrow marks the current line. You can move
BASIC TUTORIAL 217
the current line by means of the up and down arrows on your keyboard, or by clicking on a line.
Note the icons on the left-hand margin of the Coverage Viewer:
A circled minus-sign means the associated subprogram is fully expanded in the Coverage
Viewer, and can be collapsed. To collapse a subprogram (to its first line), double-click either the
circle or the first line of the subprogram.
Clicking the file symbol gives you immediate access to the associated source code.
The status bar (upper right) tells you the number and percentage of statements exercised.
4. Hover your mouse over Statements on the status bar.
A tool tip shows the number of lines covered: 10 of 41 (24%).
Note: VectorCAST’s animation feature allows you to view the step-by-step coverage of a
test case. This feature is described in the user guide accompanying your version of
VectorCAST.
The Metrics tab at the bottom of the Coverage Viewer displays a tabular summary of the coverage
achieved, on a per subprogram basis.
5. Click the Metrics tab:
This table tells you that subprogram PLACE_ORDER consists of 12 executable statements; that 8 of
BASIC TUTORIAL 218
these statements were exercised during the selected test; and that the complexity of the subprogram
is 5, meaning there are five distinct execution paths.
6. Click the Coverage tab to return to the previous view.
For each green line, you can identify the test case that most recently exercised it.
7. Hold your mouse over any green line in the Coverage Viewer.
A tool tip appears showing the name of the test case that exercised this line:
Note: If you had run multiple test cases with coverage enabled, and had multiple check
boxes selected in the Environment View, the tool tip would list all cases that provided
coverage for the selected line.
8. To access the test case that exercised a line, right-click on the line, then select the test case from the
popup menu that appears; in this example, select PLACE_ORDER.001:
Note: You could also select Window => Coverage Viewers (Coverage Results for MANAGER).
2. Scroll down the report until you come to a table similar to the metrics table you accessed for
PLACE_ORDER from the Metrics tab.
BASIC TUTORIAL 220
3. To print the Aggregate Coverage Report, click the Print button on the toolbar , or select File
=> Print from the main-menu bar.
4. To save your report into a file, select File => Save As.
When the Save As dialog box opens, enter tutorial_coverage.html for the file name, then click the
Save button .
You can open your saved report with any HTML browser (Internet Explorer, Mozilla, Netscape,
etc.).
5. Choose File => Close All in preparation for the next section.
l A shell script (.bat file on Windows, .sh or .csh on UNIX) sets the options, builds the environment,
imports and executes the test cases, and generates reports
l A test script (.tst) defines test cases to be imported by the shell script.
l The environment script (.env) defines the settings for the environment, such as the UUT(s), which
UUTs are Stub-by-Function, what is the method of stubbing, and where are the search directories.
BASIC TUTORIAL 221
2. In the first edit box, click the Browse button and navigate to any directory you choose. For the
purposes of this tutorial, we will specify the working directory as the destination for the regression
scripts.
3. Click Create.
BASIC TUTORIAL 222
VectorCAST creates the three regression scripts in the location you specified.
Tutorial Summary
You have now completed the Basic Tutorial. You:
l Built a test environment named TUTORIAL for testing a UUT named MANAGER
l Defined and executed a test case named PLACE_ORDER.001
l Viewed source coverage information
l Viewed the Test Case Management Report and the Aggregate Coverage Report for your test
environment
l Automatically built additional test cases for exercising all the execution paths through MANAGER
l Achieved 80% statement coverage, and 74% branch coverage
l Created regression scripts for this environment, which include the shell script, test script, and
environment script
Troubleshooting
Problem: Dependents are not stubbed
If you do not see unit DATABASE and subprogram GET_TABLE_RECORD (as shown below), then you
did not stub DATABASE.
BASIC TUTORIAL 223
As a result, the test harness is using the actual unit (DATABASE), which means you cannot specify any
input or expected values for subprogram GET_TABLE_RECORD.
To solve this problem, you can update the environment to change DATABASE from not stubbed to stub:
3. Click the radio button “All” under “Stub dependencies” to change DATABASE to be stubbed.
4. Click Update.
The environment rebuilds; DATABASE is now stubbed.
Test Case: "PLACE_ORDER.001"
BASIC TUTORIAL 224
File Name: "C-000001.DAT"
Requirements/Notes
Input Test Data
UUT: MANAGER
Subprogram: PLACE_ORDER
TABLE (in ) 2
SEAT (in ) 1
SOUP ONION
SALAD CAESAR
ENTREE STEAK
DESSERT
BEVERAGE MIXED_DRINK
Stubbed Unit: DATABASE
Subprogram: GET_TABLE_RECORD
DATA ( out)
NUMBER_IN_PARTY 0
CHECK_TOTAL 0
Subprogram: UPDATE_TABLE_RECORD
DATA (in )
IS_OCCUPIED TRUE
NUMBER_IN_PARTY 1
VARY FROM: 12.0000
CHECK_TOTAL To:16.0000
BY:1
You can resize the VectorCAST main window or scroll the Test Case Editor to better view the
column, if needed.
When testing more than one UUT in an environment, it is typical that the units interact. VectorCAST’s
multiple UUT (multi UUT) feature enables you to do this.
In VectorCAST, there are two types of test cases: simple test cases and compound test cases. In the Basic
Tutorial, you created and used a simple test case, which corresponded to a single invocation of a UUT. A
compound test case is a collection of simple test cases that invokes a UUT in different contexts. The data
is persistent across these invocations. Data persistence is very important when doing integration testing.
This tutorial will take you through the steps of building a compound test case to test the interaction
between the unit manager and the unit database. The unit manager is a simple database in which actual
data is stored in data objects defined within the unit. You are guided through the steps of building a
compound test case to write data into this database. You then use the same compound test case to retrieve
data from the database to verify it.
It is recommended that you review the relevant source listings in Appendix A, "Tutorial Source Code
Listings" on page 332before proceeding.
l Build a multi UUT environment by updating the environment you built in the Basic Tutorial
l Add a test case to unit DATABASE
l Use the simple test cases to create a compound case
MULTIPLE UUT TUTORIAL 226
Removing PLACE_ORDER.001
The test case present in this environment, PLACE_ORDER.001, was created on the basis of DATABASE
being a stubbed dependent of MANAGER. However, in your new environment, you want DATABASE to be a
second UUT. Therefore, you must remove PLACE_ORDER.001, because the expected values in the
stubbed unit are no longer applicable.
2. Click Yes.
The name PLACE_ORDER.001 disappears from the Environment View.
This wizard is similar to the Create Environment wizard you used in the Basic Tutorial to create the
original environment. There are no red outlines or accents because there are no errors or missing
items of information.
2. Click Choose UUTs & Stubs.
Note: Double-clicking a name in the Unit Names pane is a shortcut for selecting the name
and then clicking the right-arrow ( ).
Both DATABASE and MANAGER are now listed as Units Under Test:
4. Click Update.
5. During processing, messages display in the Message window. A message appears confirming that
the update has completed:
6. Click OK.
MULTIPLE UUT TUTORIAL 229
Note in the Environment View that DATABASE is now listed as a UUT, and also that it has two
subprograms: GET_TABLE_RECORD and UPDATE_TABLE_RECORD.
In the next section, you will create a simple DATABASE test case and a simple MANAGER test case and then
combine these two simple cases to create a compound case.
You create a compound test case by creating a separate test case for each subprogram to be included in
the test and then aggregating these test cases into a compound test case.
To create the simple test cases, you use the same procedure you used in the Basic Tutorial to create the
test case PLACE_ORDER.001 that you deleted for the purposes of this tutorial.
Insert PLACE_ORDER.001
In this section, you will:
l Create and add Input Values to the test case PLACE_ORDER.001. This test case will place an order at
a table in the restaurant.
l Create a simple test case for the subprogram GET_TABLE_RECORD, which retrieves data from the
database. This test case will be used to verify that PLACE_ORDER is updating the database properly.
l Place these test cases into a compound test case
1. In the Environment View, expand MANAGER into its subprograms, and then expand PLACE_
ORDER into its test cases.
MULTIPLE UUT TUTORIAL 230
3. Assign Input Values for Table and Seat as you did in the Basic Tutorial:
Table: 2
Seat: 1
4. Expand ORDER.
5. Assign values to the ORDER parameters as indicated below.
The idea is to populate an ORDER record with a set of Input Values you will also use as expected
values for a retrieval operation involving GET_TABLE_RECORD:
Soup ONION
Salad CAESAR
Entree STEAK
Dessert (leave unspecified)
Beverage MIXED_DRINK
These values translate into the following situation: Someone is occupying seat 1 at table 2, and has
ordered onion soup, a Caesar salad, a steak entrée, a mixed drink. This combination yields an
included dessert of PIE, so we will expect PIE when later verifying the ORDER.
MULTIPLE UUT TUTORIAL 231
6. Save the test case by clicking the Save button on the toolbar.
Because you will be making your test case part of a compound test case, and you only want to use
this test within a compound case, you need to designate it as Compound Only. Compound Only
test cases can only be executed from within a compound test. They cannot be executed individually
or as part of a batch.
In some cases, you will want to use simple test cases both individually and as part of a compound
case. In these instances, it is not necessary to apply the Compound Only attribute to the simple
cases.
7. Right-click PLACE_ORDER.001 and select Compound Only.
The test case typeface changes to italic, signifying that this test case has been designated
Compound Only.
1. In the Environment View, expand DATABASE into subprograms (if not already expanded).
2. Right-click GET_TABLE_RECORD and select Insert Test Case.
MULTIPLE UUT TUTORIAL 232
3. Keeping with our example situation, enter 2 as the input value for TABLE.
Note: Make sure you enter the value into the Input Values column, not into the Expected
Values column. You will enter the expected values for this case in the next step.
4. Expand DATA (click plus symbol ), then enter the following Expected Values:
IS_OCCUPIED TRUE
NUMBER_IN_PARTY 1
Note: Make sure you enter these values in the Expected Values column.
MULTIPLE UUT TUTORIAL 233
5. Expand ORDER.
ORDER is an array of records of size 4.
6. To view the array-indices of ORDER, right-click on <<Expand Indices: Size 4>> and select
Expand All Array Indices:
MULTIPLE UUT TUTORIAL 234
In this example, you want to verify input values written to the application database. The data
consists of an order taken for seat 1 at table 2.
7. Expand ORDER(1).
ORDER(1) corresponds to seat 1. The expected values you specify for ORDER(1) must match the
input values you previously specified in PLACE_ORDER.001. If you use any other index, the
expected results will not match.
8. Assign the following Expected Values to the appropriate fields of ORDER(1):
SOUP ONION
SALAD CAESAR
ENTREE STEAK
DESSERT PIE
BEVERAGE MIXED_DRINK
Note: Make sure you enter these values into the Expected Values column.
MULTIPLE UUT TUTORIAL 235
1. In the Environment View, right-click <<COMPOUND>> and select Insert Test Case.
A test case named <<COMPOUND>>.001 appears under <<COMPOUND>>, and is selected
(highlighted) by default.
2. Click and hold the cursor on PLACE_ORDER.001 in the Environment View; drag until the plus
An entry appears in the Test Case Editor (slot 1) as a member of test case <<COMPOUND>>.001.
3. Do the same with test case GET_TABLE_RECORD.001.
Your compound test case now has two slots: PLACE_ORDER.001, and GET_TABLE_
RECORD.001:
4. Click Save.
You are now ready to execute your compound test case.
5. In the Environment View, select <<COMPOUND>>.001, then click Execute button on the
toolbar to execute it.
An execution report for the compound test case is displayed in the Test Case Editor.
Note: If your compound test case fails, make sure PLACE_ORDER.001 uses parameters table
2, seat 1, and that GET_TABLE_RECORD.001 uses table 2 and the proper expected values
in ORDER(1).
Note that the expected values you specified were matched against corresponding actual values,
verifying the data flow from MANAGER to DATABASE.
In the Coverage Viewer, note that the statement assigning the value PIE to ORDER.DESSERT is
green, indicating that it was covered by test execution.
2. Select <<COMPOUND>>.001 in the Environment View and click the Execute button in the
toolbar.
3. Click the checkbox preceding <<COMPOUND>>.001 in the Environment View:
In the Coverage Viewer, the instances of the ‘(T)’ symbol indicate that two PLACE_ORDER
branches were covered: the first at the subprogram entry point; the second at the STEAK branch in
the case statement.
VectorCAST allows you to build more complex tests by linking multiple simple test cases together. This
feature allows you to test threads of execution while maintaining the data common to the various units
and subprograms.
MULTIPLE UUT TUTORIAL 239
In this section, you will modify test case PLACE_ORDER.001 to iterate over the 4 seats at table 2 while
iterating over the four entrées. The net effect will be to assign a different entrée to each seat.
3. Double-click ENTREE.
A dialog appears for setting parameter specifications:
7. Click OK.
You have now assigned input ranges to two parameters. By default, when two parameters are
assigned input ranges, they will iterate in parallel, which is what you want to occur in this case.
These two parameters will iterate with the following value pairs:
Seat = 1 Entree = Steak
Seat = 2 Entree = Chicken
Seat = 3 Entree = Lobster
Seat = 4 Entree = Pasta
Given this information, you can specify expected values in your compound test case for each seat.
9. Click the tab for test case GET_TABLE_RECORD.001 at the top of the Test Case Editor.
The parameter tree for GET_TABLE_RECORD.001 comes to the front. You need to edit this tree to
reflect the expected results for your compound test.
You now need to specify expected values for each of the other three seats at table 2.
10. Expand Order(2). (If you have recently re-opened the TUTORIAL environment, then the unused
array elements have been collapsed. If Order(2) is not visible, simply right-click on <<Expand
Indices: Size 4>> and choose Expand All Array Indices.)
Order(2) maps to seat 1. Specify the following expected values for seat 2:
Soup ONION
Salad CAESAR
Entree CHICKEN
Dessert NO_DESSERT (see Note)
Beverage MIXED_DRINK
Entree LOBSTER
Dessert NO_ORDER
Beverage MIXED_DRINK
12. Expand Order(4).
Enter the following expected values for seat 4:
Soup ONION
Salad CAESAR
Entree PASTA
Dessert NO_ORDER
Beverage MIXED_DRINK
Note: Be sure you have populated the Expected Values column for ORDER, and not the
Input Values column.
You now have ORDER data for each seat at table 2. Note that these orders are identical in each
case except for the Entree and the Dessert. Only the ENTREE variable is needed to exercise each
branch in the case statement.
You must now change the number of occupied seats at table 2 to reflect the current test case.
13. Scroll up to DATA and change NUMBER_IN_PARTY to 4.
14. Save.
15. Select <<COMPOUND>>.001 in the Environment View; then click to execute it.
<<COMPOUND>>.001 turns green; your test has passed. An execution report for your compound
test displays in the Test Case Editor.
16. Scroll down the report to view the green-coded results for each ORDER element:
MULTIPLE UUT TUTORIAL 243
Note: The amount of instruction given in this section will be a little less than in the previous
sections.
1. Under the MANAGER unit, insert a test case for GET_CHECK_TOTAL and make it Compound
Only.
MULTIPLE UUT TUTORIAL 244
You can now add this test case to the compound case.
Click the <<COMPOUND>>.001 tab at the top of the Test Case Editor to bring
<<COMPOUND>>.001 to the top.
5. Click the Compound Tree tab along the bottom of the Test Case Editor.
The Test Case Editor displays the slots in test case <<COMPOUND>>.001.
6. To add test case GET_CHECK_TOTAL.001, click and hold the cursor on GET_CHECK_
TOTAL.001 in the Environment View; drag until the symbol appears in the Test Case Editor;
release.
GET_CHECK_TOTAL.001 displays as slot 3 in your compound test case:
7. Save.
10. To view the coverage data, click the green checkbox preceding <<COMPOUND>>.001 in the
Environment View.
The Coverage Viewer opens:
Notice that by iterating over four entrées, you exercised four of the five case branches. The status
bar at the top right of the Coverage Viewer tells you that total branch coverage was 10 of 27, or
37%.
Tutorial Summary
This tutorial built on the environment you created in the Basic Tutorial. You changed one of the
dependent units from a smart stub into a UUT. You then added test cases to both units, and combined
these test cases into a Compound test case, which you used to test the data flow from MANAGER to
DATABASE. When test cases are combined into a Compound test case, the data remains persistent
between them.
In sum, you:
l Built a multi UUT environment by updating the environment you built in the Basic Tutorial
l Added a test case for the subprogram PLACE_ORDER in MANAGER
l Added a test case for the subprogram GET_TABLE_RECORD in DATABASE
l Used these simple test cases to create a compound case
l Verified the data flow between UUTs MANAGER and DATABASE
l Set up range iterations for a scalar parameter and an enumeral
l Added a test case to an existing compound case
WHITEBOX TUTORIAL 248
Whitebox Tutorial
This tutorial demonstrates how to use the VectorCAST Whitebox utility. Using Whitebox circumvents
the normal data and subprogram visibility issues associated with testing Ada programs by providing
direct visibility to all hidden subprograms and data objects. Without this utility, you would have to drive
all processing of hidden subprograms from those subprograms that are visible to external packages.
This tutorial walks you through the steps necessary to perform a whitebox conversion of a unit called
WHITEBOX. WHITEBOX contains a visible subprogram and a private type declaration in the package
specification. It also contains two subprograms and several objects declared in the package body.
Note: This tutorial assumes you have run at least one of the previous Ada tutorials, and that you
have set vcast_tutorial\ADA (Windows format) as the working directory for the Ada tutorials.
The whitebox utility preprocesses a UUT so that VectorCAST can directly access the subprograms and
objects that exist in the body of the UUT. It also allows you to manipulate parameters and objects based
on private types defined in the UUT.
The source files for the WHITEBOX package are provided in"Ada" on page 347 . You may wish to
review these source files before running the tutorial.
The following code fragment from Appendix A shows the procedure init_day. Notice that this procedure
is hidden by being declared in the body of the package WHITEBOX. Normally this procedure would not
be directly callable from any other external package:
--Type Declarations
type color is (red, green, blue);
type day is (monday, tuesday, wednesday, thursday);
--Hidden Procedure Specifications
procedure init_day (val : day);
current_day := val;
end init_day;
end WHITEBOX;
You will:
1. Start VectorCAST if it is not already running, or close the environment from the last tutorial by
selecting File => Close Environment.
2. If necessary, set the working directory to /vcast_tutorial/ADA by selecting File => Set Working
Directory.
WHITEBOX TUTORIAL 250
The location and name of the current working directory appear at the lower right-hand corner of the
VectorCAST main window:
1. To begin creating an environment, click the New button on the toolbar, then select Ada
Host Environment from the drop-down menu.
The Create New Environment wizard opens.
If you have previously run one of the other Ada tutorials, the wizard opens to the Name the
Environment page. If you have not previously run one of the other Ada tutorials, the wizard opens
to the Choose Compiler page. (If you need to select or change the compiler, select the Choose
Compiler page now.)
WHITEBOX TUTORIAL 251
2. On the Name the Environment page, enter white into the Environment Name field.
VectorCAST echoes your entry in capital letters.
3. Click Next.
4. Check the box preceding Whitebox.
5. Click Next.
The Locate Source Files page opens:
Note: Double-clicking a name in the Unit Names pane is a shortcut for selecting the name
and then clicking the right-arrow ( ). You can also drag-and-drop.
You will now build your specifications into an executable test harness.
WHITEBOX TUTORIAL 254
The top item listed in the Environment View is the name of the current environment (WHITE). The
only UUT is WHITEBOX, which is shown to have three subprograms: INITIALIZE, INIT_DAY,
and INIT_COLOR. Hidden procedures INIT_DAY and INIT_COLOR are now visible.
Note: You now have direct visibility to all subprograms, whether they were declared in the
specification or in the body of package WHITEBOX.
Note: Parameter VAL of type DAY, which is defined in the body of package WHITEBOX, is now
visible, and can be used as input to INIT_DAY.
WHITEBOX TUTORIAL 255
2. In the parameter tree, select MONDAY as the input value for the parameter VAL.
You can now initialize a global object hidden in the body of package WHITEBOX to see how it is
affected.
3. Expand <<GLOBAL>> and set MONDAY as the expected value for CURRENT_DAY.
Global object CURRENT_DAY of type DAY, which is defined in the body of package
WHITEBOX, is now visible.
Tutorial Summary
By gaining access to all subprograms directly with the Whitebox utility, you can circumvent the
visibility testing difficulties inherent to Ada.
Cover Tutorials
INTRODUCTION 258
Introduction
The tutorials in this chapter demonstrate how to use VectorCAST/Cover to analyze code coverage. You
should run these tutorials in the order presented.
For details on all four steps, refer to "VectorCAST/Cover Overview" on page 33.
The source modules you will use in this tutorial are components of a simple order-management
application for restaurants. The listings for this application are available in Appendix A, "Tutorial Source
Code Listings" on page 332. It is recommended that you at least scan through these listings before
proceeding with the tutorials.
This tutorial is limited to using VectorCAST in a single-language environment. If you will be using
VectorCAST/Cover in a mixed-language environment, you will find information specific to this usage in
“Using VectorCAST/Cover in a Mixed Language Environment” in the VectorCAST/Cover User’s Guide.
You can stop a tutorial at any point and return later to where you left off. Each tutorial session is
automatically saved. To return to where you left off, simply restart VectorCAST and the use File
=> Recent Environments to reopen the tutorial environment.
1. From the Welcome page, click the Start Using VectorCAST button .
2. Click the link Build a VectorCAST/Cover environment.
The first page of the Create New Coverage Environment wizard appears:
Troubleshooting:
If the former “Create Cover Environment” dialog appears instead of the new Cover Wizard, that
means you have the Coverage Option “Use Legacy code instrumenter” on. It is recommended that
you keep this option off unless VectorCAST Technical Support has instructed you otherwise.
7. Click Next.
The Locate Source Files page appears. Here you add directories with source files that you want
added to the Cover environment.
You have now created a file named Tutorial_cover.vcp and a subdirectory named Tutorial_
cover. The .vcp file is used to store information about the environment. The environment directory
is used to store files (including code-listing and analysis files) containing instrumentation and
coverage information.
The files you selected (manager.cpp and database.cpp) appear in the Source Files pane.
The Filename Tree contains three columns to the right of the environment and file names. These
columns provide coverage status information for Statement (S), Branch (B), and MC/DC Pairs (P).
These columns are currently empty because the source files have not yet been instrumented.
1. Right-click database.cpp and manager.cpp and select Instrument =>Statement from the popup
menu. (If you have an Industry mode other than Default, you will see the equivalent name for
Statement):
The Statement status column now contains a red status bar for each source file and for the
environment as well. The status bars show the percentage of code coverage achieved for each file.
For example, a file that has 50% coverage, half the bar will be green and half will be red. This
allows you to quickly see a dashboard of code coverage percentages.
Additionally, you may hover over a file name to see the exact coverage percentages.
2. Right-click manager.cpp and select Open Coverage Viewer from the popup menu, or double-click
manager.cpp.
C++ COVER TUTORIAL 264
The annotated source code for manager.cpp appears in the Coverage Viewer.
Each set of repeating numbers in the first column marks a subprogram within manager.cpp. The
ascending numbers in the second column mark the executable statements within a subprogram. The
statements in red have not been exercised; the statements in black cannot be exercised.
Instrumented versions of manager.cpp and database.cpp have been created in the VectorCAST
installation directory /Tutorial/cpp. Backups of the original files are in
manager.cpp.vcast.bak and database.cpp.vcast.bak.
You can now compile and link the files: manager_driver.cpp, manager.cpp, database.cpp,
c_cover_io.cpp into an executable program (to be named manager_driver).
> cd %VECTORCAST_DIR%\Tutorial\cpp
C:\VCAST\Tutorial\cpp>
4. Using Windows Explorer or the command line, copy the coverage I/O files from the environment
directory to the directory where the instrumented files reside. You can find the location of the
environment by looking at the lower right side of the status bar.
C:\VCAST\Tutorial\cpp>copy C:\VCAST\Environments\Tutorial_cover\c_cover_io.cpp .
1 file(s) copied.
C:\VCAST\Tutorial\cpp>copy C:\VCAST\Environments\Tutorial_cover\vcast_c_options.h .
1 file(s) copied.
C:\VCAST\Tutorial\cpp>copy C:\VCAST\Environments\Tutorial_cover\c_cover.h .
1 file(s) copied.
5. If you are using the Visual C++ compiler (for example), enter the following compile command:
C++ COVER TUTORIAL 265
Note: If you are using the Visual C++ compiler (for example) but it is not on your PATH,
enter: C:\vcast_tutorial\CPP\Tutorial_cover>vcvars32.bat
Typically, vcvars32.bat is located in the Microsoft compiler \bin directory. Optionally,
you can select Start=>Microsoft Visual Studio=>Visual Studio Tools=>Visual Studio
Command Prompt. This will open a command prompt window with vcvars32.bat already
invoked.
c_cover_io.obj
If you are using the GNU Native compiler (for example), enter the following compile command:
C:\VCAST\Tutorial\CPP>manager_driver
P=PlaceOrder C=ClearTable G=GetCheckTotal A=AddIncludedDessert :
C:\VCAST\Tutorial\CPP>manager_driver
P=PlaceOrder C=ClearTable G=GetCheckTotal A=AddIncludedDessert : P
4. Continue with C:
C:\VCAST\Tutorial\CPP>manager_driver
P=PlaceOrder C=ClearTable G=GetCheckTotal A=AddIncludedDessert : C
C:\VCAST\Tutorial\CPP>copy TESTINSS.DAT Clear_Table_Results.DAT
5. and G:
C:\VCAST\Tutorial\CPP>manager_driver
P=PlaceOrder C=ClearTable G=GetCheckTotal A=AddIncludedDessert : G
The Total is 10
C:\VCAST\Tutorial\CPP>copy TESTINSS.DAT Get_Check_Total.DAT
6. and finally A:
C:\VCAST\Tutorial\CPP>manager_driver
P=PlaceOrder C=ClearTable G=GetCheckTotal A=AddIncludedDessert : A
C:\VCAST\Tutorial\CPP>copy TESTINSS.DAT Add_Included_Dessert.DAT
7. Remove TESTINSS.DAT.
C:\VCAST\Tutorial\CPP>del TESTINSS.DAT
1. If necessary, restart VectorCAST, and use File => Recent Environments to re-open the coverage
environment.
2. In VectorCAST/Cover, select Environment => Add Test Results... from the main-menu bar, or click
on the toolbar, or drag a results file from outside VectorCAST into the Test Results pane.
Note: Do not use Coverage => Import Results from Environment. This command is used
to import coverage data from another VectorCAST environment.
3. In the Open dialog, navigate to the Tutorial\cpp directory, and multi-select the four .DAT files and
then click Open.
C++ COVER TUTORIAL 267
You are asked if you want to generate an automatic name for the test results.
5. Right-click Test Results, and select Select All Children from the popup menu.
C++ COVER TUTORIAL 268
A checkmark appears in front of each test result, and the tab for database.cpp opens in the Coverage
Viewer, because the constructor DataBase::DataBase() is the first line called when the program is
executed.
Green indicates lines that were exercised when we invoked manager_driver; red indicates
unexercised lines; black indicates non-executable statements.
The status bar at the upper-right corner of the Coverage Viewer tells you that 100% of the
executable statements in the unit database.cpp have been covered.
The status bars in the Filename Tree reflect percentage of coverage as well. Database.cpp has 100%
statement coverage.
6. Double-click manager.cpp to open it in the Coverage Viewer. The status bar shows that 58% of the
executable statements in the unit manager.cpp have been covered. By hovering over the status bar
in the Filename Tree for manager.cpp, you can easily see that 24 of 41 statements were covered.
C++ COVER TUTORIAL 269
Note: VectorCAST’s animation feature allows you to view the step-by-step coverage of a test case.
This feature is described in the user guide accompanying your version of VectorCAST.
1. Select (highlight) both units in the Source Files pane or the Tutorial_cover environment folder.
2. In the Notes tab, enter text of your choices, such as, “Statement coverage. manager_driver.exe
with A as input.”
3. Click Save.
4. Repeat for the other Test Results, changing the text to reflect the input that was used for that Test
Result.
C++ COVER TUTORIAL 272
5. Select (highlight) both units in the Source Files pane or the Tutorial_cover folder.
You see that this part of the report includes the name of the Test Result, the date and time it was added
to the environment, and the notes associated with each.
Tutorial Summary
VectorCAST/Cover is an effective tool for analyzing test coverage, and for determining what additional
testing needs to be done in order to fully exercise an application.
This tutorial took you through the entire process of using VectorCAST/Cover to analyze statement code
coverage.
The source modules you will use in this tutorial are components of a simple order-management
ADA COVER TUTORIAL 274
application for restaurants. The listings for this application are available in Appendix A, "Tutorial Source
Code Listings" on page 332. It is recommended that you at least scan through these listings before
proceeding with the tutorials.
This tutorial is limited to using VectorCAST in a single-language environment. If you will be using
VectorCAST/Cover in a mixed-language environment, you will find information specific to this usage in
“Using VectorCAST/Cover in a Mixed Language Environment” in the VectorCAST/Cover User’s Guide.
You can stop a tutorial at any point and return later to where you left off. Each tutorial session is
automatically saved. To return to where you left off, simply restart VectorCAST and the use File
=> Recent Environments to reopen the tutorial environment.
1. From the Welcome page, click the Start Using VectorCAST button .
2. Click the link Build a VectorCAST/Cover environment.
ADA COVER TUTORIAL 275
The first page of the Create New Coverage Environment wizard appears:
Troubleshooting:
If the former “Create Cover Environment” dialog appears instead of the new Cover Wizard, that
means you have the Coverage Option “Use Legacy code instrumenter” on. It is recommended that
you keep this option off unless VectorCAST Technical Support has instructed you otherwise.
You have now created a file named Tutorial_cover.vcp and a subdirectory named Tutorial_
cover. The .vcp file is used to store information about the environment. The environment directory
is used to store files (including code-listing and analysis files) containing instrumentation and
coverage information.
The files you selected (manager.adb and database.adb) appear in the Source Files pane.
The Filename Tree contains three columns to the right of the environment and file names. These
columns provide coverage status information for Statement (S), Branch (B), and MC/DC Pairs (P).
These columns are currently empty because the source files have not yet been instrumented.
1. Right-click database.adb and manager.adb select Instrument => Statement from the popup menu.
(If you have an Industry mode other than Default, you will see the equivalent name for Statement):
ADA COVER TUTORIAL 279
The Statement status column now contains a red status bar for each source file and for the
environment as well. The status bars show the percentage of code coverage achieved for each file.
For example, a file that has 50% coverage, half the bar will be green and half will be red. This
allows you to quickly see a dashboard of code coverage percentages.
Additionally, you may hover over a file name to see the exact coverage percentages.
2. Right-click manager.adb and select Open Coverage Viewer from the popup menu, or double-click
manager.adb.
The annotated source code in manager.adb appears in the Coverage Viewer:
ADA COVER TUTORIAL 280
Each set of repeating numbers in the first column marks a subprogram within
manager.adb. The ascending numbers in the second column mark the executable
statements within a subprogram. The statements in red have not been exercised; the
statements in black cannot be exercised.
Instrumented versions of manager.adb and database.adb have been created in the
VectorCAST installation directory/Tutorial/ada. Backups of the original
source files are in manager.adb.vcast.bak and database.adb.vcast.bak.
You can now compile and link the files manager_driver.cpp, manager.cpp,
database.cpp, c_cover_io.cpp into an executable program (to be named manager_
driver).
> cd %VECTORCAST_DIR%\Tutorial\ada
C:\VCAST\Tutorial\ada>
4. If you are using a GNAT compiler, before you can compile the instrumented files, you must split
each file into a types file and a residual instrumented file. To do this, you run the gnatchop
command on each instrumented file. For example:
5. Using Windows Explorer or the command line, copy the coverage I/O files from the environment
directory to the directory where the instrumented files reside. You can find the location of the
environment by looking at the lower right side of the status bar.
C:\VCAST\Tutorial\ada>copy C:\VCAST\Environments\Tutorial_cover\vcast_cover_io.adan>
2 file(s) copied.
C:\VCAST\Tutorial\ada>copy C:\VCAST\Environments\Tutorial_cover\vcast_ada_
options.ad*.
2 file(s) copied.
You can now compile and link the files manager_driver.adb, manager.adb, database.adb, and vcast_
cover_io.adbn> into an executable program (to be named manager_driver).
6. If you are using a GNAT compiler (for example), enter:
ADA COVER TUTORIAL 281
C:\vcast_tutorial\ADA>gnatmake manager_driver
gcc -c manager_driver.adb
gcc -c manager.adb
gcc -c types.ads
gcc -c database.adb
gcc -c vcast_cover_io.adb
gcc -c vcast_types_2.ads
gcc -c vcast_types_1.ads
gcc -c vcast_ada_options.adb
gnatbind -x manager_driver.ali
gnatlink manager_driver.ali
C:\VCAST\Tutorial\ada>manager_driver
P=PlaceOrder C=ClearTable G=GetCheckTotal A=AddIncludedDessert :
C:\VCAST\Tutorial\ada>manager_driver
P=PlaceOrder C=ClearTable G=GetCheckTotal A=AddIncludedDessert : P
4. Continue with C:
C:\VCAST\Tutorial\ada>manager_driver
P=PlaceOrder C=ClearTable G=GetCheckTotal A=AddIncludedDessert : C
C:\VCAST\Tutorial\ada>copy TESTINSS.DAT Clear_Table_Results.DAT
5. and G:
C:\VCAST\Tutorial\ada>manager_driver
P=PlaceOrder C=ClearTable G=GetCheckTotal A=AddIncludedDessert : G
The Total is 10
C:\VCAST\Tutorial\ada>copy TESTINSS.DAT Get_Check_Total.DAT
6. and finally A:
ADA COVER TUTORIAL 282
C:\VCAST\Tutorial\ada>manager_driver
P=PlaceOrder C=ClearTable G=GetCheckTotal A=AddIncludedDessert : A
C:\VCAST\Tutorial\ada>copy TESTINSS.DAT Add_Included_Dessert.DAT
7. Remove TESTINSS.DAT.
C:\VCAST\Tutorial\ada>del TESTINSS.DAT
1. If necessary, restart VectorCAST, and use File => Recent Environments to re-open the coverage
environment.
2. In VectorCAST/Cover, select Environment => Add Test Results... from the main-menu bar, or click
on the toolbar, or drag a results file from outside VectorCAST into the Test Results pane.
Note: Do not use Coverage => Import Results from Environment. This command is used
to import coverage data from another VectorCAST environment.
3. In the Open dialog, navigate to the Tutorial\ada directory, and multi-select the four .DAT files and
then click Open.
You are asked if you want to generate an automatic name for the test results.
VectorCAST adds each test result file, naming it the same name as its base filename.
5. Right-click Test Results, and select Select All Children from the popup menu.
A checkmark appears in front of each test results, and the tab for manager.adb opens in the
Coverage Viewer.
Green indicates lines that were exercised when we invoked manager_driver; red indicates
unexercised lines; black indicates non-executable statements.
6. The status bar at the upper-right corner of the Coverage Viewer tells you that 48% of the executable
statements in the unit manager.adb have been covered.
ADA COVER TUTORIAL 284
The status bars in the Filename Tree reflect percentage of coverage as well. Manager.adb has 48%
statement coverage. By hovering over the status bar in the Filename Tree for manager.adb, you can
easily see that 20 of 41 statements were covered.
Note: VectorCAST’s animation feature allows you to view the step-by-step coverage of a test case.
This feature is described in the user guide accompanying your version of VectorCAST.
1. Select (highlight) both units in the Source Files pane or the Tutorial_cover environment folder.
2. In the Notes tab, enter text of your choices, such as, “Statement coverage. manager_driver.exe
with A as input.”
3. Click Save.
ADA COVER TUTORIAL 287
4. Repeat for the other Test Results, changing the text to reflect the input that was used for that Test
Result.
5. Select (highlight) both units in the Source Files pane or the Tutorial_cover folder.
ADA COVER TUTORIAL 288
Tutorial Summary
VectorCAST/Cover is an effective tool for analyzing test coverage, and for determining what additional
testing needs to be done in order to fully exercise an application.
This tutorial took you through the entire process of using VectorCAST/Cover to analyze statement code
coverage.
l Compiled and linked the application using instrumented versions of the source files
l Generated test results
l Viewed the coverage achieved with these test results
l Added notes to the test results
l Generated an Aggregate Coverage report for both units
l Generated a Test Result Management report
Integration Tutorials
INTRODUCTION 291
Introduction
VectorCAST provides ways to integrate the tools you already use to enforce coding standards, define
requirements, and build your applications. The following tutorials demonstrate how to:
l integrate Gimpel Software's Lint source code analysis engine and perform static analyis on a
codebase
l integrate VectorCAST and VectorCAST/Cover with QA•C® and QA•C++ ® from Programming
Research™ to analyze units and report on coding standards
Integrating Lint
VectorCAST is integrated with Gimpel Software's Lint source code analysis engine. Lint is a static source
code analyzer that performs module-based or whole-program source code analysis on C/C++ codebases
and automatically identifies problems at their source, prior to compiling. The VectorCAST/Lint
integration is configured for checking MISRA C (C1), MISRA C (C2), MISRA C (2012), and MISRA
C++ standards, and includes an extensive list of embedded compiler option files.
VectorCAST distributes a Lint executable in the installation, but also allows you to substitute another
version of Lint if you are already a Lint user.
If you are not licensed to build a C environment, then you can run this Tutorial using
VectorCAST/Cover. Just add the source files to the Coverage environment and skip the steps where you
are instructed to run test cases. You can still perform the Lint steps as instructed in the Tutorial.
One of the source code units used in this Tutorial was obtained from the Exemplar Suite on the MISRA
website. This unit is copyright MIRA Limited, 2006, 2007. We will use this unit to demonstrate
VectorCAST/Lint’s MISRA capabilities.
You do not need to be a licensed user of Lint to run this tutorial, but you do need a VectorCAST/Lint
license (included in Evaluation License Keys).
6. Leave the Whitebox option under Build Options checked. Click Next.
7. Add the Source directory $(VECTORCAST_DIR)\Tutorial\lint to the Source directories list. Click
Next.
8. Select the units lint_example.c and mc2_0401.c as UUTs.
9. Click Build.
10. Once the environment builds, select Test => Scripting => Import Script... from the Menu Bar and
import the test script lint_example.tst.
11. Execute all test cases. You see that only 1 out of 6 test cases passed.
INTEGRATING LINT 293
12. Open the test case named MYSQRTEST.001, and switch to the Execution Report tab. You see that
the test case failed because the actual returned value is 2.1, instead of the expected 2.0. What could
be wrong? Examine the other failing test cases.
1. In the Test Case Tree, select the UUT lint_example. From the Toolbar, go to the Lint Static
Analysis icon and select Analyze from the drop-down menu.
lMessage Detail, which shows the path to the unit, and displays details about a
particular message, when one is selected.
We are going to correct each Warning issue, and then re-analyze.
3. Hover the mouse over the Warning icon next to line 15. The tooltip explains the problem with
this line.
1. From the Toolbar, go to the Lint Static Analysis icon and select Options.. from the drop-down
menu. The Lint Options tab opens.
INTEGRATING LINT 297
2. Click in the Value column next to the option MISRA, and choose MISRA C (C2) from the drop
down.
The colored text at the bottom reflects the Lint compiler file constructed for MISRA C (C2) that is
added to the command line to call Lint.
3. Select the unit mc2_0401 in the Test Case Tree.
4. From the Toolbar, go to the Lint Static Analysis icon and select Analyze from the drop-down menu.
The change to the Lint Options is saved automatically before analysis.
5. In the Lint Analysis Results window, a tab for the unit mc2_0401 opens. The Lint Messages
window shows many messages.
6. To filter the Lint Messages window so that only MISRA messages are displayed, right-click the
column heading Messages and turn off each type, one by one, except MISRA.
INTEGRATING LINT 298
7. Now that messages of the other types are turned off, there is only one Warning message per line of
non-compliant code. The picture below shows the Lint Analysis Results window with the first
occurrence of message 606 selected.
8. From the Toolbar, go to the Lint Static Analysis icon and select Generate Report => Details from
the drop-down menu.
INTEGRATING LINT 299
The Detailed Lint Summary Report from the most recent analysis is displayed.
Homework
Your homework is to figure out how to make a custom Lint Analysis report that has only MISRA
messages included in it.
Tutorial Summary
In this tutorial, you:
INTEGRATING PRQA 300
Integrating PRQA
VectorCAST is integrated with Programming Research's market leading C and C++ source code analysis
technologies. The QA•C and QA•C++ tools are consistently recognized worldwide as the most powerful,
most robust, and most technically advanced solutions available today for analyzing source code and
enforcing pre-defined coding standards (such as MISRA and JSF++). If you are already a licensed user of
QA•C or QA•C++, then you can run this tutorial to discover how easy it is to reach the PRQA
functionality when using VectorCAST or VectorCAST/Cover.
This tutorial takes you through the steps to configure PRQA for use with VectorCAST. It is assumed that
you have run one of the C or C++ tutorials in this guide. The tutorial refers to a C source code unit, but if
you choose to use QA•C++, you can easily make the substitutions.
In addition, you must be a licensed user of QA•C or QA•C++ to perform this tutorial.
This coverage environment has three source files: database.c, manager.c and manager_
driver.c. For the purposes of this tutorial, it doesn’t matter if you have any test results selected.
3. Before analyzing any units, you should ensure that the PRQA options are set correctly. From the
Toolbar, go to the QAC/QAC++ icon and select Options... from the drop-down menu.
INTEGRATING PRQA 302
VectorCAST detects whether your environment is C or C++, and automatically selects the language
mode for the QAC tool.
If you are using a different version or if you installed it in a location other than the default, then the
paths are outlined in red. Just click the Browse button and navigate to the correct location.
Troubleshooting:
If you see the FLEXlm License Finder dialog, then PRQA cannot find a license.
Cancel out of the dialog, and exit VectorCAST. Then set up the LM_LICENSE_FILE environment
variable for both VectorCAST and the Programming Research Tools.
The Analyze button animates, , to indicate that QA•C++ is analyzing in the background.
You can use VectorCAST for other tasks while the analysis is taking place.
When the analysis is finished, the Summary report is displayed in the Report Viewer:
INTEGRATING PRQA 304
The Summary report lists each unit analyzed, and provides a link. The numbers to the right are the
various error levels, with 9 being the most serious. Our results show that 1 occurrence of a level 0
error exists for each unit (because these are very simple source files). You will follow the trail to
determine the meaning of the “error”.
7. Click the link database in the Summary report.
The Analysis report for the unit database opens in the Report Viewer. You have drilled down one
level.
Note: If you ran the wrap_compile tutorial, you will see the instrumented version of the
source file in the report, because the Instrument in place option was turned on.
INTEGRATING PRQA 305
10. To get back, right-click the report and choose Back or click the Undo button .
11. Click the little arrow to the right of the Analyze button, and choose Open Message Browser
from the list:
INTEGRATING PRQA 306
The source code for database.cpp opens in the Source tab, as you would expect.
Tutorial Summary
In this tutorial, you:
Introduction
VectorCAST/Manage provides a way to manage regression testing over an entire project or organization.
Many projects have no ability to modify source code with confidence that it will still work, due to a lack
of regression testing. Regression testing demonstrates that you have not broken existing functionality
while fixing a bug or adding new functionality. Proper regression testing requires the re-execution of
hundreds to thousands of unit- and integration-tests and the efficient management of the test results.
Historically, accomplishing this has been a very difficult, time-consuming process.
VectorCAST/Manage:
VectorCAST/Manage takes existing VectorCAST environments and imports them into a Manage project.
Individual environments can be grouped into Environment Groups and Test Suites to reflect your project
architecture. An environment can be a member of multiple groups, and an Environment Group can be
assigned to multiple Test Suites. Because Environment Groups and Test Suites are easily duplicated, the
same tests can be run using various source code baselines, on different host platforms, or with a different
compiler or embedded target.
As test cases are executed in the environments, data is stored in an SQL database which enables you to
see historical trends. The SQL database stores each environment’s build status and duration and test case
execution status and duration, as well as the code coverage achieved.
INTRODUCTION 310
Terminology
The project is the repository for all information created with VectorCAST/Manage. It is analogous to the
environment in VectorCAST/C++ or VectorCAST/Ada. A project is generally organized by the user to
reflect the hierarchy of the application.
Manage projects support multiple users. Multiple users with read-permissions can open the project at the
same time, but only one user at a time has write-permission to modify the project. When a user has write-
permission, or the write-lock, the project is said to be locked, and no other user can open the project until
the write-lock is released.
A compiler node is where all compiler-specific VectorCAST options are stored. The compiler node knows
the default options for a particular compiler, and enables you to change settings or override default
compiler options for your project needs.
A data source is a location where all the work is done, that is, where the VectorCAST environments are
built and executed. It may be located in the project directory or in some other location, even on a remote
machine. A project’s data sources can be local to one machine or distributed across multiple machines.
Data from remote data sources can be pushed back to the central repository. The status from all data
sources in a project is combined into the Management Summary Report and graphical trend analysis.
Now that you have some idea about what VectorCAST/Manage can do for you, it’s time to try it out. The
CREATING A MANAGE PROJECT 311
Note: This tutorial uses a Manage project with imported C environments. However, there are only
minor differences when using Ada environments. You should build environments using the most
convenient C or Ada compiler on your system; source code and scripts are provided for both.
The first step in this tutorial involves quickly creating two unit test environments, using either a C or
Ada compiler. A zip file named manage_tutorial.zip is provided in the VectorCAST installation
directory, tutorial/manage sub-directory. It contains the familiar C and Ada tutorial files, as well as a
modification of those files in another baseline. A directory with environment scripts (.env) and test scripts
(.tst) is provided for your convenience.
PREPARING TO RUN THE TUTORIAL 312
In Windows Explorer
Using Windows Explorer, navigate to %VECTORCAST_DIR%\Tutorial\manage\manage_tutorial.zip
and copy and paste this zip file to vcast_tutorial. Unzip (extract) it there.
In a UNIX Shell
If necessary, change directory to vcast_tutorial. Then enter:
$ cp $VECTORCAST_DIR/Tutorial/manage/manage_tutorial.zip.
$ unzip manage_tutorial.zip
Archive: manage_tutorial.zip
creating: MANAGE/baseline1/
inflating: MANAGE/baseline1/ctypes.h
inflating: MANAGE/baseline1/database.adb
inflating: MANAGE/baseline1/database.ads
inflating: MANAGE/baseline1/database.c
inflating: MANAGE/baseline1/manager.adb
inflating: MANAGE/baseline1/manager.ads
inflating: MANAGE/baseline1/manager.c
inflating: MANAGE/baseline1/types.ads
creating: MANAGE/baseline2/
inflating: MANAGE/baseline2/ctypes.h
inflating: MANAGE/baseline2/database.adb
inflating: MANAGE/baseline2/database.ads
inflating: MANAGE/baseline2/database.c
inflating: MANAGE/baseline2/manager.adb
inflating: MANAGE/baseline2/manager.ads
inflating: MANAGE/baseline2/manager.c
inflating: MANAGE/baseline2/types.ads
creating: MANAGE/regression_scripts/
inflating: MANAGE/regression_scripts/ADA_DATABASE.env
inflating: MANAGE/regression_scripts/ADA_DATABASE.tst
inflating: MANAGE/regression_scripts/ADA_MANAGER.env
inflating: MANAGE/regression_scripts/ADA_MANAGER.tst
inflating: MANAGE/regression_scripts/C_DATABASE.env
inflating: MANAGE/regression_scripts/C_DATABASE.tst
inflating: MANAGE/regression_scripts/C_MANAGER.env
inflating: MANAGE/regression_scripts/C_MANAGER.tst
creating: MANAGE/unit_test_envs/
$
In the vcast_tutorial directory, the unzipped file creates a directory named MANAGE. Below that are the
two source code directories (baseline1 and baseline2) which contain both C and Ada source files, a
directory named regression_scripts which contains environment scripts (.env) and test scripts (.tst),
and an empty directory named unit_test_envs, in which you will build two unit test environments.
USING THE MANAGE PROJECT WIZARD 313
You are now ready to create a Manage project and import the two environments.
l deciding which environment configuration options to filter up to a higher, more abstract level
l specifying a data source
l verifying the group names and test suite names are satisfactory
l finishing
1. Select File => Set Working Directory and navigate to vcast_tutorial/MANAGE.
2. Click Choose.
3. Select File => New => Manage Project.
The Manage Wizard opens.
4. Give the project the name TEST_CAMPAIGN.
This option specifies whether Manage should look for built environments to import or to look for
sets of regression scripts – the shell/batch file (.sh/.bat), the test script (.tst), and the environment
script (.env). In our case, we have two existing unit test environments, so we leave the option on
“Existing Environments.”
6. Click the Add Search Directory button and select the directory where the existing
environments reside, unit_test_envs.
7. Click Choose.
8. Ensure Factor Options is checked, and add a checkmark next to Search Directories, so that both
Compiler options and Search Directories are checked.
USING THE MANAGE PROJECT WIZARD 316
Factoring options makes it easy to reuse environments in multiple contexts in the Manage project.
Options set at the environment level are “bubbled up” to higher levels in the project hierarchy,
where they can be easily modified to affect many environments at once.
There are three types of factoring:
l An environment’s Compiler options are factored to the compiler node. Default settings
are discarded because the Compiler node already has those. Overridden settings are
preserved. Compiler option differences between two environments result in multiple
compiler nodes.
l An environment’s Environment options, such as Whitebox, coverage type, Build,
Execute, Coverage, and Report options are factored up to the Test Suite node.
Environment options include all options except compiler options and Source directories.
Environment option differences between two environments result in multiple Test Suite
nodes.
l An environment’s Search directories and Type-handled directories are factored to the
Test Suite level. (Library Include directories are factored to the compiler level.)
Factoring Search Directories makes it easy to change the source code baseline used to
build the unit test environments, which is exactly what we want to do in this tutorial.
l With no factoring, environments are just put in groups according to their directory of
origin. All options remain at the individual environment level.
9. Click Next to move to the next page of the Wizard.
USING THE MANAGE PROJECT WIZARD 317
The Data Sources page indicates the default location that the Manage project will use to build and
execute the unit test environments. By default, Manage uses a sub-directory of the project directory
named build, as you can see in the Original Path.
The following columns are displayed on the Data Sources page:
l Registered – A check in this column indicates that the data source is part of the project.
Unchecked means that the data source directory is temporary and will not be saved in
the project.
l Enabled – An enabled data source sets its status display on.
l Host – The host name of the computer where the Data Source is located.
l Platform – The platform of the computer where the Data Source is located.
l Original Path – The location of the Data Source, relative to the working directory on
the machine named in the Host column. Gray text indicates a disabled Data Source; red
text indicates permissions disallow access to the Data Source or that VectorCAST
cannot find the data source.
l Alias – A nickname for the Data Source.
l Notes – Notes about the Data Source.
l Date – The timestamp when a snapshot of data in this Data Source was last pushed
back to the project (command line only).
10. Data Sources are an advanced feature; for the purposes of this tutorial, just allow the default to be
put in place by clicking Next.
11. VectorCAST/Manage begins importing the unit test environments that it finds in the specified
Search directories.
THE PROJECT TREE 318
If you created Ada environments, the environment icons are orange instead of blue.
This page of the Wizard can be used to rename nodes in the hierarchy or reorganize the hierarchy
by dragging and dropping.
12. Click Finish.
The project opens in the main window.
Node Description
Source node.
Platform node.
In this tutorial the platform is
Windows, but Solaris and Linux are
also supported.
Compiler node.
Each compiler node is associated with
one compiler template.
Environment.
Gray icon indicates unbuilt
environment. Orange icon represents an
Ada environment, blue represents
C/C++ environment.
Configuration icon.
Any node that can have a custom
configuration has this icon. Hover
mouse over to see configuration for the
node.
The status panel is divided into columns, each of which shows the status of a different operation:
When MC/DC coverage type is applied to an environment, the MC/DC branches are displayed in the
Branch column and the pairs are displayed in the MC/DC Pairs column. DO-178B Level A coverage type
uses the Statement column, the Branch column for the MC/DC branches, and the MC/DC pairs column.
Similarly, DO-178B Level B coverage type uses the Statement and Branch columns.
Build status.
Execute status.
The current level of the tree has not achieved the coverage
percentage threshold.
1. Right-click the root node of the project (TEST_CAMPAIGN) and choose Build.
BUILDING AND EXECUTING THE ENVIRONMENTS 322
This action causes VectorCAST to build the two environments in the Data Source directory and
import their associated test script. When finished building, you see the Build Status column has
green checkmarks all the way up.
2. Right-click the root node of the project (TEST_CAMPAIGN) and choose Execute.
This action causes VectorCAST to execute batch all environments. When finished executing, you
see the Execute Status column has green checkmarks all the way up.
You may have noticed the root node’s icon has changed, picturing a paper and quill ( ). This icon
indicates that a snapshot of data exists and can be stored for historical purposes.
1. Right-click the root node of the project and choose Store Results.
This action logs the build and execute status in the project database.
2. Right-click on the root node and choose Reporting.
BUILDING AND EXECUTING THE ENVIRONMENTS 323
The MDI window opens the Project Report View which has two tabs: Report and Graph. The graph
shows the Build status (blue) and the Execute status (pink) for the project named TEST_CAMPAIGN.
The status is indicated in percentage of environments that achieved successful build and execution.
Hovering the mouse over one of the columns in the graph shows a tooltip with information:
The Manage Summary Report shows the Build status and duration, as well as the Execution status
and duration for each environment under all the different configurations they have been run (which
at this point is only one configuration).
MORE ABOUT DATA SOURCES 324
By building each environment in a particular data source having its own configuration, Manage makes it
easy to execute the same environment with a different Source baseline, a different compiler, or a different
Test Suite configuration. And that is exactly what we are going to do in the next section.
Modifying a Manage project makes a change to the project file (TEST_CAMPAIGN.vcm). When you open a
project, you have the permissions to modify the project file. If another person opens the project, that
person has permissions to modify the project. Whoever tries first will need to disconnect the other user in
order to proceed with the modification. (We don’t want two users changing the project file at the same
time!)
4. Click OK.
A new Test Suite node is added to the project.
5. Hover your mouse over one of the percentage bars ( ) in the Build column.
Now that a second Test Suite is present and has two unbuilt environments out of four total, the
percentage of built/total is 50%, rather than 100%, as it was before. This information is reflected in
MODIFYING THE PROJECT 326
A tooltip shows you that the Coverage type has been changed to STATEMENT. If you built Ada
environments, the tooltip shows “Parent Lib” instead of “Search Directories.”
11. Select the Test Suite Configuration_01 and hover the mouse over the configuration icon for the
other Test Suite, Statement_Coverage.
A tooltip shows you the differences between the two Test Suites.
12. Expand Statement_Coverage.
You see that the same two environments are present in this Test Suite, and that they have not yet
been built, as indicated by the gray icons.
13. Right-click the Test Suite Statement_Coverage and choose Build/Execute.
MODIFYING THE PROJECT 328
Manage builds the two environments using the settings from their parent Test Suite, Statement_
Coverage, and then executes their test cases.
From the Status panel, you can see that both environments built successfully, both executed their
test cases and they passed, but the status for Statement coverage shows a failure.
14. Hover the mouse near the coverage status to see a tooltip with more detail.
MODIFYING THE PROJECT 329
The Manage Summary Report shows the build, execution, and coverage status for the two
environments in the different Test Suites. One Test Suite has coverage and one doesn’t.
17. Right-click the root node of the project and choose Store Results.
This action logs the build and execute status in the project database. There are now two snapshots
of data in the database.
18. To see that there are in fact two snapshots, choose Project => SQL Data.
The History Results dialog opens, listing the two snapshots, identified by their timestamps.
Tutorial Summary
In this tutorial, you:
l Created two unit test environments quickly, each having a test case with Expected Values.
l Created a Manage project and imported those environments.
TUTORIAL SUMMARY 331
l Built and executed the environments and viewed a graph and report with information about the
status.
l Duplicated a Test Suite to apply coverage.
l Built and executed the environments again, this time with coverage.
l Duplicated a Test Suite by dragging and dropping.
l Closed the environment and accepted the diffs in Manage.
l Noted the Status panel reflected the updated Test Execution status.
Appendix A: Tutorial Source Code Listings
Requirements
FR11
Number of tables
The system will support 6 tables.
FR12
Number of seats per table
The system will support 4 seats per table.
FR13
List of entrees
The system will support the following entrees: steak chicken lobster pasta none
FR14
Placing an order updates occupied status
Placing an order updates the table's occupied status to true within the table database.
FR15
Placing an order updates number in party
Placing an order updates the table's number in party within the table database.
FR16
Placing an order updates a seat's order
Placing an order updates the seat's order within the table database.
FR17
Placing an order updates check total
Placing an order increases the table's check total within the table database, by an amount
depending on the entree ordered, according to the following schedule: Entree: Amount steak: 14.0
chicken: 10.0 lobster: 18.0 pasta: 12.0 none: 0.0
FR18
Clearing a table resets occupied status
Clearing a table updates the table's occupied status to false within the table database.
REQUIREMENTS 333
FR19
Clearing a table resets number in party
Clearing a table updates the table's number in party to 0 within the table database.
FR20
Clearing a table resets orders for all seats
Clearing a table clears the orders for all seats of the table within the table database.
FR21
Clearing a table resets check total
Clearing a table updates the table's check total to 0.0 within the table database.
FR22
Obtaining check total
The system will provide a way to obtain the check total for a given table.
FR23
Size of waiting list
The system will support a waiting list of up to 10 parties.
FR24
Adding a party to waiting list
The system will provide a means of adding a party to the waiting list, with the party specified by
name.
FR25
Getting the head of the waiting list
The system will provide a means of obtaining the name of the party at the head of the waiting list.
FR27
Adding free dessert
Placing certain orders will qualify the seat for free dessert, according to the following schedule:
Steak with caesar salad and a mixed drink qualifies a seat for pie. Lobster with green salad and wine
qualifies a seat for cake.
C 334
file: ctypes.h
#ifndef _TUTORIAL_TYPES_H_
#define _TUTORIAL_TYPES_H_
#define SEATS_AT_ONE_TABLE 4
#define NUMBER_OF_TABLES 6
struct order_type
{
enum soups Soup;
enum salads Salad;
enum entrees Entree;
enum desserts Dessert;
enum beverages Beverage;
};
struct table_data_type
{
enum boolean Is_Occupied;
seat_index_type Number_In_Party;
char Designator;
char Wait_Person[10];
struct order_type Order[SEATS_AT_ONE_TABLE];
float Check_Total;
};
#endif /* _TUTORIAL_TYPES_H_ */
file: manager.c
#include "ctypes.h"
C 335
/* This function will add a free dessert to specific orders based on the
entree, salad, and beverage choiece */
void Add_Included_Dessert(struct order_type* Order)
{
if(Order->Entree == STEAK &&
Order->Salad == CAESAR &&
Order->Beverage == MIXED_DRINK) {
Order->Dessert = PIE;
Order->Dessert = CAKE;
}
}
Table_Data = Get_Table_Record(Table);
Table_Data.Is_Occupied = v_true;
Table_Data.Number_In_Party = Table_Data.Number_In_Party + 1;
Table_Data.Order[Seat] = Order;
case STEAK :
Table_Data.Check_Total = Table_Data.Check_Total + 14.0;
break;
case CHICKEN :
Table_Data.Check_Total = Table_Data.Check_Total + 10.0;
break;
case LOBSTER :
Table_Data.Check_Total = Table_Data.Check_Total + 18.0;
break;
case PASTA :
Table_Data.Check_Total = Table_Data.Check_Total + 12.0;
break;
}
Update_Table_Record(Table, Table_Data);
return 0;
}
Name++;
}
WaitingList[WaitingListSize++][i] = 0;
}
char* Get_Next_Party_To_Be_Seated(void)
{
if(WaitingListIndex > 9)
WaitingListIndex = 0;
return WaitingList[WaitingListIndex++];
}
file: database.c
#include "ctypes.h"
file: whitebox.c
struct PointerType
{
int DataIndex;
int DataValue;
};
void Initialize()
{
InitDay(WEDNESDAY);
InitColor(BLUE);
P.DataIndex = 1;
P.DataValue = 12;
}
file: manager_driver.c
#include <stdio.h>
#include <string.h>
#include "ctypes.h"
int main()
{
struct order_type order;
int Total;
char line[10];
switch (line[0])
{
case 'p': case 'P':
order.Entree = STEAK;
Place_Order(1, 1, order);
break;
case 'g': case 'G':
C++ 339
order.Entree = CHICKEN;
Place_Order(2, 2, order);
Total = Get_Check_Total(2);
printf("The Total is %d\n", Total);
break;
case 'c': case 'C':
Clear_Table(1);
break;
case 'a': case 'A':
order.Entree = STEAK;
order.Salad = CAESAR;
order.Beverage = MIXED_DRINK;
Add_Included_Dessert(&order);
break;
}
return 0;
}
C++
file: cpptypes.h
#ifndef _TYPES_
#define _TYPES_
struct OrderType
{
enum Soups Soup;
enum Salads Salad;
enum Entrees Entree;
enum Desserts Dessert;
enum Beverages Beverage;
C++ 340
};
struct TableDataType
{
bool IsOccupied;
int NumberInParty;
char Designator;
char WaitPerson[10];
OrderType Order[SeatsAtOneTable];
int CheckTotal;
};
#endif
file: manager.h
#ifndef _MANAGER_
#define _MANAGER_
#include "cpptypes.h"
#include "database.h"
class Manager
{
public:
Manager();
void AddIncludedDessert(OrderType* Order);
void PlaceOrder(int Table, int Seat, OrderType Order);
void ClearTable(int Table);
int GetCheckTotal(int Table);
int MemberVariable;
void AddPartyToWaitingList(char* Name);
char* GetNextPartyToBeSeated(void);
private:
DataBase Data;
name_type WaitingList[10];
unsigned int WaitingListSize;
unsigned int WaitingListIndex;
};
#endif
C++ 341
file: manager.cpp
#include "cpptypes.h"
#include "database.h"
#include "manager.h"
Manager::Manager(){
WaitingListSize = 0;
WaitingListIndex = 0;
}
/* This function will add a free dessert to specific orders based on the
entree, salad, and beverage choice */
void Manager::AddIncludedDessert(OrderType* Order)
{
if(!Order)
return;
Order->Dessert = Pie;
Order->Dessert = Cake;
}
}
TableData.IsOccupied = true;
TableData.NumberInParty++;
TableData.Order[Seat] = Order;
/* Add a free dessert in some case */
AddIncludedDessert(&TableData.Order[Seat]);
switch(Order.Entree) {
case Steak :
TableData.CheckTotal += 14;
C++ 342
break;
case Chicken :
TableData.CheckTotal += 10;
break;
case Lobster :
TableData.CheckTotal += 18;
break;
case Pasta :
TableData.CheckTotal += 12;
break;
default :
break;
}
Data.UpdateTableRecord(Table, &TableData);
}
char* Manager::GetNextPartyToBeSeated()
{
if(WaitingListIndex > 9)
WaitingListIndex = 0;
return WaitingList[WaitingListIndex++];
}
C++ 343
file: database.h
#ifndef _DATABASE_
#define _DATABASE_
#include "cpptypes.h"
class DataBase
{
public :
DataBase(); /* Constructor */
~DataBase(); /* Destructor */
private :
for(int J=0;J<SeatsAtOneTable;J++)
{
Data[Table].Order[J].Soup = NoSoup;
Data[Table].Order[J].Salad = NoSalad;
Data[Table].Order[J].Entree = NoEntree;
Data[Table].Order[J].Dessert = NoDessert;
Data[Table].Order[J].Beverage = NoBeverage;
}
}
#endif
file: database.cpp
#include "database.h"
TableDataType TableData[NumberOfTables];
DataBase::DataBase(){}
DataBase::~DataBase(){}
file: whitebox.h
#ifndef _WHITEBOX_
#define _WHITEBOX_
struct PointerType
{
int DataIndex;
int DataValue;
};
class WhiteBox
{
public:
WhiteBox() {}
void Initialize();
private:
C++ 345
#endif
file: whitebox.cpp
#include "whitebox.h"
void WhiteBox::Initialize()
{
InitDay(MONDAY);
InitColor(RED);
P.DataIndex = 1;
P.DataValue = 12;
}
file: manager_driver.cpp
#include "cpptypes.h"
#include "manager.h"
#include <stdio.h>
int main()
{
OrderType order;
Manager manager;
int Total;
char line[10];
C++ 346
switch (line[0])
{
case 'p': case 'P':
order.Entree = Steak;
manager.PlaceOrder(1, 1, order);
break;
case 'g': case 'G':
order.Entree = Chicken;
manager.PlaceOrder(2, 2, order);
Total = manager.GetCheckTotal(2);
printf("The Total is %d\n", Total);
break;
case 'c': case 'C':
manager.ClearTable(1);
break;
case 'a': case 'A':
order.Entree = Steak;
order.Salad = Caesar;
order.Beverage = MixedDrink;
manager.AddIncludedDessert(&order);
break;
}
return 0;
}
file: Makefile
# VCAST_COVER_ENV = CoverENV
## --- The Instrumented utility target below adds the Cover environment
## --- directory as an Include. The wrap_compile command then
## --- substitutes the compile command used in the existing Makefile.
## --- The object file dependency needed for linking the instrumented
## --- executable is then added to the existing set of object files.
## --- Lastly, the instrumented target lists each prerequisite target
## --- needed for the integration process. It sets the compiler
## --- template, compiles the source files, creates the object file
## --- dependency, and creates the instrumented executable.
##--- The c_cover_io.o target below creates the object file needed to
##--- link the instrumented executable. The target needs to include
##--- vcast_c_options.h as a prerequisite in the case that the coverage
##--- type is changed. The c_cover_io.cpp file will need to be
##--- recompiled to reflect the change to the coverage type.
# c_cover_io.o : $(VCAST_COVER_ENV)/c_cover_io.cpp $(VCAST_COVER_ENV)/vcast_c_options.h
#g++ -c $< $(INCLUDES) -o $@
Ada
file: types.ads
package TYPES is
ADA 348
type ORDER_TYPE is
record
SOUP : SOUPS := NO_ORDER;
SALAD : SALADS := NO_ORDER;
ENTREE : ENTREES := NO_ORDER;
DESSERT : DESSERTS := NO_ORDER;
BEVERAGE : BEVERAGES := NO_ORDER;
end record;
type TABLE_DATA_TYPE is
record
IS_OCCUPIED : boolean := false;
NUMBER_IN_PARTY : SEAT_RANGE_TYPE := 0;
DESIGNATOR : character := ' ';
WAIT_PERSON : WAIT_PERSON_NAME := " ";
ORDER : TABLE_ORDER_TYPE;
CHECK_TOTAL : integer := 0;
end record;
end TYPES;
file: manager.ads
with TYPES;
package MANAGER is
procedure PLACE_ORDER (
TABLE : in TYPES.TABLE_INDEX_TYPE;
SEAT : in TYPES.SEAT_INDEX_TYPE;
ORDER : in out TYPES.ORDER_TYPE);
ADA 349
procedure CLEAR_TABLE (
TABLE : in TYPES.TABLE_INDEX_TYPE);
end MANAGER;
file: manager.adb
with DATABASE;
with TYPES; use TYPES;
procedure PLACE_ORDER (
TABLE : in TYPES.TABLE_INDEX_TYPE;
SEAT : in TYPES.SEAT_INDEX_TYPE;
ORDER : in out TYPES.ORDER_TYPE) is
TABLE_DATA : TYPES.TABLE_DATA_TYPE;
begin
DATABASE.GET_TABLE_RECORD (
TABLE => TABLE,
DATA => TABLE_DATA);
TABLE_DATA.IS_OCCUPIED := true;
TABLE_DATA.NUMBER_IN_PARTY := TABLE_DATA.NUMBER_IN_PARTY + 1;
TABLE_DATA.ORDER (SEAT) := ORDER;
ADA 350
ADD_INCLUDED_DESSERT ( TABLE_DATA.ORDER(SEAT) );
case ORDER.ENTREE is
when TYPES.NO_ORDER =>
null;
when TYPES.STEAK =>
TABLE_DATA.CHECK_TOTAL := TABLE_DATA.CHECK_TOTAL + 14;
when TYPES.CHICKEN =>
TABLE_DATA.CHECK_TOTAL := TABLE_DATA.CHECK_TOTAL + 10;
when TYPES.LOBSTER =>
TABLE_DATA.CHECK_TOTAL := TABLE_DATA.CHECK_TOTAL + 18;
when TYPES.PASTA =>
TABLE_DATA.CHECK_TOTAL := TABLE_DATA.CHECK_TOTAL + 12;
end case;
DATABASE.UPDATE_TABLE_RECORD (
TABLE => TABLE,
DATA => TABLE_DATA);
end PLACE_ORDER;
procedure CLEAR_TABLE (
TABLE : in TYPES.TABLE_INDEX_TYPE) is
TABLE_DATA : TYPES.TABLE_DATA_TYPE;
NULL_ORDER : TYPES.ORDER_TYPE :=
(SOUP => TYPES.NO_ORDER,
SALAD => TYPES.NO_ORDER,
ENTREE => TYPES.NO_ORDER,
DESSERT => TYPES.NO_ORDER,
BEVERAGE => TYPES.NO_ORDER);
ADA 351
begin
DATABASE.GET_TABLE_RECORD (
TABLE => TABLE,
DATA => TABLE_DATA);
TABLE_DATA.IS_OCCUPIED := false;
TABLE_DATA.NUMBER_IN_PARTY := 1;
for SEAT in TYPES.SEAT_INDEX_TYPE loop
TABLE_DATA.ORDER (SEAT) := NULL_ORDER;
end loop;
TABLE_DATA.CHECK_TOTAL := 0;
DATABASE.UPDATE_TABLE_RECORD (
TABLE => TABLE,
DATA => TABLE_DATA);
end CLEAR_TABLE;
TABLE_DATA : TYPES.TABLE_DATA_TYPE;
begin
DATABASE.GET_TABLE_RECORD (
TABLE => TABLE,
DATA => TABLE_DATA);
return TABLE_DATA.CHECK_TOTAL;
end GET_CHECK_TOTAL;
end MANAGER;
file: database.ads
with types;
package DATABASE is
procedure GET_TABLE_RECORD (
TABLE : in TYPES.TABLE_INDEX_TYPE;
DATA : out TYPES.TABLE_DATA_TYPE);
procedure UPDATE_TABLE_RECORD (
TABLE : in TYPES.TABLE_INDEX_TYPE;
DATA : in TYPES.TABLE_DATA_TYPE);
end DATABASE;
file: database.adb
with types;
procedure GET_TABLE_RECORD (
TABLE : in TYPES.TABLE_INDEX_TYPE;
DATA : out TYPES.TABLE_DATA_TYPE) is
begin
DATA := TABLE_DATA (TABLE);
end GET_TABLE_RECORD;
procedure UPDATE_TABLE_RECORD (
TABLE : in TYPES.TABLE_INDEX_TYPE;
DATA : in TYPES.TABLE_DATA_TYPE) is
begin
TABLE_DATA (TABLE) := DATA;
end UPDATE_TABLE_RECORD;
end DATABASE;
file: manager_driver.adb
with TEXT_IO;
with TYPES;
with MANAGER;
procedure manager_driver is
CHOICE : string(1..10);
LEN : integer := 0;
ORDER : TYPES.ORDER_TYPE;
begin
TEXT_IO.PUT("P=Place_Order C=ClearTable G=Get_Check_Total A=AddIncludedDessert : ");
TEXT_IO.GET_LINE(CHOICE,LEN);
MANAGER.CLEAR_TABLE ( 1 );
end case;
end if;
end manager_driver;
file: whitebox.ads
package WHITEBOX is
private
type pointer_type is
record
data_index : integer;
data_value : integer;
end record;
end WHITEBOX;
file: whitebox.adb
package body WHITEBOX is
current_day : day;
current_color : color;
BUILD SETTINGS 355
end WHITEBOX;
Build Settings
file: types.h
#ifndef TYPES_H
#define TYPES_H
enum SkyType
{
Cloudy,
MostlyCloudy,
PartlyCloudy,
MostlySunny,
Sunny
};
typedef enum SkyType ESkyType;
enum TemperatureType
{
Hot,
Warm,
Mild,
Cool,
Cold
};
typedef enum TemperatureType ETemperatureType;
BUILD SETTINGS 356
#endif
file: sky.h
#ifndef SKY_H
#define SKY_H
#include "types.h"
#endif
file: sky.c
#include "sky.h"
case MostlySunny:
description = "Mostly Sunny";
break;
case Sunny:
description = "Sunny";
break;
}
return description;
}
file: temperature.h
#ifndef TEMPERATURE_H
#define TEMPERATURE_H
#include "types.h"
#ifdef CELSIUS
ETemperatureType temperature_condition_celsius( int degrees_celsius );
int celsius_to_fahrenheit( int celsius );
#endif
#endif
file: temperature.c
#include "temperature.h"
{
const char* description = "Unknown";
switch ( t )
{
case Hot:
description = "Hot";
break;
case Warm:
description = "Warm";
break;
case Mild:
description = "Mild";
break;
case Cool:
description = "Cool";
break;
case Cold:
description = "Cold";
break;
}
return description;
}
#ifdef CELSIUS
ETemperatureType temperature_condition_celsius( int degrees_celsius )
{
return temperature_condition_fahrenheit( celsius_to_fahrenheit( degrees_celsius ) );
}
file: weather.c
#include <stdio.h>
#include <stdlib.h>
#include "temperature.h"
#include "sky.h"
#ifdef CELSIUS
#define TEMPERATURE_SCALE "Celsius"
#elif defined(FAHRENHEIT)
#define TEMPERATURE_SCALE "Fahrenheit"
BUILD SETTINGS 359
#endif
if ( argc != 3 )
{
printf( "USAGE: weather [temperature in degrees %s] [percentage of cloud coverage]
\n", TEMPERATURE_SCALE );
return 1;
}
#ifdef CELSIUS
temperature_cond = temperature_condition_celsius( atoi( argv[1] ) );
#elif defined(FAHRENHEIT)
temperature_cond = temperature_condition_fahrenheit( atoi( argv[1] ) );
#endif
temperature_desc = temperature_description( temperature_cond );
file: Makefile
INC_DIR=inc
SRC_DIR=src
HEADERS=$(INC_DIR)/types.h $(INC_DIR)/temperature.h $(INC_DIR)/sky.h
OBJECTS=weather.o temperature.o sky.o
DEGREE_TYPE=-DCELSIUS
weather: $(OBJECTS)
$(CC) -o weather weather.o temperature.o sky.o
clean:
rm -f weather.exe $(OBJECTS)
file: Makefile.nmake
CC=cl.exe
INC_DIR=inc
SRC_DIR=src
HEADERS=$(INC_DIR)/types.h $(INC_DIR)/temperature.h $(INC_DIR)/sky.h
OBJECTS=weather.obj temperature.obj sky.obj
DEGREE_TYPE=CELSIUS
weather.exe: $(OBJECTS)
$(CC) weather.obj temperature.obj sky.obj
clean:
del weather.exe $(OBJECTS)
Index: ACTUAL RESULTS – EXISTING INSTALLED INSTANCES DETECTED
- 361 -
Index: EXPECTED RESULTS – INTEGRATION TESTING
- 362 -
Index: LINT – TEST CASE
- 363 -
Index: TEST CASES – WHITEBOX TEST ENVIRONMENT
- 364 -
Index: WHITEBOX TUTORIAL – WIZARD
Whitebox Tutorial
building a test environment 249
Windows
installation 15
Wizard
data source 317
Manage Project 313
- 365 -