summaryrefslogtreecommitdiff
path: root/tests/test_config.h
blob: 44d11017577bf1e9f7dc6bc8b7a36312e891ce7f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/* -*- C++ -*- */
// $Id$

// ============================================================================
// = FILENAME
//    test_config.h
//
// = AUTHOR
//    Prashant Jain <pjain@cs.wustl.edu> and Tim Harrison <harrison@cs.wustl.edu>
// 
// ============================================================================

#if !defined (ACE_TEST_CONFIG_H)
#define ACE_TEST_CONFIG_H

#include <iostream.h>
#include <fstream.h>

#if defined (ACE_WIN32)
#define ACE_DEFAULT_TEST_FILE "C:\\temp\\ace_test_file"
#define ACE_TEMP_FILE_NAME "C:\\temp\\ace_temp_file"
#define ACE_LOG_DIRECTORY "C:\\temp\\log\\"
#define MAKE_PIPE_NAME(X) "\\\\.\\pipe\\"#X
#else
#define ACE_DEFAULT_TEST_FILE "/tmp/ace_test_file"
#define ACE_TEMP_FILE_NAME "/tmp/ace_temp_file"
#define ACE_LOG_DIRECTORY "log/"
#define MAKE_PIPE_NAME(X) X
#endif /* ACE_WIN32 */

const int ACE_NS_MAX_ENTRIES = 2000;
const int ACE_MAX_TIMERS = 4;
const int ACE_MAX_THREADS = 4;
const int ACE_MAX_DELAY = 10;
const int ACE_MAX_INTERVAL = 0;
const int ACE_MAX_ITERATIONS = 10;

class ACE_Test_Output
{
public:
  ACE_Test_Output (void): output_file_ (0)
    {
    }

  ~ACE_Test_Output (void)
    {
      delete this->output_file_;
    }

  int set_output (char *filename)
    {
      char temp[BUFSIZ];
      // Ignore the error value since the directory may already exist.
      ACE_OS::mkdir (ACE_LOG_DIRECTORY);
      ACE_OS::sprintf (temp, "%s%s%s", 
		       ACE_LOG_DIRECTORY, 
		       ACE::basename (filename, ACE_DIRECTORY_SEPARATOR_CHAR),
		       ".log");

      ACE_NEW_RETURN (this->output_file_, ofstream (temp), -1);
      
      ACE_Log_Msg::instance()->msg_ostream (this->output_file_);
      ACE_Log_Msg::instance()->clr_flags (ACE_Log_Msg::STDERR | ACE_Log_Msg::LOGGER);
      ACE_Log_Msg::instance()->set_flags (ACE_Log_Msg::OSTREAM);
      return 0;
    }

  ofstream *output_file (void)
    {
      return this->output_file_;
    }
  
  void flush (void)
    {
      this->output_file_->flush ();
    }

private:
  ofstream *output_file_;
};

static ACE_Test_Output ace_file_stream;

#define ACE_START_TEST \
  if (ace_file_stream.set_output (argv[0]) == -1) \
    ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "set_output failed"), -1); \
  ACE_DEBUG ((LM_DEBUG, "starting %s test at %T\n", argv[0]));

#define ACE_END_TEST \
  ACE_DEBUG ((LM_DEBUG, "Ending %s test at %T\n", argv[0])); \
  ace_file_stream.flush ();

#define ACE_NEW_THREAD \
  ACE_Log_Msg::instance()->msg_ostream (ace_file_stream.output_file ()); \
  ACE_Log_Msg::instance()->clr_flags (ACE_Log_Msg::STDERR | ACE_Log_Msg::LOGGER ); \
  ACE_Log_Msg::instance()->set_flags (ACE_Log_Msg::OSTREAM);

#endif /* ACE_TEST_CONFIG_H */