Merge pull request #8 from sikofitt/add-tests

Add tests
This commit is contained in:
Eric 2017-02-26 17:34:19 -08:00 committed by GitHub
commit 6e1067f030
13 changed files with 727 additions and 3 deletions

View File

@ -46,6 +46,7 @@ interface
uses uses
Classes, Classes,
SysUtils,
Logger.HandlerInterface; Logger.HandlerInterface;
const const
@ -96,6 +97,7 @@ type
published published
property UnixFacility: longint read FUnixFacility write SetFacility; property UnixFacility: longint read FUnixFacility write SetFacility;
end; end;
EPlatformNotSupported = class(Exception) end;
procedure closelog; cdecl; external; procedure closelog; cdecl; external;
procedure openlog(__ident: PChar; __option: longint; __facilit: longint); procedure openlog(__ident: PChar; __option: longint; __facilit: longint);
@ -107,11 +109,21 @@ implementation
constructor SysLogHandler.Create(const LoggingFacility: longint); constructor SysLogHandler.Create(const LoggingFacility: longint);
begin begin
{$IFDEF WIN}
Raise EPlatformNotSupported.Create ('SysLogHandler is not supported under Windows.') at
get_caller_addr(get_frame),
get_caller_frame(get_frame);
{$ENDIF WIN}
FUnixFacility := LoggingFacility; FUnixFacility := LoggingFacility;
end; end;
procedure SysLogHandler.SetFacility(const UnixFacility: longint); procedure SysLogHandler.SetFacility(const UnixFacility: longint);
begin begin
{$IFDEF WIN}
Raise EPlatformNotSupported.Create ('SysLogHandler is not supported under Windows.') at
get_caller_addr(get_frame),
get_caller_frame(get_frame);
{$ENDIF WIN}
FUnixFacility := UnixFacility; FUnixFacility := UnixFacility;
end; end;

View File

