Example 6: Testcase with structure and array elements

This example illustrates how to create and execute a test for the function block functionBlockWithArrayAndStruct provided by the following ST-code:

TYPE
structA : STRUCT
ele1 : INT;
ele2 : INT;
END_STRUCT;
END_TYPE
 
FUNCTION_BLOCK functionBlockWithArrayAndStruct
VAR_INPUT
input_array : ARRAY [0..1] OF INT;
input_struct : structA;
END_VAR
VAR_OUTPUT
output_array : ARRAY [0..1] OF INT;
output_struct : structA;
END_VAR
 
output_array[0] := input_array[0] + 1;
output_array[1] := input_array[1] + 2;
output_struct.ele1 := input_struct.ele1 + 1;
output_struct.ele2 := input_struct.ele2 + 2;
END_FUNCTION_BLOCK

This example contains inputs and outputs based on a structured data type or ARRAY data type. This restriction applies to them:

Behavior for structure and array elements

Only one column exists per input or output that is based on a →structured data type or →array data type. You have to enhance the column name to address one element. See "Accessing the structured data type and structure elements" and "Accessing the ARRAY data type and ARRAY elements", if you need information on the appropriate syntax.
Moveover, you must insert an additonal column per structure or array element that should be specified within the test case. For all other elements, specify the defaults within the worksheet Defaults.
Please mind that the test framework does not check whether the test case includes each element for such input variables.

The procedure of how to test this function block is analogous to the previous examples . Hence, this procedure is not listed in this example again. Instead, this article concentrates on the action to be done in the test suite.

The following illustration shows the worksheet for the test case after the test suite has been created (top) and the modified worksheet for the test case (bottom):

images/download/attachments/500236851/TF_TestsuiteExampleAddition6-version-2-modificationdate-1662717270301-api-v2.png

These pieces of data have changed - with reference to the test-suite (above):

  • The title of column B, C, D and E was expanded to specify the 1st structure or array element in the test case. Example: input_array became input_array[0] and input_struct became input_struct.ele2 .

  • Column C, E, G and I were inserted to specify the 2nd structure or array element in the test case. Example: input_array[1] and input_struct.ele2

As usual, also the test sequences and test data have been entered in the worksheet for the test case.
images/s/b2ic8e/9012/1ca6q62/_/images/icons/emoticons/information.svg Since the test case contains all columns for the structure and or array elements, it is not necessary to modify the worksheet Defaults for this example.

If you execute this test case, the console will display PASS as a result of the test execution.
As the test case includes array variables and variables based on a structured data type, a warning is displayed during the execution to indicate that the test framework does not check whether the test case includes each element for those input variables. This warning can be ignored for this example.