~ubuntu-branches/ubuntu/saucy/lazarus/saucy

« back to all changes in this revision

Viewing changes to test/lazutils/testlazloggercase.pas

  • Committer: Package Import Robot
  • Author(s): Paul Gevers, Abou Al Montacir, Bart Martens, Paul Gevers
  • Date: 2013-06-08 14:12:17 UTC
  • mfrom: (1.1.9)
  • Revision ID: package-import@ubuntu.com-20130608141217-7k0cy9id8ifcnutc
Tags: 1.0.8+dfsg-1
[ Abou Al Montacir ]
* New upstream major release and multiple maintenace release offering many
  fixes and new features marking a new milestone for the Lazarus development
  and its stability level.
  - The detailed list of changes can be found here:
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_release_notes
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_fixes_branch
* LCL changes:
  - LCL is now a normal package.
      + Platform independent parts of the LCL are now in the package LCLBase
      + LCL is automatically recompiled when switching the target platform,
        unless pre-compiled binaries for this target are already installed.
      + No impact on existing projects.
      + Linker options needed by LCL are no more added to projects that do
        not use the LCL package.
  - Minor changes in LCL basic classes behaviour
      + TCustomForm.Create raises an exception if a form resource is not
        found.
      + TNotebook and TPage: a new implementation of these classes was added.
      + TDBNavigator: It is now possible to have focusable buttons by setting
        Options = [navFocusableButtons] and TabStop = True, useful for
        accessibility and for devices with neither mouse nor touch screen.
      + Names of TControlBorderSpacing.GetSideSpace and GetSpace were swapped
        and are now consistent. GetSideSpace = Around + GetSpace.
      + TForm.WindowState=wsFullscreen was added
      + TCanvas.TextFitInfo was added to calculate how many characters will
        fit into a specified Width. Useful for word-wrapping calculations.
      + TControl.GetColorResolvingParent and
        TControl.GetRGBColorResolvingParent were added, simplifying the work
        to obtain the final color of the control while resolving clDefault
        and the ParentColor.
      + LCLIntf.GetTextExtentExPoint now has a good default implementation
        which works in any platform not providing a specific implementation.
        However, Widgetset specific implementation is better, when available.
      + TTabControl was reorganized. Now it has the correct class hierarchy
        and inherits from TCustomTabControl as it should.
  - New unit in the LCL:
      + lazdialogs.pas: adds non-native versions of various native dialogs,
        for example TLazOpenDialog, TLazSaveDialog, TLazSelectDirectoryDialog.
        It is used by widgetsets which either do not have a native dialog, or
        do not wish to use it because it is limited. These dialogs can also be
        used by user applications directly.
      + lazdeviceapis.pas: offers an interface to more hardware devices such
        as the accelerometer, GPS, etc. See LazDeviceAPIs
      + lazcanvas.pas: provides a TFPImageCanvas descendent implementing
        drawing in a LCL-compatible way, but 100% in Pascal.
      + lazregions.pas. LazRegions is a wholly Pascal implementation of
        regions for canvas clipping, event clipping, finding in which control
        of a region tree one an event should reach, for drawing polygons, etc.
      + customdrawncontrols.pas, customdrawndrawers.pas,
        customdrawn_common.pas, customdrawn_android.pas and
        customdrawn_winxp.pas: are the Lazarus Custom Drawn Controls -controls
        which imitate the standard LCL ones, but with the difference that they
        are non-native and support skinning.
  - New APIs added to the LCL to improve support of accessibility software
    such as screen readers.
* IDE changes:
  - Many improvments.
  - The detailed list of changes can be found here:
    http://wiki.lazarus.freepascal.org/New_IDE_features_since#v1.0_.282012-08-29.29
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_release_notes#IDE_Changes
* Debugger / Editor changes:
  - Added pascal sources and breakpoints to the disassembler
  - Added threads dialog.
