[#BloombergLP-ball-TestObserver]
= xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/ball.adoc[ball]::TestObserver
:relfileprefix: ../../
:mrdocs:

This class provides an instrumented implementation of the `Observer` protocol suitable for testing systems that use `Observer`&period; 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&period;

== Synopsis

Declared in `&lt;ball&lowbar;testobserver&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
class TestObserver
    : public xref:BloombergLP/ball/Observer.adoc[Observer]
----

== Description

By default, the `publish` method prints no diagnostic information to the `bsl&colon;&colon;ostream` supplied at construction&period; This diagnostic information can be enabled by a call to `setVerbose` with a non&hyphen;zero argument&period; A subsequent call to `setVerbose` with a zero argument will restore the default behavior of `publish`&period;

== Base Classes

[cols="1,4"]
|===
| Name| Description
| `xref:BloombergLP/ball/Observer.adoc[Observer]`
| This class provides a protocol for receiving and processing log record output&period;
|===

== Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/ball/TestObserver/2constructor-02.adoc[`TestObserver`]         [.small]#[constructor]#
| Constructors
| xref:BloombergLP/ball/TestObserver/2destructor.adoc[`&#126;TestObserver`] [.small]#[destructor]# [.small]#[virtual]#
| Destroy this test observer&period;
| xref:BloombergLP/ball/TestObserver/id.adoc[`id`] 
| Return the unique (per process) integer identifier of this test observer&period;
| xref:BloombergLP/ball/TestObserver/lastPublishedContext.adoc[`lastPublishedContext`] 
| Return a reference to the context most recently published by this test observer&period; The behavior is undefined unless `publish` has been called at least once, and no other thread is manipulating this object concurrently (i&period;e&period;, this function is _not_ thread safe)&period;
| xref:BloombergLP/ball/TestObserver/lastPublishedRecord.adoc[`lastPublishedRecord`] 
| Return a reference to the record most recently published by this test observer&period; The behavior is undefined unless `publish` has been called at least once, and no other thread is manipulating this object concurrently (i&period;e&period;, this function is _not_ thread safe)&period;
| xref:BloombergLP/ball/TestObserver/numPublishedRecords.adoc[`numPublishedRecords`] 
| Return the total number of records that this test observer has published&period;
| xref:BloombergLP/ball/TestObserver/numReleases.adoc[`numReleases`] 
| Return the total number of times that `releaseRecords` has been called on this test observer&period;
| xref:BloombergLP/ball/TestObserver/publish-0b.adoc[`publish`] 
| Store the most recently published log `record` and `context`&period;
| xref:BloombergLP/ball/TestObserver/releaseRecords.adoc[`releaseRecords`]  [.small]#[virtual]#
| Discard any shared reference to a `Record` object that was supplied to the `publish` method, and is held by this observer&period; Note that this operation should be called if resources underlying the previously provided shared&hyphen;pointers must be released&period;
| xref:BloombergLP/ball/TestObserver/setVerbose.adoc[`setVerbose`] 
| Set the internal verbose mode of this test observer to the specified (boolean) `flagValue`&period; The default mode is _not_ verbose&period; If `flagValue` is non&hyphen;zero, calls to `publish` will print appropriate diagnostics to the `bsl&colon;&colon;ostream` associated with this test observer&period; This printing is suppressed if `flagValue` is 0&period;
| xref:BloombergLP/ball/TestObserver/2conversion.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration&lt;TestObserver, UsesBslmaAllocator&gt;`] 
| Declare that this type uses a `bslma` allocator&period;
|===


== Static Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/ball/TestObserver/numInstances.adoc[`numInstances`] 
| Return the total number of instances of this class that have been created since this process has begun&period;
|===



[.small]#Created with https://www.mrdocs.com[MrDocs]#
