The ASSERT statement asserts whether a condition is true or false, compares two values and determines if they are equal, or asserts whether a statement should be executed or not.
>>-ASSERT-------------------------------------------------------> >--+-TRUE--(--test-expression--)----------------------+-+--------------------------------+->< +-FALSE--(--test-expression--)---------------------+ '-TEXT--(--display-expression--)-' +-COMPARE--(--actual_exp--,expected_exp--+----+--)-+ | '-,z-' | '-UNREACHABLE--------------------------------------'
The following example shows the usage of the ASSERT TRUE, ASSERT FALSE and ASSERT UNREACHABLE statements. You must code the routines that are used in this example.
asserts: package;
main: proc options(main);
dcl n fixed bin;
n = 1;
assert true( n> 0 );
assert true( n= 2 ) text('n not equal to 2');
assert unreachable;
end;
ibmpasu:
proc( packagename_ptr, procname_ptr, assert_sourceline,
text_addr, text_length )
ext( '_IBMPASU')
options( byvalue linkage(optlink) );
dcl packagename_ptr pointer;
dcl procname_ptr pointer;
dcl assert_sourceline fixed bin(31);
dcl text_addr pointer;
dcl text_length fixed bin(31);
dcl assert_packagename char(100) var based(packagename_ptr);
dcl assert_procname char(100) var based(procname_ptr);
dcl assert_text char(text_length) based(text_addr);
put skip edit( 'unreachable code hit on line ',
trim(assert_sourceline),
' in ',
assert_packagename,
':', assert_procname )
( a );
if text_length = 0 then;
else
put skip list( assert_text );
end;
ibmpast:
proc( packagename_ptr, procname_ptr, assert_sourceline,
text_addr, text_length )
ext( '_IBMPAST')
options( byvalue linkage(optlink) );
dcl packagename_ptr pointer;
dcl procname_ptr pointer;
dcl assert_sourceline fixed bin(31);
dcl text_addr pointer;
dcl text_length fixed bin(31);
dcl assert_packagename char(100) var based(packagename_ptr);
dcl assert_procname char(100) var based(procname_ptr);
dcl assert_text char(text_length) based(text_addr);
put skip edit( 'conditional assertion failed on line ',
trim(assert_sourceline),
' in ',
assert_packagename,
':', assert_procname )
( a );
if text_length = 0 then;
else
put skip list( assert_text );
end;
The following example shows the usage of the ASSERT COMPARE statement. You must code the routines that are used in this example.
asserts: package;
main: proc options(main);
dcl n fixed bin;
n = 1;
assert compare(n,1);
assert compare(n,2) text("n not equal to 2");
assert unreachable;
end;
ibmpasc:
proc( packagename_ptr, procname_ptr, assert_sourceline,
actual_addr, actual_length,
expected_addr, expected_length,
text_addr, text_length )
ext( '_IBMPASC')
options( byvalue linkage(optlink) );
dcl packagename_ptr pointer;
dcl procname_ptr pointer;
dcl assert_sourceline fixed bin(31);
dcl actual_addr pointer;
dcl actual_length fixed bin(31);
dcl expected_addr pointer;
dcl expected_length fixed bin(31);
dcl text_addr pointer;
dcl text_length fixed bin(31);
dcl assert_packagename char(100) var based(packagename_ptr);
dcl assert_procname char(100) var based(procname_ptr);
dcl assert_text char(text_length) based(text_addr);
dcl actual_text char(actual_length) based(actual_addr);
dcl expected_text char(expected_length)
based(expected_addr);
put skip edit( 'compare code hit on line ',
trim(assert_sourceline),
' in ',
assert_packagename,
':', assert_procname )
( a );
if text_length = 0 then;
else
put skip list( assert_text );
if actual_length = 0 then;
else
put skip list( actual_text );
if expected_length = 0 then;
else
put skip list( expected_text );
end;
Condition code | Meaning |
---|---|
430 | SIGNAL ASSERTION |
431 | An ASSERT TRUE/FALSE statement without a TEXT clause failed |
432 | An ASSERT TRUE/FALSE statement with a TEXT clause failed |
433 | An ASSERT UNREACHABLE statement without a TEXT clause failed |
434 | An ASSERT UNREACHABLE statement with a TEXT clause failed |
435 | An ASSERT COMPARE statement without a TEXT clause failed |
436 | An ASSERT COMPARE statement with a TEXT clause failed |