BDE 4.14.0 Production release
Loading...
Searching...
No Matches
ball::TestObserver Class Reference

#include <ball_testobserver.h>

Inheritance diagram for ball::TestObserver:
ball::Observer

Public Member Functions

 BSLMF_NESTED_TRAIT_DECLARATION (TestObserver, bslma::UsesBslmaAllocator)
 
 TestObserver (bsl::ostream *stream, bslma::Allocator *basicAllocator=0)
 
 TestObserver (bsl::ostream &stream, bslma::Allocator *basicAllocator=0)
 
 ~TestObserver () BSLS_KEYWORD_OVERRIDE
 Destroy this test observer.
 
void publish (const Record &record, const Context &context) BSLS_KEYWORD_OVERRIDE
 
void publish (const bsl::shared_ptr< const Record > &record, const Context &context) BSLS_KEYWORD_OVERRIDE
 
void releaseRecords () BSLS_KEYWORD_OVERRIDE
 
void setVerbose (int flagValue)
 
int id () const
 
const ContextlastPublishedContext () const
 
const RecordlastPublishedRecord () const
 
int numPublishedRecords () const
 
int numReleases () const
 
- Public Member Functions inherited from ball::Observer
virtual ~Observer ()
 Destroy this observer.
 

Static Public Member Functions

static int numInstances ()
 

Detailed Description

This class provides an instrumented implementation of the Observer protocol suitable for testing systems that use Observer. Each instance receives a unique (per process) integer identifier at construction, and keeps count of the number of records that it has published, as well as the contents of the most recently published record and context.

By default, the publish method prints no diagnostic information to the bsl::ostream supplied at construction. This diagnostic information can be enabled by a call to setVerbose with a non-zero argument. A subsequent call to setVerbose with a zero argument will restore the default behavior of publish.

See ball_testobserver

Constructor & Destructor Documentation

◆ TestObserver() [1/2]

ball::TestObserver::TestObserver ( bsl::ostream *  stream,
bslma::Allocator basicAllocator = 0 
)
inlineexplicit

Create a test observer having a unique integer identifier, whose publish method will print diagnostic information (if any) to the specified stream. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used. By default, this observer prints nothing to stream. Note that the setVerbose method can affect this default behavior.

◆ TestObserver() [2/2]

ball::TestObserver::TestObserver ( bsl::ostream &  stream,
bslma::Allocator basicAllocator = 0 
)
inlineexplicit

Create a test observer having a unique integer identifier, whose publish method will print diagnostic information (if any) to the specified stream. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used. By default, this observer prints nothing to stream. Note that the setVerbose method can affect this default behavior.

Deprecated:
Use the constructor taking bsl::ostream * instead.

◆ ~TestObserver()

ball::TestObserver::~TestObserver ( )

Member Function Documentation

◆ BSLMF_NESTED_TRAIT_DECLARATION()

ball::TestObserver::BSLMF_NESTED_TRAIT_DECLARATION ( TestObserver  ,
bslma::UsesBslmaAllocator   
)

◆ id()

int ball::TestObserver::id ( ) const
inline

Return the unique (per process) integer identifier of this test observer.

◆ lastPublishedContext()

const Context & ball::TestObserver::lastPublishedContext ( ) const
inline

Return a reference to the context most recently published by this test observer. The behavior is undefined unless publish has been called at least once, and no other thread is manipulating this object concurrently (i.e., this function is not thread safe).

◆ lastPublishedRecord()

const Record & ball::TestObserver::lastPublishedRecord ( ) const
inline

Return a reference to the record most recently published by this test observer. The behavior is undefined unless publish has been called at least once, and no other thread is manipulating this object concurrently (i.e., this function is not thread safe).

◆ numInstances()

int ball::TestObserver::numInstances ( )
inlinestatic

Return the total number of instances of this class that have been created since this process has begun.

◆ numPublishedRecords()

int ball::TestObserver::numPublishedRecords ( ) const
inline

Return the total number of records that this test observer has published.

◆ numReleases()

int ball::TestObserver::numReleases ( ) const
inline

Return the total number of times that releaseRecords has been called on this test observer.

◆ publish() [1/2]

void ball::TestObserver::publish ( const bsl::shared_ptr< const Record > &  record,
const Context context 
)
virtual

Store as the most recently published data the specified log record and publishing context. If this test observer is in verbose mode, print an appropriate diagnostic message to the stream specified at construction. Note that at construction test observers are not in verbose mode, but that the setVerbose method can affect this mode, and thus the behavior of this method.

Reimplemented from ball::Observer.

◆ publish() [2/2]

void ball::TestObserver::publish ( const Record record,
const Context context 
)
virtual

Store as the most recently published data the specified log record and publishing context. If this test observer is in verbose mode, print an appropriate diagnostic message to the stream specified at construction. Note that at construction test observers are not in verbose mode, but that the setVerbose method can affect this mode, and thus the behavior of this method.

Deprecated:
Use the alternative publish overload instead.

Reimplemented from ball::Observer.

◆ releaseRecords()

void ball::TestObserver::releaseRecords ( )
inlinevirtual

Discard any shared reference to a Record object that was supplied to the publish method, and is held by this observer. Note that this operation should be called if resources underlying the previously provided shared-pointers must be released.

Reimplemented from ball::Observer.

◆ setVerbose()

void ball::TestObserver::setVerbose ( int  flagValue)
inline

Set the internal verbose mode of this test observer to the specified (boolean) flagValue. The default mode is not verbose. If flagValue is non-zero, calls to publish will print appropriate diagnostics to the bsl::ostream associated with this test observer. This printing is suppressed if flagValue is 0.


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