📄 xpdunittestmodule.pas
字号:
unit XPDUnitTestModule;
{
$Source: /cvsroot/dunit/dunit/Contrib/DUnitWizard/Source/DelphiExperts/DUnitProject/XPDUnitTestModule.pas,v $
$Revision: 1.2 $
$Date: 2004/05/03 15:07:16 $
Last amended by $Author: pvspain $
$State: Exp $
TXPDUnitTestModuleForm:
Copyright (c) 2003 by The Excellent Programming Company Pty Ltd
(Australia) (ABN 27 005 394 918). All rights reserved.
Contact Paul Spain via email: paul@xpro.com.au
This unit 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.
This unit 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 this unit; if not, the license can be viewed at:
http://www.gnu.org/copyleft/lesser.html
or write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
}
interface
{$I JEDI.inc}
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, ExtCtrls, XPDUnitCommon, IniFiles, ComCtrls, ImgList,
XPTestedUnitParser, XPTestedUnitUtils, XPParserFilters;
type
////////////////////////////////////////////////////////////////////////////
// TXPDUnitTestModuleForm declaration
////////////////////////////////////////////////////////////////////////////
TXPDUnitTestModuleForm = class(TForm)
Label1: TLabel;
UnitName: TEdit;
Label2: TLabel;
UnitFileName: TEdit;
Label3: TLabel;
UnitPath: TEdit;
SelectPath: TSpeedButton;
GroupBox1: TGroupBox;
AddToTestModule: TCheckBox;
AddToProject: TCheckBox;
CancelTestModule: TBitBtn;
CreateTestModule: TBitBtn;
Label4: TLabel;
NodeImages: TImageList;
Classes: TPanel;
TestClassesView: TTreeView;
Splitter1: TSplitter;
TestedClassesView: TTreeView;
Label5: TLabel;
StateImages: TImageList;
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure SelectPathClick(Sender: TObject);
procedure CreateTestModuleClick(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure UnitNameChange(Sender: TObject);
procedure TestedClassesViewClick(Sender: TObject);
private
FParameters: IXPDUnitParameters;
FBehaviours: IXPDUnitBehaviours;
FPersistedValues: TIniFile;
FTestedModuleParser: IXPTestedUnitParser;
FTestedModuleFilter: IXPTestedModuleFilter;
FTestClassFilter: IXPTestClassFilter;
procedure ParseCurrentUnit;
procedure PopulateTestedClasses;
procedure UpdateTestClasses;
function GetTestClasses: IXPParserTree;
function ClickedOnStateIcon(out ANode: TTreeNode): boolean;
procedure SetNodeState(const ANode: TTreeNode; const Enabled: boolean);
function TreeToParser(const ANode: TTreeNode): IXPParserNode;
procedure UpdateNodeImage(const ANode: TTreeNode);
procedure UpdateNodeState(const ANode: TTreeNode);
procedure SetSelectedTestNode;
public
property Parameters: IXPDUnitParameters
read FParameters;
property TestClasses: IXPParserTree
read GetTestClasses;
end;
///////////////////////////////////////////////////////////////////////////////
// Unit entry point
///////////////////////////////////////////////////////////////////////////////
function ShowXPDUnitTestModuleForm(out TestClasses: IXPParserTree;
out Parameters: IXPDUnitParameters): boolean;
implementation
uses
{$IFNDEF DELPHI6_UP}
XPInterfacedObject, // IInterface
FileCtrl, // SelectDirectory()
{$ELSE}
QDialogs, // SelectDirectory()
{$ENDIF}
{$IFDEF GUI_DEMO}
TestedUnitStream,
{$ENDIF}
XPDUnitSetup, // CreateXPDUnitBehaviours()
XPDUnitParameters; // CreateXPDUnitParameters()
const CVSID: string = '$Header: /cvsroot/dunit/dunit/Contrib/DUnitWizard/Source/DelphiExperts/DUnitProject/XPDUnitTestModule.pas,v 1.2 2004/05/03 15:07:16 pvspain Exp $';
{$R *.DFM}
var
LForm: TXPDUnitTestModuleForm;
///////////////////////////////////////////////////////////////////////////////
// Unit entry point
///////////////////////////////////////////////////////////////////////////////
function ShowXPDUnitTestModuleForm(out TestClasses: IXPParserTree;
out Parameters: IXPDUnitParameters): boolean;
begin
// Singleton instance of form. Destroyed in finalization section
// Don't assign Owner as this form is part of a package, which can be removed
// from IDE at any time. We want to be in control of form destruction.
if not System.Assigned(LForm) then
LForm := TXPDUnitTestModuleForm.Create(nil);
// Extract user's settings
TestClasses := LForm.TestClasses;
Parameters := LForm.Parameters;
// Modal form
Result := (LForm.ShowModal = mrOK);
end;
////////////////////////////////////////////////////////////////////////////
// TXPDUnitTestModuleForm implementation
////////////////////////////////////////////////////////////////////////////
procedure TXPDUnitTestModuleForm.FormCreate(Sender: TObject);
begin
FBehaviours := XPDUnitSetup.CreateXPDUnitBehaviours;
FParameters := XPDUnitParameters.CreateXPDUnitParameters;
FPersistedValues := TIniFile.Create(XPDUnitSetupFile);
FTestedModuleParser := XPTestedUnitParser.CreateXPTestedUnitParser;
FTestedModuleFilter := XPParserFilters.CreateTestedModuleFilter;
FTestClassFilter := XPParserFilters.CreateTestClassFilter;
end;
procedure TXPDUnitTestModuleForm.FormDestroy(Sender: TObject);
begin
FPersistedValues.Free;
// Clear local reference
LForm := nil;
end;
procedure TXPDUnitTestModuleForm.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
Action := caFree;
// Persist our geometry
FPersistedValues.WriteInteger('TestModuleForm', 'Width', Width);
FPersistedValues.WriteInteger('TestModuleForm', 'Height', Height);
FPersistedValues.WriteInteger('TestModuleForm', 'TestedClassesViewWidth',
TestedClassesView.Width);
end;
procedure TXPDUnitTestModuleForm.FormShow(Sender: TObject);
begin
// Reload our persisted data
Width := FPersistedValues.ReadInteger('TestModuleForm', 'Width', Width);
Height := FPersistedValues.ReadInteger('TestModuleForm', 'Height', Height);
TestedClassesView.Width := FPersistedValues.ReadInteger('TestModuleForm',
'TestedClassesViewWidth', TestedClassesView.Width);
AddToTestModule.Checked := FPersistedValues.ReadBool(sBehaviours,
iAddCurrentToTestModule, dAddCurrentToTestModule);
AddToProject.Checked := FPersistedValues.ReadBool(sBehaviours,
iAddCurrentToProject, dAddCurrentToProject);
// Initialise fields for *current* invocation
FParameters.ClearValues;
FParameters.EvaluateValues;
UnitName.Text := FParameters.Values[dpUnitName];
// Unit filename initialised by UnitNameChange()
UnitPath.Text := FParameters.Values[dpUnitPath];
// Setup tested class tree view
PopulateTestedClasses;
// Setup new test class tree view
UpdateTestClasses;
end;
procedure TXPDUnitTestModuleForm.PopulateTestedClasses;
var
SectionNode: IXPParserNode;
ClassNode: IXPParserNode;
VisibilityNode: IXPParserNode;
MethodNode: IXPParserNode;
CurrentSection: TTreeNode;
CurrentClass: TTreeNode;
CurrentVisibility: TTreeNode;
const
RootNode = nil;
NoRecurse = false;
procedure AssignImages(const Node: TTreeNode; const ImageIndex: integer);
begin
Node.ImageIndex := ImageIndex;
Node.SelectedIndex := ImageIndex;
UpdateNodeImage(Node);
end;
begin
// Setup tested class tree view
ParseCurrentUnit;
FTestedModuleFilter.SetInput(FTestedModuleParser.ParseTree, FBehaviours);
FTestedModuleFilter.Children.Start;
TestedClassesView.Items.BeginUpdate;
try
TestedClassesView.Items.Clear;
while FTestedModuleFilter.Children.Next(SectionNode) do
begin
CurrentSection := TestedClassesView.Items.AddChildObject(RootNode,
SectionNode.Name, pointer(SectionNode));
AssignImages(CurrentSection, System.Ord(niSection));
SectionNode.Children.Start;
while SectionNode.Children.Next(ClassNode) do
begin
CurrentClass := TestedClassesView.Items.AddChildObject(CurrentSection,
ClassNode.Name, pointer(ClassNode));
AssignImages(CurrentClass, System.Ord(niClass));
ClassNode.Children.Start;
while ClassNode.Children.Next(VisibilityNode) do
begin
CurrentVisibility := TestedClassesView.Items.AddChildObject(
CurrentClass, VisibilityNode.Name, pointer(VisibilityNode));
AssignImages(CurrentVisibility, System.Ord(niVisibility));
VisibilityNode.Children.Start;
while VisibilityNode.Children.Next(MethodNode) do
AssignImages(TestedClassesView.Items.AddChildObject(
CurrentVisibility, MethodNode.Name, pointer(MethodNode)),
System.Ord(niMethod));
end;
end;
end;
finally
TestedClassesView.Items.EndUpdate;
end;
// Display tested classes with only topmost node expanded (showing class
// names)
TestedClassesView.FullCollapse;
if TestedClassesView.Items.GetFirstNode <> nil then
TestedClassesView.Items.GetFirstNode.Expand(NoRecurse);
end;
procedure TXPDUnitTestModuleForm.UpdateTestClasses;
var
SectionNode: IXPParserNode;
ClassNode: IXPParserNode;
VisibilityNode: IXPParserNode;
MethodNode: IXPParserNode;
CurrentSection: TTreeNode;
CurrentClass: TTreeNode;
CurrentVisibility: TTreeNode;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -