diff -r ebc84c812384 -r 46218c8b8afa Symbian3/PDK/Source/GUID-5AA3E9E4-9727-5B54-81CB-DADA73DEC51E.dita --- a/Symbian3/PDK/Source/GUID-5AA3E9E4-9727-5B54-81CB-DADA73DEC51E.dita Thu Mar 11 15:24:26 2010 +0000 +++ b/Symbian3/PDK/Source/GUID-5AA3E9E4-9727-5B54-81CB-DADA73DEC51E.dita Thu Mar 11 18:02:22 2010 +0000 @@ -1,67 +1,67 @@ - - - - - -Using -__DECLARE_TESTThis topic explains how to use declare test macro. -

To illustrate the use of the __DECLARE_TEST macro, we -can define the class TEgInvariant. It has a very simple state, -a single data member iData. An object is in an invalid state -when iData is greater than 100.

-class TEgInvariant - { -public: - void SetData(TUint a); - TUint Data(); - void DoSomeThing(); -private: - TUint iData; -__DECLARE_TEST; - }; -

Then we define the getter/setter functions for iData:

-void TEgInvariant::SetData(TUint a) - { - iData=a; - } - -TUint TEgInvariant::Data() - { - return iData; - } -

TEgInvariant::DoSomeThing() is a function that would perform -some useful work. We verify the object’s state at its beginning and end through __TEST_INVARIANT.

-void TEgInvariant::DoSomeThing() - { - __TEST_INVARIANT; - - //...do something with iData - - __TEST_INVARIANT; - } -

TEgInvariant::__DbgTestInvariant() performs the invariance -test:

-void TEgInvariant::__DbgTestInvariant() const - { -#if defined(_DEBUG) - if(iData > 100) - User::Invariant(); -#endif - } -

We could test the class with the following code:

- TEgInvariant Eg; - - Eg.SetData(10); - Eg.DoSomeThing(); - - Eg.SetData(1000); - Eg.DoSomeThing(); -

In debug builds, the second call to DoSomeThing() causes -a panic, alerting us to a problem in the code that needs fixing.

+ + + + + +Using +__DECLARE_TESTThis topic explains how to use declare test macro. +

To illustrate the use of the __DECLARE_TEST macro, we +can define the class TEgInvariant. It has a very simple state, +a single data member iData. An object is in an invalid state +when iData is greater than 100.

+class TEgInvariant + { +public: + void SetData(TUint a); + TUint Data(); + void DoSomeThing(); +private: + TUint iData; +__DECLARE_TEST; + }; +

Then we define the getter/setter functions for iData:

+void TEgInvariant::SetData(TUint a) + { + iData=a; + } + +TUint TEgInvariant::Data() + { + return iData; + } +

TEgInvariant::DoSomeThing() is a function that would perform +some useful work. We verify the object’s state at its beginning and end through __TEST_INVARIANT.

+void TEgInvariant::DoSomeThing() + { + __TEST_INVARIANT; + + //...do something with iData + + __TEST_INVARIANT; + } +

TEgInvariant::__DbgTestInvariant() performs the invariance +test:

+void TEgInvariant::__DbgTestInvariant() const + { +#if defined(_DEBUG) + if(iData > 100) + User::Invariant(); +#endif + } +

We could test the class with the following code:

+ TEgInvariant Eg; + + Eg.SetData(10); + Eg.DoSomeThing(); + + Eg.SetData(1000); + Eg.DoSomeThing(); +

In debug builds, the second call to DoSomeThing() causes +a panic, alerting us to a problem in the code that needs fixing.

\ No newline at end of file