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