URIBox2.pas 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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: 22848: URIBox2.pas
  11. {
  12. { Rev 1.0 9/7/2003 05:55:24 AM JPMugaas
  13. { URI2 test restored.
  14. }
  15. {
  16. { Rev 1.0 2003.04.11 10:01:34 PM czhower
  17. }
  18. {
  19. { Rev 1.0 11/12/2002 09:21:38 PM JPMugaas
  20. { Initial check in. Import from FTP VC.
  21. }
  22. unit URIBox2;
  23. interface
  24. uses
  25. IndyBox,
  26. IdURI;
  27. type
  28. TURIBox = class(TIndyBox)
  29. public
  30. procedure Test; override;
  31. end;
  32. implementation
  33. uses
  34. Classes,
  35. SysUtils;
  36. { TURIBox }
  37. procedure TURIBox.Test;
  38. var
  39. URI : TIdURI;
  40. TestData : TStringList;
  41. sindex, testindex : Integer;
  42. str : String;
  43. sin, sout, full, protocol, host, path, document, port, username,
  44. password, bookmark, parameters : String;
  45. begin
  46. URI := TIdURI.Create;
  47. TestData := TStringList.Create;
  48. try
  49. TestData.LoadFromFile(GetDataDir + 'uri.dat');
  50. testindex := 0;
  51. sindex := 0;
  52. while sindex < TestData.Count do
  53. begin
  54. str := TestData[sindex];
  55. if Length(str) > 0 then
  56. begin
  57. if str[1] = ':' then
  58. begin
  59. // Begin by resetting the component
  60. URI.URI := '';
  61. Inc(testindex);
  62. if TestData.Count < sindex + 12 then
  63. begin
  64. raise Exception.Create('Insufficient data in uri.dat file for test '
  65. + IntToStr(testindex));
  66. end else
  67. begin
  68. sin := TestData[sindex + 1];
  69. sout := TestData[sindex + 2];
  70. full := TestData[sindex + 3];
  71. protocol := TestData[sindex + 4];
  72. host := TestData[sindex + 5];
  73. path := TestData[sindex + 6];
  74. document := TestData[sindex + 7];
  75. port := TestData[sindex + 8];
  76. username := TestData[sindex + 9];
  77. password := TestData[sindex + 10];
  78. parameters := TestData[sindex + 11];
  79. bookmark := TestData[sindex + 12];
  80. Inc(sindex, 12);
  81. if sin = 'Components' then
  82. begin
  83. URI.URI := '';
  84. URI.Protocol := protocol;
  85. URI.Host := Host;
  86. URI.Path := Path;
  87. URI.Document := Document;
  88. URI.Port := Port;
  89. URI.Username := Username;
  90. URI.Password := Password;
  91. URI.Params := Parameters;
  92. URI.Bookmark := Bookmark;
  93. end else
  94. begin
  95. URI.URI := sin;
  96. end;
  97. Status('Checking URI of test ' + IntToStr(testindex));
  98. Status('URI in: ' + sin);
  99. Status('URI expected: ' + sout + ', got: ' + URI.URI);
  100. Check(URI.URI = sout, 'Test ' + IntToStr(testindex)
  101. + ' failed on URI.');
  102. Status('Full URI expected: ' + full + ', got: ' + URI.GetFullURI);
  103. Check(URI.GetFullURI = full, 'Test ' + IntToStr(testindex)
  104. + ' failed on full URI.');
  105. Status('Protocol expected: ' + protocol + ', got: ' + URI.Protocol);
  106. Check(URI.Protocol = protocol, 'Test ' + IntToStr(testindex)
  107. + ' failed on protocol.');
  108. Status('Host expected: ' + host + ', got: ' + URI.Host);
  109. Check(URI.Host = host, 'Test ' + IntToStr(testindex)
  110. + ' failed on host.');
  111. Status('Path expected: ' + path + ', got: ' + URI.Path);
  112. Check(URI.Path = Path, 'Test ' + IntToStr(testindex)
  113. + ' failed on path.');
  114. Status('Document expected: ' + document + ', got: ' + URI.Document);
  115. Check(URI.Document = Document, 'Test ' + IntToStr(testindex)
  116. + ' failed on document.');
  117. Status('Port expected: ' + port + ', got: ' + URI.Port);
  118. Check(URI.Port = Port, 'Test ' + IntToStr(testindex)
  119. + ' failed on port.');
  120. Status('Username expected: ' + username + ', got: ' + URI.Username);
  121. Check(URI.Username = Username, 'Test ' + IntToStr(testindex)
  122. + ' failed on username.');
  123. Status('Password expected: ' + password + ', got: ' + URI.Password);
  124. Check(URI.Password = password, 'Test ' + IntToStr(testindex)
  125. + ' failed on password.');
  126. Status('Parameters expected: ' + parameters + ', got: ' + URI.Params);
  127. Check(URI.Params = Parameters, 'Test ' + IntToStr(testindex)
  128. + ' failed on parameters.');
  129. Status('Bookmark expected: ' + bookmark + ', got: ' + URI.Bookmark);
  130. Check(URI.Bookmark = Bookmark, 'Test ' + IntToStr(testindex)
  131. + ' failed on bookmark.');
  132. end;
  133. end;
  134. end;
  135. Inc(sindex);
  136. end;
  137. finally
  138. FreeAndNil(URI);
  139. FreeAndNil(TestData);
  140. end;
  141. end;
  142. initialization
  143. TIndyBox.RegisterBox(TURIBox, 'URI', 'Misc');
  144. end.