Skip to content

Commit

Permalink
* fixed: multiline exceptions
Browse files Browse the repository at this point in the history
+ documentation
+ unit tests
  • Loading branch information
magicxor committed Apr 9, 2015
1 parent 6abb022 commit 201d052
Show file tree
Hide file tree
Showing 14 changed files with 1,162 additions and 272 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Get list of page titles from list of URLs

### Compilation guide

In order to compile this sources on Windows, you need to install the Embarcadero RAD Studio XE7 Update 1 environment.
In order to compile this sources on Windows, you need to install the Embarcadero RAD Studio XE8 environment.

### Known bugs

Expand Down
103 changes: 103 additions & 0 deletions Test/TestuWebScraper.pas
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.
29 changes: 29 additions & 0 deletions Test/URL2TitleTests.dpr
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.
Loading

0 comments on commit 201d052

Please sign in to comment.