summaryrefslogtreecommitdiff
path: root/tests/webtbs/tw6491.pp
blob: b6c888c4f1a9183bc8e9387382535e4874dda755 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
program TestExtractDrive;

{$IFDEF FPC}
  {$mode objfpc}{$H+}
{$ELSE}
  {$APPTYPE CONSOLE}
{$ENDIF}

uses
  SysUtils;

var
  err : boolean;

function tiRemoveDrive(pStrPath : string) : string;
var
  sDrive : string;
begin
  sDrive := extractFileDrive(pStrPath);
  if sDrive <> '' then begin
    result := copy(pStrPath, length(sDrive)+1, length(pStrPath) - length(sDrive));
  end else begin
    result := pStrPath;
  end;
end;


procedure CheckEquals(expected, actual, msg: string);
const
  c = '%s: Expected <%s> but found <%s>';
begin
  if expected <> actual then
    begin
      Writeln(Format(c, [msg, expected, actual]));
      err:=true;
    end
  else
    Writeln('...test passed.');
end;


begin
{$if not(defined(Windows) or defined(go32v2) or defined(os2) or defined(emx))}
  AllowDirectorySeparators:=['\'];
  AllowDriveSeparators:=[':'];
{$endif}
  Writeln('Start tests...');
  { What I use in my application }
  CheckEquals('', tiRemoveDrive('c:'), 'Failed on 1');
  CheckEquals('\temp', tiRemoveDrive('c:\temp'), 'Failed on 2');
  CheckEquals('\temp\hos.txt', tiRemoveDrive('c:\temp\hos.txt'), 'Failed on 3');
  CheckEquals('\Program Files\My Program\run.bat', tiRemoveDrive('c:\Program Files\My Program\run.bat'), 'Failed on 4');
  { To put the previous four test in a different way, calling ExtractFileDrive directly. }
  CheckEquals('c:', ExtractFileDrive('c:'), 'Failed on 5');
  CheckEquals('c:', ExtractFileDrive('c:\temp'), 'Failed on 6');
  CheckEquals('c:', ExtractFileDrive('c:\temp\hos.txt'), 'Failed on 6');
  CheckEquals('c:', ExtractFileDrive('c:\Program Files\My Program\run.bat'), 'Failed on 7');
  Writeln('Done.');
  if err then
    halt(1);
end.