@ -0,0 +1,82 @@
{*******************************************************}
{ Renegade BBS }
{ Copyright (c) 1990-2013 The Renegade Dev Team }
{ Copyleft (ↄ) 2016-2017 Renegade BBS }
{ This file is part of Renegade BBS }
{ Renegade is free software: you can redistribute it }
{ and/or modify it under the terms of the GNU General }
{ Public License as published by the Free Software }
{ Foundation, either version 3 of the License, or }
{ (at your option) any later version. }
{ Renegade is distributed in the hope that it will be }
{ useful, but WITHOUT ANY WARRANTY; without even the }
{ implied warranty of MERCHANTABILITY or FITNESS FOR }
{ A PARTICULAR PURPOSE. See the GNU General Public }
{ License for more details. }
{ You should have received a copy of the GNU General }
{ Public License along with Renegade. If not, see }
{ <http://www.gnu.org/licenses/>. }
{*******************************************************}
{ _______ __ }
{ | _ .-----.-----.-----.-----.---.-.--| .-----. }
{ |. l | -__| | -__| _ | _ | _ | -__| }
{ |. _ |_____|__|__|_____|___ |___._|_____|_____| }
{ |: | | |_____| }
{ |::.|:. | }
{ `--- ---' }
{*******************************************************}
{$mode objfpc}
{$codepage utf8}
{$h+}
{ namespace Renegade.Logger }
{ Program to test the Logger.ConsoleHandler class }
Program ConsoleHandlerTest;
Uses
Classes,
SysUtils,
Renegade.Logger,
Logger.ConsoleHandler,
Logger.LoggerInterface;
const
Message = 'This is a log message';
CurrentClass = 'ConsoleHandler';
var
Handler : ConsoleHandler;
Logger : RTLogger;
Context : array [1..4] of ansistring = (CurrentClass, 'True', 'Testing', 'True');
begin
Handler := ConsoleHandler.Create;
Logger := RTLogger.Create(Handler);
Logger.Emergency(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Alert(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Critical(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Error(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Warning(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Notice(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Info(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Debug(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_EMERG, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_ALERT, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_CRIT, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_ERR, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_WARNING, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_NOTICE, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_INFO, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_DEBUG, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.LOG(LOG_UNKNOWN, Message, [Context[1], Context[2], Context[3], Context[4]]);
//RenameFile('renegade.log', CurrentClass + 'StreamTest.log');
end.

82
tests/FileHandlerTest.pp Normal file
View File

@ -0,0 +1,82 @@
{*******************************************************}
{ Renegade BBS }
{ Copyright (c) 1990-2013 The Renegade Dev Team }
{ Copyleft (ↄ) 2016-2017 Renegade BBS }
{ This file is part of Renegade BBS }
{ Renegade is free software: you can redistribute it }
{ and/or modify it under the terms of the GNU General }
{ Public License as published by the Free Software }
{ Foundation, either version 3 of the License, or }
{ (at your option) any later version. }
{ Renegade is distributed in the hope that it will be }
{ useful, but WITHOUT ANY WARRANTY; without even the }
{ implied warranty of MERCHANTABILITY or FITNESS FOR }
{ A PARTICULAR PURPOSE. See the GNU General Public }
{ License for more details. }
{ You should have received a copy of the GNU General }
{ Public License along with Renegade. If not, see }
{ <http://www.gnu.org/licenses/>. }
{*******************************************************}
{ _______ __ }
{ | _ .-----.-----.-----.-----.---.-.--| .-----. }
{ |. l | -__| | -__| _ | _ | _ | -__| }
{ |. _ |_____|__|__|_____|___ |___._|_____|_____| }
{ |: | | |_____| }
{ |::.|:. | }
{ `--- ---' }
{*******************************************************}
{$mode objfpc}
{$codepage utf8}
{$h+}
{ namespace Renegade.Logger }
{ Program to test the Logger.FileHandler class }
Program FileHandlerTest;
Uses
Classes,
SysUtils,
Renegade.Logger,
Logger.FileHandler,
Logger.LoggerInterface;
const
Message = 'This is a log message';
CurrentClass = 'FileHandler';
var
Handler : FileHandler;
Logger : RTLogger;
Context : array [1..4] of ansistring = (CurrentClass, 'True', 'Testing', 'True');
begin
Handler := FileHandler.Create('renegade.log');
Logger := RTLogger.Create(Handler);
Logger.Emergency(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Alert(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Critical(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Error(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Warning(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Notice(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Info(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Debug(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_EMERG, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_ALERT, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_CRIT, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_ERR, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_WARNING, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_NOTICE, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_INFO, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_DEBUG, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.LOG(LOG_UNKNOWN, Message, [Context[1], Context[2], Context[3], Context[4]]);
RenameFile('renegade.log', CurrentClass + 'Test.log');
end.

23
tests/Makefile.fpc Normal file
View File

@ -0,0 +1,23 @@
#
# Makefile.fpc for hash units example
#
[target]
programs=NullHandlerTest ConsoleHandlerTest FileHandlerTest RecordHandlerReadTest RecordHandlerTest StreamHandlerFileTest StreamHandlerStreamTest StreamHandlerStreamTStreamTest SysLogHandlerTest
[require]
packages=
[install]
fpcpackage=y
[compiler]
options=-Fu..
[default]
fpcdir=${FPCDIR}

81
tests/NullHandlerTest.pp Normal file
View File

@ -0,0 +1,81 @@
{*******************************************************}
{ Renegade BBS }
{ Copyright (c) 1990-2013 The Renegade Dev Team }
{ Copyleft (ↄ) 2016-2017 Renegade BBS }
{ This file is part of Renegade BBS }
{ Renegade is free software: you can redistribute it }
{ and/or modify it under the terms of the GNU General }
{ Public License as published by the Free Software }
{ Foundation, either version 3 of the License, or }
{ (at your option) any later version. }
{ Renegade is distributed in the hope that it will be }
{ useful, but WITHOUT ANY WARRANTY; without even the }
{ implied warranty of MERCHANTABILITY or FITNESS FOR }
{ A PARTICULAR PURPOSE. See the GNU General Public }
{ License for more details. }
{ You should have received a copy of the GNU General }
{ Public License along with Renegade. If not, see }
{ <http://www.gnu.org/licenses/>. }
{*******************************************************}
{ _______ __ }
{ | _ .-----.-----.-----.-----.---.-.--| .-----. }
{ |. l | -__| | -__| _ | _ | _ | -__| }
{ |. _ |_____|__|__|_____|___ |___._|_____|_____| }
{ |: | | |_____| }
{ |::.|:. | }
{ `--- ---' }
{*******************************************************}
{$mode objfpc}
{$codepage utf8}
{$h+}
{ namespace Renegade.Logger }
{ Program to test the Logger.NullHandler class }
Program NullHandlerTest;
Uses
Classes,
SysUtils,
Renegade.Logger,
Logger.NullHandler,
Logger.LoggerInterface;
const
Message = 'This is a log message';
CurrentClass = 'NullHandler';
var
Handler : NullHandler;
Logger : RTLogger;
Context : array [1..4] of ansistring = (CurrentClass, 'True', 'Testing', 'True');
begin
Handler := NullHandler.Create;
Logger := RTLogger.Create(Handler);
Logger.Emergency(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Alert(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Critical(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Error(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Warning(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Notice(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Info(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Debug(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_EMERG, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_ALERT, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_CRIT, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_ERR, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_WARNING, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_NOTICE, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_INFO, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_DEBUG, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.LOG(LOG_UNKNOWN, Message, [Context[1], Context[2], Context[3], Context[4]]);
//RenameFile('renegade.log', CurrentClass + 'Test.log');
end.

View File

@ -41,12 +41,14 @@
Program to read data we wrote to renegade.log Program to read data we wrote to renegade.log
using Logger.RecordHandler. using Logger.RecordHandler.
} }
program LoggerRecordRead; program RecordHandlerReadTest;
uses uses
SysUtils, SysUtils,
Classes; Classes;
const
LogFile = 'RecordHandlerTest.log';
type type
TLogRecord = record TLogRecord = record
Level: byte; Level: byte;
@ -57,14 +59,15 @@ type
Context: string[255]; Context: string[255];
LogDateTime: TDateTime; LogDateTime: TDateTime;
end; end;
var var
LogRecord: TLogRecord; LogRecord: TLogRecord;
FileRecord: file of TLogRecord; FileRecord: file of TLogRecord;
i: byte; i: byte;
begin begin
if FileExists('renegade.log') then if FileExists(LogFile) then
begin begin
AssignFile(FileRecord, 'renegade.log'); AssignFile(FileRecord, LogFile);
Reset(FileRecord); Reset(FileRecord);

View File

@ -0,0 +1,81 @@
{*******************************************************}
{ Renegade BBS }
{ Copyright (c) 1990-2013 The Renegade Dev Team }
{ Copyleft (ↄ) 2016-2017 Renegade BBS }
{ This file is part of Renegade BBS }
{ Renegade is free software: you can redistribute it }
{ and/or modify it under the terms of the GNU General }
{ Public License as published by the Free Software }
{ Foundation, either version 3 of the License, or }
{ (at your option) any later version. }
{ Renegade is distributed in the hope that it will be }
{ useful, but WITHOUT ANY WARRANTY; without even the }
{ implied warranty of MERCHANTABILITY or FITNESS FOR }
{ A PARTICULAR PURPOSE. See the GNU General Public }
{ License for more details. }
{ You should have received a copy of the GNU General }
{ Public License along with Renegade. If not, see }
{ <http://www.gnu.org/licenses/>. }
{*******************************************************}
{ _______ __ }
{ | _ .-----.-----.-----.-----.---.-.--| .-----. }
{ |. l | -__| | -__| _ | _ | _ | -__| }
{ |. _ |_____|__|__|_____|___ |___._|_____|_____| }
{ |: | | |_____| }
{ |::.|:. | }
{ `--- ---' }
{*******************************************************}
{$mode objfpc}
{$codepage utf8}
{$h+}
{ namespace Renegade.Logger }
{ Program to test the Logger.RecordHandler class }
Program RecordHandlerTest;
Uses
Classes,
SysUtils,
Renegade.Logger,
Logger.RecordHandler,
Logger.LoggerInterface;
const
Message = 'This is a log message';
CurrentClass = 'RecordHandler';
var
Handler : RecordHandler;
Logger : RTLogger;
Context : array [1..4] of ansistring = (CurrentClass, 'True', 'Testing', 'True');
begin
Handler := RecordHandler.Create;
Logger := RTLogger.Create(Handler);
Logger.Emergency(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Alert(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Critical(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Error(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Warning(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Notice(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Info(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Debug(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_EMERG, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_ALERT, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_CRIT, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_ERR, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_WARNING, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_NOTICE, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_INFO, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_DEBUG, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.LOG(LOG_UNKNOWN, Message, [Context[1], Context[2], Context[3], Context[4]]);
RenameFile('renegade.log', CurrentClass + 'Test.log');
end.

View File

@ -0,0 +1,81 @@
{*******************************************************}
{ Renegade BBS }
{ Copyright (c) 1990-2013 The Renegade Dev Team }
{ Copyleft (ↄ) 2016-2017 Renegade BBS }
{ This file is part of Renegade BBS }
{ Renegade is free software: you can redistribute it }
{ and/or modify it under the terms of the GNU General }
{ Public License as published by the Free Software }
{ Foundation, either version 3 of the License, or }
{ (at your option) any later version. }
{ Renegade is distributed in the hope that it will be }
{ useful, but WITHOUT ANY WARRANTY; without even the }
{ implied warranty of MERCHANTABILITY or FITNESS FOR }
{ A PARTICULAR PURPOSE. See the GNU General Public }
{ License for more details. }
{ You should have received a copy of the GNU General }
{ Public License along with Renegade. If not, see }
{ <http://www.gnu.org/licenses/>. }
{*******************************************************}
{ _______ __ }
{ | _ .-----.-----.-----.-----.---.-.--| .-----. }
{ |. l | -__| | -__| _ | _ | _ | -__| }
{ |. _ |_____|__|__|_____|___ |___._|_____|_____| }
{ |: | | |_____| }
{ |::.|:. | }
{ `--- ---' }
{*******************************************************}
{$mode objfpc}
{$codepage utf8}
{$h+}
{ namespace Renegade.Logger }
{ Program to test the Logger.NullHandler class }
Program StreamHandlerFileTest;
Uses
Classes,
SysUtils,
Renegade.Logger,
Logger.StreamHandler,
Logger.LoggerInterface;
const
Message = 'This is a log message';
CurrentClass = 'StreamHandler';
var
Handler : StreamHandler;
Logger : RTLogger;
Context : array [1..4] of ansistring = (CurrentClass, 'True', 'Testing', 'True');
begin
Handler := StreamHandler.Create('renegade.log');
Logger := RTLogger.Create(Handler);
Logger.Emergency(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Alert(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Critical(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Error(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Warning(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Notice(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Info(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Debug(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_EMERG, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_ALERT, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_CRIT, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_ERR, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_WARNING, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_NOTICE, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_INFO, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_DEBUG, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.LOG(LOG_UNKNOWN, Message, [Context[1], Context[2], Context[3], Context[4]]);
RenameFile('renegade.log', CurrentClass + 'FileTest.log');
end.

View File

@ -0,0 +1,87 @@
{*******************************************************}
{ Renegade BBS }
{ Copyright (c) 1990-2013 The Renegade Dev Team }
{ Copyleft (ↄ) 2016-2017 Renegade BBS }
{ This file is part of Renegade BBS }
{ Renegade is free software: you can redistribute it }
{ and/or modify it under the terms of the GNU General }
{ Public License as published by the Free Software }
{ Foundation, either version 3 of the License, or }
{ (at your option) any later version. }
{ Renegade is distributed in the hope that it will be }
{ useful, but WITHOUT ANY WARRANTY; without even the }
{ implied warranty of MERCHANTABILITY or FITNESS FOR }
{ A PARTICULAR PURPOSE. See the GNU General Public }
{ License for more details. }
{ You should have received a copy of the GNU General }
{ Public License along with Renegade. If not, see }
{ <http://www.gnu.org/licenses/>. }
{*******************************************************}
{ _______ __ }
{ | _ .-----.-----.-----.-----.---.-.--| .-----. }
{ |. l | -__| | -__| _ | _ | _ | -__| }
{ |. _ |_____|__|__|_____|___ |___._|_____|_____| }
{ |: | | |_____| }
{ |::.|:. | }
{ `--- ---' }
{*******************************************************}
{$mode objfpc}
{$codepage utf8}
{$h+}
{ namespace Renegade.Logger }
{ Program to test the Logger.StreamHandler class }
{ using TMemoryStream to show how you can use any }
{ custom TStream implementation. }
Program StreamHandlerStreamTStreamTest;
Uses
Classes,
SysUtils,
Renegade.Logger,
Logger.StreamHandler,
Logger.LoggerInterface;
const
Message = 'This is a log message';
CurrentClass = 'StreamHandler';
var
Handler : StreamHandler;
MemoryStream : TMemoryStream; // Test using a TMemoryStream
Logger : RTLogger;
Context : array [1..4] of ansistring = (CurrentClass, 'True', 'Testing', 'True');
begin
MemoryStream := TMemoryStream.Create;
Handler := StreamHandler.Create(MemoryStream);
Logger := RTLogger.Create(Handler);
Logger.Emergency(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Alert(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Critical(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Error(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Warning(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Notice(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Info(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Debug(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_EMERG, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_ALERT, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_CRIT, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_ERR, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_WARNING, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_NOTICE, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_INFO, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_DEBUG, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.LOG(LOG_UNKNOWN, Message, [Context[1], Context[2], Context[3], Context[4]]);
//RenameFile('renegade.log', CurrentClass + 'StreamTest.log');
MemoryStream.SaveToFile(CurrentClass + 'StreamTStreamTest.log');
MemoryStream.Free;
end.

View File

@ -0,0 +1,83 @@
{*******************************************************}
{ Renegade BBS }
{ Copyright (c) 1990-2013 The Renegade Dev Team }
{ Copyleft (ↄ) 2016-2017 Renegade BBS }
{ This file is part of Renegade BBS }
{ Renegade is free software: you can redistribute it }
{ and/or modify it under the terms of the GNU General }
{ Public License as published by the Free Software }
{ Foundation, either version 3 of the License, or }
{ (at your option) any later version. }
{ Renegade is distributed in the hope that it will be }
{ useful, but WITHOUT ANY WARRANTY; without even the }
{ implied warranty of MERCHANTABILITY or FITNESS FOR }
{ A PARTICULAR PURPOSE. See the GNU General Public }
{ License for more details. }
{ You should have received a copy of the GNU General }
{ Public License along with Renegade. If not, see }
{ <http://www.gnu.org/licenses/>. }
{*******************************************************}
{ _______ __ }
{ | _ .-----.-----.-----.-----.---.-.--| .-----. }
{ |. l | -__| | -__| _ | _ | _ | -__| }
{ |. _ |_____|__|__|_____|___ |___._|_____|_____| }
{ |: | | |_____| }
{ |::.|:. | }
{ `--- ---' }
{*******************************************************}
{$mode objfpc}
{$codepage utf8}
{$h+}
{ namespace Renegade.Logger }
{ Program to test the Logger.StreamHandler class using TStream }
Program StreamHandlerStreamTest;
Uses
Classes,
SysUtils,
Renegade.Logger,
Logger.StreamHandler,
Logger.LoggerInterface;
const
Message = 'This is a log message';
CurrentClass = 'StreamHandler';
var
Handler : StreamHandler;
FileStream : TFileStream; // Test using a TFileStream
Logger : RTLogger;
Context : array [1..4] of ansistring = (CurrentClass, 'True', 'Testing', 'True');
begin
FileStream := TFileStream.Create('renegade.log', fmOpenWrite or fmCreate);
Handler := StreamHandler.Create(FileStream);
Logger := RTLogger.Create(Handler);
Logger.Emergency(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Alert(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Critical(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Error(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Warning(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Notice(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Info(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Debug(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_EMERG, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_ALERT, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_CRIT, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_ERR, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_WARNING, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_NOTICE, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_INFO, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_DEBUG, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.LOG(LOG_UNKNOWN, Message, [Context[1], Context[2], Context[3], Context[4]]);
RenameFile('renegade.log', CurrentClass + 'StreamTest.log');
end.

View File

@ -0,0 +1,83 @@
{*******************************************************}
{ Renegade BBS }
{ Copyright (c) 1990-2013 The Renegade Dev Team }
{ Copyleft (ↄ) 2016-2017 Renegade BBS }
{ This file is part of Renegade BBS }
{ Renegade is free software: you can redistribute it }
{ and/or modify it under the terms of the GNU General }
{ Public License as published by the Free Software }
{ Foundation, either version 3 of the License, or }
{ (at your option) any later version. }
{ Renegade is distributed in the hope that it will be }
{ useful, but WITHOUT ANY WARRANTY; without even the }
{ implied warranty of MERCHANTABILITY or FITNESS FOR }
{ A PARTICULAR PURPOSE. See the GNU General Public }
{ License for more details. }
{ You should have received a copy of the GNU General }
{ Public License along with Renegade. If not, see }
{ <http://www.gnu.org/licenses/>. }
{*******************************************************}
{ _______ __ }
{ | _ .-----.-----.-----.-----.---.-.--| .-----. }
{ |. l | -__| | -__| _ | _ | _ | -__| }
{ |. _ |_____|__|__|_____|___ |___._|_____|_____| }
{ |: | | |_____| }
{ |::.|:. | }
{ `--- ---' }
{*******************************************************}
{$mode objfpc}
{$codepage utf8}
{$h+}
{ namespace Renegade.Logger }
{ Program to test the Logger.SysLogHandler class }
Program SysLogHandlerTest;
Uses
Classes,
SysUtils,
Renegade.Logger,
Logger.SysLogHandler,
Logger.LoggerInterface;
const
Message = 'This is a log message';
CurrentClass = 'SysLogHandler';
var
Handler : SysLogHandler;
Logger : RTLogger;
Context : array [1..4] of ansistring = (CurrentClass, 'True', 'Testing', 'True');
begin
Handler := SysLogHandler.Create(LOG_DAEMON); // man syslog for others
Logger := RTLogger.Create(Handler);
Logger.Emergency(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Alert(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Critical(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Error(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Warning(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Notice(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Info(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Debug(Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_EMERG, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_ALERT, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_CRIT, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_ERR, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_WARNING, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_NOTICE, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_INFO, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.Log(LOG_DEBUG, Message, [Context[1], Context[2], Context[3], Context[4]]);
Logger.LOG(LOG_UNKNOWN, Message, [Context[1], Context[2], Context[3], Context[4]]);
//RenameFile('renegade.log', CurrentClass + 'StreamTest.log');
// tail -f /var/log/syslog for results.
end.

13
tests/autogen.sh Executable file
View File

@ -0,0 +1,13 @@
#!/bin/bash
fpcBase=$1
if [ "$fpcBase" == "" ]; then
echo "Need an FPC base to fpc sources"
echo "Usually /usr/lib{32,64}/fpc/{fpc-version}/ on Linux machines."
echo "or C:\FPC\..\.. on Windows machines."
exit 255
fi
[ -f "Makefile" ] && rm Makefile
FPCDIR="$fpcBase" fpcmake

View File

@ -0,0 +1,13 @@
#!/bin/bash
if [ ! -f "RecordHandlerTest" ]; then
echo " Run ./autogen.sh [fpc/unit/base] and then run make"
echo " and run this program again"
exit 255;
fi
echo ""
seq 1 100 | while read i
do
echo -en "\r\033[K Current Record : $i";
#./RecordHandlerTest
sleep 2 # Computer is to fast, need a delay.
done