EMailAddress.pas 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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: 11241: EMailAddress.pas
  11. {
  12. { Rev 1.0 11/12/2002 09:15:50 PM JPMugaas
  13. { Initial check in. Import from FTP VC.
  14. }
  15. unit EMailAddress;
  16. interface
  17. {
  18. 2001-Feb-03 - Peter Mee
  19. - Added support for e-mail address creation.
  20. 2001-Jan-28 - Peter Mee
  21. - Created to support e-mail address extraction.
  22. }
  23. uses
  24. IndyBox;
  25. type
  26. TEMailAddressBox = class(TIndyBox)
  27. public
  28. procedure Test; override;
  29. end;
  30. implementation
  31. uses
  32. Classes,
  33. IdEMailAddress,
  34. SysUtils;
  35. procedure TEMailAddressBox.Test;
  36. var
  37. TestAddresses : TStringList;
  38. i, j, count : Integer;
  39. EA : TIdEMailAddressList;
  40. begin
  41. TestAddresses := TStringList.Create;
  42. EA := TIdEMailAddressList.Create(Nil);
  43. try
  44. TestAddresses.LoadFromFile(GetDataDir + 'EMailAddress.dat');
  45. count := 0;
  46. i := 1;
  47. while count < TestAddresses.Count do
  48. begin
  49. // Locate the next line in TestResults containing ':' only.
  50. while count < TestAddresses.Count do
  51. begin
  52. if Length(TestAddresses[count]) > 0 then
  53. begin
  54. if TestAddresses[count][1] = ':' then
  55. begin
  56. break;
  57. end;
  58. end;
  59. Inc(Count);
  60. end;
  61. if count >= TestAddresses.Count then
  62. begin
  63. break;
  64. end;
  65. // The next line is the test line
  66. Inc(Count);
  67. EA.EMailAddresses := TestAddresses[count];
  68. Inc(count);
  69. Check(StrToInt(TestAddresses[count]) = EA.Count,
  70. 'Test ' + IntToStr(i)
  71. + ', incorrect number of output addresses: '
  72. + TestAddresses[count] + 'expected, '
  73. + IntToStr(EA.Count) + ' found' );
  74. // Now compare the list of addresses against those in the results file
  75. // Each address spans two lines in the results file - the address and
  76. // the name in that order.
  77. Inc(count);
  78. for j := 0 to EA.Count - 1 do
  79. begin
  80. Check( (EA.Items[j].Address = TestAddresses[count]),
  81. 'Extract Test ' + IntToStr(i)
  82. + '. Address ' + IntToStr(j) + ' (' + TestAddresses[count]
  83. + ') failed: ' + EA.Items[j].Address);
  84. Check( (EA.Items[j].Name = TestAddresses[count + 1]),
  85. 'Test ' + IntToStr(i)
  86. + '. Name ' + IntToStr(j) + ' (' + TestAddresses[count + 1]
  87. + ') failed: ' + EA.Items[j].Name);
  88. Inc(count, 2);
  89. end;
  90. // Now put the address(es) back into arpa format.
  91. for j := 0 to EA.Count - 1 do
  92. begin
  93. Check(EA.Items[j].Text = TestAddresses[count],
  94. 'Revert Test ' + IntToStr(i)
  95. + ' Address ' + IntToStr(j) + ' (' + TestAddresses[count]
  96. + ') failed: ' + EA.Items[j].Text);
  97. Inc(count);
  98. end;
  99. Inc(i);
  100. end;
  101. finally
  102. EA.Free;
  103. TestAddresses.Free;
  104. end;
  105. end;
  106. initialization
  107. TIndyBox.RegisterBox(TEMailAddressBox, 'EMailAddress', 'Misc');
  108. end.