Mega Code Archive

 
Categories / Delphi / Examples
 

Custom Plugins for AQTest

Title: Custom Plugins for AQTest Question: AQTest is a wonderful testing tool especially regression testing. Also, it gives a beautiful way to have Custom Plugins. With custom plugins facility we can test modules the way we want it. Testing can be made more systematic in this process. This write up explains how we can go about creating a custom plugin for AQTest Answer: A plugin for AQTest is a DLL with the following methods exported: AQTestPlugInInit; { Required to create the Plug in object } AQTestPlugInDescription; { A Decent description for the plug in..} AQTestPlugInFinalize; { Clean up the mess. } The main thing about the plugin is the - a TLB file has to be included in the resource of the DLL. The extension should 'pls'. The dpr file might look like below. library TestPlugIn; {$E pls} // The Extension has to be pls. uses SysUtils, Classes, uniTestA in 'uniTestA.Pas'; // Our Pas file TestPlugIn_TLB in 'TestPlugIn_TLB.Pas'; // The TLB file with the methods made available // by the plug in exports AQTestPlugInInit; AQTestPlugInDescription; AQTestPlugInFinalize; {$R TestPlugIn.TLB} begin end. The next step is to generate a TLB file which can be done by selecting File-New-ActiveX-TypeLibrary in the Delphi Main Menu option. Define the interface here with all the methods. Create a new unit and include the following in the uses clauses: ComObj, ActiveX // - Because the object we need to export must be inherited from // TAutoIntfObject TestPlugIn_TLB // - The Type library's pas version since the class implements the interface. Windows, Dialogs and SysUtils The next step is defining our class: TTestPlugIn = class(TAutoIntfClass, ITestPlugIn) public constructor Create; function GetRandomValue(i: integer): integer; // This is the method defined by the interface end; and fill up the implementation details for the same. constructor Create; begin inherited Create(GetModuleTypeLib, ITestPlugIn); end; Note: the implementation of GetModuleTypeLib goes as below: { As given in one of the sample files } function GetModuleTypeLib: ITypeLib; var Buffer: array [0..MAX_PATH] of Char; ModuleName : string; Size : Integer; begin Size := GetModuleFileName(HInstance, Buffer, SizeOf(Buffer)); SetString(ModuleName, Buffer, Size); OleCheck(LoadTypeLib(PWideChar(WideString(ModuleName)), Result)); end; Once that is complete we need to give the implementation of the interface methods. Now our class is ready. The next thing we need to do is provide the implementation for the exported functions. For this purpose a Global Variable of type OleVariant has to be defined. var PIManager: OleVariant; Once that is done, we can start off with the implementation the exported methods: function AQTestPlugInInit(PlugInManager: IDispatch): WordBool; stdcall; var Obj: ITestPlugIn; begin Result := True; try PIManager := PlugInManager; { Init the Global Variable here.. } // Create an instance of the plugin class we created.. Obj := TTestPlugIn.Create; // VIOLA we have added it.. PIManager.AddName(PlugInName, False, Obj as IDispatch); except Result := False; end; end; function AQTestPlugInDescription: WideString; stdcall; begin Result := 'Test Plgin' + #9 + ' AQTest is a beauty'; end; function AQTestPlugInFinalise; stdcall; begin PIManager.RemoveName(PlugInName); end; Complie the file and Install the plugin in AQTest and Test.. Sri Ram