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