URIBox.pas 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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: 17981: URIBox.pas
  11. {
  12. { Rev 1.7 2003.07.11 4:07:46 PM czhower
  13. { Removed deprecated BXBoxster reference.
  14. }
  15. {
  16. { Rev 1.6 6/24/2003 01:13:38 PM JPMugaas
  17. { Updates for minor API change.
  18. }
  19. {
  20. { Rev 1.5 2003.04.13 9:36:14 PM czhower
  21. }
  22. {
  23. Rev 1.4 4/12/2003 12:14:38 PM BGooijen
  24. Did not compile on D4 and D5
  25. }
  26. {
  27. { Rev 1.3 2003.04.11 11:11:00 PM czhower
  28. }
  29. {
  30. { Rev 1.2 2003.04.11 11:01:52 PM czhower
  31. }
  32. {
  33. { Rev 1.1 2003.04.11 10:12:14 PM czhower
  34. }
  35. unit URIBox;
  36. interface
  37. {$I IdCompilerDefines.inc}
  38. uses
  39. SysUtils, Classes, BXBubble, Forms;
  40. type
  41. TdmodURI = class(TDataModule)
  42. URI: TBXBubble;
  43. procedure URITest(Sender: TBXBubble);
  44. private
  45. public
  46. end;
  47. var
  48. dmodURI: TdmodURI;
  49. implementation
  50. {$R *.dfm}
  51. uses
  52. IdURI;
  53. procedure TdmodURI.URITest(Sender: TBXBubble);
  54. var
  55. LURI : TIdURI;
  56. TestData : TStringList;
  57. sindex, testindex : Integer;
  58. str : String;
  59. sin, sout, full, protocol, host, path, document, port, username,
  60. password, bookmark, parameters : String;
  61. begin
  62. with URI do begin
  63. LURI := TIdURI.Create; try
  64. TestData := TStringList.Create; try
  65. TestData.LoadFromFile(DataDir + 'URI.dat');
  66. testindex := 0;
  67. sindex := 0;
  68. while sindex < TestData.Count do begin
  69. str := TestData[sindex];
  70. if str <> '' then begin
  71. if str[1] = ':' then begin
  72. // Begin by resetting the component
  73. LURI.URI := '';
  74. Inc(testindex);
  75. if TestData.Count < sindex + 12 then begin
  76. raise Exception.Create('Insufficient data in LURI.dat file for test '
  77. + IntToStr(testindex));
  78. end else begin
  79. sin := TestData[sindex + 1];
  80. sout := TestData[sindex + 2];
  81. full := TestData[sindex + 3];
  82. protocol := TestData[sindex + 4];
  83. host := TestData[sindex + 5];
  84. path := TestData[sindex + 6];
  85. document := TestData[sindex + 7];
  86. port := TestData[sindex + 8];
  87. username := TestData[sindex + 9];
  88. password := TestData[sindex + 10];
  89. parameters := TestData[sindex + 11];
  90. bookmark := TestData[sindex + 12];
  91. Inc(sindex, 12);
  92. if sin = 'Components' then begin
  93. LURI.URI := '';
  94. LURI.Protocol := protocol;
  95. LURI.Host := Host;
  96. LURI.Path := Path;
  97. LURI.Document := Document;
  98. LURI.Port := Port;
  99. LURI.Username := Username;
  100. LURI.Password := Password;
  101. LURI.Params := Parameters;
  102. LURI.Bookmark := Bookmark;
  103. end else begin
  104. LURI.URI := sin;
  105. end;
  106. Status('Checking URI of test ' + IntToStr(testindex));
  107. Status('URI in: ' + sin);
  108. Status('URI expected: ' + sout + ', got: ' + LURI.URI);
  109. Check(LURI.URI = sout, 'Test ' + IntToStr(testindex)
  110. + ' failed on LURI.');
  111. Status('Full URI expected: ' + full + ', got: ' + LURI.GetFullURI);
  112. Check(LURI.GetFullURI = full, 'Test ' + IntToStr(testindex)
  113. + ' failed on full LURI.');
  114. Status('Protocol expected: ' + protocol + ', got: ' + LURI.Protocol);
  115. Check(LURI.Protocol = protocol, 'Test ' + IntToStr(testindex)
  116. + ' failed on protocol.');
  117. Status('Host expected: ' + host + ', got: ' + LURI.Host);
  118. Check(LURI.Host = host, 'Test ' + IntToStr(testindex)
  119. + ' failed on host.');
  120. Status('Path expected: ' + path + ', got: ' + LURI.Path);
  121. Check(LURI.Path = Path, 'Test ' + IntToStr(testindex)
  122. + ' failed on path.');
  123. Status('Document expected: ' + document + ', got: ' + LURI.Document);
  124. Check(LURI.Document = Document, 'Test ' + IntToStr(testindex)
  125. + ' failed on document.');
  126. Status('Port expected: ' + port + ', got: ' + LURI.Port);
  127. Check(LURI.Port = Port, 'Test ' + IntToStr(testindex)
  128. + ' failed on port.');
  129. Status('Username expected: ' + username + ', got: ' + LURI.Username);
  130. Check(LURI.Username = Username, 'Test ' + IntToStr(testindex)
  131. + ' failed on username.');
  132. Status('Password expected: ' + password + ', got: ' + LURI.Password);
  133. Check(LURI.Password = password, 'Test ' + IntToStr(testindex)
  134. + ' failed on password.');
  135. Status('Parameters expected: ' + parameters + ', got: ' + LURI.Params);
  136. Check(LURI.Params = Parameters, 'Test ' + IntToStr(testindex)
  137. + ' failed on parameters.');
  138. Status('Bookmark expected: ' + bookmark + ', got: ' + LURI.Bookmark);
  139. Check(LURI.Bookmark = Bookmark, 'Test ' + IntToStr(testindex)
  140. + ' failed on bookmark.');
  141. end;
  142. end;
  143. end;
  144. Inc(sindex);
  145. end;
  146. finally FreeAndNil(TestData); end;
  147. finally FreeAndNil(LURI); end;
  148. end;
  149. end;
  150. end.