Debian Codegraph @

src/services/castletestfairy.pas

raw
1 {
2 Copyright 2020-2023 Michalis Kamburelis.
3
4 This file is part of "Castle Game Engine".
5
6 "Castle Game Engine" is free software; see the file COPYING.txt,
7 included in this distribution, for details about the copyright.
8
9 "Castle Game Engine" is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 ----------------------------------------------------------------------------
14 }
15
16 { Test Fairy integration (TTestFairy). }
17 unit CastleTestFairy;
18
19 {$I castleconf.inc}
20
21 interface
22
23 uses Classes;
24
25 type
26 { TestFairy integration.
27 On Android ( https://github.com/castle-engine/castle-engine/blob/master/tools/build-tool/data/android/integrated-services/test_fairy/README.md )
28 and on iOS ( https://github.com/castle-engine/castle-engine/blob/master/tools/build-tool/data/ios/services/test_fairy/README.md ).
29 }
30 TTestFairy = class(TComponent)
31 strict private
32 class procedure LogCallback(const Message: String);
33 class procedure FinalizeRemoteLogging;
34 public
35 { Send CGE logs to TestFairy.
36 This is onlly necessary on iOS, on Android all the logs are automatically send to TestFairy.
37 It does nothing in case TestFairy service is not used. }
38 class procedure InitializeRemoteLogging;
39 end;
40
41 implementation
42
43 uses SysUtils,
44 CastleApplicationProperties, CastleLog, CastleUtils, CastleTimeUtils;
45
46 class procedure TTestFairy.InitializeRemoteLogging;
47 begin
48 // While it would work on all platforms, it's pointless (not handled) on other than iOS platforms
49 {$ifdef CASTLE_IOS}
50 { In case logging started before TTestFairy.InitializeRemoteLogging was called,
51 push to TestFairy some introductory messages. }
52 {$warnings off} // using deprecated knowingly, it should be renamed
53 if Log then
54 {$warnings on}
55 begin
56 TTestFairy.LogCallback('Log for "' + ApplicationName + '".' + NL);
57 if ApplicationProperties.Version <> '' then
58 TTestFairy.LogCallback(' Version: ' + ApplicationProperties.Version + '.' + NL);
59 TTestFairy.LogCallback(' TestFairy logging started on ' + DateTimeToAtStr(CastleNow) + '.' + NL);
60 TTestFairy.LogCallback(' Castle Game Engine version: ' + CastleEngineVersion + '.' + NL);
61 TTestFairy.LogCallback(' Compiled with ' + SCompilerDescription + '.' + NL);
62 TTestFairy.LogCallback(' Platform: ' + SPlatformDescription + '.' + NL);
63 end;
64
65 if ApplicationProperties.OnLog.IndexOf({$ifdef FPC}@{$endif} LogCallback) = -1 then
66 ApplicationProperties.OnLog.Add({$ifdef FPC}@{$endif} LogCallback);
67 {$endif}
68 end;
69
70 class procedure TTestFairy.FinalizeRemoteLogging;
71 begin
72 ApplicationProperties.OnLog.Remove({$ifdef FPC}@{$endif} LogCallback);
73 end;
74
75 {$ifdef CASTLE_IOS}
76 procedure CGE_TestFairyLog(Message: PChar); cdecl; external;
77 {$endif}
78
79 class procedure TTestFairy.LogCallback(const Message: String);
80 begin
81 {$ifdef CASTLE_IOS}
82 CGE_TestFairyLog(PChar(Message));
83 {$endif}
84 end;
85
86 end.