David Reiss | ea2cba8 | 2009-03-30 21:35:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 20 | using System; |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 21 | using System.Linq; |
| 22 | using System.Diagnostics; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 23 | using System.Collections.Generic; |
David Reiss | d831a21 | 2009-02-13 03:09:52 +0000 | [diff] [blame] | 24 | using System.Threading; |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 25 | using System.Security.Cryptography.X509Certificates; |
David Reiss | d831a21 | 2009-02-13 03:09:52 +0000 | [diff] [blame] | 26 | using Thrift.Collections; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 27 | using Thrift.Protocol; |
| 28 | using Thrift.Transport; |
| 29 | using Thrift.Test; |
Nobuaki Sukegawa | 474ddbd | 2016-02-17 23:44:27 +0900 | [diff] [blame] | 30 | using System.Security.Authentication; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 31 | |
| 32 | namespace Test |
| 33 | { |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 34 | public class TestClient |
| 35 | { |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 36 | private class TestParams |
| 37 | { |
| 38 | public int numIterations = 1; |
| 39 | public string host = "localhost"; |
| 40 | public int port = 9090; |
| 41 | public string url; |
| 42 | public string pipe; |
| 43 | public bool buffered; |
| 44 | public bool framed; |
| 45 | public string protocol; |
| 46 | public bool encrypted = false; |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame] | 47 | protected bool _isFirstTransport = true; |
| 48 | |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 49 | |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 50 | public TTransport CreateTransport() |
| 51 | { |
| 52 | if (url == null) |
| 53 | { |
| 54 | // endpoint transport |
| 55 | TTransport trans = null; |
| 56 | if (pipe != null) |
| 57 | trans = new TNamedPipeClientTransport(pipe); |
| 58 | else |
| 59 | { |
| 60 | if (encrypted) |
| 61 | { |
Nobuaki Sukegawa | 88c5ee7 | 2016-09-04 18:49:18 +0900 | [diff] [blame^] | 62 | string certPath = "../keys/client.p12"; |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 63 | X509Certificate cert = new X509Certificate2(certPath, "thrift"); |
Nobuaki Sukegawa | 474ddbd | 2016-02-17 23:44:27 +0900 | [diff] [blame] | 64 | trans = new TTLSSocket(host, port, 0, cert, (o, c, chain, errors) => true, null, SslProtocols.Tls); |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 65 | } |
| 66 | else |
| 67 | { |
| 68 | trans = new TSocket(host, port); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | // layered transport |
| 73 | if (buffered) |
| 74 | trans = new TBufferedTransport(trans); |
| 75 | if (framed) |
| 76 | trans = new TFramedTransport(trans); |
| 77 | |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame] | 78 | if (_isFirstTransport) |
| 79 | { |
| 80 | //ensure proper open/close of transport |
| 81 | trans.Open(); |
| 82 | trans.Close(); |
| 83 | _isFirstTransport = false; |
| 84 | } |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 85 | return trans; |
| 86 | } |
| 87 | else |
| 88 | { |
| 89 | return new THttpClient(new Uri(url)); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | public TProtocol CreateProtocol(TTransport transport) |
| 94 | { |
| 95 | if (protocol == "compact") |
| 96 | return new TCompactProtocol(transport); |
| 97 | else if (protocol == "json") |
| 98 | return new TJSONProtocol(transport); |
| 99 | else |
| 100 | return new TBinaryProtocol(transport); |
| 101 | } |
| 102 | }; |
| 103 | |
| 104 | private const int ErrorBaseTypes = 1; |
| 105 | private const int ErrorStructs = 2; |
| 106 | private const int ErrorContainers = 4; |
| 107 | private const int ErrorExceptions = 8; |
| 108 | private const int ErrorUnknown = 64; |
| 109 | |
| 110 | private class ClientTest |
| 111 | { |
| 112 | private readonly TTransport transport; |
| 113 | private readonly ThriftTest.Client client; |
| 114 | private readonly int numIterations; |
| 115 | private bool done; |
| 116 | |
| 117 | public int ReturnCode { get; set; } |
| 118 | |
| 119 | public ClientTest(TestParams param) |
| 120 | { |
| 121 | transport = param.CreateTransport(); |
| 122 | client = new ThriftTest.Client(param.CreateProtocol(transport)); |
| 123 | numIterations = param.numIterations; |
| 124 | } |
| 125 | public void Execute() |
| 126 | { |
| 127 | if (done) |
| 128 | { |
| 129 | Console.WriteLine("Execute called more than once"); |
| 130 | throw new InvalidOperationException(); |
| 131 | } |
| 132 | |
| 133 | for (int i = 0; i < numIterations; i++) |
| 134 | { |
| 135 | try |
| 136 | { |
| 137 | if (!transport.IsOpen) |
| 138 | transport.Open(); |
| 139 | } |
| 140 | catch (TTransportException ex) |
| 141 | { |
| 142 | Console.WriteLine("*** FAILED ***"); |
| 143 | Console.WriteLine("Connect failed: " + ex.Message); |
| 144 | ReturnCode |= ErrorUnknown; |
| 145 | Console.WriteLine(ex.Message + " ST: " + ex.StackTrace); |
| 146 | continue; |
| 147 | } |
| 148 | |
| 149 | try |
| 150 | { |
| 151 | ReturnCode |= ExecuteClientTest(client); |
| 152 | } |
| 153 | catch (Exception ex) |
| 154 | { |
| 155 | Console.WriteLine("*** FAILED ***"); |
| 156 | Console.WriteLine(ex.Message + " ST: " + ex.StackTrace); |
| 157 | ReturnCode |= ErrorUnknown; |
| 158 | } |
| 159 | } |
| 160 | try |
| 161 | { |
| 162 | transport.Close(); |
| 163 | } |
| 164 | catch(Exception ex) |
| 165 | { |
| 166 | Console.WriteLine("Error while closing transport"); |
| 167 | Console.WriteLine(ex.Message + " ST: " + ex.StackTrace); |
| 168 | } |
| 169 | done = true; |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | public static int Execute(string[] args) |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 174 | { |
| 175 | try |
| 176 | { |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 177 | TestParams param = new TestParams(); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 178 | int numThreads = 1; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 179 | try |
| 180 | { |
| 181 | for (int i = 0; i < args.Length; i++) |
| 182 | { |
| 183 | if (args[i] == "-u") |
| 184 | { |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 185 | param.url = args[++i]; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 186 | } |
| 187 | else if (args[i] == "-n") |
| 188 | { |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 189 | param.numIterations = Convert.ToInt32(args[++i]); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 190 | } |
| 191 | else if (args[i] == "-pipe") // -pipe <name> |
| 192 | { |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 193 | param.pipe = args[++i]; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 194 | Console.WriteLine("Using named pipes transport"); |
| 195 | } |
| 196 | else if (args[i].Contains("--host=")) |
| 197 | { |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 198 | param.host = args[i].Substring(args[i].IndexOf("=") + 1); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 199 | } |
| 200 | else if (args[i].Contains("--port=")) |
| 201 | { |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 202 | param.port = int.Parse(args[i].Substring(args[i].IndexOf("=")+1)); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 203 | } |
| 204 | else if (args[i] == "-b" || args[i] == "--buffered" || args[i] == "--transport=buffered") |
| 205 | { |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 206 | param.buffered = true; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 207 | Console.WriteLine("Using buffered sockets"); |
| 208 | } |
| 209 | else if (args[i] == "-f" || args[i] == "--framed" || args[i] == "--transport=framed") |
| 210 | { |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 211 | param.framed = true; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 212 | Console.WriteLine("Using framed transport"); |
| 213 | } |
| 214 | else if (args[i] == "-t") |
| 215 | { |
| 216 | numThreads = Convert.ToInt32(args[++i]); |
| 217 | } |
| 218 | else if (args[i] == "--compact" || args[i] == "--protocol=compact") |
| 219 | { |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 220 | param.protocol = "compact"; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 221 | Console.WriteLine("Using compact protocol"); |
| 222 | } |
| 223 | else if (args[i] == "--json" || args[i] == "--protocol=json") |
| 224 | { |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 225 | param.protocol = "json"; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 226 | Console.WriteLine("Using JSON protocol"); |
| 227 | } |
| 228 | else if (args[i] == "--ssl") |
| 229 | { |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 230 | param.encrypted = true; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 231 | Console.WriteLine("Using encrypted transport"); |
| 232 | } |
| 233 | } |
| 234 | } |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 235 | catch (Exception ex) |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 236 | { |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 237 | Console.WriteLine("*** FAILED ***"); |
| 238 | Console.WriteLine("Error while parsing arguments"); |
| 239 | Console.WriteLine(ex.Message + " ST: " + ex.StackTrace); |
| 240 | return ErrorUnknown; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 241 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 242 | |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 243 | var tests = Enumerable.Range(0, numThreads).Select(_ => new ClientTest(param)).ToArray(); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 244 | //issue tests on separate threads simultaneously |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 245 | var threads = tests.Select(test => new Thread(test.Execute)).ToArray(); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 246 | DateTime start = DateTime.Now; |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 247 | foreach (var t in threads) |
| 248 | t.Start(); |
| 249 | foreach (var t in threads) |
| 250 | t.Join(); |
| 251 | Console.WriteLine("Total time: " + (DateTime.Now - start)); |
| 252 | Console.WriteLine(); |
| 253 | return tests.Select(t => t.ReturnCode).Aggregate((r1, r2) => r1 | r2); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 254 | } |
| 255 | catch (Exception outerEx) |
| 256 | { |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 257 | Console.WriteLine("*** FAILED ***"); |
| 258 | Console.WriteLine("Unexpected error"); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 259 | Console.WriteLine(outerEx.Message + " ST: " + outerEx.StackTrace); |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 260 | return ErrorUnknown; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 261 | } |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 262 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 263 | |
Jens Geyer | 71e814a | 2014-12-13 23:40:35 +0100 | [diff] [blame] | 264 | public static string BytesToHex(byte[] data) { |
| 265 | return BitConverter.ToString(data).Replace("-", string.Empty); |
| 266 | } |
| 267 | |
| 268 | public static byte[] PrepareTestData(bool randomDist) |
| 269 | { |
| 270 | byte[] retval = new byte[0x100]; |
| 271 | int initLen = Math.Min(0x100,retval.Length); |
| 272 | |
| 273 | // linear distribution, unless random is requested |
| 274 | if (!randomDist) { |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 275 | for (var i = 0; i < initLen; ++i) { |
Jens Geyer | 71e814a | 2014-12-13 23:40:35 +0100 | [diff] [blame] | 276 | retval[i] = (byte)i; |
| 277 | } |
| 278 | return retval; |
| 279 | } |
| 280 | |
| 281 | // random distribution |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 282 | for (var i = 0; i < initLen; ++i) { |
Jens Geyer | 71e814a | 2014-12-13 23:40:35 +0100 | [diff] [blame] | 283 | retval[i] = (byte)0; |
| 284 | } |
| 285 | var rnd = new Random(); |
| 286 | for (var i = 1; i < initLen; ++i) { |
| 287 | while( true) { |
| 288 | int nextPos = rnd.Next() % initLen; |
| 289 | if (retval[nextPos] == 0) { |
| 290 | retval[nextPos] = (byte)i; |
| 291 | break; |
| 292 | } |
| 293 | } |
| 294 | } |
| 295 | return retval; |
| 296 | } |
| 297 | |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 298 | public static int ExecuteClientTest(ThriftTest.Client client) |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 299 | { |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 300 | int returnCode = 0; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 301 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 302 | Console.Write("testVoid()"); |
| 303 | client.testVoid(); |
| 304 | Console.WriteLine(" = void"); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 305 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 306 | Console.Write("testString(\"Test\")"); |
| 307 | string s = client.testString("Test"); |
| 308 | Console.WriteLine(" = \"" + s + "\""); |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 309 | if ("Test" != s) |
| 310 | { |
| 311 | Console.WriteLine("*** FAILED ***"); |
| 312 | returnCode |= ErrorBaseTypes; |
| 313 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 314 | |
Nobuaki Sukegawa | a649e74 | 2015-09-21 13:53:25 +0900 | [diff] [blame] | 315 | Console.Write("testBool(true)"); |
| 316 | bool t = client.testBool((bool)true); |
| 317 | Console.WriteLine(" = " + t); |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 318 | if (!t) |
| 319 | { |
| 320 | Console.WriteLine("*** FAILED ***"); |
| 321 | returnCode |= ErrorBaseTypes; |
| 322 | } |
Nobuaki Sukegawa | a649e74 | 2015-09-21 13:53:25 +0900 | [diff] [blame] | 323 | Console.Write("testBool(false)"); |
| 324 | bool f = client.testBool((bool)false); |
| 325 | Console.WriteLine(" = " + f); |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 326 | if (f) |
| 327 | { |
| 328 | Console.WriteLine("*** FAILED ***"); |
| 329 | returnCode |= ErrorBaseTypes; |
| 330 | } |
Nobuaki Sukegawa | a649e74 | 2015-09-21 13:53:25 +0900 | [diff] [blame] | 331 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 332 | Console.Write("testByte(1)"); |
| 333 | sbyte i8 = client.testByte((sbyte)1); |
| 334 | Console.WriteLine(" = " + i8); |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 335 | if (1 != i8) |
| 336 | { |
| 337 | Console.WriteLine("*** FAILED ***"); |
| 338 | returnCode |= ErrorBaseTypes; |
| 339 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 340 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 341 | Console.Write("testI32(-1)"); |
| 342 | int i32 = client.testI32(-1); |
| 343 | Console.WriteLine(" = " + i32); |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 344 | if (-1 != i32) |
| 345 | { |
| 346 | Console.WriteLine("*** FAILED ***"); |
| 347 | returnCode |= ErrorBaseTypes; |
| 348 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 349 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 350 | Console.Write("testI64(-34359738368)"); |
| 351 | long i64 = client.testI64(-34359738368); |
| 352 | Console.WriteLine(" = " + i64); |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 353 | if (-34359738368 != i64) |
| 354 | { |
| 355 | Console.WriteLine("*** FAILED ***"); |
| 356 | returnCode |= ErrorBaseTypes; |
| 357 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 358 | |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 359 | // TODO: Validate received message |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 360 | Console.Write("testDouble(5.325098235)"); |
| 361 | double dub = client.testDouble(5.325098235); |
| 362 | Console.WriteLine(" = " + dub); |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 363 | if (5.325098235 != dub) |
| 364 | { |
| 365 | Console.WriteLine("*** FAILED ***"); |
| 366 | returnCode |= ErrorBaseTypes; |
| 367 | } |
Nobuaki Sukegawa | 228b328 | 2015-10-10 03:11:49 +0900 | [diff] [blame] | 368 | Console.Write("testDouble(-0.000341012439638598279)"); |
| 369 | dub = client.testDouble(-0.000341012439638598279); |
| 370 | Console.WriteLine(" = " + dub); |
| 371 | if (-0.000341012439638598279 != dub) |
| 372 | { |
| 373 | Console.WriteLine("*** FAILED ***"); |
| 374 | returnCode |= ErrorBaseTypes; |
| 375 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 376 | |
Jens Geyer | 71e814a | 2014-12-13 23:40:35 +0100 | [diff] [blame] | 377 | byte[] binOut = PrepareTestData(true); |
| 378 | Console.Write("testBinary(" + BytesToHex(binOut) + ")"); |
| 379 | try |
| 380 | { |
| 381 | byte[] binIn = client.testBinary(binOut); |
| 382 | Console.WriteLine(" = " + BytesToHex(binIn)); |
| 383 | if (binIn.Length != binOut.Length) |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 384 | { |
| 385 | Console.WriteLine("*** FAILED ***"); |
| 386 | returnCode |= ErrorBaseTypes; |
| 387 | } |
Jens Geyer | 71e814a | 2014-12-13 23:40:35 +0100 | [diff] [blame] | 388 | for (int ofs = 0; ofs < Math.Min(binIn.Length, binOut.Length); ++ofs) |
| 389 | if (binIn[ofs] != binOut[ofs]) |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 390 | { |
| 391 | Console.WriteLine("*** FAILED ***"); |
| 392 | returnCode |= ErrorBaseTypes; |
| 393 | } |
Jens Geyer | 71e814a | 2014-12-13 23:40:35 +0100 | [diff] [blame] | 394 | } |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 395 | catch (Thrift.TApplicationException ex) |
Jens Geyer | 71e814a | 2014-12-13 23:40:35 +0100 | [diff] [blame] | 396 | { |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 397 | Console.WriteLine("*** FAILED ***"); |
| 398 | returnCode |= ErrorBaseTypes; |
| 399 | Console.WriteLine(ex.Message + " ST: " + ex.StackTrace); |
Jens Geyer | 71e814a | 2014-12-13 23:40:35 +0100 | [diff] [blame] | 400 | } |
| 401 | |
Jens Geyer | 80aa53e | 2015-02-18 22:04:09 +0100 | [diff] [blame] | 402 | // binary equals? only with hashcode option enabled ... |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 403 | Console.WriteLine("Test CrazyNesting"); |
| 404 | if( typeof(CrazyNesting).GetMethod("Equals").DeclaringType == typeof(CrazyNesting)) |
Jens Geyer | 80aa53e | 2015-02-18 22:04:09 +0100 | [diff] [blame] | 405 | { |
| 406 | CrazyNesting one = new CrazyNesting(); |
| 407 | CrazyNesting two = new CrazyNesting(); |
| 408 | one.String_field = "crazy"; |
| 409 | two.String_field = "crazy"; |
| 410 | one.Binary_field = new byte[10] { 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0xFF }; |
| 411 | two.Binary_field = new byte[10] { 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0xFF }; |
| 412 | if (!one.Equals(two)) |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 413 | { |
| 414 | Console.WriteLine("*** FAILED ***"); |
| 415 | returnCode |= ErrorContainers; |
Jens Geyer | 80aa53e | 2015-02-18 22:04:09 +0100 | [diff] [blame] | 416 | throw new Exception("CrazyNesting.Equals failed"); |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 417 | } |
Jens Geyer | 80aa53e | 2015-02-18 22:04:09 +0100 | [diff] [blame] | 418 | } |
| 419 | |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 420 | // TODO: Validate received message |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 421 | Console.Write("testStruct({\"Zero\", 1, -3, -5})"); |
| 422 | Xtruct o = new Xtruct(); |
| 423 | o.String_thing = "Zero"; |
| 424 | o.Byte_thing = (sbyte)1; |
| 425 | o.I32_thing = -3; |
| 426 | o.I64_thing = -5; |
| 427 | Xtruct i = client.testStruct(o); |
| 428 | Console.WriteLine(" = {\"" + i.String_thing + "\", " + i.Byte_thing + ", " + i.I32_thing + ", " + i.I64_thing + "}"); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 429 | |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 430 | // TODO: Validate received message |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 431 | Console.Write("testNest({1, {\"Zero\", 1, -3, -5}, 5})"); |
| 432 | Xtruct2 o2 = new Xtruct2(); |
| 433 | o2.Byte_thing = (sbyte)1; |
| 434 | o2.Struct_thing = o; |
| 435 | o2.I32_thing = 5; |
| 436 | Xtruct2 i2 = client.testNest(o2); |
| 437 | i = i2.Struct_thing; |
| 438 | Console.WriteLine(" = {" + i2.Byte_thing + ", {\"" + i.String_thing + "\", " + i.Byte_thing + ", " + i.I32_thing + ", " + i.I64_thing + "}, " + i2.I32_thing + "}"); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 439 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 440 | Dictionary<int, int> mapout = new Dictionary<int, int>(); |
| 441 | for (int j = 0; j < 5; j++) |
| 442 | { |
| 443 | mapout[j] = j - 10; |
| 444 | } |
| 445 | Console.Write("testMap({"); |
| 446 | bool first = true; |
| 447 | foreach (int key in mapout.Keys) |
| 448 | { |
| 449 | if (first) |
| 450 | { |
| 451 | first = false; |
| 452 | } |
| 453 | else |
| 454 | { |
| 455 | Console.Write(", "); |
| 456 | } |
| 457 | Console.Write(key + " => " + mapout[key]); |
| 458 | } |
| 459 | Console.Write("})"); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 460 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 461 | Dictionary<int, int> mapin = client.testMap(mapout); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 462 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 463 | Console.Write(" = {"); |
| 464 | first = true; |
| 465 | foreach (int key in mapin.Keys) |
| 466 | { |
| 467 | if (first) |
| 468 | { |
| 469 | first = false; |
| 470 | } |
| 471 | else |
| 472 | { |
| 473 | Console.Write(", "); |
| 474 | } |
| 475 | Console.Write(key + " => " + mapin[key]); |
| 476 | } |
| 477 | Console.WriteLine("}"); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 478 | |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 479 | // TODO: Validate received message |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 480 | List<int> listout = new List<int>(); |
| 481 | for (int j = -2; j < 3; j++) |
| 482 | { |
| 483 | listout.Add(j); |
| 484 | } |
| 485 | Console.Write("testList({"); |
| 486 | first = true; |
| 487 | foreach (int j in listout) |
| 488 | { |
| 489 | if (first) |
| 490 | { |
| 491 | first = false; |
| 492 | } |
| 493 | else |
| 494 | { |
| 495 | Console.Write(", "); |
| 496 | } |
| 497 | Console.Write(j); |
| 498 | } |
| 499 | Console.Write("})"); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 500 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 501 | List<int> listin = client.testList(listout); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 502 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 503 | Console.Write(" = {"); |
| 504 | first = true; |
| 505 | foreach (int j in listin) |
| 506 | { |
| 507 | if (first) |
| 508 | { |
| 509 | first = false; |
| 510 | } |
| 511 | else |
| 512 | { |
| 513 | Console.Write(", "); |
| 514 | } |
| 515 | Console.Write(j); |
| 516 | } |
| 517 | Console.WriteLine("}"); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 518 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 519 | //set |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 520 | // TODO: Validate received message |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 521 | THashSet<int> setout = new THashSet<int>(); |
| 522 | for (int j = -2; j < 3; j++) |
| 523 | { |
| 524 | setout.Add(j); |
| 525 | } |
| 526 | Console.Write("testSet({"); |
| 527 | first = true; |
| 528 | foreach (int j in setout) |
| 529 | { |
| 530 | if (first) |
| 531 | { |
| 532 | first = false; |
| 533 | } |
| 534 | else |
| 535 | { |
| 536 | Console.Write(", "); |
| 537 | } |
| 538 | Console.Write(j); |
| 539 | } |
| 540 | Console.Write("})"); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 541 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 542 | THashSet<int> setin = client.testSet(setout); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 543 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 544 | Console.Write(" = {"); |
| 545 | first = true; |
| 546 | foreach (int j in setin) |
| 547 | { |
| 548 | if (first) |
| 549 | { |
| 550 | first = false; |
| 551 | } |
| 552 | else |
| 553 | { |
| 554 | Console.Write(", "); |
| 555 | } |
| 556 | Console.Write(j); |
| 557 | } |
| 558 | Console.WriteLine("}"); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 559 | |
| 560 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 561 | Console.Write("testEnum(ONE)"); |
| 562 | Numberz ret = client.testEnum(Numberz.ONE); |
| 563 | Console.WriteLine(" = " + ret); |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 564 | if (Numberz.ONE != ret) |
| 565 | { |
| 566 | Console.WriteLine("*** FAILED ***"); |
| 567 | returnCode |= ErrorStructs; |
| 568 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 569 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 570 | Console.Write("testEnum(TWO)"); |
| 571 | ret = client.testEnum(Numberz.TWO); |
| 572 | Console.WriteLine(" = " + ret); |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 573 | if (Numberz.TWO != ret) |
| 574 | { |
| 575 | Console.WriteLine("*** FAILED ***"); |
| 576 | returnCode |= ErrorStructs; |
| 577 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 578 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 579 | Console.Write("testEnum(THREE)"); |
| 580 | ret = client.testEnum(Numberz.THREE); |
| 581 | Console.WriteLine(" = " + ret); |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 582 | if (Numberz.THREE != ret) |
| 583 | { |
| 584 | Console.WriteLine("*** FAILED ***"); |
| 585 | returnCode |= ErrorStructs; |
| 586 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 587 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 588 | Console.Write("testEnum(FIVE)"); |
| 589 | ret = client.testEnum(Numberz.FIVE); |
| 590 | Console.WriteLine(" = " + ret); |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 591 | if (Numberz.FIVE != ret) |
| 592 | { |
| 593 | Console.WriteLine("*** FAILED ***"); |
| 594 | returnCode |= ErrorStructs; |
| 595 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 596 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 597 | Console.Write("testEnum(EIGHT)"); |
| 598 | ret = client.testEnum(Numberz.EIGHT); |
| 599 | Console.WriteLine(" = " + ret); |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 600 | if (Numberz.EIGHT != ret) |
| 601 | { |
| 602 | Console.WriteLine("*** FAILED ***"); |
| 603 | returnCode |= ErrorStructs; |
| 604 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 605 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 606 | Console.Write("testTypedef(309858235082523)"); |
| 607 | long uid = client.testTypedef(309858235082523L); |
| 608 | Console.WriteLine(" = " + uid); |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 609 | if (309858235082523L != uid) |
| 610 | { |
| 611 | Console.WriteLine("*** FAILED ***"); |
| 612 | returnCode |= ErrorStructs; |
| 613 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 614 | |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 615 | // TODO: Validate received message |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 616 | Console.Write("testMapMap(1)"); |
| 617 | Dictionary<int, Dictionary<int, int>> mm = client.testMapMap(1); |
| 618 | Console.Write(" = {"); |
| 619 | foreach (int key in mm.Keys) |
| 620 | { |
| 621 | Console.Write(key + " => {"); |
| 622 | Dictionary<int, int> m2 = mm[key]; |
| 623 | foreach (int k2 in m2.Keys) |
| 624 | { |
| 625 | Console.Write(k2 + " => " + m2[k2] + ", "); |
| 626 | } |
| 627 | Console.Write("}, "); |
| 628 | } |
| 629 | Console.WriteLine("}"); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 630 | |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 631 | // TODO: Validate received message |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 632 | Insanity insane = new Insanity(); |
| 633 | insane.UserMap = new Dictionary<Numberz, long>(); |
| 634 | insane.UserMap[Numberz.FIVE] = 5000L; |
| 635 | Xtruct truck = new Xtruct(); |
| 636 | truck.String_thing = "Truck"; |
| 637 | truck.Byte_thing = (sbyte)8; |
| 638 | truck.I32_thing = 8; |
| 639 | truck.I64_thing = 8; |
| 640 | insane.Xtructs = new List<Xtruct>(); |
| 641 | insane.Xtructs.Add(truck); |
| 642 | Console.Write("testInsanity()"); |
| 643 | Dictionary<long, Dictionary<Numberz, Insanity>> whoa = client.testInsanity(insane); |
| 644 | Console.Write(" = {"); |
| 645 | foreach (long key in whoa.Keys) |
| 646 | { |
| 647 | Dictionary<Numberz, Insanity> val = whoa[key]; |
| 648 | Console.Write(key + " => {"); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 649 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 650 | foreach (Numberz k2 in val.Keys) |
| 651 | { |
| 652 | Insanity v2 = val[k2]; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 653 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 654 | Console.Write(k2 + " => {"); |
| 655 | Dictionary<Numberz, long> userMap = v2.UserMap; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 656 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 657 | Console.Write("{"); |
| 658 | if (userMap != null) |
| 659 | { |
| 660 | foreach (Numberz k3 in userMap.Keys) |
| 661 | { |
| 662 | Console.Write(k3 + " => " + userMap[k3] + ", "); |
| 663 | } |
| 664 | } |
| 665 | else |
| 666 | { |
| 667 | Console.Write("null"); |
| 668 | } |
| 669 | Console.Write("}, "); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 670 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 671 | List<Xtruct> xtructs = v2.Xtructs; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 672 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 673 | Console.Write("{"); |
| 674 | if (xtructs != null) |
| 675 | { |
| 676 | foreach (Xtruct x in xtructs) |
| 677 | { |
| 678 | Console.Write("{\"" + x.String_thing + "\", " + x.Byte_thing + ", " + x.I32_thing + ", " + x.I32_thing + "}, "); |
| 679 | } |
| 680 | } |
| 681 | else |
| 682 | { |
| 683 | Console.Write("null"); |
| 684 | } |
| 685 | Console.Write("}"); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 686 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 687 | Console.Write("}, "); |
| 688 | } |
| 689 | Console.Write("}, "); |
| 690 | } |
| 691 | Console.WriteLine("}"); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 692 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 693 | sbyte arg0 = 1; |
| 694 | int arg1 = 2; |
| 695 | long arg2 = long.MaxValue; |
| 696 | Dictionary<short, string> multiDict = new Dictionary<short, string>(); |
| 697 | multiDict[1] = "one"; |
| 698 | Numberz arg4 = Numberz.FIVE; |
| 699 | long arg5 = 5000000; |
| 700 | Console.Write("Test Multi(" + arg0 + "," + arg1 + "," + arg2 + "," + multiDict + "," + arg4 + "," + arg5 + ")"); |
| 701 | Xtruct multiResponse = client.testMulti(arg0, arg1, arg2, multiDict, arg4, arg5); |
| 702 | Console.Write(" = Xtruct(byte_thing:" + multiResponse.Byte_thing + ",String_thing:" + multiResponse.String_thing |
| 703 | + ",i32_thing:" + multiResponse.I32_thing + ",i64_thing:" + multiResponse.I64_thing + ")\n"); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 704 | |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 705 | try |
| 706 | { |
| 707 | Console.WriteLine("testException(\"Xception\")"); |
| 708 | client.testException("Xception"); |
| 709 | Console.WriteLine("*** FAILED ***"); |
| 710 | returnCode |= ErrorExceptions; |
| 711 | } |
| 712 | catch (Xception ex) |
| 713 | { |
| 714 | if (ex.ErrorCode != 1001 || ex.Message != "Xception") |
| 715 | { |
| 716 | Console.WriteLine("*** FAILED ***"); |
| 717 | returnCode |= ErrorExceptions; |
| 718 | } |
| 719 | } |
| 720 | catch (Exception ex) |
| 721 | { |
| 722 | Console.WriteLine("*** FAILED ***"); |
| 723 | returnCode |= ErrorExceptions; |
| 724 | Console.WriteLine(ex.Message + " ST: " + ex.StackTrace); |
| 725 | } |
| 726 | try |
| 727 | { |
| 728 | Console.WriteLine("testException(\"TException\")"); |
| 729 | client.testException("TException"); |
| 730 | Console.WriteLine("*** FAILED ***"); |
| 731 | returnCode |= ErrorExceptions; |
| 732 | } |
| 733 | catch (Thrift.TException) |
| 734 | { |
| 735 | // OK |
| 736 | } |
| 737 | catch (Exception ex) |
| 738 | { |
| 739 | Console.WriteLine("*** FAILED ***"); |
| 740 | returnCode |= ErrorExceptions; |
| 741 | Console.WriteLine(ex.Message + " ST: " + ex.StackTrace); |
| 742 | } |
| 743 | try |
| 744 | { |
| 745 | Console.WriteLine("testException(\"ok\")"); |
| 746 | client.testException("ok"); |
| 747 | // OK |
| 748 | } |
| 749 | catch (Exception ex) |
| 750 | { |
| 751 | Console.WriteLine("*** FAILED ***"); |
| 752 | returnCode |= ErrorExceptions; |
| 753 | Console.WriteLine(ex.Message + " ST: " + ex.StackTrace); |
| 754 | } |
| 755 | |
| 756 | try |
| 757 | { |
| 758 | Console.WriteLine("testMultiException(\"Xception\", ...)"); |
| 759 | client.testMultiException("Xception", "ignore"); |
| 760 | Console.WriteLine("*** FAILED ***"); |
| 761 | returnCode |= ErrorExceptions; |
| 762 | } |
| 763 | catch (Xception ex) |
| 764 | { |
| 765 | if (ex.ErrorCode != 1001 || ex.Message != "This is an Xception") |
| 766 | { |
| 767 | Console.WriteLine("*** FAILED ***"); |
| 768 | returnCode |= ErrorExceptions; |
| 769 | } |
| 770 | } |
| 771 | catch (Exception ex) |
| 772 | { |
| 773 | Console.WriteLine("*** FAILED ***"); |
| 774 | returnCode |= ErrorExceptions; |
| 775 | Console.WriteLine(ex.Message + " ST: " + ex.StackTrace); |
| 776 | } |
| 777 | try |
| 778 | { |
| 779 | Console.WriteLine("testMultiException(\"Xception2\", ...)"); |
| 780 | client.testMultiException("Xception2", "ignore"); |
| 781 | Console.WriteLine("*** FAILED ***"); |
| 782 | returnCode |= ErrorExceptions; |
| 783 | } |
| 784 | catch (Xception2 ex) |
| 785 | { |
| 786 | if (ex.ErrorCode != 2002 || ex.Struct_thing.String_thing != "This is an Xception2") |
| 787 | { |
| 788 | Console.WriteLine("*** FAILED ***"); |
| 789 | returnCode |= ErrorExceptions; |
| 790 | } |
| 791 | } |
| 792 | catch (Exception ex) |
| 793 | { |
| 794 | Console.WriteLine("*** FAILED ***"); |
| 795 | returnCode |= ErrorExceptions; |
| 796 | Console.WriteLine(ex.Message + " ST: " + ex.StackTrace); |
| 797 | } |
| 798 | try |
| 799 | { |
| 800 | Console.WriteLine("testMultiException(\"success\", \"OK\")"); |
| 801 | if ("OK" != client.testMultiException("success", "OK").String_thing) |
| 802 | { |
| 803 | Console.WriteLine("*** FAILED ***"); |
| 804 | returnCode |= ErrorExceptions; |
| 805 | } |
| 806 | } |
| 807 | catch (Exception ex) |
| 808 | { |
| 809 | Console.WriteLine("*** FAILED ***"); |
| 810 | returnCode |= ErrorExceptions; |
| 811 | Console.WriteLine(ex.Message + " ST: " + ex.StackTrace); |
| 812 | } |
| 813 | |
| 814 | Stopwatch sw = new Stopwatch(); |
| 815 | sw.Start(); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 816 | Console.WriteLine("Test Oneway(1)"); |
| 817 | client.testOneway(1); |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 818 | sw.Stop(); |
| 819 | if (sw.ElapsedMilliseconds > 1000) |
| 820 | { |
| 821 | Console.WriteLine("*** FAILED ***"); |
| 822 | returnCode |= ErrorBaseTypes; |
| 823 | } |
T Jake Luciani | 7070aaa | 2011-01-27 02:51:51 +0000 | [diff] [blame] | 824 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 825 | Console.Write("Test Calltime()"); |
Nobuaki Sukegawa | 88c5ee7 | 2016-09-04 18:49:18 +0900 | [diff] [blame^] | 826 | var times = 50; |
| 827 | sw.Reset(); |
| 828 | sw.Start(); |
| 829 | for (int k = 0; k < times; ++k) |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 830 | client.testVoid(); |
Nobuaki Sukegawa | 88c5ee7 | 2016-09-04 18:49:18 +0900 | [diff] [blame^] | 831 | sw.Stop(); |
| 832 | Console.WriteLine(" = {0} ms a testVoid() call", sw.ElapsedMilliseconds / times); |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 833 | return returnCode; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 834 | } |
| 835 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 836 | } |