Drag[en]gine Script Module DragonScript  1.23
Dragengine.TestSystem.TestCaseECBehaviorPersistency Class Reference

Base class for testing BehaviorElementClass behaviors persistency. More...

Inheritance diagram for Dragengine.TestSystem.TestCaseECBehaviorPersistency:
Dragengine.TestSystem.TestCaseECBehavior Dragengine.TestSystem.TestCase

Classes

class  TestBehaviorElementClass
 Helper class to store the created element aside. More...
 

Public Member Functions

void init ()
 Initialize test. More...
 
TestCaseECBehaviorPersistency new (String id, UnicodeString name)
 Create test. More...
 
bool run (TestSuite testSuite)
 Run test. More...
 
void setElement (BehaviorElement element)
 Set element. More...
 
- Public Member Functions inherited from Dragengine.TestSystem.TestCaseECBehavior
bool getCreateAndAddElementShouldFail ()
 Calling createAndAddElement() on element stub should fail by throwing an exception. More...
 
bool getPreloadShouldFail ()
 Preloading on element class should fail. More...
 
void setCreateAndAddElementShouldFail (bool shouldFail)
 Set calling createAndAddElement() on element stub should fail by throwing an exception. More...
 
void setPreloadShouldFail (bool shouldFail)
 Set preloading on element class should fail. More...
 
- Public Member Functions inherited from Dragengine.TestSystem.TestCase
void assertColor (Color found, Color expected, float range)
 Fail test if colors are not equal within range. More...
 
void assertDiffers (Object found, Object shouldNot)
 Fail test if found equals expected. More...
 
void assertDVector (DVector found, DVector expected)
 Fail test if vectors are not equal within range of 1mm. More...
 
void assertDVector (DVector found, DVector expected, float range)
 Fail test if vectors are not equal within range. More...
 
void assertEquals (Object found, Object expected)
 Fail test if found does not equal expected. More...
 
void assertFalse (bool found)
 Fail test if found is not false. More...
 
void assertNotNull (Object found)
 Fail test if found is not null. More...
 
void assertNull (Object found)
 Fail test if found is not null. More...
 
void assertQuaternion (Quaternion found, Quaternion expected)
 Fail test if quaternions are not equal within range of 1mm. More...
 
void assertQuaternion (Quaternion found, Quaternion expected, float range)
 Fail test if quaternions are not equal within range. More...
 
void assertThrows (Block ablock)
 Fail test if ablock does not throw an exception. More...
 
void assertTrue (bool found)
 Fail test if found is not true. More...
 
void assertVector (DVector found, DVector expected, float range)
 Fail test if vectors are not equal within range. More...
 
void assertVector (Vector found, Vector expected)
 Fail test if vectors are not equal within range of 1mm. More...
 
bool getEnabled ()
 Test case is enabled. More...
 
Exception getException ()
 Exception if test case failed. More...
 
String getID ()
 Identifier. More...
 
UnicodeString getName ()
 Display name. More...
 
State getState ()
 Test state. More...
 
TestSuite getTestSuite ()
 Test suite. More...
 
void setEnabled (bool enabled)
 Set if test case is enabled. More...
 
void setException (Exception exception)
 Set exception if test case failed. More...
 
void setState (State state)
 Set test state. More...
 
void setTestSuite (TestSuite testSuite)
 Set test suite. More...
 

Protected Member Functions

void addBehaviors ()
 Add behaviors to element class. More...
 
void dataPersisted ()
 Element data has been persisted. More...
 
void elementCreated ()
 Element created. More...
 
void explicitRead (PersistencyEnvironment env)
 Explicit read test ensuring behaviors read all data. More...
 
BehaviorElement getElement ()
 Element to use for testing. More...
 
BehaviorElementClass getElementClass ()
 Element class to use for testing. More...
 
GameWorld getGameWorld ()
 Game world to use for testing. More...
 
MemoryFile getPersistedData ()
 Persisted behavior element data. More...
 
PreloadCounter getPreloadCounter ()
 Preload counter used to preload element class resources. More...
 
StubElement getStubElement ()
 Stub element to use for testing. More...
 
bool testBehaviors (TestSuite testSuite)
 Test behaviors. More...
 
- Protected Member Functions inherited from Dragengine.TestSystem.TestCaseECBehavior
void assertEnumProperty (ECPEnumeration property, Enumeration value, Set enumerationValues)
 Assert element class enumeration property. More...
 
void assertFloatProperty (ECPFloat property, float value)
 Assert element class float property. More...
 
void assertFloatProperty (ECPFloat property, float value, float limitLower)
 Assert element class float property. More...
 
void assertFloatProperty (ECPFloat property, float value, float limitLower, float limitUpper)
 Assert element class float property. More...
 
void assertIntegerProperty (ECPInteger property, int value)
 Assert element class integer property. More...
 
void assertIntegerProperty (ECPInteger property, int value, int limitLower)
 Assert element class integer property. More...
 
void assertIntegerProperty (ECPInteger property, int value, int limitLower, int limitUpper)
 Assert element class integer property. More...
 

Additional Inherited Members

- Public Attributes inherited from Dragengine.TestSystem.TestCase
bool pEnabled
 Test case is enabled. More...
 
Exception pException
 Exception if test case failed. More...
 
String pID
 Test identifier. More...
 
UnicodeString pName
 Test name. More...
 
State pState
 Test state. More...
 
WeakReference pTestSuite
 Test suite. More...
 

Detailed Description

Base class for testing BehaviorElementClass behaviors persistency.

Version
1.5

