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; |
| 21 | using System.Collections.Generic; |
David Reiss | d831a21 | 2009-02-13 03:09:52 +0000 | [diff] [blame] | 22 | using System.Threading; |
| 23 | using Thrift.Collections; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 24 | using Thrift.Protocol; |
| 25 | using Thrift.Transport; |
| 26 | using Thrift.Test; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 27 | |
| 28 | namespace Test |
| 29 | { |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 30 | public class TestClient |
| 31 | { |
| 32 | private static int numIterations = 1; |
| 33 | private static string protocol = ""; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 34 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 35 | public static void Execute(string[] args) |
| 36 | { |
| 37 | try |
| 38 | { |
| 39 | string host = "localhost"; |
| 40 | int port = 9090; |
| 41 | string url = null, pipe = null; |
| 42 | int numThreads = 1; |
| 43 | bool buffered = false, framed = false, encrypted = false; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 44 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 45 | try |
| 46 | { |
| 47 | for (int i = 0; i < args.Length; i++) |
| 48 | { |
| 49 | if (args[i] == "-u") |
| 50 | { |
| 51 | url = args[++i]; |
| 52 | } |
| 53 | else if (args[i] == "-n") |
| 54 | { |
| 55 | numIterations = Convert.ToInt32(args[++i]); |
| 56 | } |
| 57 | else if (args[i] == "-pipe") // -pipe <name> |
| 58 | { |
| 59 | pipe = args[++i]; |
| 60 | Console.WriteLine("Using named pipes transport"); |
| 61 | } |
| 62 | else if (args[i].Contains("--host=")) |
| 63 | { |
| 64 | host = args[i].Substring(args[i].IndexOf("=") + 1); |
| 65 | } |
| 66 | else if (args[i].Contains("--port=")) |
| 67 | { |
| 68 | port = int.Parse(args[i].Substring(args[i].IndexOf("=")+1)); |
| 69 | } |
| 70 | else if (args[i] == "-b" || args[i] == "--buffered" || args[i] == "--transport=buffered") |
| 71 | { |
| 72 | buffered = true; |
| 73 | Console.WriteLine("Using buffered sockets"); |
| 74 | } |
| 75 | else if (args[i] == "-f" || args[i] == "--framed" || args[i] == "--transport=framed") |
| 76 | { |
| 77 | framed = true; |
| 78 | Console.WriteLine("Using framed transport"); |
| 79 | } |
| 80 | else if (args[i] == "-t") |
| 81 | { |
| 82 | numThreads = Convert.ToInt32(args[++i]); |
| 83 | } |
| 84 | else if (args[i] == "--compact" || args[i] == "--protocol=compact") |
| 85 | { |
| 86 | protocol = "compact"; |
| 87 | Console.WriteLine("Using compact protocol"); |
| 88 | } |
| 89 | else if (args[i] == "--json" || args[i] == "--protocol=json") |
| 90 | { |
| 91 | protocol = "json"; |
| 92 | Console.WriteLine("Using JSON protocol"); |
| 93 | } |
| 94 | else if (args[i] == "--ssl") |
| 95 | { |
| 96 | encrypted = true; |
| 97 | Console.WriteLine("Using encrypted transport"); |
| 98 | } |
| 99 | } |
| 100 | } |
| 101 | catch (Exception e) |
| 102 | { |
| 103 | Console.WriteLine(e.StackTrace); |
| 104 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 105 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 106 | //issue tests on separate threads simultaneously |
| 107 | Thread[] threads = new Thread[numThreads]; |
| 108 | DateTime start = DateTime.Now; |
| 109 | for (int test = 0; test < numThreads; test++) |
| 110 | { |
| 111 | Thread t = new Thread(new ParameterizedThreadStart(ClientThread)); |
| 112 | threads[test] = t; |
| 113 | if (url == null) |
| 114 | { |
| 115 | // endpoint transport |
| 116 | TTransport trans = null; |
| 117 | if (pipe != null) |
| 118 | trans = new TNamedPipeClientTransport(pipe); |
| 119 | else |
| 120 | { |
| 121 | if (encrypted) |
| 122 | trans = new TTLSSocket(host, port, "../../../../../keys/client.pem"); |
| 123 | else |
| 124 | trans = new TSocket(host, port); |
| 125 | } |
Jens Geyer | c1d7943 | 2014-04-22 22:52:43 +0200 | [diff] [blame] | 126 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 127 | // layered transport |
| 128 | if (buffered) |
| 129 | trans = new TBufferedTransport(trans as TStreamTransport); |
| 130 | if (framed) |
| 131 | trans = new TFramedTransport(trans); |
Jens Geyer | c1d7943 | 2014-04-22 22:52:43 +0200 | [diff] [blame] | 132 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 133 | //ensure proper open/close of transport |
| 134 | trans.Open(); |
| 135 | trans.Close(); |
| 136 | t.Start(trans); |
| 137 | } |
| 138 | else |
| 139 | { |
| 140 | THttpClient http = new THttpClient(new Uri(url)); |
| 141 | t.Start(http); |
| 142 | } |
| 143 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 144 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 145 | for (int test = 0; test < numThreads; test++) |
| 146 | { |
| 147 | threads[test].Join(); |
| 148 | } |
| 149 | Console.Write("Total time: " + (DateTime.Now - start)); |
| 150 | } |
| 151 | catch (Exception outerEx) |
| 152 | { |
| 153 | Console.WriteLine(outerEx.Message + " ST: " + outerEx.StackTrace); |
| 154 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 155 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 156 | Console.WriteLine(); |
| 157 | Console.WriteLine(); |
| 158 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 159 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 160 | public static void ClientThread(object obj) |
| 161 | { |
| 162 | TTransport transport = (TTransport)obj; |
| 163 | for (int i = 0; i < numIterations; i++) |
| 164 | { |
| 165 | ClientTest(transport); |
| 166 | } |
| 167 | transport.Close(); |
| 168 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 169 | |
Jens Geyer | 71e814a | 2014-12-13 23:40:35 +0100 | [diff] [blame^] | 170 | public static string BytesToHex(byte[] data) { |
| 171 | return BitConverter.ToString(data).Replace("-", string.Empty); |
| 172 | } |
| 173 | |
| 174 | public static byte[] PrepareTestData(bool randomDist) |
| 175 | { |
| 176 | byte[] retval = new byte[0x100]; |
| 177 | int initLen = Math.Min(0x100,retval.Length); |
| 178 | |
| 179 | // linear distribution, unless random is requested |
| 180 | if (!randomDist) { |
| 181 | for (var i = 0; i < initLen; ++i) { |
| 182 | retval[i] = (byte)i; |
| 183 | } |
| 184 | return retval; |
| 185 | } |
| 186 | |
| 187 | // random distribution |
| 188 | for (var i = 0; i < initLen; ++i) { |
| 189 | retval[i] = (byte)0; |
| 190 | } |
| 191 | var rnd = new Random(); |
| 192 | for (var i = 1; i < initLen; ++i) { |
| 193 | while( true) { |
| 194 | int nextPos = rnd.Next() % initLen; |
| 195 | if (retval[nextPos] == 0) { |
| 196 | retval[nextPos] = (byte)i; |
| 197 | break; |
| 198 | } |
| 199 | } |
| 200 | } |
| 201 | return retval; |
| 202 | } |
| 203 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 204 | public static void ClientTest(TTransport transport) |
| 205 | { |
| 206 | TProtocol proto; |
| 207 | if (protocol == "compact") |
| 208 | proto = new TCompactProtocol(transport); |
| 209 | else if (protocol == "json") |
| 210 | proto = new TJSONProtocol(transport); |
| 211 | else |
| 212 | proto = new TBinaryProtocol(transport); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 213 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 214 | ThriftTest.Client client = new ThriftTest.Client(proto); |
| 215 | try |
| 216 | { |
| 217 | if (!transport.IsOpen) |
| 218 | { |
| 219 | transport.Open(); |
| 220 | } |
| 221 | } |
| 222 | catch (TTransportException ttx) |
| 223 | { |
| 224 | Console.WriteLine("Connect failed: " + ttx.Message); |
| 225 | return; |
| 226 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 227 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 228 | long start = DateTime.Now.ToFileTime(); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 229 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 230 | Console.Write("testVoid()"); |
| 231 | client.testVoid(); |
| 232 | Console.WriteLine(" = void"); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 233 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 234 | Console.Write("testString(\"Test\")"); |
| 235 | string s = client.testString("Test"); |
| 236 | Console.WriteLine(" = \"" + s + "\""); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 237 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 238 | Console.Write("testByte(1)"); |
| 239 | sbyte i8 = client.testByte((sbyte)1); |
| 240 | Console.WriteLine(" = " + i8); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 241 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 242 | Console.Write("testI32(-1)"); |
| 243 | int i32 = client.testI32(-1); |
| 244 | Console.WriteLine(" = " + i32); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 245 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 246 | Console.Write("testI64(-34359738368)"); |
| 247 | long i64 = client.testI64(-34359738368); |
| 248 | Console.WriteLine(" = " + i64); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 249 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 250 | Console.Write("testDouble(5.325098235)"); |
| 251 | double dub = client.testDouble(5.325098235); |
| 252 | Console.WriteLine(" = " + dub); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 253 | |
Jens Geyer | 71e814a | 2014-12-13 23:40:35 +0100 | [diff] [blame^] | 254 | byte[] binOut = PrepareTestData(true); |
| 255 | Console.Write("testBinary(" + BytesToHex(binOut) + ")"); |
| 256 | try |
| 257 | { |
| 258 | byte[] binIn = client.testBinary(binOut); |
| 259 | Console.WriteLine(" = " + BytesToHex(binIn)); |
| 260 | if (binIn.Length != binOut.Length) |
| 261 | throw new Exception("testBinary: length mismatch"); |
| 262 | for (int ofs = 0; ofs < Math.Min(binIn.Length, binOut.Length); ++ofs) |
| 263 | if (binIn[ofs] != binOut[ofs]) |
| 264 | throw new Exception("testBinary: content mismatch at offset " + ofs.ToString()); |
| 265 | } |
| 266 | catch (Thrift.TApplicationException e) |
| 267 | { |
| 268 | Console.Write("testBinary(" + BytesToHex(binOut) + "): "+e.Message); |
| 269 | } |
| 270 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 271 | Console.Write("testStruct({\"Zero\", 1, -3, -5})"); |
| 272 | Xtruct o = new Xtruct(); |
| 273 | o.String_thing = "Zero"; |
| 274 | o.Byte_thing = (sbyte)1; |
| 275 | o.I32_thing = -3; |
| 276 | o.I64_thing = -5; |
| 277 | Xtruct i = client.testStruct(o); |
| 278 | 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] | 279 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 280 | Console.Write("testNest({1, {\"Zero\", 1, -3, -5}, 5})"); |
| 281 | Xtruct2 o2 = new Xtruct2(); |
| 282 | o2.Byte_thing = (sbyte)1; |
| 283 | o2.Struct_thing = o; |
| 284 | o2.I32_thing = 5; |
| 285 | Xtruct2 i2 = client.testNest(o2); |
| 286 | i = i2.Struct_thing; |
| 287 | 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] | 288 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 289 | Dictionary<int, int> mapout = new Dictionary<int, int>(); |
| 290 | for (int j = 0; j < 5; j++) |
| 291 | { |
| 292 | mapout[j] = j - 10; |
| 293 | } |
| 294 | Console.Write("testMap({"); |
| 295 | bool first = true; |
| 296 | foreach (int key in mapout.Keys) |
| 297 | { |
| 298 | if (first) |
| 299 | { |
| 300 | first = false; |
| 301 | } |
| 302 | else |
| 303 | { |
| 304 | Console.Write(", "); |
| 305 | } |
| 306 | Console.Write(key + " => " + mapout[key]); |
| 307 | } |
| 308 | Console.Write("})"); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 309 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 310 | Dictionary<int, int> mapin = client.testMap(mapout); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 311 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 312 | Console.Write(" = {"); |
| 313 | first = true; |
| 314 | foreach (int key in mapin.Keys) |
| 315 | { |
| 316 | if (first) |
| 317 | { |
| 318 | first = false; |
| 319 | } |
| 320 | else |
| 321 | { |
| 322 | Console.Write(", "); |
| 323 | } |
| 324 | Console.Write(key + " => " + mapin[key]); |
| 325 | } |
| 326 | Console.WriteLine("}"); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 327 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 328 | List<int> listout = new List<int>(); |
| 329 | for (int j = -2; j < 3; j++) |
| 330 | { |
| 331 | listout.Add(j); |
| 332 | } |
| 333 | Console.Write("testList({"); |
| 334 | first = true; |
| 335 | foreach (int j in listout) |
| 336 | { |
| 337 | if (first) |
| 338 | { |
| 339 | first = false; |
| 340 | } |
| 341 | else |
| 342 | { |
| 343 | Console.Write(", "); |
| 344 | } |
| 345 | Console.Write(j); |
| 346 | } |
| 347 | Console.Write("})"); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 348 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 349 | List<int> listin = client.testList(listout); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 350 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 351 | Console.Write(" = {"); |
| 352 | first = true; |
| 353 | foreach (int j in listin) |
| 354 | { |
| 355 | if (first) |
| 356 | { |
| 357 | first = false; |
| 358 | } |
| 359 | else |
| 360 | { |
| 361 | Console.Write(", "); |
| 362 | } |
| 363 | Console.Write(j); |
| 364 | } |
| 365 | Console.WriteLine("}"); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 366 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 367 | //set |
| 368 | THashSet<int> setout = new THashSet<int>(); |
| 369 | for (int j = -2; j < 3; j++) |
| 370 | { |
| 371 | setout.Add(j); |
| 372 | } |
| 373 | Console.Write("testSet({"); |
| 374 | first = true; |
| 375 | foreach (int j in setout) |
| 376 | { |
| 377 | if (first) |
| 378 | { |
| 379 | first = false; |
| 380 | } |
| 381 | else |
| 382 | { |
| 383 | Console.Write(", "); |
| 384 | } |
| 385 | Console.Write(j); |
| 386 | } |
| 387 | Console.Write("})"); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 388 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 389 | THashSet<int> setin = client.testSet(setout); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 390 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 391 | Console.Write(" = {"); |
| 392 | first = true; |
| 393 | foreach (int j in setin) |
| 394 | { |
| 395 | if (first) |
| 396 | { |
| 397 | first = false; |
| 398 | } |
| 399 | else |
| 400 | { |
| 401 | Console.Write(", "); |
| 402 | } |
| 403 | Console.Write(j); |
| 404 | } |
| 405 | Console.WriteLine("}"); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 406 | |
| 407 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 408 | Console.Write("testEnum(ONE)"); |
| 409 | Numberz ret = client.testEnum(Numberz.ONE); |
| 410 | Console.WriteLine(" = " + ret); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 411 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 412 | Console.Write("testEnum(TWO)"); |
| 413 | ret = client.testEnum(Numberz.TWO); |
| 414 | Console.WriteLine(" = " + ret); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 415 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 416 | Console.Write("testEnum(THREE)"); |
| 417 | ret = client.testEnum(Numberz.THREE); |
| 418 | Console.WriteLine(" = " + ret); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 419 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 420 | Console.Write("testEnum(FIVE)"); |
| 421 | ret = client.testEnum(Numberz.FIVE); |
| 422 | Console.WriteLine(" = " + ret); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 423 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 424 | Console.Write("testEnum(EIGHT)"); |
| 425 | ret = client.testEnum(Numberz.EIGHT); |
| 426 | Console.WriteLine(" = " + ret); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 427 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 428 | Console.Write("testTypedef(309858235082523)"); |
| 429 | long uid = client.testTypedef(309858235082523L); |
| 430 | Console.WriteLine(" = " + uid); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 431 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 432 | Console.Write("testMapMap(1)"); |
| 433 | Dictionary<int, Dictionary<int, int>> mm = client.testMapMap(1); |
| 434 | Console.Write(" = {"); |
| 435 | foreach (int key in mm.Keys) |
| 436 | { |
| 437 | Console.Write(key + " => {"); |
| 438 | Dictionary<int, int> m2 = mm[key]; |
| 439 | foreach (int k2 in m2.Keys) |
| 440 | { |
| 441 | Console.Write(k2 + " => " + m2[k2] + ", "); |
| 442 | } |
| 443 | Console.Write("}, "); |
| 444 | } |
| 445 | Console.WriteLine("}"); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 446 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 447 | Insanity insane = new Insanity(); |
| 448 | insane.UserMap = new Dictionary<Numberz, long>(); |
| 449 | insane.UserMap[Numberz.FIVE] = 5000L; |
| 450 | Xtruct truck = new Xtruct(); |
| 451 | truck.String_thing = "Truck"; |
| 452 | truck.Byte_thing = (sbyte)8; |
| 453 | truck.I32_thing = 8; |
| 454 | truck.I64_thing = 8; |
| 455 | insane.Xtructs = new List<Xtruct>(); |
| 456 | insane.Xtructs.Add(truck); |
| 457 | Console.Write("testInsanity()"); |
| 458 | Dictionary<long, Dictionary<Numberz, Insanity>> whoa = client.testInsanity(insane); |
| 459 | Console.Write(" = {"); |
| 460 | foreach (long key in whoa.Keys) |
| 461 | { |
| 462 | Dictionary<Numberz, Insanity> val = whoa[key]; |
| 463 | Console.Write(key + " => {"); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 464 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 465 | foreach (Numberz k2 in val.Keys) |
| 466 | { |
| 467 | Insanity v2 = val[k2]; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 468 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 469 | Console.Write(k2 + " => {"); |
| 470 | Dictionary<Numberz, long> userMap = v2.UserMap; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 471 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 472 | Console.Write("{"); |
| 473 | if (userMap != null) |
| 474 | { |
| 475 | foreach (Numberz k3 in userMap.Keys) |
| 476 | { |
| 477 | Console.Write(k3 + " => " + userMap[k3] + ", "); |
| 478 | } |
| 479 | } |
| 480 | else |
| 481 | { |
| 482 | Console.Write("null"); |
| 483 | } |
| 484 | Console.Write("}, "); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 485 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 486 | List<Xtruct> xtructs = v2.Xtructs; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 487 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 488 | Console.Write("{"); |
| 489 | if (xtructs != null) |
| 490 | { |
| 491 | foreach (Xtruct x in xtructs) |
| 492 | { |
| 493 | Console.Write("{\"" + x.String_thing + "\", " + x.Byte_thing + ", " + x.I32_thing + ", " + x.I32_thing + "}, "); |
| 494 | } |
| 495 | } |
| 496 | else |
| 497 | { |
| 498 | Console.Write("null"); |
| 499 | } |
| 500 | Console.Write("}"); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 501 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 502 | Console.Write("}, "); |
| 503 | } |
| 504 | Console.Write("}, "); |
| 505 | } |
| 506 | Console.WriteLine("}"); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 507 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 508 | sbyte arg0 = 1; |
| 509 | int arg1 = 2; |
| 510 | long arg2 = long.MaxValue; |
| 511 | Dictionary<short, string> multiDict = new Dictionary<short, string>(); |
| 512 | multiDict[1] = "one"; |
| 513 | Numberz arg4 = Numberz.FIVE; |
| 514 | long arg5 = 5000000; |
| 515 | Console.Write("Test Multi(" + arg0 + "," + arg1 + "," + arg2 + "," + multiDict + "," + arg4 + "," + arg5 + ")"); |
| 516 | Xtruct multiResponse = client.testMulti(arg0, arg1, arg2, multiDict, arg4, arg5); |
| 517 | Console.Write(" = Xtruct(byte_thing:" + multiResponse.Byte_thing + ",String_thing:" + multiResponse.String_thing |
| 518 | + ",i32_thing:" + multiResponse.I32_thing + ",i64_thing:" + multiResponse.I64_thing + ")\n"); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 519 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 520 | Console.WriteLine("Test Oneway(1)"); |
| 521 | client.testOneway(1); |
T Jake Luciani | 7070aaa | 2011-01-27 02:51:51 +0000 | [diff] [blame] | 522 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 523 | Console.Write("Test Calltime()"); |
| 524 | var startt = DateTime.UtcNow; |
| 525 | for ( int k=0; k<1000; ++k ) |
| 526 | client.testVoid(); |
| 527 | Console.WriteLine(" = " + (DateTime.UtcNow - startt).TotalSeconds.ToString() + " ms a testVoid() call" ); |
| 528 | } |
| 529 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 530 | } |