BreakApartTest.pas 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. { $HDR$}
  2. {**********************************************************************}
  3. { Unit archived using Team Coherence }
  4. { Team Coherence is Copyright 2002 by Quality Software Components }
  5. { }
  6. { For further information / comments, visit our WEB site at }
  7. { http://www.TeamCoherence.com }
  8. {**********************************************************************}
  9. {}
  10. { $Log: 11229: BreakApartTest.pas
  11. {
  12. { Rev 1.0 11/12/2002 09:14:50 PM JPMugaas
  13. { Initial check in. Import from FTP VC.
  14. }
  15. unit BreakApartTest;
  16. interface
  17. uses
  18. Classes,
  19. IndyBox;
  20. type
  21. TBreakApartBox = class (TIndyBox)
  22. public
  23. procedure Test; override;
  24. end;
  25. implementation
  26. uses
  27. IdGlobal,
  28. SysUtils;
  29. { TBreakApartBox }
  30. procedure TBreakApartBox.Test;
  31. var
  32. LList : TStringList;
  33. LData : TStringList;
  34. LIndex, LTest, LResults, LCount : Integer;
  35. LStr, LBreak : String;
  36. begin
  37. LData := TStringList.Create;
  38. LList := TStringList.Create;
  39. try
  40. LData.LoadFromFile(GetDataDir + 'BreakApart.dat');
  41. LIndex := 0;
  42. LTest := 0;
  43. while LIndex < LData.Count do
  44. begin
  45. if Length(LData[LIndex]) > 0 then
  46. begin
  47. LStr := LData[LIndex];
  48. if LStr[1] = ':' then
  49. begin
  50. Inc(LIndex);
  51. if LIndex + 2 > LData.Count then
  52. begin
  53. Check(false, 'Insufficient data for test ' + IntToStr(LTest));
  54. end;
  55. Inc(LTest);
  56. Status('---Beginning test ' + IntToStr(LTest));
  57. LStr := LData[LIndex];
  58. LBreak := LData[LIndex + 1];
  59. Status('Data string: ' + LStr);
  60. Status('Break string: ' + LBreak);
  61. LResults := StrToInt(LData[LIndex + 2]);
  62. Status('Results expected: ' + IntToStr(LResults));
  63. Inc(LIndex, 3); // Now indexing the first result
  64. LList.Clear;
  65. BreakApart(LStr, LBreak, TStrings(LList));
  66. for LCount := 0 to LList.Count - 1 do
  67. begin
  68. Status('Output string ' + IntToStr(LCount) + ': ' + LList[LCount]);
  69. end;
  70. Check(LResults = LList.Count, 'Test ' + IntToStr(LTest)
  71. + ' error. Incorrect number of results');
  72. for LCount := 0 to LList.Count - 1 do
  73. begin
  74. Check(LList[LCount] = LData[LIndex + LCount],
  75. 'Test ' + IntToStr(LTest) + ' error. Result '
  76. + IntToStr(LCount + 1) + ' does not match expected result');
  77. end;
  78. Inc(LIndex, LList.Count);
  79. end;
  80. end;
  81. Inc(LIndex);
  82. end;
  83. for LCount := 0 to LList.Count - 1 do
  84. begin
  85. Status(LList[LCount]);
  86. end;
  87. finally
  88. FreeAndNil(LList);
  89. FreeAndNil(LData);
  90. end;
  91. end;
  92. initialization
  93. TIndyBox.RegisterBox(TBreakApartBox, 'BreakApart', 'Misc');
  94. end.