This class helps to test ECBehavior subclasses persistency by providing the boiler plate code required to set up such tests. In particular this base class does the following:

  • Create a GameWorld instance
  • Create a BehaviorElementClass instance
  • Wait for preloading resources to finish
  • Create a StubElement instance
  • Create BehaviorElement instance
  • Write BehaviorElement instance to MemoryFile
  • Dispose of BehaviorElement instance
  • Create new BehaviorElement instance by reading MemoryFile
  • Safely tear down all created resources

This class calls hook methods at specific points during the test to allow the subclass to set up the behaviors in the required layout as well as running the tests. The following example implementation shows how a subclass can be written.

class MyTestCase extends TestCaseECBehaviorPersistency
public func new()
end
protected var ECBehaviorComponent behavior
// Overwrite method to add behaviors to element class. Created behaviors
// have to be store aside if required during tests later on. Overwriting
// this method is mandatory
protected func void addBehaviors()
behavior = ECBehaviorComponent.new(getElementClass(), null)
end
// Overwrite method to set element stub properties. This simulates mapper setting
// object properties in the world editor. Overwriting this method is optional.
protected func void setStubProperties()
getStubElement().setPropertyValueFor("component.model", "/content/models/test.demodel")
end
// Overwrite method to set up element after it has been created. Overwriting
// this method is optional. This is though typically required to modify the
// behavior instance states for persisting state
protected func void elementCreated()
getElement().setPosition(DVector.new(2, 1, 3))
end
// Overwrite method to modify the persisted data. Overwriting this method is
// optional. This can be used to inject behavior data written in deprecated
// formats to verify these deprecated formats still can be loaded
protected func void dataPersisted()
getData().getFileWriter(true).writeInt(8) // append an integer=8
end
// Overwrite to run your tests on the behavior. Overwriting this method is mandatory.
// This method is called after the behavior element has been loaded from memory file
protected func bool testBehaviors(TestSuite testSuite)
var ECBehaviorComponent.Instance component = behavior.instance(getElement())
assertNotNull(component.getComponent())
// Return true to continue testing during the next frame update or false
// if the test finished successfully.
return false
end
end
StubElement getStubElement()
Stub element to use for testing.
void addBehaviors()
Add behaviors to element class.
TestCaseECBehaviorPersistency new(String id, UnicodeString name)
Create test.
void dataPersisted()
Element data has been persisted.
bool testBehaviors(TestSuite testSuite)
Test behaviors.
BehaviorElement getElement()
Element to use for testing.
void assertNotNull(Object found)
Fail test if found is not null.

Member Function Documentation

◆ addBehaviors()

void Dragengine.TestSystem.TestCaseECBehaviorPersistency.addBehaviors ( )
protected

Add behaviors to element class.

Reimplemented from Dragengine.TestSystem.TestCaseECBehavior.

◆ dataPersisted()

void Dragengine.TestSystem.TestCaseECBehaviorPersistency.dataPersisted ( )
protected

Element data has been persisted.

◆ elementCreated()

void Dragengine.TestSystem.TestCaseECBehaviorPersistency.elementCreated ( )
protected

Element created.

Reimplemented from Dragengine.TestSystem.TestCaseECBehavior.

◆ explicitRead()

void Dragengine.TestSystem.TestCaseECBehaviorPersistency.explicitRead ( PersistencyEnvironment  env)
protected

Explicit read test ensuring behaviors read all data.

◆ getElement()

BehaviorElement Dragengine.TestSystem.TestCaseECBehaviorPersistency.getElement ( )
protected

Element to use for testing.

Reimplemented from Dragengine.TestSystem.TestCaseECBehavior.

◆ getElementClass()

BehaviorElementClass Dragengine.TestSystem.TestCaseECBehaviorPersistency.getElementClass ( )
protected

Element class to use for testing.

Reimplemented from Dragengine.TestSystem.TestCaseECBehavior.

◆ getGameWorld()

GameWorld Dragengine.TestSystem.TestCaseECBehaviorPersistency.getGameWorld ( )
protected

Game world to use for testing.

Reimplemented from Dragengine.TestSystem.TestCaseECBehavior.

◆ getPersistedData()

MemoryFile Dragengine.TestSystem.TestCaseECBehaviorPersistency.getPersistedData ( )
protected

Persisted behavior element data.

◆ getPreloadCounter()

PreloadCounter Dragengine.TestSystem.TestCaseECBehaviorPersistency.getPreloadCounter ( )
protected

Preload counter used to preload element class resources.

Reimplemented from Dragengine.TestSystem.TestCaseECBehavior.

◆ getStubElement()

StubElement Dragengine.TestSystem.TestCaseECBehaviorPersistency.getStubElement ( )
protected

Stub element to use for testing.

Reimplemented from Dragengine.TestSystem.TestCaseECBehavior.

◆ init()

void Dragengine.TestSystem.TestCaseECBehaviorPersistency.init ( )

Initialize test.

Reimplemented from Dragengine.TestSystem.TestCaseECBehavior.

◆ new()

TestCaseECBehaviorPersistency Dragengine.TestSystem.TestCaseECBehaviorPersistency.new ( String  id,
UnicodeString  name 
)

Create test.

Reimplemented from Dragengine.TestSystem.TestCaseECBehavior.

◆ run()

bool Dragengine.TestSystem.TestCaseECBehaviorPersistency.run ( TestSuite  testSuite)

Run test.

Reimplemented from Dragengine.TestSystem.TestCaseECBehavior.

◆ setElement()

void Dragengine.TestSystem.TestCaseECBehaviorPersistency.setElement ( BehaviorElement  element)

Set element.

For internal use only.

◆ testBehaviors()

bool Dragengine.TestSystem.TestCaseECBehaviorPersistency.testBehaviors ( TestSuite  testSuite)
protected

Test behaviors.

Reimplemented from Dragengine.TestSystem.TestCaseECBehavior.


The documentation for this class was generated from the following file: