// Test allocate and free //% set debug_print_ccode = true main module TESTALLOC use TEXTIO declare Flex_array is packed array [1..?n] of char P is pointer Flex_array T1,T2,T3,T4: static P temp1: static packed array[1..5] of char temp2: static packed array[1..7] of char h1: static integer initially 3 h2: static integer initially 22 bf,bt: static boolean enddeclare exception didnt_work guard T1 := allocate P ("ABCDE") T2 := allocate P ((h1+h2)/5) // 5 T3 := allocate P (N: 5) T4 := allocate P (N: 6) if high(T1@)<>5 or high(T2@)<>5 or high(T3@)<>5 or high(T4@)<>6 do tty_line ("High failed") raise didnt_work endif T2@ :="ABCDE" T3@ := "ABCDE" T4@ := "ABCDEF" temp1 := "ABCDE" temp2 := "ABCDEFG" BT := t1@=t2@ and t1@=t3@ and t1@<>t4@ and t1@=temp1 and t1@<>temp2 // true BF := t1@<>t2@ or t1@<>t3@ or t1@=t4@ or t1@<>temp1 or t1@=temp2 // false if not bt or bf do out_string (tty, "First = failed, BT=") out_boolean (tty, BT) out_string (tty, " BF=") out_boolean (tty, BF) raise didnt_work endif // Next test t1@ := "12345" BF := t1@=t2@ and t1@=t3@ and t1@=t4@ and t1@=temp1 and t1@=temp2 // false BT := t1@<>t2@ or t1@<>t3@ or t1@<>t4@ or t1@<>temp1 or t1@<>temp2 // true if not bt or bf do out_string (tty, "Second = test failed, BT=") out_boolean (tty, BT) out_string (tty, " BF=") out_boolean (tty, BF) raise didnt_work endif tty_line ("Passed") catch case didnt_work: tty_line ("FAILED!!!") endguard endmodule