Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / orbsvcs / tests / HTIOP / test_config.h
blobd44559b8963e37ef96d7ef7daa28060f65570375
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 #else
49 # define ACE_LOG_DIRECTORY_FOR_MKDIR ACE_TEXT ("log/")
50 # define ACE_LOG_DIRECTORY ACE_TEXT ("log/")
51 # define MAKE_PIPE_NAME(X) ACE_TEXT (X)
52 #endif /* ACE_WIN32 */
54 #if !defined (ACE_DEFAULT_TEST_DIR)
55 # define ACE_DEFAULT_TEST_DIR ACE_TEXT ("")
56 #endif
58 #define ACE_LOG_FILE_EXT_NAME ACE_TEXT (".log")
60 #if defined (ACE_HAS_WINCE) || defined (ACE_HAS_PHARLAP)
61 size_t const ACE_MAX_CLIENTS = 4;
62 #else
63 size_t const ACE_MAX_CLIENTS = 30;
64 #endif /* ACE_HAS_WINCE */
66 size_t const ACE_NS_MAX_ENTRIES = 1000;
67 size_t const ACE_DEFAULT_USECS = 1000;
68 size_t const ACE_MAX_TIMERS = 4;
69 size_t const ACE_MAX_DELAY = 10;
70 size_t const ACE_MAX_INTERVAL = 0;
71 size_t const ACE_MAX_ITERATIONS = 10;
72 size_t const ACE_MAX_PROCESSES = 10;
73 size_t const ACE_MAX_THREADS = 4;
75 #ifndef ACE_START_TEST
76 #define ACE_START_TEST(NAME) \
77 const ACE_TCHAR *program = NAME; \
78 if (ACE_LOG_MSG->open (program, ACE_Log_Msg::OSTREAM | ACE_Log_Msg::VERBOSE_LITE) != 0) \
79 ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("open log_msg failed")), -1); \
80 if (ace_file_stream::instance()->set_output (program) != 0) \
81 ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("set_output failed")), -1); \
82 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Starting %s test at %D\n"), program))
83 #endif /* ACE_START_TEST */
85 #ifndef ACE_END_TEST
86 #define ACE_END_TEST \
87 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Ending %s test at %D\n"), program)); \
88 ace_file_stream::instance()->close ()
89 #endif /* ACE_END_TEST */
91 #define ACE_CLOSE_TEST_LOG ace_file_stream::instance()->close ()
93 #define ACE_APPEND_LOG(NAME) \
94 const ACE_TCHAR *program = NAME; \
95 if (ACE_LOG_MSG->open (program, ACE_Log_Msg::OSTREAM | ACE_Log_Msg::VERBOSE_LITE) != 0) \
96 ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("open log_msg failed")), -1); \
97 if (ace_file_stream::instance()->set_output (program, 1) != 0) \
98 ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("set_output failed")), -1); \
99 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Starting %s test at %D\n"), program));
101 #define ACE_END_LOG \
102 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Ending %s test at %D\n\n"), program)); \
103 ACE_LOG_MSG->set_flags(ACE_Log_Msg::SILENT); \
104 ace_file_stream::instance()->close ();
106 #if defined (ACE_VXWORKS)
107 // This is the only way I could figure out to avoid an error
108 // about attempting to unlink a non-existent file.
110 #include "ace/OS_NS_fcntl.h"
112 #define ACE_INIT_LOG(NAME) \
113 ACE_TCHAR temp[MAXPATHLEN]; \
114 ACE_OS::sprintf (temp, ACE_TEXT ("%s%s%s"), \
115 ACE_LOG_DIRECTORY, \
116 ACE::basename (NAME, ACE_DIRECTORY_SEPARATOR_CHAR), \
117 ACE_LOG_FILE_EXT_NAME); \
118 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Deleting old log file %s (if any)\n\n"), temp)); \
119 int fd_init_log; \
120 if ((fd_init_log = ACE_OS::open (temp, \
121 O_WRONLY|O_CREAT, \
122 S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) != ERROR) \
124 ACE_OS::close (fd_init_log); \
125 ACE_OS::unlink (temp); \
128 #else /* ! VXWORKS */
129 # if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR)
130 # define ACE_INIT_LOG_FMT ACE_TEXT ("%ls%ls%ls")
131 # else
132 # define ACE_INIT_LOG_FMT ACE_TEXT ("%s%s%s")
133 # endif /* !ACE_WIN32 && ACE_USES_WCHAR */
134 #define ACE_INIT_LOG(NAME) \
135 ACE_TCHAR temp[MAXPATHLEN]; \
136 ACE_OS::sprintf (temp, ACE_INIT_LOG_FMT, \
137 ACE_LOG_DIRECTORY, \
138 ACE::basename (NAME, ACE_DIRECTORY_SEPARATOR_CHAR), \
139 ACE_LOG_FILE_EXT_NAME); \
140 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Deleting old log file %s (if any)\n\n"), temp)); \
141 ACE_OS::unlink (temp);
142 #endif /* ! VXWORKS */
144 #if defined (ACE_LACKS_IOSTREAM_TOTALLY)
145 #define OFSTREAM FILE
146 #else
147 #define OFSTREAM ofstream
148 #endif /* ACE_LACKS_IOSTREAM_TOTALLY */
150 class ACE_Test_Output
152 public:
153 ACE_Test_Output (void);
154 ~ACE_Test_Output (void);
155 static ACE_Test_Output *instance (void);
156 int set_output (const ACE_TCHAR *filename, int append = 0);
157 OFSTREAM *output_file (void);
158 void close (void);
159 const ACE_TCHAR *dll_name (void);
160 const ACE_TCHAR *name (void);
161 static void close_singleton (void);
163 private:
164 static ACE_Test_Output *instance_;
166 OFSTREAM *output_file_;
169 typedef ACE_Test_Output ace_file_stream;
171 #endif /* ACE_TEST_CONFIG_H */