Bdb packages | Design docs | Source docs | Guidelines | Recent releases

Search | Site Map .

Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

/CdbBdbTests/CdbBdbTestIterator.cc

Go to the documentation of this file.
00001 /// The implementation of the CdbBdbTestIterator class.
00002 /**
00003   * @see CdbBdbTestIterator
00004   */
00005 
00006 #include "CdbBdbTests/CdbBdbTestIterator.hh"
00007 #include "CdbBase/CdbPathNameItr.hh"
00008 
00009 #include <assert.h>
00010 
00011 /// This is the generic solution for the test
00012 ///
00013 template < class T >
00014 void
00015 CdbBdbTestIterator<T>::exerciseIterator( )
00016 {
00017   // Check default constructor for the iterator and compatibility
00018   // with the base type.
00019 
00020     T                          itr;
00021     typename T::InterfaceType& ifaceItr = itr;
00022 
00023   // Check constructors and assignment operators
00024 
00025     T itr1( itr );
00026     T itr2( 0 );
00027     T itr3 = itr;
00028 //    T itr4 = 0;
00029 
00030   // Check the cloning. This operation should return non 0 pointer.
00031 
00032     typename T::InterfaceType* ifaceItrPtr = itr.clone( );
00033     assert( 0 != ifaceItrPtr );
00034 
00035   // Check the iterator interface
00036   //
00037   // Note, that these tests are done against the base interface of
00038   // the iterator instead of its concrete instance.
00039 
00040     CdbStatus status = ifaceItr.reset( );
00041     assert( CdbStatus::Error == status );
00042 
00043     bool nextIsOk = ifaceItr.next( );
00044     assert( false == nextIsOk );
00045 
00046     bool isValid = ifaceItr.isValid( );
00047     assert( false == isValid );
00048 
00049     if( isValid ) {
00050 
00051       // The following code, which msut never be executed, will compile but will
00052       // crash because the iterator's context is not setup yet.
00053 
00054         typename T::ValueType value = ifaceItr.value( );
00055 
00056         assert( 0 );
00057     }
00058 }
00059 
00060 /// This is a specialized solution for specified class
00061 /// whose interface differs from others.
00062 template <>
00063 void
00064 CdbBdbTestIterator<CdbPathNameItr>::exerciseIterator( )
00065 {
00066   // Check default constructor for the iterator and compatibility
00067   // with the base type.
00068 
00069     CdbPathNameItr                 itr;
00070     CdbPathNameItr::InterfaceType& ifaceItr = itr;
00071 
00072   // Check constructors and assignment operators
00073 
00074     CdbPathNameItr itr1( itr );
00075     CdbPathNameItr itr3 = itr;
00076 
00077   // Check the cloning. This operation should return non 0 pointer.
00078 
00079     CdbPathNameItr::InterfaceType* ifaceItrPtr = itr.clone( );
00080     assert( 0 != ifaceItrPtr );
00081 
00082   // Check the iterator interface
00083   //
00084   // Note, that these tests are done against the base interface of
00085   // the iterator instead of its concrete instance.
00086 
00087     CdbStatus status = ifaceItr.reset( );
00088     assert( CdbStatus::Error == status );
00089 
00090     bool nextIsOk = ifaceItr.next( );
00091     assert( false == nextIsOk );
00092 
00093     bool isValid = ifaceItr.isValid( );
00094     assert( false == isValid );
00095 
00096     if( isValid ) {
00097 
00098       // The following code, which msut never be executed, will compile but will
00099       // crash because the iterator's context is not setup yet.
00100 
00101         CdbPathNameItr::ValueType value = ifaceItr.value( );
00102 
00103         assert( 0 );
00104     }
00105 }
00106 
00107 /////////////////
00108 // End Of File //
00109 /////////////////

 


BaBar Public Site | SLAC | News | Links | Who's Who | Contact Us

Page Owner: Jacek Becla
Last Update: October 04, 2002