RTRT for C: How to easily check an array that contains different values?


Today, I encounter the situation that requires me to compare an array to another one that contains expected values . Normally, I would use native code (written in C) to solve this problem. But I decide to dig up IBM Rational Test RealTime Online Documentation to see if a solution exists. Well, it does. My problem can be solved by using the so-called Pseudo-variables. In this article I will describe it for you guys along with my usual approach (the native code way).

Problem description

int ExpectedValue[5] = {1, 2, 3, 4, 5};
ArrayUnderTest = getArray();
void setArray (){
for(int i = 0; i < 5; i++)
ArrayUnderTest[i] = ExpectedValue[i];

Assume that I want to test whether the function setArray() behaves correctly. Then what I have to do is to check whether each element of ArrayUnderTest is equal to its corresponding element of ExpectedValue. Here is the solutions.


Using Native Code

First of all, I declare a temporary array with Boolean type. After calling the function under test, I can write a “for” loop to compare each element of ArrayUnderTest . If nothing goes wrong, each element of the temporary array is TRUE.

Native Code

Using Pseudo-Variable

Pseudo-variables I, I1, I2 …, are variables which are generated by RTRT where In is the current index of the nth dimension of the parameter

The identifiers I1, I2, … are reserved to access different dimensions of an array. For a three-dimensional matrix, I1 represents the index for the first dimension, I2 the index for the second dimension, and I3 the index for the third dimension.

So here is the result of using pseudo-variables


You can find more detail about pseudo-variable by searching for “Expected value expression for C” in Rational Test RealTime Online Documentation.

Leave a Reply