Doxygen changes
[ACE_TAO.git] / ACE / tests / test_config.h
blobe606f048a217d9d3462a68900562ddfb1cfa4975
1 // -*- C++ -*-
3 // ============================================================================
4 /**
5 * @file test_config.h
7 * This file factors out common macros and other utilities used by the
8 * ACE automated regression tests. It also shows how to redirect ACE_DEBUG/ACE_ERROR
9 * output to a file.
11 * @author Prashant Jain <pjain@cs.wustl.edu>
12 * @author Tim Harrison <harrison@cs.wustl.edu>
13 * @author David Levine <levine@cs.wustl.edu>
15 // ============================================================================
17 #ifndef ACE_TEST_CONFIG_H
18 #define ACE_TEST_CONFIG_H
20 // This first #undef protects against command-line definitions.
21 #undef ACE_NDEBUG
23 #include "ace/config-all.h"
25 #if !defined (ACE_LACKS_PRAGMA_ONCE)
26 # pragma once
27 #endif /* ACE_LACKS_PRAGMA_ONCE */
29 #if defined (ACE_NLOGGING)
30 // ACE_NLOGGING must not be set if the tests are to produce any output.
31 #undef ACE_NLOGGING
32 #endif /* ACE_NLOGGING */
34 #include "ace/OS_NS_errno.h"
35 #include "ace/OS_NS_stdio.h"
36 #include "ace/Log_Msg.h"
38 #if defined (ACE_HAS_WINCE)
39 // Note that Pocket PC 2002 will NOT create a directory if it does not start with a leading '\'.
40 // PPC 2002 only accepts '\log' as a valid directory name, while 'log\' works under WinCE 3.0.
41 # define ACE_LOG_DIRECTORY_FOR_MKDIR ACE_TEXT ("\\log")
42 # define ACE_LOG_DIRECTORY ACE_TEXT ("\\log\\")
43 # define MAKE_PIPE_NAME(X) ACE_TEXT ("\\\\.\\pipe\\"#X)
44 #elif defined (ACE_WIN32)
45 # define ACE_LOG_DIRECTORY ACE_TEXT ("log\\")
46 # define ACE_LOG_DIRECTORY_FOR_MKDIR ACE_TEXT ("log\\")
47 # define MAKE_PIPE_NAME(X) ACE_TEXT ("\\\\.\\pipe\\"#X)
48 #elif defined (ANDROID)
49 # define ACE_LOG_DIRECTORY_FOR_MKDIR ACE_TEXT ("/sdcard/log/")
50 # define ACE_LOG_DIRECTORY ACE_TEXT ("/sdcard/log/")
51 # define MAKE_PIPE_NAME(X) ACE_TEXT (X)
52 #else
53 # define ACE_LOG_DIRECTORY_FOR_MKDIR ACE_TEXT ("log/")
54 # define ACE_LOG_DIRECTORY ACE_TEXT ("log/")
55 # define MAKE_PIPE_NAME(X) ACE_TEXT (X)
56 #endif /* ACE_WIN32 */
58 #if !defined (ACE_DEFAULT_TEST_DIR)
59 # define ACE_DEFAULT_TEST_DIR ACE_TEXT ("")
60 #endif
62 #if !defined (ACE_LOG_FILE_EXT_NAME)
63 # define ACE_LOG_FILE_EXT_NAME ACE_TEXT (".log")
64 #endif /* ACE_LOG_FILE_EXT_NAME */
66 #if defined (ACE_HAS_WINCE) || defined (ACE_HAS_PHARLAP)
67 size_t const ACE_MAX_CLIENTS = 4;
68 #else
69 size_t const ACE_MAX_CLIENTS = 30;
70 #endif /* ACE_HAS_WINCE */
72 size_t const ACE_NS_MAX_ENTRIES = 1000;
73 size_t const ACE_DEFAULT_USECS = 1000;
74 size_t const ACE_MAX_TIMERS = 4;
75 size_t const ACE_MAX_DELAY = 10;
76 size_t const ACE_MAX_INTERVAL = 0;
77 size_t const ACE_MAX_ITERATIONS = 10;
78 size_t const ACE_MAX_PROCESSES = 10;
79 size_t const ACE_MAX_THREADS = 4;
81 #if defined ACE_HAS_CONSOLE_TEST_OUTPUT
82 #ifndef ACE_START_TEST
83 # define ACE_START_TEST(NAME) const ACE_TCHAR *program = NAME; ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Starting %s test at %D\n"), NAME))
84 #endif /* ACE_START_TEST */
86 #ifndef ACE_END_TEST
87 # define ACE_END_TEST ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Ending %s test %D\n"), program));
88 #endif /* ACE_END_TEST */
89 #endif /* ACE_HAS_CONSOLE_TEST_OUTPUT */
91 #ifdef ACE_TEST_LOG_TO_STDERR
92 # define ACE_TEST_LOG_MSG_FLAGS ACE_Log_Msg::STDERR | ACE_Log_Msg::VERBOSE_LITE
93 # define ACE_TEST_SET_OUTPUT(APPEND)
94 # define ACE_CLOSE_TEST_LOG
95 #else
96 # define ACE_TEST_LOG_MSG_FLAGS ACE_Log_Msg::OSTREAM | ACE_Log_Msg::VERBOSE_LITE
97 # define ACE_TEST_SET_OUTPUT(APPEND) \
98 if (ace_file_stream::instance ()->set_output (program, APPEND) != 0) \
99 ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("set_output failed")), -1);
100 # define ACE_CLOSE_TEST_LOG ace_file_stream::instance ()->close ()
101 #endif
103 #define ACE_START_TEST_TEMPLATE(NAME, APPEND) \
104 const ACE_TCHAR *program = NAME; \
105 if (ACE_LOG_MSG->open (program, ACE_TEST_LOG_MSG_FLAGS) != 0) \
106 ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("open log_msg failed")), -1); \
107 ACE_TEST_SET_OUTPUT (APPEND); \
108 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Starting %s test at %D\n"), program))
110 #ifndef ACE_START_TEST
111 # define ACE_START_TEST(NAME) ACE_START_TEST_TEMPLATE (NAME, 0)
112 #endif /* ACE_START_TEST */
114 #ifndef ACE_END_TEST
115 #define ACE_END_TEST \
116 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Ending %s test at %D\n"), program)); \
117 ACE_CLOSE_TEST_LOG;
118 #endif /* ACE_END_TEST */
120 #ifndef ACE_APPEND_LOG
121 # define ACE_APPEND_LOG(NAME) ACE_START_TEST_TEMPLATE (NAME, 1)
122 #endif /* ACE_APPEND_LOG */
124 #define ACE_END_LOG \
125 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Ending %s test at %D\n\n"), program)); \
126 ACE_LOG_MSG->set_flags(ACE_Log_Msg::SILENT); \
127 ACE_CLOSE_TEST_LOG;
129 #if defined (ACE_VXWORKS)
130 // This is the only way I could figure out to avoid an error
131 // about attempting to unlink a non-existent file.
133 #include "ace/OS_NS_fcntl.h"
135 #define ACE_INIT_LOG(NAME) \
136 ACE_TCHAR temp[MAXPATHLEN]; \
137 ACE_OS::sprintf (temp, ACE_TEXT ("%s%s%s"), \
138 ACE_LOG_DIRECTORY, \
139 ACE::basename (NAME, ACE_DIRECTORY_SEPARATOR_CHAR), \
140 ACE_LOG_FILE_EXT_NAME); \
141 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Deleting old log file %s (if any)\n\n"), temp)); \
142 int fd_init_log; \
143 if ((fd_init_log = ACE_OS::open (temp, \
144 O_WRONLY|O_CREAT, \
145 S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) != ERROR) \
147 ACE_OS::close (fd_init_log); \
148 ACE_OS::unlink (temp); \
151 #else /* ! VXWORKS */
152 # if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR)
153 # define ACE_INIT_LOG_FMT ACE_TEXT ("%ls%ls%ls")
154 # else
155 # define ACE_INIT_LOG_FMT ACE_TEXT ("%s%s%s")
156 # endif /* !ACE_WIN32 && ACE_USES_WCHAR */
157 #define ACE_INIT_LOG(NAME) \
158 ACE_TCHAR temp[MAXPATHLEN]; \
159 ACE_OS::sprintf (temp, ACE_INIT_LOG_FMT, \
160 ACE_LOG_DIRECTORY, \
161 ACE::basename (NAME, ACE_DIRECTORY_SEPARATOR_CHAR), \
162 ACE_LOG_FILE_EXT_NAME); \
163 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Deleting old log file %s (if any)\n\n"), temp)); \
164 ACE_OS::unlink (temp);
165 #endif /* ! VXWORKS */
167 #if defined (ACE_LACKS_IOSTREAM_TOTALLY)
168 #define OFSTREAM FILE
169 #else
170 #define OFSTREAM ofstream
171 #endif /* ACE_LACKS_IOSTREAM_TOTALLY */
173 #include "Test_Output_Export.h"
175 class Test_Output_Export ACE_Test_Output
177 public:
178 ACE_Test_Output (void);
179 ~ACE_Test_Output (void);
180 static ACE_Test_Output *instance (void);
181 int set_output (const ACE_TCHAR *filename, int append = 0);
182 OFSTREAM *output_file (void);
183 void close (void);
184 const ACE_TCHAR *dll_name (void);
185 const ACE_TCHAR *name (void);
186 static void close_singleton (void);
188 private:
189 static ACE_Test_Output *instance_;
191 OFSTREAM *output_file_;
194 typedef ACE_Test_Output ace_file_stream;
196 #endif /* ACE_TEST_CONFIG_H */