-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+ documentation + unit tests
- Loading branch information
Showing
14 changed files
with
1,162 additions
and
272 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
unit TestuWebScraper; | ||
{ | ||
Delphi DUnit Test Case | ||
---------------------- | ||
This unit contains a skeleton test case class generated by the Test Case Wizard. | ||
Modify the generated code to correctly setup and call the methods from the unit | ||
being tested. | ||
} | ||
|
||
interface | ||
|
||
uses | ||
TestFramework, System.Variants, IdSSLOpenSSL, uWebScraper, System.Threading, | ||
Generics.Collections, IdHTTP, IdIOHandlerStack, System.SysUtils, IdTCPConnection, | ||
System.Generics.Defaults, IdTCPClient, System.UITypes, System.Classes, | ||
IdIOHandlerSocket, IdComponent, System.Types, IdBaseComponent, IdSSL, IdIOHandler, | ||
System.Math, System.NetEncoding, System.RegularExpressions; | ||
|
||
type | ||
// Test methods for class TWebScraper | ||
|
||
TestTWebScraper = class(TTestCase) | ||
strict private | ||
FWebScraper: TWebScraper; | ||
public | ||
procedure SetUp; override; | ||
procedure TearDown; override; | ||
published | ||
procedure TestGetTitlesFromURLs; | ||
end; | ||
|
||
const | ||
URLsToTest: TArray<string> = [ | ||
'http://stackoverflow.com/', // HTTP with EN title | ||
'http://habrahabr.ru/interesting/', // HTTP with RU title | ||
'http://www.yandex.ru/', // HTTP with RU title | ||
|
||
'https://encrypted.google.com/', // HTTPS with EN title | ||
'https://www.youtube.com/', // HTTPS with EN title | ||
'https://www.python.org/', // HTTPS with EN title | ||
'https://vk.com/', // HTTPS with RU title | ||
|
||
'http://☃.net/', // punycode domain | ||
'http://㯙㯜㯙㯟.net/', // punycode domain | ||
'http://💩.la', // punycode domain | ||
|
||
'http://википедия.орг.рф/', // international domain | ||
'http://кто.рф/', // international domain | ||
|
||
'http://vk.com/', // HTTP -> HTTPS redirect | ||
'http://гугл.рф/', // HTTP -> HTTPS redirect | ||
|
||
'http://www.mindlis.ru/', // timeout | ||
'http://СИБИРСКИЙ-ФЕДЕРАЛЬНЫЙ-ОКРУГ.РФ', // timeout | ||
'https://naydenov.tk/', // error: no HTTPS | ||
'http://youtu.be/404.', // 404 | ||
'http://stackoverflow.com/404' // 404 | ||
]; | ||
|
||
implementation | ||
|
||
procedure TestTWebScraper.SetUp; | ||
begin | ||
FWebScraper := TWebScraper.Create; | ||
end; | ||
|
||
procedure TestTWebScraper.TearDown; | ||
begin | ||
FWebScraper.Free; | ||
FWebScraper := nil; | ||
end; | ||
|
||
procedure TestTWebScraper.TestGetTitlesFromURLs; | ||
var | ||
URLStrings: TStringList; | ||
ResultStrings: TStringList; | ||
s: string; | ||
begin | ||
URLStrings := TStringList.Create; | ||
for s in URLsToTest do | ||
URLStrings.Add(s); | ||
try | ||
ResultStrings := TStringList.Create; | ||
try | ||
FWebScraper.GetTitlesFromURLs(URLStrings, ResultStrings); | ||
// Validate method results | ||
(URLStrings.Count = ResultStrings.Count); | ||
finally | ||
FreeAndNil(ResultStrings); | ||
end; | ||
finally | ||
FreeAndNil(URLStrings); | ||
end; | ||
end; | ||
|
||
initialization | ||
|
||
// Register any test cases with the test runner | ||
RegisterTest(TestTWebScraper.Suite); | ||
|
||
end. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
program URL2TitleTests; | ||
{ | ||
Delphi DUnit Test Project | ||
------------------------- | ||
This project contains the DUnit test framework and the GUI/Console test runners. | ||
Add "CONSOLE_TESTRUNNER" to the conditional defines entry in the project options | ||
to use the console test runner. Otherwise the GUI test runner will be used by | ||
default. | ||
} | ||
|
||
{$IFDEF CONSOLE_TESTRUNNER} | ||
{$APPTYPE CONSOLE} | ||
{$ENDIF} | ||
|
||
uses | ||
TestuWebScraper in 'TestuWebScraper.pas', | ||
uWebScraper in '..\uWebScraper.pas', | ||
uUserAgent in '..\uUserAgent.pas', | ||
DUnitTestRunner; | ||
|
||
{$R *.RES} | ||
|
||
begin | ||
ReportMemoryLeaksOnShutdown := true; | ||
DUnitTestRunner.RunRegisteredTests; | ||
|
||
end. |
Oops, something went wrong.