123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646 |
- { Program to test the system unit inc/dec routines }
- { By Carl Eric Codere Copyright (c) 2002 }
- program tincdec;
- const
- INCDEC_COUNT_SIMPLE = 8;
- INCDEC_COUNT_COMPLEX = -12;
- INIT_U8BIT = $0F;
- INIT_U16BIT = $FF00;
- INIT_U32BIT = $FF00FF00;
- INIT_S8BIT = $0F;
- INIT_S16BIT = -13333;
- INIT_S32BIT = -2335754;
- INIT_S64BIT = Low(longint);
- var
- global_s8bit : shortint;
- global_s16bit : smallint;
- global_s32bit :longint;
- global_s64bit : int64;
- global_u8bit : byte;
- global_u16bit : word;
- global_u32bit : longword;
- { the result must be calculated manually since
- FPC 1.0.x does not support adding directly 64-bit
- constants
- }
- result_s64bit_complex : int64;
- procedure init_globals;
- begin
- global_s8bit := INIT_S8BIT;
- global_s16bit := INIT_S16BIT;
- global_s32bit := longint(INIT_S32BIT);
- global_s64bit := INIT_S64BIT;
- global_u8bit := INIT_U8BIT;
- global_u16bit := INIT_U16BIT;
- global_u32bit := INIT_U32BIT;
- result_s64bit_complex := INIT_S64BIT;
- result_s64bit_complex := result_s64bit_complex + INCDEC_COUNT_COMPLEX;
- end;
- procedure fail;
- begin
- WriteLn('Failed!');
- Halt(1);
- end;
- function getcomplex_count_s32 : longint;
- begin
- getcomplex_count_s32 := INCDEC_COUNT_COMPLEX;
- end;
- function getcomplex_count_s8 :shortint;
- begin
- getcomplex_count_s8 := INCDEC_COUNT_COMPLEX;
- end;
- function getcomplex_count_s64 : int64;
- begin
- getcomplex_count_s64 := INCDEC_COUNT_COMPLEX;
- end;
- {***********************************************************************}
- { INC }
- {***********************************************************************}
- procedure test_inc_s8;
- var
- b: smallint;
- _result : boolean;
- begin
- _result := true;
- Write('Inc() signed 8-bit tests...');
- init_globals;
- Inc(global_s8bit);
- if global_S8bit <> (INIT_S8BIT+1) then
- _result := false;
- init_globals;
- Inc(global_S8bit, INCDEC_COUNT_SIMPLE);
- if global_S8bit <> (INCDEC_COUNT_SIMPLE+INIT_S8BIT) then
- _result := false;
- init_globals;
- Inc(global_S8bit, INCDEC_COUNT_COMPLEX);
- if global_S8bit <> (INCDEC_COUNT_COMPLEX+INIT_S8BIT) then
- _result := false;
- init_globals;
- b:= INCDEC_COUNT_SIMPLE;
- Inc(global_S8bit, b);
- if global_S8bit <> (INCDEC_COUNT_SIMPLE+INIT_S8BIT) then
- _result := false;
- init_globals;
- b:= INCDEC_COUNT_COMPLEX;
- Inc(global_S8bit, b);
- if global_S8bit <> (INCDEC_COUNT_COMPLEX+INIT_S8BIT) then
- _result := false;
- init_globals;
- Inc(global_S8bit, getcomplex_count_s32);
- if global_S8bit <> (INCDEC_COUNT_COMPLEX+INIT_S8BIT) then
- _result := false;
- init_globals;
- Inc(global_S8bit, getcomplex_count_s8);
- if global_S8bit <> (INCDEC_COUNT_COMPLEX+INIT_S8BIT) then
- _result := false;
- if not _result then
- fail
- else
- WriteLn('Success!');
- end;
- procedure test_inc_s16;
- var
- b: smallint;
- _result : boolean;
- begin
- _result := true;
- Write('Inc() signed 16-bit tests...');
- init_globals;
- Inc(global_s16bit);
- if global_S16bit <> (INIT_S16BIT+1) then
- _result := false;
- init_globals;
- Inc(global_s16bit, INCDEC_COUNT_SIMPLE);
- if global_s16bit <> (INCDEC_COUNT_SIMPLE+INIT_s16BIT) then
- _result := false;
- init_globals;
- Inc(global_s16bit, INCDEC_COUNT_COMPLEX);
- if global_s16bit <> (INCDEC_COUNT_COMPLEX+INIT_s16BIT) then
- _result := false;
- init_globals;
- b:= INCDEC_COUNT_SIMPLE;
- Inc(global_s16bit, b);
- if global_s16bit <> (INCDEC_COUNT_SIMPLE+INIT_s16BIT) then
- _result := false;
- init_globals;
- b:= INCDEC_COUNT_COMPLEX;
- Inc(global_s16bit, b);
- if global_s16bit <> (INCDEC_COUNT_COMPLEX+INIT_s16BIT) then
- _result := false;
- init_globals;
- Inc(global_s16bit, getcomplex_count_s32);
- if global_s16bit <> (INCDEC_COUNT_COMPLEX+INIT_s16BIT) then
- _result := false;
- init_globals;
- Inc(global_s16bit, getcomplex_count_s8);
- if global_s16bit <> (INCDEC_COUNT_COMPLEX+INIT_s16BIT) then
- _result := false;
- if not _result then
- fail
- else
- WriteLn('Success!');
- end;
- procedure test_inc_s32;
- var
- b: smallint;
- _result : boolean;
- begin
- _result := true;
- Write('Inc() signed 32-bit tests...');
- init_globals;
- Inc(global_s32bit);
- if global_S32bit <> (INIT_S32BIT+1) then
- _result := false;
- init_globals;
- Inc(global_s32bit, INCDEC_COUNT_SIMPLE);
- if global_s32bit <> (INCDEC_COUNT_SIMPLE+INIT_s32BIT) then
- _result := false;
- init_globals;
- Inc(global_s32bit, INCDEC_COUNT_COMPLEX);
- if global_s32bit <> (INCDEC_COUNT_COMPLEX+INIT_s32BIT) then
- _result := false;
- init_globals;
- b:= INCDEC_COUNT_SIMPLE;
- Inc(global_s32bit, b);
- if global_s32bit <> (INCDEC_COUNT_SIMPLE+INIT_s32BIT) then
- _result := false;
- init_globals;
- b:= INCDEC_COUNT_COMPLEX;
- Inc(global_s32bit, b);
- if global_s32bit <> (INCDEC_COUNT_COMPLEX+INIT_s32BIT) then
- _result := false;
- init_globals;
- Inc(global_s32bit, getcomplex_count_s32);
- if global_s32bit <> (INCDEC_COUNT_COMPLEX+INIT_s32BIT) then
- _result := false;
- init_globals;
- Inc(global_s32bit, getcomplex_count_s8);
- if global_s32bit <> (INCDEC_COUNT_COMPLEX+INIT_s32BIT) then
- _result := false;
- init_globals;
- Inc(global_s32bit, getcomplex_count_s64);
- if global_s32bit <> (INCDEC_COUNT_COMPLEX+INIT_s32BIT) then
- _result := false;
- if not _result then
- fail
- else
- WriteLn('Success!');
- end;
- procedure test_inc_s64;
- var
- b: int64;
- _result : boolean;
- begin
- _result := true;
- Write('Inc() signed 64-bit tests...');
- init_globals;
- Inc(global_s64bit);
- if global_S64bit <> (result_s64bit_complex-INCDEC_COUNT_COMPLEX+1) then
- _result := false;
- init_globals;
- Inc(global_s64bit, INCDEC_COUNT_COMPLEX);
- if global_s64bit <> (result_s64bit_complex) then
- _result := false;
- init_globals;
- Inc(global_s64bit, INCDEC_COUNT_COMPLEX);
- if global_s64bit <> (result_s64bit_complex) then
- _result := false;
- init_globals;
- b:= INCDEC_COUNT_COMPLEX;
- Inc(global_s64bit, b);
- if global_s64bit <> (result_s64bit_complex) then
- _result := false;
- {$ifndef ver1_0}
- init_globals;
- Inc(global_s64bit, getcomplex_count_s8);
- if global_s64bit <> (INCDEC_COUNT_COMPLEX+INIT_S64BIT) then
- _result := false;
- init_globals;
- Inc(global_s64bit, getcomplex_count_s32);
- if global_s64bit <> (INCDEC_COUNT_COMPLEX+INIT_s64BIT) then
- _result := false;
- {$endif}
- if not _result then
- fail
- else
- WriteLn('Success!');
- end;
- procedure test_inc_u32;
- var
- b: smallint;
- _result : boolean;
- begin
- _result := true;
- Write('Inc() unsigned 32-bit tests...');
- init_globals;
- Inc(global_u32bit);
- if global_u32bit <> (INIT_U32BIT+1) then
- _result := false;
- init_globals;
- Inc(global_u32bit, INCDEC_COUNT_SIMPLE);
- if global_u32bit <> (INCDEC_COUNT_SIMPLE+INIT_u32BIT) then
- _result := false;
- init_globals;
- Inc(global_u32bit, INCDEC_COUNT_COMPLEX);
- if global_u32bit <> (INCDEC_COUNT_COMPLEX+INIT_u32BIT) then
- _result := false;
- init_globals;
- b:= INCDEC_COUNT_SIMPLE;
- Inc(global_u32bit, b);
- if global_u32bit <> (INCDEC_COUNT_SIMPLE+INIT_u32BIT) then
- _result := false;
- init_globals;
- b:= INCDEC_COUNT_COMPLEX;
- Inc(global_u32bit, b);
- if global_u32bit <> (INCDEC_COUNT_COMPLEX+INIT_u32BIT) then
- _result := false;
- init_globals;
- Inc(global_u32bit, getcomplex_count_s32);
- if global_u32bit <> (INCDEC_COUNT_COMPLEX+INIT_u32BIT) then
- _result := false;
- init_globals;
- Inc(global_u32bit, getcomplex_count_s8);
- if global_u32bit <> (INCDEC_COUNT_COMPLEX+INIT_u32BIT) then
- _result := false;
- init_globals;
- Inc(global_u32bit, getcomplex_count_s64);
- if global_u32bit <> (INCDEC_COUNT_COMPLEX+INIT_u32BIT) then
- _result := false;
- if not _result then
- fail
- else
- WriteLn('Success!');
- end;
- {***********************************************************************}
- { DEC }
- {***********************************************************************}
- procedure test_dec_s8;
- var
- b: smallint;
- _result : boolean;
- l: byte;
- begin
- _result := true;
- Write('dec() signed 8-bit tests...');
- init_globals;
- dec(global_S8bit, INCDEC_COUNT_SIMPLE);
- if global_S8bit <> (INIT_S8BIT-INCDEC_COUNT_SIMPLE) then
- _result := false;
- init_globals;
- dec(global_S8bit, INCDEC_COUNT_COMPLEX);
- if global_S8bit <> (INIT_S8BIT-INCDEC_COUNT_COMPLEX) then
- _result := false;
- init_globals;
- b:= INCDEC_COUNT_SIMPLE;
- dec(global_S8bit, b);
- if global_S8bit <> (INIT_S8BIT-INCDEC_COUNT_SIMPLE) then
- _result := false;
- init_globals;
- b:= INCDEC_COUNT_COMPLEX;
- dec(global_S8bit, b);
- if global_S8bit <> (INIT_S8BIT-INCDEC_COUNT_COMPLEX) then
- _result := false;
- init_globals;
- dec(global_S8bit, getcomplex_count_s32);
- if global_S8bit <> (INIT_S8BIT-INCDEC_COUNT_COMPLEX) then
- _result := false;
- init_globals;
- dec(global_S8bit, getcomplex_count_s8);
- if global_S8bit <> (INIT_S8BIT-INCDEC_COUNT_COMPLEX) then
- _result := false;
- { extra test for overflow checking }
- l:=byte(high(shortint));
- global_s8bit := high(shortint);
- dec(global_s8bit,l);
- if global_s8bit <> 0 then
- _result := false;
- if not _result then
- fail
- else
- WriteLn('Success!');
- end;
- procedure test_dec_s16;
- var
- b: smallint;
- _result : boolean;
- begin
- _result := true;
- Write('dec() signed 16-bit tests...');
- init_globals;
- dec(global_s16bit, INCDEC_COUNT_SIMPLE);
- if global_s16bit <> (INIT_S16BIT-INCDEC_COUNT_SIMPLE) then
- _result := false;
- init_globals;
- dec(global_s16bit, INCDEC_COUNT_COMPLEX);
- if global_s16bit <> (INIT_S16BIT-INCDEC_COUNT_COMPLEX) then
- _result := false;
- init_globals;
- b:= INCDEC_COUNT_SIMPLE;
- dec(global_s16bit, b);
- if global_s16bit <> (INIT_S16BIT-INCDEC_COUNT_SIMPLE) then
- _result := false;
- init_globals;
- b:= INCDEC_COUNT_COMPLEX;
- dec(global_s16bit, b);
- if global_s16bit <> (INIT_S16BIT-INCDEC_COUNT_COMPLEX) then
- _result := false;
- init_globals;
- dec(global_s16bit, getcomplex_count_s32);
- if global_s16bit <> (INIT_S16BIT-INCDEC_COUNT_COMPLEX) then
- _result := false;
- init_globals;
- dec(global_s16bit, getcomplex_count_s8);
- if global_s16bit <> (INIT_S16BIT-INCDEC_COUNT_COMPLEX) then
- _result := false;
- if not _result then
- fail
- else
- WriteLn('Success!');
- end;
- procedure test_dec_s32;
- var
- b: smallint;
- _result : boolean;
- begin
- _result := true;
- Write('dec() signed 32-bit tests...');
- init_globals;
- dec(global_s32bit, INCDEC_COUNT_SIMPLE);
- if global_s32bit <> (INIT_S32BIT-INCDEC_COUNT_SIMPLE) then
- _result := false;
- init_globals;
- dec(global_s32bit, INCDEC_COUNT_COMPLEX);
- if global_s32bit <> (INIT_S32BIT-INCDEC_COUNT_COMPLEX) then
- _result := false;
- init_globals;
- b:= INCDEC_COUNT_SIMPLE;
- dec(global_s32bit, b);
- if global_s32bit <> (INIT_S32BIT-INCDEC_COUNT_SIMPLE) then
- _result := false;
- init_globals;
- b:= INCDEC_COUNT_COMPLEX;
- dec(global_s32bit, b);
- if global_s32bit <> (INIT_S32BIT-INCDEC_COUNT_COMPLEX) then
- _result := false;
- init_globals;
- dec(global_s32bit, getcomplex_count_s32);
- if global_s32bit <> (INIT_S32BIT-INCDEC_COUNT_COMPLEX) then
- _result := false;
- init_globals;
- dec(global_s32bit, getcomplex_count_s8);
- if global_s32bit <> (INIT_S32BIT-INCDEC_COUNT_COMPLEX) then
- _result := false;
- init_globals;
- dec(global_s32bit, getcomplex_count_s64);
- if global_s32bit <> (INIT_S32BIT-INCDEC_COUNT_COMPLEX) then
- _result := false;
- if not _result then
- fail
- else
- WriteLn('Success!');
- end;
- procedure test_dec_s64;
- var
- b: smallint;
- _result : boolean;
- begin
- _result := true;
- Write('dec() signed 64-bit tests...');
- {$ifndef ver1_0}
- init_globals;
- dec(global_s64bit, getcomplex_count_s8);
- if global_s64bit <> (INIT_S64BIT-INCDEC_COUNT_COMPLEX) then
- _result := false;
- init_globals;
- dec(global_s64bit, getcomplex_count_s32);
- if global_s64bit <> (INIT_S64BIT-INCDEC_COUNT_COMPLEX) then
- _result := false;
- {$endif}
- if not _result then
- fail
- else
- WriteLn('Success!');
- end;
- procedure test_dec_u32;
- var
- b: smallint;
- _result : boolean;
- begin
- _result := true;
- Write('dec() unsigned 32-bit tests...');
- init_globals;
- dec(global_u32bit, INCDEC_COUNT_SIMPLE);
- if global_u32bit <> (INIT_u32BIT-INCDEC_COUNT_SIMPLE) then
- _result := false;
- init_globals;
- dec(global_u32bit, INCDEC_COUNT_COMPLEX);
- if global_u32bit <> (INIT_u32BIT-INCDEC_COUNT_COMPLEX) then
- _result := false;
- init_globals;
- b:= INCDEC_COUNT_SIMPLE;
- dec(global_u32bit, b);
- if global_u32bit <> (INIT_u32BIT-INCDEC_COUNT_SIMPLE) then
- _result := false;
- init_globals;
- b:= INCDEC_COUNT_COMPLEX;
- dec(global_u32bit, b);
- if global_u32bit <> (INIT_u32BIT-INCDEC_COUNT_COMPLEX) then
- _result := false;
- init_globals;
- dec(global_u32bit, getcomplex_count_s32);
- if global_u32bit <> (INIT_u32BIT-INCDEC_COUNT_COMPLEX) then
- _result := false;
- init_globals;
- dec(global_u32bit, getcomplex_count_s8);
- if global_u32bit <> (INIT_u32BIT-INCDEC_COUNT_COMPLEX) then
- _result := false;
- init_globals;
- dec(global_u32bit, getcomplex_count_s64);
- if global_u32bit <> (INIT_u32BIT-INCDEC_COUNT_COMPLEX) then
- _result := false;
- if not _result then
- fail
- else
- WriteLn('Success!');
- end;
- procedure test_inc_ptr;
- type
- tstruct = packed record
- b: byte;
- w: word;
- end;
- const
- word_array : array[1..4] of word =
- ($0000,$FFFF,$F0F0,$F00F);
- struct_array : array[1..4] of tstruct = (
- (b:00;w:0001),
- (b:01;w:0102),
- (b:02;w:0203),
- (b:03;w:0304)
- );
- var
- _result : boolean;
- pw : ^word;
- podd : ^tstruct;
- i: integer;
- B : byte;
- begin
- _result := true;
- Write('Inc() pointer to word...');
- pw:=@word_array;
- for i:=1 to 4 do
- begin
- if (word_array[i] <> pw^) then
- _result := false;
- Inc(pw)
- end;
- pw:=@word_array;
- inc(pw,2);
- if pw^<>word_array[3] then
- _result := false;
- pw:=@word_array;
- b:=2;
- inc(pw,b);
- if pw^<>word_array[3] then
- _result := false;
- podd:=@struct_array;
- b:=3;
- inc(podd,b);
- if (podd^.b<>struct_array[4].b) and (podd^.w<>struct_array[4].w) then
- _result := false;
- podd:=@struct_array;
- inc(podd,3);
- if (podd^.b<>struct_array[4].b) and (podd^.w<>struct_array[4].w) then
- _result := false;
- if not _result then
- fail
- else
- WriteLn('Success!');
- end;
- Begin
- test_inc_s8;
- test_inc_s16;
- test_inc_s32;
- test_inc_s64;
- test_inc_u32;
- test_inc_ptr;
- test_dec_s8;
- test_dec_s16;
- test_dec_s32;
- test_dec_s64;
- test_dec_u32;
- end.
|