| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- (* _ _
- * | |__ _ __ ___ ___ | | __
- * | '_ \| '__/ _ \ / _ \| |/ /
- * | |_) | | | (_) | (_) | <
- * |_.__/|_| \___/ \___/|_|\_\
- *
- * Microframework which helps to develop web Pascal applications.
- *
- * Copyright (c) 2012-2020 Silvio Clecio <[email protected]>
- *
- * Brook framework is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * Brook framework 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Brook framework; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *)
- program Test_LibraryLoader;
- {$I Tests.inc}
- uses
- SysUtils,
- Classes,
- libsagui,
- BrookLibraryLoader;
- type
- TEventHolder = class
- private
- FSender: TObject;
- FPassed: Boolean;
- public
- procedure DoNotifyEvent(ASender: TObject);
- property Sender: TObject read FSender write FSender;
- property Passed: Boolean read FPassed write FPassed;
- end;
- procedure TEventHolder.DoNotifyEvent(ASender: TObject);
- begin
- FPassed := ASender = FSender;
- end;
- procedure Test_LibraryLoaderCreate;
- var
- LL: TBrookLibraryLoader;
- C: TComponent;
- begin
- C := TComponent.Create(nil);
- LL := TBrookLibraryLoader.Create(C);
- try
- Assert(LL.Owner = C);
- Assert(LL.LibraryName = SG_LIB_NAME);
- finally
- LL.Destroy;
- C.Destroy;
- end;
- end;
- procedure Test_LibraryLoaderLoad;
- begin
- SgLib.Unload;
- Assert(SgLib.Handle = NilHandle);
- TBrookLibraryLoader.Load(SG_LIB_NAME);
- Assert(SgLib.Handle <> NilHandle);
- SgLib.Unload;
- Assert(SgLib.Handle = NilHandle);
- TBrookLibraryLoader.Load;
- Assert(SgLib.Handle <> NilHandle);
- end;
- procedure Test_LibraryLoaderUnload;
- begin
- SgLib.Load(SG_LIB_NAME);
- Assert(SgLib.Handle <> NilHandle);
- TBrookLibraryLoader.Unload;
- Assert(SgLib.Handle = NilHandle);
- end;
- procedure Test_LibraryLoaderIsLoaded;
- begin
- Assert(not TBrookLibraryLoader.IsLoaded);
- TBrookLibraryLoader.Load;
- Assert(TBrookLibraryLoader.IsLoaded);
- TBrookLibraryLoader.Unload;
- Assert(not TBrookLibraryLoader.IsLoaded);
- end;
- procedure Test_LibraryLoaderOpen;
- var
- LL: TBrookLibraryLoader;
- begin
- LL := TBrookLibraryLoader.Create(nil);
- try
- Assert(not LL.Active);
- LL.Open;
- Assert(LL.Active);
- finally
- LL.Destroy;
- end;
- end;
- procedure Test_LibraryLoaderClose;
- var
- LL: TBrookLibraryLoader;
- begin
- LL := TBrookLibraryLoader.Create(nil);
- try
- LL.Open;
- Assert(LL.Active);
- LL.Close;
- Assert(not LL.Active);
- finally
- LL.Destroy;
- end;
- end;
- procedure Test_LibraryLoaderActive;
- var
- LL: TBrookLibraryLoader;
- begin
- LL := TBrookLibraryLoader.Create(nil);
- try
- Assert(not LL.Active);
- LL.Active := not LL.Active;
- Assert(LL.Active);
- finally
- LL.Destroy;
- end;
- end;
- procedure Test_LibraryLoaderLibraryName;
- var
- LL: TBrookLibraryLoader;
- begin
- LL := TBrookLibraryLoader.Create(nil);
- try
- Assert(LL.LibraryName = LL.LIB_NAME);
- LL.LibraryName := '';
- Assert(LL.LibraryName = LL.LIB_NAME);
- LL.LibraryName := 'test';
- Assert(LL.LibraryName = 'test');
- finally
- LL.Destroy;
- end;
- end;
- procedure Test_LibraryLoaderVersion;
- var
- LL: TBrookLibraryLoader;
- begin
- LL := TBrookLibraryLoader.Create(nil);
- try
- Assert(LL.Version = '');
- LL.Open;
- Assert(LL.Version = Format('%d.%d.%d', [SG_VERSION_MAJOR, SG_VERSION_MINOR,
- SG_VERSION_PATCH]));
- finally
- LL.Destroy;
- end;
- end;
- procedure Test_LibraryLoaderOnLoad;
- var
- LL: TBrookLibraryLoader;
- EH: TEventHolder;
- begin
- LL := TBrookLibraryLoader.Create(nil);
- EH := TEventHolder.Create;
- try
- LL.OnLoad := EH.DoNotifyEvent;
- EH.Sender := LL;
- EH.Passed := False;
- LL.Open;
- Assert(EH.Passed);
- EH.Passed := False;
- LL.Open;
- Assert(not EH.Passed);
- finally
- LL.Destroy;
- EH.Destroy;
- end;
- end;
- procedure Test_LibraryLoaderOnUnload;
- var
- LL: TBrookLibraryLoader;
- EH: TEventHolder;
- begin
- LL := TBrookLibraryLoader.Create(nil);
- EH := TEventHolder.Create;
- try
- LL.Open;
- LL.OnUnload := EH.DoNotifyEvent;
- EH.Sender := LL;
- EH.Passed := False;
- LL.Close;
- Assert(EH.Passed);
- EH.Passed := False;
- LL.Close;
- Assert(not EH.Passed);
- finally
- LL.Destroy;
- EH.Destroy;
- end;
- end;
- begin
- {$IF (NOT DEFINED(FPC)) AND DEFINED(DEBUG)}
- ReportMemoryLeaksOnShutdown := True;
- {$ENDIF}
- Test_LibraryLoaderCreate;
- // Test_LibraryLoaderDestroy - not required
- Test_LibraryLoaderLoad;
- Test_LibraryLoaderUnload;
- Test_LibraryLoaderIsLoaded;
- Test_LibraryLoaderOpen;
- Test_LibraryLoaderClose;
- // Test_LibraryLoaderDefineProperties - not required
- Test_LibraryLoaderActive;
- Test_LibraryLoaderLibraryName;
- Test_LibraryLoaderVersion;
- Test_LibraryLoaderOnLoad;
- Test_LibraryLoaderOnUnload;
- end.
|