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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
|
// **********************************************************************
//
// Copyright (c) 2003-2016 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************
using System;
using System.Diagnostics;
namespace TestCommon
{
public abstract class Application
{
public
Application()
{
}
//
// This runmain() must be called by the global main(). runmain()
// initializes the Communicator, calls run(), and destroys
// the Communicator upon return from run(). It thereby handles
// all exceptions properly, i.e., error messages are printed
// if exceptions propagate to main(), and the Communicator is
// always destroyed, regardless of exceptions.
//
public int runmain(string[] args)
{
Ice.InitializationData initData = getInitData(ref args);
return runmain(args, initData);
}
public int runmain(string[] args, Ice.InitializationData initializationData)
{
_testName = AppDomain.CurrentDomain.FriendlyName;
if(_communicator != null)
{
Console.Out.WriteLine(_testName + ": only one instance of the Application class can be used");
return 1;
}
//
// We parse the properties here to extract Ice.ProgramName.
//
if(initializationData == null)
{
initializationData = getInitData(ref args);
}
Ice.InitializationData initData;
if(initializationData != null)
{
initData = (Ice.InitializationData)initializationData.Clone();
}
else
{
initData = new Ice.InitializationData();
}
initData.properties = Ice.Util.createProperties(ref args, initData.properties);
//
// If the process logger is the default logger, we replace it with a
// a logger that uses the program name as the prefix.
//
if(Ice.Util.getProcessLogger() is Ice.LoggerI)
{
Ice.Util.setProcessLogger(new Ice.ConsoleLoggerI(initData.properties.getProperty("Ice.ProgramName")));
}
int status = 0;
try
{
_communicator = Ice.Util.initialize(ref args, initData);
status = run(args);
}
catch(Exception ex)
{
Console.Out.WriteLine(_testName + ": " + ex);
status = 1;
}
if(_communicator != null)
{
_communicator.destroy();
_communicator = null;
}
return status;
}
public void stop()
{
if(_communicator != null)
{
_communicator.shutdown();
}
}
public abstract int run(string[] args);
//
// Hook to override the initialization data. This hook is
// necessary because some properties must be set prior to
// communicator initialization.
//
protected virtual Ice.InitializationData getInitData(ref string[] args)
{
Ice.InitializationData initData = new Ice.InitializationData();
initData.properties = Ice.Util.createProperties(ref args);
args = initData.properties.parseCommandLineOptions("Test", args);
return initData;
}
//
// Return the application name, i.e., argv[0].
//
public string appName()
{
return _testName;
}
public Ice.Communicator communicator()
{
return _communicator;
}
public string getTestEndpoint(int num)
{
return getTestEndpoint(num, "");
}
public string getTestEndpoint(int num, string prot)
{
return getTestEndpoint(_communicator.getProperties(), num, prot);
}
static public string getTestEndpoint(Ice.Properties properties, int num)
{
return getTestEndpoint(properties, num, "");
}
static public string getTestEndpoint(Ice.Properties properties, int num, string prot)
{
string protocol = prot;
if(protocol == "")
{
protocol = properties.getPropertyWithDefault("Ice.Default.Protocol", "default");
}
int basePort = properties.getPropertyAsIntWithDefault("Test.BasePort", 12010);
return protocol + " -p " + (basePort + num);
}
public string getTestHost()
{
return getTestHost(_communicator.getProperties());
}
static public string getTestHost(Ice.Properties properties)
{
return properties.getPropertyWithDefault("Ice.Default.Host", "127.0.0.1");
}
public string getTestProtocol()
{
return getTestProtocol(_communicator.getProperties());
}
static public string getTestProtocol(Ice.Properties properties)
{
return properties.getPropertyWithDefault("Ice.Default.Protocol", "tcp");
}
public int getTestPort(int num)
{
return getTestPort(_communicator.getProperties(), num);
}
static public int getTestPort(Ice.Properties properties, int num)
{
return properties.getPropertyAsIntWithDefault("Test.BasePort", 12010) + num;
}
protected static void test(bool b)
{
if(!b)
{
Debug.Assert(false);
throw new Exception();
}
}
private string _testName;
private Ice.Communicator _communicator;
}
public abstract class AllTests
{
protected static void test(bool b)
{
if(!b)
{
Debug.Assert(false);
throw new Exception();
}
}
public static void Write(string msg)
{
Console.Out.Write(msg);
}
public static void WriteLine(string msg)
{
Console.Out.WriteLine(msg);
}
public static void Flush()
{
Console.Out.Flush();
}
}
}
|