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