summaryrefslogtreecommitdiff
path: root/TAO/tests/ORB_Local_Config/Bunch/Test.cpp
blob: ae61bdaca04389b4b1daaf8d3ca8d1f69641fb0c (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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// $Id$

/// It's a test - we need ACE_ASSERT
#ifdef ACE_NDEBUG
#  undef ACE_NDEBUG
#endif

// The following is required to be able to access
// ace_svc_desc_TAO_*_Parser, below
#include "tao/CORBALOC_Parser.h"
#include "tao/CORBANAME_Parser.h"

#include "ace/ARGV.h"
#include "ace/Service_Config.h"
#include "ace/Dynamic_Service.h"

ACE_RCSID (tests, server, "$Id$")


#include "Service_Configuration_Per_ORB.h"

// @brief The "new" interfaces must be compatible with the "old" ones

int
testCompatibility (int , ACE_TCHAR *[])
{
  ACE_TRACE ("testCompatibility");

  // This uses the same default ACE_Service_Repository
  ACE_Service_Gestalt_Test glob;

  // Use the "old" interface
  ACE_ASSERT (0 == ACE_Service_Config::process_directive
                     (ace_svc_desc_TAO_CORBANAME_Parser));
  ACE_ASSERT (0 == ACE_Service_Config::process_directive
                     (ace_svc_desc_TAO_CORBALOC_Parser));

  {
    // This uses the same default ACE_Service_Repository
    ACE_Service_Gestalt_Test one;

    ACE_Service_Object* p20 =
      ACE_Dynamic_Service<ACE_Service_Object>::instance (&one, "CORBANAME_Parser");
    ACE_ASSERT ((p20 != 0));

    ACE_Service_Object* p21 =
      ACE_Dynamic_Service<ACE_Service_Object>::instance (&one, "CORBALOC_Parser");
    ACE_ASSERT ((p21 != 0));

    ACE_DEBUG ((LM_DEBUG, "\tglobal.services_count () -> %d\n",
                one.services_count ()));
    ACE_ASSERT (one.services_count () > 2);

    // Exiting this scope should fini all services ...
  }

  ACE_Service_Object* p20 =
    ACE_Dynamic_Service<ACE_Service_Object>::instance (&glob, "CORBANAME_Parser");
  ACE_ASSERT ((p20 == 0));

  ACE_Service_Object* p21 =
    ACE_Dynamic_Service<ACE_Service_Object>::instance (&glob, "CORBALOC_Parser");
  ACE_ASSERT ((p21 == 0));

  return 0;
}

// @brief Test commandline processing


int
testCommandLineDirectives (int , ACE_TCHAR *[])
{
  ACE_TRACE ("testCommandLineDirectives");

  ACE_ARGV new_argv;
  ACE_ASSERT (new_argv.add (ACE_TEXT ("-f")) != -1
              && new_argv.add (ACE_TEXT ("-S")) != -1
              && new_argv.add (ACE_TEXT ("d1")) != -1
              && new_argv.add (ACE_TEXT ("-S")) != -1
              && new_argv.add (ACE_TEXT ("d2")) != -1);

  ACE_Service_Gestalt_Test g(5);
  ACE_ASSERT (g.parse_args (new_argv.argc (),
                            new_argv.argv ()) != -1
              || errno == ENOENT);

  ACE_DEBUG ((LM_DEBUG, "\tg.command_line_directives_count () -> %d\n",
              g.command_line_directives_count ()));

  ACE_ASSERT (2 == g.command_line_directives_count ());
  return 0;
}





// @brief Test the helper components used to implement the temporary
// substitution of the repository currently used as "global" for the
// sake of registering static services, which are dependent on a dynamic
// service

int
testTSSGestalt (int , ACE_TCHAR *[])
{
  ACE_TRACE ("testTSSGestalt");

  ACE_Service_Gestalt_Test one (10);  // Localized ones go here

  ACE_Service_Gestalt *global_instance = ACE_Service_Config::instance ();

  ACE_ASSERT (global_instance == ACE_Service_Config::instance ());
  ACE_ASSERT (global_instance != &one);

  {
    ACE_Service_Config_Guard temporary (&one);

    ACE_Service_Gestalt *global_instance2 = ACE_Service_Config::instance ();

    ACE_ASSERT (global_instance != global_instance2);
    ACE_ASSERT (global_instance2 == &one);
  }

  ACE_ASSERT (global_instance == ACE_Service_Config::instance ());
  ACE_ASSERT (global_instance != &one);

  return 0;
}



// @brief the main driver

int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  testCompatibility (argc, argv);
  testCommandLineDirectives (argc, argv);
  testTSSGestalt(argc, argv);
  return 0;
}