123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619 |
- program tcnvstr1;
- {****************************************************************}
- { CODE GENERATOR TEST PROGRAM }
- { Copyright (c) 2002, Carl Eric Codere }
- {****************************************************************}
- { NODE TESTED : secondtypeconvert() -> second_string_string }
- {****************************************************************}
- { PRE-REQUISITES: secondload() }
- { secondassign() }
- { secondtypeconv() }
- {****************************************************************}
- { DEFINES: }
- { FPC = Target is FreePascal compiler }
- {****************************************************************}
- { REMARKS: Same type short conversion is not tested, except for }
- { shortstrings , since it requires special handling. }
- { }
- { }
- {****************************************************************}
- {$ifdef fpc}
- {$mode objfpc}
- {$ifndef ver1_0}
- {$define haswidestring}
- {$endif}
- {$else}
- {$ifndef ver70}
- {$define haswidestring}
- {$endif}
- {$endif}
- {$define hasshortstring}
- uses
- jdk15;
- {$H+}
- {$macro on}
- {$define writeln:=JLSystem.fout.println}
- {$define write:=JLSystem.fout.print}
- const
- { exactly 255 characters in length }
- BIG_STRING =
- ' This is a small text documentation to verify the validity of'+
- ' the string conversion routines. Of course the conversion routines'+
- ' should normally work like a charm, and this can only test that there'+
- ' aren''t any problems with maximum length strings. This fix!';
- { < 255 characters in length }
- SMALL_STRING = 'This is a small hello!';
- { > 255 characters in length }
- HUGE_STRING_END = ' the goal of this experiment';
- HUGE_STRING =
- ' This is a huge text documentation to verify the validity of'+
- ' the string conversion routines. Of course the conversion routines'+
- ' should normally work like a charm, and this can only test that there'+
- ' aren''t any problems with maximum length strings. I hope you understand'+
- HUGE_STRING_END;
- EMPTY_STRING = '';
- type
- shortstr = string[127];
- var
- {$ifdef hasshortstring}
- s2: shortstr;
- {$endif}
- str_ansi: ansistring;
- {$ifdef hasshortstring}
- str_short: shortstring;
- {$endif}
- {$ifdef haswidestring}
- str_wide : widestring;
- {$endif}
- procedure fail;
- begin
- Raise JLException.create('failure');
- end;
- {$ifdef hasshortstring}
- procedure test_ansi_to_short;
- var
- p: pchar;
- begin
- {************************************************************************}
- { ansistring -> shortstring }
- {************************************************************************}
- WriteLn('Test ansistring -> shortstring');
- { ansistring -> shortstring }
- str_short := '';
- str_ansi:='';
- str_ansi := SMALL_STRING;
- str_short:=str_ansi;
- Write('small ansistring -> shortstring...');
- if str_short = str_ansi then
- WriteLn('Success.')
- else
- fail;
- str_short := '';
- str_ansi:='';
- str_ansi := EMPTY_STRING;
- str_short:=str_ansi;
- Write('empty ansistring -> shortstring...');
- if str_short = str_ansi then
- WriteLn('Success.')
- else
- fail;
- str_short := '';
- str_ansi:='';
- str_ansi := BIG_STRING;
- str_short:=str_ansi;
- Write('big ansistring -> shortstring...');
- jlsystem.fout.println;
- jlsystem.fout.println('const: '+BIG_STRING);
- jlsystem.fout.println('ansi : '+unicodestring(str_ansi));
- jlsystem.fout.println('short: '+unicodestring(str_short));
- if str_short = str_ansi then
- WriteLn('Success.')
- else
- fail;
- Write('huge ansistring -> shortstring...');
- str_short := '';
- str_ansi:='';
- str_ansi := HUGE_STRING;
- str_short:=str_ansi;
- { Delphi 3/Delphi 6 does not consider these as the same string }
- if str_short <> str_ansi then
- WriteLn('Success.')
- else
- fail;
- {}
- s2 := '';
- str_ansi:='';
- str_ansi := SMALL_STRING;
- s2:=str_ansi;
- Write('small ansistring -> shortstring...');
- if s2 = str_ansi then
- WriteLn('Success.')
- else
- fail;
- s2 := '';
- str_ansi:='';
- str_ansi := EMPTY_STRING;
- s2:=str_ansi;
- Write('empty ansistring -> shortstring...');
- if s2 = str_ansi then
- WriteLn('Success.')
- else
- fail;
- str_ansi:='';
- p:=pchar(str_ansi);
- Write('empty ansistring -> pchar...');
- if p^<>#0 then
- fail;
- if p[0]<>#0 then
- fail
- else
- Writeln('Success');
- s2 := '';
- str_ansi:='';
- str_ansi := BIG_STRING;
- s2:=str_ansi;
- Write('big ansistring -> shortstring...');
- { Should fail, since comparing different string lengths }
- if s2 <> str_ansi then
- WriteLn('Success.')
- else
- fail;
- str_ansi := BIG_STRING;
- Write('big ansistring -> pchar...');
- p:=pchar(str_ansi);
- if p^<>' ' then
- fail;
- if p[0]<>' ' then
- fail;
- if length(p)<>length(BIG_STRING) then
- fail
- else
- Writeln('Success');
- s2 := '';
- str_ansi:='';
- str_ansi := HUGE_STRING;
- s2:=str_ansi;
- Write('huge ansistring -> shortstring...');
- { Should fail, since comparing different string lengths }
- if s2 <> str_ansi then
- WriteLn('Success.')
- else
- fail;
- end;
- procedure test_short_to_short;
- begin
- {************************************************************************}
- { shortstring -> shortstring }
- {************************************************************************}
- WriteLn('Test shortstring -> shortstring...');
- { shortstring -> shortstring }
- str_short := '';
- s2:='';
- s2 := SMALL_STRING;
- str_short:=s2;
- Write('small shortstring -> shortstring...');
- if str_short = s2 then
- WriteLn('Success.')
- else
- fail;
- str_short := '';
- s2:='';
- s2 := EMPTY_STRING;
- str_short:=s2;
- Write('empty shortstring -> shortstring...');
- if str_short = s2 then
- WriteLn('Success.')
- else
- fail;
- {$ifdef fpc}
- { Delphi does not compile these }
- str_short := '';
- s2:='';
- s2 := BIG_STRING;
- str_short:=s2;
- Write('big shortstring -> shortstring...');
- if str_short = s2 then
- WriteLn('Success.')
- else
- fail;
- str_short := '';
- s2:='';
- s2 := HUGE_STRING;
- str_short:=s2;
- Write('huge shortstring -> shortstring...');
- { Delphi 3/Delphi 6 does not consider these as the same string }
- if str_short = s2 then
- WriteLn('Success.')
- else
- fail;
- {$endif}
- s2 := '';
- str_short:='';
- str_short := SMALL_STRING;
- Write('small shortstring -> shortstring...');
- s2:=str_short;
- if s2 = str_short then
- WriteLn('Success.')
- else
- fail;
- s2 := '';
- str_short:='';
- str_short := EMPTY_STRING;
- Write('empty shortstring -> shortstring...');
- s2:=str_short;
- if s2 = str_short then
- WriteLn('Success.')
- else
- fail;
- s2 := '';
- str_short:='';
- str_short := BIG_STRING;
- Write('big shortstring -> shortstring...');
- s2:=str_short;
- { Should fail, since comparing different string lengths }
- if s2 <> str_short then
- WriteLn('Success.')
- else
- fail;
- {$ifdef fpc}
- s2 := '';
- str_short:='';
- writeln(length(ShortstringClass(@str_short).fdata));
- writeln(length(str_short));
- str_short := HUGE_STRING;
- writeln(length(ShortstringClass(@str_short).fdata));
- writeln(length(str_short));
- Write('huge shortstring -> shortstring...');
- s2:=str_short;
- writeln(unicodestring(s2));
- writeln(unicodestring(str_short));
- { Should fail, since comparing different string lengths }
- if s2 <> str_short then
- WriteLn('Success.')
- else
- fail;
- {$endif}
- end;
- procedure test_short_to_ansi;
- begin
- {************************************************************************}
- { shortstring -> ansistring }
- {************************************************************************}
- WriteLn('Test shortstring -> ansistring');
- Write('small shortstring -> ansistring...');
- { shortstring -> ansistring }
- str_short := SMALL_STRING;
- str_ansi:=str_short;
- if str_short = str_ansi then
- WriteLn('Success.')
- else
- fail;
- Write('empty shortstring -> ansistring...');
- str_short := EMPTY_STRING;
- str_ansi:=str_short;
- if str_short = str_ansi then
- WriteLn('Success.')
- else
- fail;
- Write('big shortstring -> ansistring...');
- str_short := BIG_STRING;
- str_ansi:=str_short;
- if str_short = str_ansi then
- WriteLn('Success.')
- else
- fail;
- Write('small shortstring -> ansistring...');
- { shortstring -> ansistring }
- s2 := SMALL_STRING;
- str_ansi:=s2;
- if s2 = str_ansi then
- WriteLn('Success.')
- else
- fail;
- Write('empty shortstring -> ansistring...');
- s2 := EMPTY_STRING;
- str_ansi:=s2;
- if s2 = str_ansi then
- WriteLn('Success.')
- else
- fail;
- end;
- {$endif}
- {$ifdef haswidestring}
- procedure test_wide_to_ansi;
- begin
- {************************************************************************}
- { widestring -> ansistring }
- {************************************************************************}
- WriteLn('Test widestring -> ansistring');
- Write('small widestring -> ansistring...');
- { widestring -> ansistring }
- str_wide := SMALL_STRING;
- str_ansi:=str_wide;
- if str_wide = str_ansi then
- WriteLn('Success.')
- else
- fail;
- Write('empty widestring -> ansistring...');
- str_wide := EMPTY_STRING;
- str_ansi:=str_wide;
- if str_wide = str_ansi then
- WriteLn('Success.')
- else
- fail;
- Write('big widestring -> ansistring...');
- str_wide := BIG_STRING;
- str_ansi:=str_wide;
- if str_wide = str_ansi then
- WriteLn('Success.')
- else
- fail;
- Write('huge widestring -> ansistring...');
- str_wide := HUGE_STRING;
- str_ansi:=str_wide;
- if str_wide = str_ansi then
- WriteLn('Success.')
- else
- fail;
- end;
- {$ifdef hasshortstring}
- procedure test_short_to_wide;
- begin
- {************************************************************************}
- { shortstring -> widestring }
- {************************************************************************}
- WriteLn('Test shortstring -> widestring');
- Write('small shortstring -> widestring...');
- { shortstring -> widestring }
- str_short := SMALL_STRING;
- str_wide:=str_short;
- if str_short = str_wide then
- WriteLn('Success.')
- else
- fail;
- Write('empty shortstring -> widestring...');
- str_short := EMPTY_STRING;
- str_wide:=str_short;
- if str_short = str_wide then
- WriteLn('Success.')
- else
- fail;
- Write('big shortstring -> widestring...');
- str_short := BIG_STRING;
- str_wide:=str_short;
- if str_short = str_wide then
- WriteLn('Success.')
- else
- fail;
- {$ifdef hasshortstring}
- Write('small shortstring -> widestring...');
- { shortstring -> widestring }
- s2 := SMALL_STRING;
- str_wide:=s2;
- if s2 = str_wide then
- WriteLn('Success.')
- else
- fail;
- Write('empty shortstring -> widestring...');
- s2 := EMPTY_STRING;
- str_wide:=s2;
- if s2 = str_wide then
- WriteLn('Success.')
- else
- fail;
- {$endif}
- end;
- {$endif}
- procedure test_ansi_to_wide;
- begin
- {************************************************************************}
- { ansistring -> widestring }
- {************************************************************************}
- WriteLn('Test ansistring -> widestring');
- Write('small ansistring -> widestring...');
- { ansistring -> widestring }
- str_ansi := SMALL_STRING;
- str_wide:=str_ansi;
- if str_ansi = str_wide then
- WriteLn('Success.')
- else
- fail;
- Write('empty ansistring -> widestring...');
- str_ansi := EMPTY_STRING;
- str_wide:=str_ansi;
- if str_ansi = str_wide then
- WriteLn('Success.')
- else
- fail;
- Write('big ansistring -> widestring...');
- str_ansi := BIG_STRING;
- str_wide:=str_ansi;
- if str_ansi = str_wide then
- WriteLn('Success.')
- else
- fail;
- {$ifdef hasshortstring}
- Write('small ansistring -> widestring...');
- { ansistring -> widestring }
- s2 := SMALL_STRING;
- str_wide:=s2;
- if s2 = str_wide then
- WriteLn('Success.')
- else
- fail;
- Write('empty ansistring -> widestring...');
- s2 := EMPTY_STRING;
- str_wide:=s2;
- if s2 = str_wide then
- WriteLn('Success.')
- else
- fail;
- {$endif hasshortstring}
- end;
- {$ifdef hasshortstring}
- procedure test_wide_to_short;
- begin
- {************************************************************************}
- { widestring -> shortstring }
- {************************************************************************}
- WriteLn('Test widestring -> shortstring');
- { widestring -> shortstring }
- str_short := '';
- str_wide:='';
- str_wide := SMALL_STRING;
- Write('small widestring -> shortstring...');
- str_short:=str_wide;
- if str_short = str_wide then
- WriteLn('Success.')
- else
- fail;
- str_short := '';
- str_wide:='';
- str_wide := EMPTY_STRING;
- Write('empty widestring -> shortstring...');
- str_short:=str_wide;
- if str_short = str_wide then
- WriteLn('Success.')
- else
- fail;
- Write('big widestring -> shortstring...');
- str_short := '';
- str_wide:='';
- str_wide := BIG_STRING;
- str_short:=str_wide;
- if str_short = str_wide then
- WriteLn('Success.')
- else
- fail;
- Write('huge widestring -> shortstring...');
- str_wide := HUGE_STRING;
- str_short:=str_wide;
- if str_short <> str_wide then
- WriteLn('Success.')
- else
- fail;
- {}
- Write('small widestring -> shortstring...');
- s2 := '';
- str_wide:='';
- str_wide := SMALL_STRING;
- s2:=str_wide;
- if s2 = str_wide then
- WriteLn('Success.')
- else
- fail;
- Write('empty widestring -> shortstring...');
- s2 := '';
- str_wide:='';
- str_wide := EMPTY_STRING;
- s2:=str_wide;
- if s2 = str_wide then
- WriteLn('Success.')
- else
- fail;
- Write('big widestring -> shortstring...');
- s2 := '';
- str_wide:='';
- str_wide := BIG_STRING;
- s2:=str_wide;
- if s2 <> str_wide then
- WriteLn('Success.')
- else
- fail;
- Write('huge widestring -> shortstring...');
- s2 := '';
- str_wide:='';
- str_wide := HUGE_STRING;
- s2:=str_wide;
- if s2 <> str_wide then
- WriteLn('Success.')
- else
- fail;
- end;
- {$endif}
- {$endif}
- Begin
- {$ifdef hasshortstring}
- test_ansi_to_short;
- test_short_to_short;
- test_short_to_ansi;
- {$endif}
- { requires widestring support }
- {$ifdef haswidestring}
- {$ifdef hasshortstring}
- test_short_to_wide;
- {$endif}
- test_ansi_to_wide;
- {$ifdef hasshortstring}
- test_wide_to_short;
- {$endif}
- test_wide_to_ansi;
- {$endif}
- End.
|