2 //=============================================================================
4 * @file Log_Msg_Backend_Test.cpp
6 * This program tests the ACE_Log_Msg class's use of a custom backend,
7 * including its initialization and reset as well as logging information
10 * @author Steve Huston <shuston@riverace.com>
12 //=============================================================================
14 #include "test_config.h"
16 #include "ace/Log_Msg.h"
17 #include "ace/Log_Msg_Backend.h"
18 #include "ace/Log_Record.h"
20 class Backend
: public ACE_Log_Msg_Backend
24 : reset_ (false), open_ (false), close_ (false), log_count_ (0) {}
26 //FUZZ: disable check_for_lack_ACE_OS
27 ///FUZZ: enable check_for_lack_ACE_OS
28 int open (const ACE_TCHAR
*logger_key
) override
;
30 int reset () override
;
32 //FUZZ: disable check_for_lack_ACE_OS
33 ///FUZZ: enable check_for_lack_ACE_OS
34 int close () override
;
36 ssize_t
log (ACE_Log_Record
&log_record
) override
;
38 // Test probes to see if things worked as specified.
39 bool hooks_ok () const;
40 unsigned int log_count () const { return this->log_count_
; }
46 unsigned int log_count_
;
50 Backend::open (const ACE_TCHAR
*)
70 Backend::log (ACE_Log_Record
&)
76 // Test probes to see if things worked as specified.
78 Backend::hooks_ok () const
80 // Close should not have been called yet.
81 const ACE_TCHAR
*yes
= ACE_TEXT ("yes");
82 const ACE_TCHAR
*no
= ACE_TEXT ("no");
84 ACE_TEXT ("Open: %s, Reset: %s, Close: %s\n"),
85 this->open_
? yes
: no
,
86 this->reset_
? yes
: no
,
87 this->close_
? yes
: no
));
88 return this->open_
&& this->reset_
&& !this->close_
;
94 run_main (int, ACE_TCHAR
*[])
96 // Set up the backend prior to ACE_START_TEST so the initialization can
97 // call the back end's reset().
99 ACE_Log_Msg_Backend
*old_b
= ACE_Log_Msg::msg_backend (&b
);
101 ACE_START_TEST (ACE_TEXT ("Log_Msg_Backend_Test"));
107 ACE_ERROR ((LM_ERROR
,
108 ACE_TEXT ("Old backend (%@) not 0 at start\n"),
113 // Reopen to get the backend established.
114 u_long flags
= ACE_LOG_MSG
->flags ();
115 flags
|= ACE_Log_Msg::CUSTOM
;
116 if (-1 == ACE_LOG_MSG
->open (ACE_TEXT ("Log_Msg_Backend_Test"), flags
))
118 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("%p\n"), ACE_TEXT ("Reopening log")));
122 // Make sure messages are getting routed correctly.
123 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Message 1\n")));
124 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Message 2\n")));
125 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Message 3\n")));
126 unsigned int count
= b
.log_count ();
129 ACE_ERROR ((LM_ERROR
,
130 ACE_TEXT ("Backend counted %u; expected 3\n"),
135 // Should have seen the hooks other than close() so far. Note that
136 // hooks_ok() logs a message so check counts before checking hooks.
139 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("Hooks not called correctly\n")));
145 // Reset the backend to avoid references to our soon-to-be-destroyed one.
146 ACE_Log_Msg::msg_backend (old_b
);