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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
|
unit TestArgV;
{$mode objfpc}{$H+}
interface
uses
SysUtils, fpcunit, testutils, testregistry, TestBase, GDBMIDebugger, LCLProc,
FileUtil, LazUTF8, DbgIntfDebuggerBase, TestDbgControl, TestDbgTestSuites,
TestDbgConfig, TestDbgCompilerProcess, TestWatches;
const
BREAK_LINE_ARGV = 40;
type
{ TTestArgV }
{ TTestArgBase }
TTestArgBase = class(TGDBTestCase)
protected
function TestHex(const s: array of string): String; virtual;
function TestHex64(const w: WideString): String;
function TestSourceName: String; virtual;
function TestBreakLine: integer; virtual;
function StartTest(ConrolVar: Pointer; var dbg: TGDBMIDebugger; NamePostFix: String=''): Boolean;
procedure RunAndCheckVal(dbg: TGDBMIDebugger; AName: String; const AExp: Array of string);
procedure EndTest(dbg: TGDBMIDebugger);
end;
{ TTestArgWideBase }
TTestArgWinWideBase = class(TTestArgBase)
protected
function TestHex(const s: array of string): String; override;
end;
TTestArgV = class(TTestArgWinWideBase)
published
procedure TestArgvBasic;
procedure TestArgvBasicTab;
procedure TestArgvBasicQuote;
procedure TestArgvUtf1;
procedure TestArgvUtf2;
end;
{ TTestExeName }
TTestExeName = class(TTestArgWinWideBase)
published
procedure TestExeNameUtf1;
procedure TestExeNameUtf2;
end;
implementation
var
ControlTestArgV, ControlTestArgVBasic, ControlTestArgVBasicTab, ControlTestArgVBasicQuote,
ControlTestArgVUtf1, ControlTestArgVUtf2: Pointer;
ControlTestExeName: Pointer;
{ TTestArgWideBase }
function TTestArgWinWideBase.TestHex(const s: array of string): String;
var
w: WideString;
i: Integer;
begin
{$IFDEF WINDOWS}
w := '';
for i := 0 to Length(s) - 1 do begin
if w <> '' then w := w + ' ';
w := w + UTF8Decode(s[i]);
end;
Result := TestHex64(w);
exit;
{$ENDIF}
Result := inherited TestHex(s);
end;
{ TTestExeName }
procedure TTestExeName.TestExeNameUtf1;
var
dbg: TGDBMIDebugger;
begin
if not StartTest(ControlTestExeName, dbg, 'äÖ') then
exit;
try
dbg.Arguments := '';
RunAndCheckVal(dbg, 'äÖ', ['äÖ']);
finally
EndTest(dbg);
end;
end;
procedure TTestExeName.TestExeNameUtf2;
var
dbg: TGDBMIDebugger;
begin
if not StartTest(ControlTestExeName, dbg, 'あs') then
exit;
if Debugger.HasFlag('no_exe_u2') then
FIgnoreReason := 'no_exe_u2 flag';
try
dbg.Arguments := '';
RunAndCheckVal(dbg, 'あs', ['あs']);
finally
EndTest(dbg);
end;
end;
{ TTestArgV }
function TTestArgBase.StartTest(ConrolVar: Pointer; var dbg: TGDBMIDebugger;
NamePostFix: String): Boolean;
var
TestExeName, s: String;
begin
Result := False;
if SkipTest then exit;
if not TestControlCanTest(ConrolVar) then exit;
Result := True;
ClearTestErrors;
TestCompile(AppDir + TestSourceName, TestExeName);
if NamePostFix <> '' then begin
s := TestExeName;
TestExeName := UTF8StringReplace(s, 'ArgVPrg', 'ArgVPrg'+NamePostFix, []);
RenameFile(s, TestExeName);
CreatedExecutableList.AddExe(TestExeName, '');
end;
dbg := StartGDB(AppDir, TestExeName);
end;
function TTestArgBase.TestHex(const s: array of string): String;
var
i, j: Integer;
begin
Result := '';
for i := 0 to length(s)-1 do begin
for j := 1 to length(s[i]) do
Result := Result + IntToHex(ord(s[i][j]), 2);
Result := Result + ' ';
end;
delete(Result, Length(Result), 1);
end;
function TTestArgBase.TestHex64(const w: WideString): String;
var
i: Integer;
begin
Result := '';
for i := 1 to Length(w) do
Result := Result + IntToHex(ord(w[i]), 4);
end;
function TTestArgBase.TestSourceName: String;
begin
Result := 'ArgVPrg.pas';
end;
function TTestArgBase.TestBreakLine: integer;
begin
Result := BREAK_LINE_ARGV;
end;
procedure TTestArgBase.RunAndCheckVal(dbg: TGDBMIDebugger; AName: String;
const AExp: array of string);
var
s, s2: string;
t: TDBGType;
begin
dbg.AddTestBreakPoint(TestSourceName, TestBreakLine);
dbg.Run;
if not TestTrue(s+' not in error state', dbg.State <> dsError, 0) then
exit;
if not TestTrue(s+' not in stop state', dbg.State <> dsStop, 0) then
exit;
t := nil;
TestTrue('Can eval', dbg.EvaluateWait('S', s, t, [], 15000));
FreeAndNil(t);
s2 := TestHex(AExp);
TestTrue(AName + '[['+s2+']] in '+s, pos(s2, s) > 0);
end;
procedure TTestArgBase.EndTest(dbg: TGDBMIDebugger);
begin
dbg.Done;
CleanGdb;
dbg.Free;
AssertTestErrors;
end;
procedure TTestArgV.TestArgvBasic;
var
dbg: TGDBMIDebugger;
begin
if not StartTest(ControlTestArgVBasic, dbg) then
exit;
try
dbg.Arguments := 'a b c -d=e1 ab';
{$IFDEF WINDOWS}
RunAndCheckVal(dbg, 'a b c -d=e1 a\b$^!)x', ['a b c -d=e1 ab']);
{$ELSE}
RunAndCheckVal(dbg, 'a b c -d=e1 ab', ['a', 'b', 'c', '-d=e1', 'ab']);
{$ENDIF}
finally
EndTest(dbg);
end;
end;
procedure TTestArgV.TestArgvBasicTab;
var
dbg: TGDBMIDebugger;
begin
if not StartTest(ControlTestArgVBasicTab, dbg) then
exit;
try
dbg.Arguments := 'd=e1 "A'#9'x"';
{$IFDEF WINDOWS}
RunAndCheckVal(dbg, 'd=e1 "A'#9'x"', ['d=e1 "A'#9'x"']);
{$ELSE}
RunAndCheckVal(dbg, 'd=e1"A'#9'x"', ['d=e1', 'A'#9'x']);
{$ENDIF}
finally
EndTest(dbg);
end;
end;
procedure TTestArgV.TestArgvBasicQuote;
var
dbg: TGDBMIDebugger;
begin
if not StartTest(ControlTestArgVBasicQuote, dbg) then
exit;
try
{$IFDEF WINDOWS}
//dbg.Arguments := '"A "" B"';
//RunAndCheckVal(dbg, '', ['A " B']);
{$ENDIF}
{$IFDEF UNIX}
dbg.Arguments := '"A B" ''a b''';
RunAndCheckVal(dbg, '', ['A B', 'a b']);
{$ENDIF}
finally
EndTest(dbg);
end;
end;
procedure TTestArgV.TestArgvUtf1;
var
dbg: TGDBMIDebugger;
begin
if not StartTest(ControlTestArgVUtf1, dbg) then
exit;
try
dbg.Arguments := 'a b c ä ö ';
RunAndCheckVal(dbg, 'a b c ä ö ', ['a', 'b', 'c', 'ä', 'ö']);
finally
EndTest(dbg);
end;
end;
procedure TTestArgV.TestArgvUtf2;
var
dbg: TGDBMIDebugger;
begin
if not StartTest(ControlTestArgVUtf2, dbg) then
exit;
if Debugger.HasFlag('no_arg_u2') then
FIgnoreReason := 'no_arg_u2 flag';
try
dbg.Arguments := 'a b c ä ö 😁 X あsf';
RunAndCheckVal(dbg, 'a b c ä ö 😁 X あsf', ['a', 'b', 'c', 'ä', 'ö', '😁', 'X', 'あsf']);
finally
EndTest(dbg);
end;
end;
initialization
RegisterDbgTest(TTestArgV);
RegisterDbgTest(TTestExeName);
ControlTestArgV := TestControlRegisterTest('TTestArgV');
ControlTestArgVBasic := TestControlRegisterTest('ArgV Basic', ControlTestArgV);
ControlTestArgVBasicTab := TestControlRegisterTest('ArgV Basic Tab', ControlTestArgV);
ControlTestArgVBasicQuote := TestControlRegisterTest('ArgV Basic Quote', ControlTestArgV);
ControlTestArgVUtf1 := TestControlRegisterTest('ArgV Utf1', ControlTestArgV);
ControlTestArgVUtf2 := TestControlRegisterTest('ArgV Utf2', ControlTestArgV);
ControlTestExeName := TestControlRegisterTest('TTestExeName');
end.
|