program Test_uString;

(* Description: Automaticky test funkci v jednotce uString.
   Language   : Borland Pascal 7.0
   Author     : Adam Wild, SofCon spol.s r.o.

   Prelozit test s novou uString a pote spustit. Pokud test zjisti chybu,
   vypise hlasku. V opacnem pripade (je-li vse OK) se program automaticky
   ukonci a prejde zpet do DOSu. V DosExitCode vraci kod chyby.
*)

uses
  Crt,
  uPom,
  NumToStr,
  uString;

const
  S1 = 'Nazdar ';
  S2 : string[20] = '123456789 ';
var
  Cmd:tCmd;
  S3:tParamStr;
  TextChars:tCharSet;
  FlOk:boolean;

Begin
  FlOk:=True;
  ClrScr;
  writeln('Test uString ',uString.cVer);

 {tCmd}
  S3:='Cau ';
  Cmd.InitCmd('Ahoj '+S2+S1+S3+cVer+S10+ByteStrDec(255,2));
  if Cmd.ReadRest<>'Ahoj '+S2+S1+S3+cVer+S10+ByteStrDec(255,2) then
  begin FlOk:=False; writeln('InitCmd Error'); end;

 {UpperCase}
  if UpperCase('')<>''         then begin FlOk:=False; writeln('UpperCase Error'); end;
  if UpperCase('AHOJ')<>'AHOJ' then begin FlOk:=False; writeln('UpperCase Error'); end;
  if UpperCase('aHoJ')<>'AHOJ' then begin FlOk:=False; writeln('UpperCase Error'); end;
  if UpperCase('ahoj')<>'AHOJ' then begin FlOk:=False; writeln('UpperCase Error'); end;

 {LowerCase}
  if LowerCase('')<>''         then begin FlOk:=False; writeln('LowerCase Error'); end;
  if LowerCase('ahoj')<>'ahoj' then begin FlOk:=False; writeln('LowerCase Error'); end;
  if LowerCase('aHoJ')<>'ahoj' then begin FlOk:=False; writeln('LowerCase Error'); end;
  if LowerCase('AHOJ')<>'ahoj' then begin FlOk:=False; writeln('LowerCase Error'); end;

 {UpCaseEach1stChar}
  if UpCaseEach1stChar('')<>''   then begin FlOk:=False; writeln('UpCaseEach1stWordChar Error'); end;
  if UpCaseEach1stChar('a')<>'A' then begin FlOk:=False; writeln('UpCaseEach1stWordChar Error'); end;
  if UpCaseEach1stChar('A')<>'A' then begin FlOk:=False; writeln('UpCaseEach1stWordChar Error'); end;
  if UpCaseEach1stChar('ahoj')<>'Ahoj' then begin FlOk:=False; writeln('UpCaseEach1stWordChar Error'); end;
  if UpCaseEach1stChar('AHOJ')<>'Ahoj' then begin FlOk:=False; writeln('UpCaseEach1stWordChar Error'); end;
  if UpCaseEach1stChar('ahoj aHOJ')<>'Ahoj Ahoj' then begin FlOk:=False; writeln('UpCaseEach1stWordChar Error'); end;
  if UpCaseEach1stChar(' a hO j,aHOJ')<>' A Ho J,Ahoj' then
     begin FlOk:=False; writeln('UpCaseEach1stWordChar Error'); end;

 {CompareStr}
  if CompareStr('',''         )<>0 then begin FlOk:=False; writeln('CompareStr Error'); end;
  if CompareStr('adasd',''    )<=0 then begin FlOk:=False; writeln('CompareStr Error'); end;
  if CompareStr('','sdsd'     )>=0 then begin FlOk:=False; writeln('CompareStr Error'); end;
  if CompareStr('abcd','bcde' )>=0 then begin FlOk:=False; writeln('CompareStr Error'); end;
  if CompareStr('abcd','abcde')>=0 then begin FlOk:=False; writeln('CompareStr Error'); end;
  if CompareStr('abcde','abcd')<=0 then begin FlOk:=False; writeln('CompareStr Error'); end;
  if CompareStr('abcd','abcd' )<>0 then begin FlOk:=False; writeln('CompareStr Error'); end;
  if CompareStr('BCDA','ABCD' )<=0 then begin FlOk:=False; writeln('CompareStr Error'); end;

 {CompareText}
  if CompareText('ABCD','ABCD')<>0 then begin FlOk:=False; writeln('CompareText Error'); end;
  if CompareText('abcd','ABCD')<>0 then begin FlOk:=False; writeln('CompareText Error'); end;

 {PosText}
  if PosText('','Ahoj')      <>0 then begin FlOk:=False; writeln('PosText Error'); end;
  if PosText('A','Ahoj')     <>1 then begin FlOk:=False; writeln('PosText Error'); end;
  if PosText('B','Ahoj')     <>0 then begin FlOk:=False; writeln('PosText Error'); end;
  if PosText('Ahoj','Ahoj')  <>1 then begin FlOk:=False; writeln('PosText Error'); end;
  if PosText('Ahog','Ahoj')  <>0 then begin FlOk:=False; writeln('PosText Error'); end;
  if PosText('Ahoja','Ahoj') <>0 then begin FlOk:=False; writeln('PosText Error'); end;
  if PosText('ahoj','AHOJ')  <>1 then begin FlOk:=False; writeln('PosText Error'); end;
  if PosText('ahoj','AhAHoJ')<>3 then begin FlOk:=False; writeln('PosText Error'); end;

 {PosI}
  if PosI('','Ahoj'      ,1)<>0 then begin FlOk:=False; writeln('PosI Error'); end;
  if PosI('Ahoj','Ah'    ,0)<>0 then begin FlOk:=False; writeln('PosI Error'); end;
  if PosI('Ahoj','Ahoj'  ,1)<>1 then begin FlOk:=False; writeln('PosI Error'); end;
  if PosI('Ahoj','AAhoj' ,1)<>2 then begin FlOk:=False; writeln('PosI Error'); end;
  if PosI('Ahoj','AhAhoj',1)<>3 then begin FlOk:=False; writeln('PosI Error'); end;
  if PosI('Ahoj','aAhoj' ,1)<>2 then begin FlOk:=False; writeln('PosI Error'); end;
  if PosI('Ahoj','aAhoj' ,2)<>2 then begin FlOk:=False; writeln('PosI Error'); end;
  if PosI('Ahoj','aAhoj' ,3)<>0 then begin FlOk:=False; writeln('PosI Error'); end;
  if PosI('Ahoj','aahoj' ,1)<>0 then begin FlOk:=False; writeln('PosI Error'); end;
  if PosI('Ahoj',' Ahoj' ,9)<>0 then begin FlOk:=False; writeln('PosI Error'); end;
                 {123456789012345678}
  if PosI('Ahoj','AhoAhoAhoj'        ,1) <> 7 then begin FlOk:=False; writeln('PosI Error'); end;
  if PosI('Ahoj','asdds Ahoj ds Ahoj',7) <> 7 then begin FlOk:=False; writeln('PosI Error'); end;
  if PosI('Ahoj','asdds Ahoj ds Ahoj',0) <> 7 then begin FlOk:=False; writeln('PosI Error'); end;
  if PosI('Ahoj','asdds Ahoj ds Ahoj',8) <>15 then begin FlOk:=False; writeln('PosI Error'); end;
  if PosI('Ahoj','asdds Ahoj ds Ahoj',16)<> 0 then begin FlOk:=False; writeln('PosI Error'); end;
  if PosI('Ahoj','asdds Ahoj ds Ahoj',15)<>15 then begin FlOk:=False; writeln('PosI Error'); end;

 {PosW}          {123456789012345678}
  TextChars:=['a'..'z','A'..'Z','_'];
  if PosW('Ahoj','AhoAhoAhoj'        ,TextChars)<> 0 then begin FlOk:=False; writeln('PosW Error'); end;
  if PosW('Ahoj','Ahoj ds Ahoj'      ,TextChars)<> 1 then begin FlOk:=False; writeln('PosW Error'); end;
  if PosW('Ahoj','asdds Ahoj ds Ahoj',TextChars)<> 7 then begin FlOk:=False; writeln('PosW Error'); end;
  if PosW('Ahoj','Ahoj'              ,TextChars)<> 1 then begin FlOk:=False; writeln('PosW Error'); end;
  if PosW('Ahoj','Ahoj_'             ,TextChars)<> 0 then begin FlOk:=False; writeln('PosW Error'); end;
  if PosW('Ahoj','Ahoj_ ds Ahoj'     ,TextChars)<>10 then begin FlOk:=False; writeln('PosW Error'); end;

 {Trim}
  if Trim('')<>''                   then begin FlOk:=False; writeln('Trim Error'); end;
  if Trim('Ahoj')<>'Ahoj'           then begin FlOk:=False; writeln('Trim Error'); end;
  if Trim('  Ahoj  ')<>'Ahoj'       then begin FlOk:=False; writeln('Trim Error'); end;
  if Trim(#$1B+' Ahoj'+#$7)<>'Ahoj' then begin FlOk:=False; writeln('Trim Error'); end;
  if Trim(' Ah oj ')<>'Ah oj'       then begin FlOk:=False; writeln('Trim Error'); end;

 {TrimLeft}
  if TrimLeft('')<>''                       then begin FlOk:=False; writeln('TrimLeft Error'); end;
  if TrimLeft('Ahoj')<>'Ahoj'               then begin FlOk:=False; writeln('TrimLeft Error'); end;
  if TrimLeft('  Ahoj  ')<>'Ahoj  '         then begin FlOk:=False; writeln('TrimLeft Error'); end;
  if TrimLeft(#$1B+' Ahoj'+#$7)<>'Ahoj'+#$7 then begin FlOk:=False; writeln('TrimLeft Error'); end;
  if TrimLeft(' Ah oj ')<>'Ah oj '          then begin FlOk:=False; writeln('TrimLeft Error'); end;

 {TrimRight}
  if TrimRight('')<>''                       then begin FlOk:=False; writeln('TrimRight Error'); end;
  if TrimRight('Ahoj')<>'Ahoj'               then begin FlOk:=False; writeln('TrimRight Error'); end;
  if TrimRight('  Ahoj  ')<>'  Ahoj'         then begin FlOk:=False; writeln('TrimRight Error'); end;
  if TrimRight(#$1B+' Ahoj'+#$7)<>#$1B+' Ahoj' then begin FlOk:=False; writeln('TrimRight Error'); end;
  if TrimRight(' Ah oj ')<>' Ah oj'          then begin FlOk:=False; writeln('TrimRight Error'); end;

 {Enlarge}
  if Enlarge('' ,0,' ')<>''                  then begin FlOk:=False; writeln('Enlarge Error'); end;
  if Enlarge('a',0,' ')<>'a'                 then begin FlOk:=False; writeln('Enlarge Error'); end;
  if Enlarge('' ,1,' ')<>' '                 then begin FlOk:=False; writeln('Enlarge Error'); end;
  if Enlarge('a',1,' ')<>'a'                 then begin FlOk:=False; writeln('Enlarge Error'); end;
  if Enlarge('a',2,' ')<>'a '                then begin FlOk:=False; writeln('Enlarge Error'); end;
  if Enlarge('' ,4,'p')<>'pppp'              then begin FlOk:=False; writeln('Enlarge Error'); end;
  if Enlarge('Ahoj',2,' ')<>'Ahoj'           then begin FlOk:=False; writeln('Enlarge Error'); end;
  if Enlarge('Ahoj',4,' ')<>'Ahoj'           then begin FlOk:=False; writeln('Enlarge Error'); end;
  if Enlarge('Ahoj',5,' ')<>'Ahoj '          then begin FlOk:=False; writeln('Enlarge Error'); end;
  if Enlarge('Ahoj',6,' ')<>' Ahoj '         then begin FlOk:=False; writeln('Enlarge Error'); end;
  if Enlarge('Ahoj',7,' ')<>' Ahoj  '        then begin FlOk:=False; writeln('Enlarge Error'); end;
  if Enlarge('Ahoj',10,' ')<>'   Ahoj   '    then begin FlOk:=False; writeln('Enlarge Error'); end;
  if Enlarge('Ahoj',9,'-')<>'--Ahoj---'      then begin FlOk:=False; writeln('Enlarge Error'); end;

 {EnlargeLeft}
  if EnlargeLeft('' ,0,' ')<>''              then begin FlOk:=False; writeln('EnlargeLeft Error'); end;
  if EnlargeLeft('a',0,' ')<>'a'             then begin FlOk:=False; writeln('EnlargeLeft Error'); end;
  if EnlargeLeft('' ,1,' ')<>' '             then begin FlOk:=False; writeln('EnlargeLeft Error'); end;
  if EnlargeLeft('a',1,' ')<>'a'             then begin FlOk:=False; writeln('EnlargeLeft Error'); end;
  if EnlargeLeft('a',2,' ')<>' a'            then begin FlOk:=False; writeln('EnlargeLeft Error'); end;
  if EnlargeLeft('' ,4,'p')<>'pppp'          then begin FlOk:=False; writeln('EnlargeLeft Error'); end;
  if EnlargeLeft('Ahoj',2,' ')<>'Ahoj'       then begin FlOk:=False; writeln('EnlargeLeft Error'); end;
  if EnlargeLeft('Ahoj',4,' ')<>'Ahoj'       then begin FlOk:=False; writeln('EnlargeLeft Error'); end;
  if EnlargeLeft('Ahoj',5,' ')<>' Ahoj'      then begin FlOk:=False; writeln('EnlargeLeft Error'); end;
  if EnlargeLeft('Ahoj',10,' ')<>'      Ahoj'then begin FlOk:=False; writeln('EnlargeLeft Error'); end;

 {EnlargeRight}
  if EnlargeRight('' ,0,' ')<>''              then begin FlOk:=False; writeln('EnlargeRight Error'); end;
  if EnlargeRight('a',0,' ')<>'a'             then begin FlOk:=False; writeln('EnlargeRight Error'); end;
  if EnlargeRight('' ,1,' ')<>' '             then begin FlOk:=False; writeln('EnlargeRight Error'); end;
  if EnlargeRight('a',1,' ')<>'a'             then begin FlOk:=False; writeln('EnlargeRight Error'); end;
  if EnlargeRight('a',2,' ')<>'a '            then begin FlOk:=False; writeln('EnlargeRight Error'); end;
  if EnlargeRight('' ,4,'p')<>'pppp'          then begin FlOk:=False; writeln('EnlargeRight Error'); end;
  if EnlargeRight('Ahoj',2,' ')<>'Ahoj'       then begin FlOk:=False; writeln('EnlargeRight Error'); end;
  if EnlargeRight('Ahoj',4,' ')<>'Ahoj'       then begin FlOk:=False; writeln('EnlargeRight Error'); end;
  if EnlargeRight('Ahoj',5,' ')<>'Ahoj '      then begin FlOk:=False; writeln('EnlargeRight Error'); end;
  if EnlargeRight('Ahoj',10,' ')<>'Ahoj      'then begin FlOk:=False; writeln('EnlargeRight Error'); end;

 {StringOfChar}
  if StringOfChar('A',1)<>'A'                then begin FlOk:=False; writeln('StringOfChar Error'); end;
  if StringOfChar(#0,0)<>''                  then begin FlOk:=False; writeln('StringOfChar Error'); end;
  if StringOfChar(#0,9)<>#0#0#0#0#0#0#0#0#0  then begin FlOk:=False; writeln('StringOfChar Error'); end;
  if StringOfChar('a',0)<>''                 then begin FlOk:=False; writeln('StringOfChar Error'); end;
  if StringOfChar('a',15)<>'aaaaaaaaaaaaaaa' then begin FlOk:=False; writeln('StringOfChar Error'); end;

 {SetLength}
  S2:='gfgi i'; SetLength(S2,0); if S2<>''   then begin FlOk:=False; writeln('SetLength Error'); end;
  S2:='gfgi i'; SetLength(S2,3); if S2<>'gfg'then begin FlOk:=False; writeln('SetLength Error'); end;
  S2:='gfgi i'; SetLength(S2,255); if Length(S2)<>255 then begin FlOk:=False; writeln('SetLength Error'); end;

 {WrapText}
      {1234567890123456789012345678901234567890}
  S3:='';
  if WrapText(S3,10)<>''                     then begin FlOk:=False; writeln('WrapText Error'); end;
  S3:='Ahoj Nazdar';
  if WrapText(S3,11)<>'Ahoj Nazdar'          then begin FlOk:=False; writeln('WrapText Error'); end;
  S3:='Ahoj Nazdar';
  if WrapText(S3,10)<>'Ahoj '#13#10'Nazdar'  then begin FlOk:=False; writeln('WrapText Error'); end;
  S3:='Ahoj';
  if WrapText(S3,10)<>'Ahoj'                 then begin FlOk:=False; writeln('WrapText Error'); end;
  S3:='Ahoj';
  if WrapText(S3,4)<>'Ahoj'                  then begin FlOk:=False; writeln('WrapText Error'); end;
  S3:='Ahoj';
  if WrapText(S3,3)<>'Aho'#13#10'j'          then begin FlOk:=False; writeln('WrapText Error'); end;
  S3:='A hoj';
  if WrapText(S3,3)<>'A '#13#10'hoj'         then begin FlOk:=False; writeln('WrapText Error'); end;
  S3:='Ahoj ';
  if WrapText(S3,4)<>'Ahoj'#13#10' '         then begin FlOk:=False; writeln('WrapText Error'); end;
  S3:='Ahoj a';
  if WrapText(S3,4)<>'Ahoj'#13#10' a'        then begin FlOk:=False; writeln('WrapText Error'); end;
  S3:='Ahoj Nazdar Cau,Naschle.Dobry Den';
  if WrapText(S3,9)<>'Ahoj '#13#10'Nazdar '#13#10'Cau,'#13#10'Naschle.'#13#10'Dobry Den'
  then begin FlOk:=False; writeln('WrapText Error'); end;
  S3:='Ahoj Nazdar Cau,Naschle.Dobry Den';
  if WrapText(S3,8)<>'Ahoj '#13#10'Nazdar '#13#10'Cau,'#13#10'Naschle.'#13#10'Dobry '#13#10'Den'
  then begin FlOk:=False; writeln('WrapText Error'); end;
  S3:='Ahoj Nazdar Cau,Naschle.Dobry Den';
  if WrapText(S3,6)<>'Ahoj '#13#10'Nazdar'#13#10' Cau,'#13#10'Naschl'#13#10'e.'#13#10'Dobry '#13#10'Den'
  then begin FlOk:=False; writeln('WrapText Error'); end;
  if WrapText('Toto je pokusny retezec pro funkci WrapText',10)<>
     'Toto je '#13#10'pokusny '#13#10'retezec '#13#10'pro funkci'#13#10' WrapText'
  then begin FlOk:=False; writeln('WrapText Error'); end;

 {ReverseStr}
  if ReverseStr('')<>''                 then begin FlOk:=False; writeln('ReverseStr Error'); end;
  if ReverseStr(' ')<>' '               then begin FlOk:=False; writeln('ReverseStr Error'); end;
  if ReverseStr('abcdefgh')<>'hgfedcba' then begin FlOk:=False; writeln('ReverseStr Error'); end;
  S2:='a 434 8344 344';
  if ReverseStr(S2)<>'443 4438 434 a'   then begin FlOk:=False; writeln('ReverseStr Error'); end;
  S2:=ReverseStr(S2);
  if S2<>'443 4438 434 a'               then begin FlOk:=False; writeln('ReverseStr Error'); end;

  if FlOk then
    writeln('ALL TESTS OK')
  else
  begin
    writeln('V knihovne USTRING je chyba, zmackni Enter');
    readln;
    Halt(255);
  end;
End.