* Components changes:
  - TAChart: many fixes and new features
  - CodeTool: support Delphi style generics and new syntax extensions.
  - AggPas: removed to honor free licencing. (Closes: Bug#708695)
[Bart Martens]
* New debian/watch file fixing issues with upstream RC release.
[Abou Al Montacir]
* Avoid changing files in .pc hidden directory, these are used by quilt for
  internal purpose and could lead to surprises during build.
[Paul Gevers]
* Updated get-orig-source target and it compinion script orig-tar.sh so that they
  repack the source file, allowing bug 708695 to be fixed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
unit TestLazLoggerCase;
 
2
 
 
3
{$mode objfpc}{$H+}
 
4
 
 
5
interface
 
6
 
 
7
uses
 
8
  Classes, SysUtils, fpcunit, testutils, testregistry, LazLoggerBase, LazLogger, LazClasses;
 
9
 
 
10
type
 
11
  TStringArray = array of string;
 
12
 
 
13
  { TTestLazLogger }
 
14
 
 
15
  TTestLazLogger = class(TTestCase)
 
16
  protected
 
17
    FTheLogger: TLazLoggerFile;
 
18
    FOnDbgOutCount, FOnDebugLnCount: Integer;
 
19
    FOnDbgOutText, FOnDebugLnText: string;
 
20
    FArgcMem, FArgVSaved: PPChar;
 
21
    FArgCSaved: Integer;
 
22
    FArgs: TStringArray;
 
23
 
 
24
    procedure TestOnDbgOut(Sender: TObject; S: string; var Handled: Boolean);
 
25
    procedure TestOnDebugln(Sender: TObject; S: string; var Handled: Boolean);
 
26
    procedure InitLogger;
 
27
    procedure AssertDbgOut(Name: string; ExpCount: integer; ExpText: String);
 
28
    procedure AssertDebugLn(Name: string; ExpCount: integer; ExpText: String);
 
29
    procedure SaveArgs;
 
30
    procedure RestoreArgs;
 
31
    procedure SetArgv(List: TStringArray);
 
32
    procedure SetArgs(List: array of string);
 
33
  published
 
34
    procedure TestEvent;
 
35
    procedure TestFilter;
 
36
    procedure TestReCreate;
 
37
  end;
 
38
 
 
39
  TLazLoggerForTest = class(TLazLogger)
 
40
  end;
 
41
 
 
42
implementation
 
43
 
 
44
procedure TTestLazLogger.TestOnDbgOut(Sender: TObject; S: string; var Handled: Boolean);
 
45
begin
 
46
  inc(FOnDbgOutCount);
 
47
  FOnDbgOutText := FOnDbgOutText + s;
 
48
  Handled := True;
 
49
end;
 
50
 
 
51
procedure TTestLazLogger.TestOnDebugln(Sender: TObject; S: string; var Handled: Boolean);
 
52
begin
 
53
  inc(FOnDebugLnCount);
 
54
  FOnDebugLnText := FOnDebugLnText + s + LineEnding;
 
55
  Handled := True;
 
56
end;
 
57
 
 
58
procedure TTestLazLogger.InitLogger;
 
59
begin
 
60
  FreeAndNil(FTheLogger);
 
61
  FTheLogger := TLazLoggerFile.Create;
 
62
  FTheLogger.OnDebugLn  := @TestOnDebugln;
 
63
  FTheLogger.OnDbgOut  := @TestOnDbgOut;
 
64
  FOnDebugLnCount := 0;
 
65
  FOnDebugLnText := '';
 
66
end;
 
67
 
 
68
procedure TTestLazLogger.AssertDbgOut(Name: string; ExpCount: integer; ExpText: String);
 
69
begin
 
70
  AssertEquals(Name + ' DbgOut call count', ExpCount, FOnDbgOutCount);
 
71
  AssertEquals(Name + ' DbgOut text', ExpText, FOnDbgOutText);
 
72
  FOnDbgOutCount := 0;
 
73
  FOnDbgOutText := '';
 
74
end;
 
75
 
 
76
procedure TTestLazLogger.AssertDebugLn(Name: string; ExpCount: integer; ExpText: String);
 
77
begin
 
78
  AssertEquals(Name + ' DebugLn call count', ExpCount, FOnDebugLnCount);
 
79
  AssertEquals(Name + ' DebugLn text', ExpText, FOnDebugLnText);
 
80
  FOnDebugLnCount := 0;
 
81
  FOnDebugLnText := '';
 
82
end;
 
83
 
 
84
procedure TTestLazLogger.SaveArgs;
 
85
begin
 
86
  FArgVSaved := argv;
 
87
  FArgCSaved := argc;
 
88
end;
 
89
 
 
90
procedure TTestLazLogger.RestoreArgs;
 
91
begin
 
92
  argv := FArgVSaved;
 
93
  argc := FArgCSaved;
 
94
end;
 
95
 
 
96
procedure TTestLazLogger.SetArgv(List: TStringArray);
 
97
var
 
98
  i: Integer;
 
99
begin
 
100
  if List = nil then begin
 
101
    argc := 0;
 
102
    argv := nil;
 
103
    ReAllocMem(FArgcMem, 0);
 
104
    exit;
 
105
  end;
 
106
  argc := Length(List);
 
107
  ReAllocMem(FArgcMem, argc * SizeOf(PChar));
 
108
  argv := FArgcMem;
 
109
  for i := 0 to argc - 1 do
 
110
    FArgcMem[i] := PChar(List[i]);
 
111
end;
 
112
 
 
113
procedure TTestLazLogger.SetArgs(List: array of string);
 
114
var
 
115
  i: Integer;
 
116
begin
 
117
  if Length(List) = 0 then begin
 
118
    SetArgv(nil);
 
119
    Exit;
 
120
  end;
 
121
  SetLength(FArgs, Length(List));
 
122
  for i := 0 to Length(List) - 1 do
 
123
    FArgs[i] := List[i];
 
124
  SetArgv(FArgs);
 
125
end;
 
126
 
 
127
procedure TTestLazLogger.TestEvent;
 
128
begin
 
129
  InitLogger;
 
130
 
 
131
  FTheLogger.DebugLn('a');
 
132
  AssertDebugLn('debugln a', 1, 'a'+LineEnding);
 
133
  AssertDbgOut('debugln a', 0, '');
 
134
 
 
135
  FTheLogger.DebugLn('b', 'c');
 
136
  AssertDebugLn('debugln b,c', 1, 'bc'+LineEnding);
 
137
  AssertDbgOut('debugln b,c', 0, '');
 
138
 
 
139
  FTheLogger.DebugLn(['d', 1]);
 
140
  AssertDebugLn('debugln d,1', 1, 'd1'+LineEnding);
 
141
  AssertDbgOut('debugln d,1', 0, '');
 
142
 
 
143
  FTheLogger.DebugLn('e %d', [1]);
 
144
  AssertDebugLn('debugln e,1', 1, 'e 1'+LineEnding);
 
145
  AssertDbgOut('debugln e,1', 0, '');
 
146
 
 
147
 
 
148
  FTheLogger.DbgOut('a');
 
149
  AssertDbgOut('DbgOut a', 1, 'a');
 
150
  AssertDebugLn('DbgOut a', 0, '');
 
151
 
 
152
  FTheLogger.DbgOut('b', 'c');
 
153
  AssertDbgOut('DbgOut b,c', 1, 'bc');
 
154
  AssertDebugLn('DbgOut b,c', 0, '');
 
155
 
 
156
  FTheLogger.DbgOut(['d', 1]);
 
157
  AssertDbgOut('DbgOut d,1', 1, 'd1');
 
158
  AssertDebugLn('DbgOut d,1', 0, '');
 
159
 
 
160
  FTheLogger.DbgOut('e %d', [1]);
 
161
  AssertDbgOut('DbgOut e,1', 1, 'e 1');
 
162
  AssertDebugLn('DbgOut e,1', 0, '');
 
163
 
 
164
  FTheLogger.DebugLnEnter('a');
 
165
  AssertDebugLn('DebugLnEnter() a', 1, 'a'+LineEnding);
 
166
  AssertDbgOut('DebugLnEnter() a', 0, '');
 
167
 
 
168
  FTheLogger.DebugLn('in enter');
 
169
  AssertDebugLn('debugln in enter', 1, '  in enter'+LineEnding);
 
170
  AssertDbgOut('debugln in enter', 0, '');
 
171
 
 
172
  FTheLogger.DebugLnExit('b');
 
173
  AssertDebugLn('DebugLnExit() b', 1, 'b'+LineEnding);
 
174
  AssertDbgOut('DebugLnExit() b', 0, '');
 
175
 
 
176
  FTheLogger.DebugLn('after exit');
 
177
  AssertDebugLn('debugln after exit', 1, 'after exit'+LineEnding);
 
178
  AssertDbgOut('debugln after exit', 0, '');
 
179
 
 
180
 
 
181
  FreeAndNil(FTheLogger);
 
182
end;
 
183
 
 
184
procedure TTestLazLogger.TestFilter;
 
185
  procedure FilterInit(List: array of string);
 
186
  begin
 
187
    SetArgs(List);
 
188
    InitLogger;
 
189
    FTheLogger.ParamForEnabledLogGroups := '--dbe=';
 
190
  end;
 
191
 
 
192
  procedure FilterInitNoParam(List: array of string);
 
193
  begin
 
194
    SetArgs(List);
 
195
    InitLogger;
 
196
  end;
 
197
 
 
198
  Procedure TestNoGroup(Name: String);
 
199
  begin
 
200
    FTheLogger.DebugLn('NoGroup'+Name);
 
201
    AssertDebugLn(Name + 'debugln NoGroup'+Name, 1, 'NoGroup'+Name+LineEnding);
 
202
 
 
203
    FTheLogger.DebugLn('NoGroupNil'+Name);
 
204
    AssertDebugLn(Name + 'debugln [nil] NoGroupNil'+Name, 1, 'NoGroupNil'+Name+LineEnding);
 
205
  end;
 
206
 
 
207
  Procedure TestGroup(Name: String; g: PLazLoggerLogGroup; ExpLog: Boolean);
 
208
  begin
 
209
    FTheLogger.DebugLn(g, 'Group'+Name);
 
210
    if ExpLog then
 
211
      AssertDebugLn(Name + 'debugln ['+g^.ConfigName+'] Group'+Name, 1, 'Group'+Name+LineEnding)
 
212
    else
 
213
      AssertDebugLn(Name + 'debugln ['+g^.ConfigName+'] Group'+Name, 0, '');
 
214
 
 
215
    FTheLogger.DebugLn(g, ['Group2',Name]);
 
216
    if ExpLog then
 
217
      AssertDebugLn(Name + 'debugln ['+g^.ConfigName+'] [Group2,'+Name+']', 1, 'Group2'+Name+LineEnding)
 
218
    else
 
219
      AssertDebugLn(Name + 'debugln ['+g^.ConfigName+'] [Group2,'+Name+']', 0, '');
 
220
  end;
 
221
 
 
222
var
 
223
  g1: PLazLoggerLogGroup;
 
224
  s, a: String;
 
225
begin
 
226
  SaveArgs;
 
227
  try
 
228
    {%region g1 not default enabled}
 
229
      s := 'g1(false)';
 
230
      a := '';
 
231
      FilterInit(['exe', '--debug-log=a', a]);
 
232
      g1 := FTheLogger.RegisterLogGroup('g1');
 
233
      TestNoGroup(Format('%s -- %s', [s, a]));
 
234
      TestGroup  (Format('%s -- %s', [s, a]), g1, False);
 
235
      g1^.Enabled := True;
 
236
      TestGroup  (Format('%s -- %s', [s+'->enabled', a]), g1, True);
 
237
 
 
238
      a := '--dbe=';
 
239
      FilterInit(['exe', '--debug-log=a', a]);
 
240
      g1 := FTheLogger.RegisterLogGroup('g1');
 
241
      TestNoGroup(Format('%s -- %s', [s, a]));
 
242
      TestGroup  (Format('%s -- %s', [s, a]), g1, False);
 
243
 
 
244
      a := '--dbe=g1';
 
245
      FilterInit(['exe', '--debug-log=a', a]);
 
246
      g1 := FTheLogger.RegisterLogGroup('g1');
 
247
      TestNoGroup(Format('%s -- %s', [s, a]));
 
248
      TestGroup  (Format('%s -- %s', [s, a]), g1, True);
 
249
      g1^.Enabled := False;
 
250
      TestGroup  (Format('%s -- %s', [s+'->disabled', a]), g1, False);
 
251
 
 
252
      a := '--dbe=+g1';
 
253
      FilterInit(['exe', '--debug-log=a', a]);
 
254
      g1 := FTheLogger.RegisterLogGroup('g1');
 
255
      TestNoGroup(Format('%s -- %s', [s, a]));
 
256
      TestGroup  (Format('%s -- %s', [s, a]), g1, True);
 
257
 
 
258
      a := '--dbe=-g1';
 
259
      FilterInit(['exe', '--debug-log=a', a]);
 
260
      g1 := FTheLogger.RegisterLogGroup('g1');
 
261
      TestNoGroup(Format('%s -- %s', [s, a]));
 
262
      TestGroup  (Format('%s -- %s', [s, a]), g1, False);
 
263
 
 
264
      a := '--dbe=g2';
 
265
      FilterInit(['exe', '--debug-log=a', a]);
 
266
      g1 := FTheLogger.RegisterLogGroup('g1');
 
267
      TestNoGroup(Format('%s -- %s', [s, a]));
 
268
      TestGroup  (Format('%s -- %s', [s, a]), g1, False);
 
269
 
 
270
      a := '--dbe=g2,g1';
 
271
      FilterInit(['exe', '--debug-log=a', a]);
 
272
      g1 := FTheLogger.RegisterLogGroup('g1');
 
273
      TestNoGroup(Format('%s -- %s', [s, a]));
 
274
      TestGroup  (Format('%s -- %s', [s, a]), g1, True);
 
275
 
 
276
      a := '--dbe=g1,g2';
 
277
      FilterInit(['exe', '--debug-log=a', a]);
 
278
      g1 := FTheLogger.RegisterLogGroup('g1');
 
279
      TestNoGroup(Format('%s -- %s', [s, a]));
 
280
      TestGroup  (Format('%s -- %s', [s, a]), g1, True);
 
281
 
 
282
      a := '--dbe=-g2,g1';
 
283
      FilterInit(['exe', '--debug-log=a', a]);
 
284
      g1 := FTheLogger.RegisterLogGroup('g1');
 
285
      TestNoGroup(Format('%s -- %s', [s, a]));
 
286
      TestGroup  (Format('%s -- %s', [s, a]), g1, True);
 
287
 
 
288
      a := '--dbe=-';
 
289
      FilterInit(['exe', '--debug-log=a', a]);
 
290
      g1 := FTheLogger.RegisterLogGroup('g1');
 
291
      TestNoGroup(Format('%s -- %s', [s, a]));
 
292
      TestGroup  (Format('%s -- %s', [s, a]), g1, False);
 
293
 
 
294
      a := '--dbe=- --dbe=+g1';
 
295
      FilterInit(['exe', '--debug-log=a', '--dbe=-', '--dbe=+g1']);
 
296
      g1 := FTheLogger.RegisterLogGroup('g1');
 
297
      TestNoGroup(Format('%s -- %s', [s, a]));
 
298
      TestGroup  (Format('%s -- %s', [s, a]), g1, True);
 
299
    {%endregion g1 not default enabled}
 
300
 
 
301
    {%region g1 default enabled}
 
302
      s := 'g1(true)';
 
303
      a := '';
 
304
      FilterInit(['exe', '--debug-log=a', a]);
 
305
      g1 := FTheLogger.RegisterLogGroup('g1', True);
 
306
      TestNoGroup(Format('%s -- %s', [s, a]));
 
307
      TestGroup  (Format('%s -- %s', [s, a]), g1, True);
 
308
 
 
309
      a := '--dbe=g1';
 
310
      FilterInit(['exe', '--debug-log=a', a]);
 
311
      g1 := FTheLogger.RegisterLogGroup('g1', True);
 
312
      TestNoGroup(Format('%s -- %s', [s, a]));
 
313
      TestGroup  (Format('%s -- %s', [s, a]), g1, True);
 
314
 
 
315
      a := '--dbe=+g1';
 
316
      FilterInit(['exe', '--debug-log=a', a]);
 
317
      g1 := FTheLogger.RegisterLogGroup('g1', True);
 
318
      TestNoGroup(Format('%s -- %s', [s, a]));
 
319
      TestGroup  (Format('%s -- %s', [s, a]), g1, True);
 
320
 
 
321
      a := '--dbe=-g1';
 
322
      FilterInit(['exe', '--debug-log=a', a]);
 
323
      g1 := FTheLogger.RegisterLogGroup('g1', True);
 
324
      TestNoGroup(Format('%s -- %s', [s, a]));
 
325
      TestGroup  (Format('%s -- %s', [s, a]), g1, False);
 
326
 
 
327
      a := '--dbe=-g2';
 
328
      FilterInit(['exe', '--debug-log=a', a]);
 
329
      g1 := FTheLogger.RegisterLogGroup('g1', True);
 
330
      TestNoGroup(Format('%s -- %s', [s, a]));
 
331
      TestGroup  (Format('%s -- %s', [s, a]), g1, True);
 
332
 
 
333
      a := '--dbe=g2,-g1';
 
334
      FilterInit(['exe', '--debug-log=a', a]);
 
335
      g1 := FTheLogger.RegisterLogGroup('g1', True);
 
336
      TestNoGroup(Format('%s -- %s', [s, a]));
 
337
      TestGroup  (Format('%s -- %s', [s, a]), g1, False);
 
338
 
 
339
      a := '--dbe=-';
 
340
      FilterInit(['exe', '--debug-log=a', a]);
 
341
      g1 := FTheLogger.RegisterLogGroup('g1', True);
 
342
      TestNoGroup(Format('%s -- %s', [s, a]));
 
343
      TestGroup  (Format('%s -- %s', [s, a]), g1, False);
 
344
    {%endregion g1 default enabled}
 
345
 
 
346
 
 
347
    {%region g1 not default enabled / param after}
 
348
      s := 'g1(false)';
 
349
      a := '';
 
350
      FilterInitNoParam(['exe', '--debug-log=a', a]);
 
351
      g1 := FTheLogger.RegisterLogGroup('g1');
 
352
      FTheLogger.ParamForEnabledLogGroups := '--dbe=';
 
353
      TestNoGroup(Format('Param late: %s -- %s', [s, a]));
 
354
      TestGroup  (Format('Param late: %s -- %s', [s, a]), g1, False);
 
355
 
 
356
      a := '--dbe=';
 
357
      FilterInitNoParam(['exe', '--debug-log=a', a]);
 
358
      FTheLogger.ParamForEnabledLogGroups := '--dbe=';
 
359
      g1 := FTheLogger.RegisterLogGroup('g1');
 
360
      TestNoGroup(Format('Param late: %s -- %s', [s, a]));
 
361
      TestGroup  (Format('Param late: %s -- %s', [s, a]), g1, False);
 
362
 
 
363
      a := '--dbe=g1';
 
364
      FilterInitNoParam(['exe', '--debug-log=a', a]);
 
365
      FTheLogger.ParamForEnabledLogGroups := '--dbe=';
 
366
      g1 := FTheLogger.RegisterLogGroup('g1');
 
367
      TestNoGroup(Format('Param late: %s -- %s', [s, a]));
 
368
      TestGroup  (Format('Param late: %s -- %s', [s, a]), g1, True);
 
369
 
 
370
      a := '--dbe=+g1';
 
371
      FilterInitNoParam(['exe', '--debug-log=a', a]);
 
372
      g1 := FTheLogger.RegisterLogGroup('g1');
 
373
      FTheLogger.ParamForEnabledLogGroups := '--dbe=';
 
374
      TestNoGroup(Format('Param late: %s -- %s', [s, a]));
 
375
      TestGroup  (Format('Param late: %s -- %s', [s, a]), g1, True);
 
376
 
 
377
      a := '--dbe=-g1';
 
378
      FilterInitNoParam(['exe', '--debug-log=a', a]);
 
379
      g1 := FTheLogger.RegisterLogGroup('g1');
 
380
      FTheLogger.ParamForEnabledLogGroups := '--dbe=';
 
381
      TestNoGroup(Format('Param late: %s -- %s', [s, a]));
 
382
      TestGroup  (Format('Param late: %s -- %s', [s, a]), g1, False);
 
383
 
 
384
      a := '--dbe=g2';
 
385
      FilterInitNoParam(['exe', '--debug-log=a', a]);
 
386
      g1 := FTheLogger.RegisterLogGroup('g1');
 
387
      FTheLogger.ParamForEnabledLogGroups := '--dbe=';
 
388
      TestNoGroup(Format('Param late: %s -- %s', [s, a]));
 
389
      TestGroup  (Format('Param late: %s -- %s', [s, a]), g1, False);
 
390
 
 
391
      a := '--dbe=g2,g1';
 
392
      FilterInitNoParam(['exe', '--debug-log=a', a]);
 
393
      g1 := FTheLogger.RegisterLogGroup('g1');
 
394
      FTheLogger.ParamForEnabledLogGroups := '--dbe=';
 
395
      TestNoGroup(Format('Param late: %s -- %s', [s, a]));
 
396
      TestGroup  (Format('Param late: %s -- %s', [s, a]), g1, True);
 
397
 
 
398
      a := '--dbe=g1,g2';
 
399
      FilterInitNoParam(['exe', '--debug-log=a', a]);
 
400
      g1 := FTheLogger.RegisterLogGroup('g1');
 
401
      FTheLogger.ParamForEnabledLogGroups := '--dbe=';
 
402
      TestNoGroup(Format('Param late: %s -- %s', [s, a]));
 
403
      TestGroup  (Format('Param late: %s -- %s', [s, a]), g1, True);
 
404
 
 
405
      a := '--dbe=-g2,g1';
 
406
      FilterInitNoParam(['exe', '--debug-log=a', a]);
 
407
      g1 := FTheLogger.RegisterLogGroup('g1');
 
408
      FTheLogger.ParamForEnabledLogGroups := '--dbe=';
 
409
      TestNoGroup(Format('Param late: %s -- %s', [s, a]));
 
410
      TestGroup  (Format('Param late: %s -- %s', [s, a]), g1, True);
 
411
 
 
412
      a := '--dbe=-';
 
413
      FilterInitNoParam(['exe', '--debug-log=a', a]);
 
414
      g1 := FTheLogger.RegisterLogGroup('g1');
 
415
      FTheLogger.ParamForEnabledLogGroups := '--dbe=';
 
416
      TestNoGroup(Format('Param late: %s -- %s', [s, a]));
 
417
      TestGroup  (Format('Param late: %s -- %s', [s, a]), g1, False);
 
418
 
 
419
      a := '--dbe=- --dbe=+g1';
 
420
      FilterInitNoParam(['exe', '--debug-log=a', '--dbe=-', '--dbe=+g1']);
 
421
      g1 := FTheLogger.RegisterLogGroup('g1');
 
422
      FTheLogger.ParamForEnabledLogGroups := '--dbe=';
 
423
      TestNoGroup(Format('Param late: %s -- %s', [s, a]));
 
424
      TestGroup  (Format('Param late: %s -- %s', [s, a]), g1, True);
 
425
    {%endregion g1 not default enabled}
 
426
  finally
 
427
    SetArgv(nil);
 
428
    RestoreArgs;
 
429
    FreeAndNil(FTheLogger);
 
430
  end;
 
431
end;
 
432
 
 
433
function CreateDebugLogger: TRefCountedObject;
 
434
begin
 
435
  Result := TLazLoggerForTest.Create;
 
436
  TLazLoggerFile(Result).Assign(GetExistingDebugLogger);
 
437
end;
 
438
 
 
439
procedure TTestLazLogger.TestReCreate;
 
440
begin
 
441
  AssertTrue('DebugLogger is TLazLoggerFile', DebugLogger is TLazLoggerFile);
 
442
 
 
443
  DebugLogger.MaxNestPrefixLen := 122;
 
444
  LazDebugLoggerCreator := @CreateDebugLogger;
 
445
 
 
446
  AssertTrue('still DebugLogger is TLazLoggerFile', DebugLogger is TLazLoggerFile);
 
447
 
 
448
  RecreateDebugLogger;
 
449
  AssertTrue('DebugLogger is TLazLoggerForTest', LazLoggerBase.DebugLogger is TLazLoggerForTest);
 
450
  AssertEquals('MaxNestPrefixLen = 122', 122, TLazLoggerForTest(LazLoggerBase.DebugLogger).MaxNestPrefixLen);
 
451
 
 
452
end;
 
453
 
 
454
 
 
455
initialization
 
456
 
 
457
  RegisterTest(TTestLazLogger);
 
458
end.
 
459