Use override/default for RTPortableServer
[ACE_TAO.git] / ACE / tests / Log_Msg_Backend_Test.cpp
blob8a37c7a118a3e7ad48b9e0655c547b1bd1edb6e9
2 //=============================================================================
3 /**
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
8 * through the backend.
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
22 public:
23 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_; }
42 private:
43 bool reset_;
44 bool open_;
45 bool close_;
46 unsigned int log_count_;
49 int
50 Backend::open (const ACE_TCHAR *)
52 this->open_ = true;
53 return 0;
56 int
57 Backend::reset ()
59 this->reset_ = true;
60 return 0;
63 int
64 Backend::close ()
66 return 0;
69 ssize_t
70 Backend::log (ACE_Log_Record &)
72 ++this->log_count_;
73 return 1;
76 // Test probes to see if things worked as specified.
77 bool
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");
83 ACE_DEBUG ((LM_DEBUG,
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_;
91 // Main function.
93 int
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().
98 Backend b;
99 ACE_Log_Msg_Backend *old_b = ACE_Log_Msg::msg_backend (&b);
101 ACE_START_TEST (ACE_TEXT ("Log_Msg_Backend_Test"));
103 int status = 0;
105 if (old_b != 0)
107 ACE_ERROR ((LM_ERROR,
108 ACE_TEXT ("Old backend (%@) not 0 at start\n"),
109 old_b));
110 ++status;
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")));
119 ++status;
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 ();
127 if (count != 3)
129 ACE_ERROR ((LM_ERROR,
130 ACE_TEXT ("Backend counted %u; expected 3\n"),
131 count));
132 ++status;
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.
137 if (!b.hooks_ok ())
139 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Hooks not called correctly\n")));
140 ++status;
143 ACE_END_TEST;
145 // Reset the backend to avoid references to our soon-to-be-destroyed one.
146 ACE_Log_Msg::msg_backend (old_b);
148 return status;