OpenCTF  1.7.0
Open Component Test Framework
TComponentHandler Class Reference

A test handler for a given type of components. More...

Inheritance diagram for TComponentHandler:
IComponentHandler

Public Member Functions

 TComponentHandler (const TClass ComponentClass, const string Suitename='')
 Creates a handler instance. More...
 
 TComponentHandler ()
 Creates a handler instance. More...
 
IComponentHandler Exclude (TComponentClass ExcludedClass)
 Exclude a component class from tests Example: More...
 
ITestSuite GetSuite ()
 Get the test suite.
 

Protected Member Functions

Boolean Accepts (const TComponent Component)
 This methods decides if the passed component should be included in the test suite. More...
 
 AddTest (const ITest Test)
 this method is a shortcut for CurrentSuite.AddTest(...)); More...
 
 AddTests ()
 Adds all component tests for the component to the test suite. More...
 
 AddFormTests ()
 Adds tests for the form to the test suite. More...
 
 CheckEvents (const string *Events)
 Checks for assigned event handlers. More...
 
 CheckUnassignedEvents (const string *Events)
 Checks for unassigned event handlers. More...
 
 CheckProperties (const string *Properties)
 Checks for assigned properties. More...
 
 CheckUnassignedProperties (const string *Properties)
 Check for unassigned properties. More...
 
Boolean Handles (const TComponent Form)
 Form filter method. More...
 
Boolean HasProperty (const TComponent Component, const string PropName, const TTypeKinds AKinds=[])
 Checks for the existence of a property.
 

Protected Attributes

TComponent Form
 The form or datamodule which will be tested. More...
 

Detailed Description

A test handler for a given type of components.

  • The method TComponentHandler::Accepts controls which components will be tested, it can be overriden to change the default behaviour.

Constructor & Destructor Documentation

◆ TComponentHandler() [1/2]

TComponentHandler::TComponentHandler ( const TClass  ComponentClass,
const string  Suitename = '' 
)

Creates a handler instance.

This constructor will create a handler instance which will by default generate a test for every component in the form (or datamodule) which is a subtype of the given component class.

Parameters
ComponentClassthe component class which will be accepted (and tested).
Suitenameoptional test suite name

◆ TComponentHandler() [2/2]

TComponentHandler::TComponentHandler ( )

Creates a handler instance.

This constructor will create a handler instance which will by default generate a test for every component in the form (or datamodule) which is a subtype of TComponent.

Member Function Documentation

◆ Accepts()

Boolean TComponentHandler::Accepts ( const TComponent  Component)
protected

This methods decides if the passed component should be included in the test suite.

The default implementation checks if the component class is a subclass of the handled class. This method may be overriden to add more filter conditions.

Parameters
Componentthe component to be checked

Referenced by GetSuite().

◆ AddFormTests()

TComponentHandler::AddFormTests ( )
protected

Adds tests for the form to the test suite.

  • To add tests for the form, overwrite the empty default declaration of this method.

Referenced by GetSuite().

◆ AddTest()

TComponentHandler::AddTest ( const ITest  Test)
protected

this method is a shortcut for CurrentSuite.AddTest(...));

Parameters
Testthe test that will be added to the CurrentSuite

◆ AddTests()

TComponentHandler::AddTests ( )
protected

Adds all component tests for the component to the test suite.

  • If you write a new component handler, you have to provide an implementation of this method.

Example:

procedure TMenuItemHandler.AddTests;
begin
inherited;
CurrentSuite.AddTest(TMenuItemTest.Create(CurrentComponent));
end;

Referenced by GetSuite().

◆ CheckEvents()

TComponentHandler::CheckEvents ( const string *  Events)
protected

Checks for assigned event handlers.

procedure TCustomClientDataSetTestHandler.AddTests(const SubComponent: TComponent);
begin
inherited;
// check if the OnReconcileError event handler is assigned
CheckEvents(['OnReconcileError']);
// check if the ProviderName property is assigned
CheckProperties(['ProviderName']);
end;

◆ CheckProperties()

TComponentHandler::CheckProperties ( const string *  Properties)
protected

Checks for assigned properties.

procedure TDbAwareComponentTestHandler.AddTests(const
SubComponent: TComponent);
begin
CheckProperties(['DataSource', 'DataField']);
end;

◆ CheckUnassignedEvents()

TComponentHandler::CheckUnassignedEvents ( const string *  Events)
protected

Checks for unassigned event handlers.

See also
CheckEvents

◆ CheckUnassignedProperties()

TComponentHandler::CheckUnassignedProperties ( const string *  Properties)
protected

Check for unassigned properties.

See also
CheckProperties

◆ Exclude()

IComponentHandler TComponentHandler::Exclude ( TComponentClass  ExcludedClass)

Exclude a component class from tests Example:

OpenCTF.Add((TComponentNameTests.Create)
.Exclude(TLabel) // exclude TLabel from tests (allow default name)
.Exclude(TFrame) // and TFrame
.Exclude(TPanel) // and TPanel
);
Parameters
ExcludedClassthe class to be excluded from tests

◆ Handles()

Boolean TComponentHandler::Handles ( const TComponent  Form)
protected

Form filter method.

This method decides if the handler will generate test cases for the given form.

The default implementation always returns True.

If you write a component handler, you can overwrite this method to allow only special form classes to be processed.

For example, a component handler for visual components can overwrite this method and check if the passed parameter is a subclass of TCustomForm:

Result := Form is TCustomForm;
Parameters
FormThe form (or datamodule) to be tested.

Member Data Documentation

◆ Form

TComponentHandler::Form
protected

The form or datamodule which will be tested.

See also
GetForm For reading
SetForm For writing

Referenced by GetSuite().