public CrazyNesting DeepCopy() { var tmp21 = new CrazyNesting(); if ((String_field != null) && __isset.string_field) { tmp21.String_field = this.String_field; } tmp21.__isset.string_field = this.__isset.string_field; if ((Set_field != null) && __isset.set_field) { tmp21.Set_field = this.Set_field.DeepCopy(); } tmp21.__isset.set_field = this.__isset.set_field; if ((List_field != null)) { tmp21.List_field = this.List_field.DeepCopy(); } if ((Binary_field != null) && __isset.binary_field) { tmp21.Binary_field = this.Binary_field.ToArray(); } tmp21.__isset.binary_field = this.__isset.binary_field; return(tmp21); }
public static async Task <int> ExecuteClientTestAsync(ThriftTest.Client client) { var returnCode = 0; Console.Write("testVoid()"); await client.testVoidAsync(MakeTimeoutToken()); Console.WriteLine(" = void"); Console.Write("testString(\"Test\")"); var s = await client.testStringAsync("Test", MakeTimeoutToken()); Console.WriteLine(" = \"" + s + "\""); if ("Test" != s) { Console.WriteLine("*** FAILED ***"); returnCode |= ErrorBaseTypes; } Console.Write("testBool(true)"); var t = await client.testBoolAsync((bool)true, MakeTimeoutToken()); Console.WriteLine(" = " + t); if (!t) { Console.WriteLine("*** FAILED ***"); returnCode |= ErrorBaseTypes; } Console.Write("testBool(false)"); var f = await client.testBoolAsync((bool)false, MakeTimeoutToken()); Console.WriteLine(" = " + f); if (f) { Console.WriteLine("*** FAILED ***"); returnCode |= ErrorBaseTypes; } Console.Write("testByte(1)"); var i8 = await client.testByteAsync((sbyte)1, MakeTimeoutToken()); Console.WriteLine(" = " + i8); if (1 != i8) { Console.WriteLine("*** FAILED ***"); returnCode |= ErrorBaseTypes; } Console.Write("testI32(-1)"); var i32 = await client.testI32Async(-1, MakeTimeoutToken()); Console.WriteLine(" = " + i32); if (-1 != i32) { Console.WriteLine("*** FAILED ***"); returnCode |= ErrorBaseTypes; } Console.Write("testI64(-34359738368)"); var i64 = await client.testI64Async(-34359738368, MakeTimeoutToken()); Console.WriteLine(" = " + i64); if (-34359738368 != i64) { Console.WriteLine("*** FAILED ***"); returnCode |= ErrorBaseTypes; } // TODO: Validate received message Console.Write("testDouble(5.325098235)"); var dub = await client.testDoubleAsync(5.325098235, MakeTimeoutToken()); Console.WriteLine(" = " + dub); if (5.325098235 != dub) { Console.WriteLine("*** FAILED ***"); returnCode |= ErrorBaseTypes; } Console.Write("testDouble(-0.000341012439638598279)"); dub = await client.testDoubleAsync(-0.000341012439638598279, MakeTimeoutToken()); Console.WriteLine(" = " + dub); if (-0.000341012439638598279 != dub) { Console.WriteLine("*** FAILED ***"); returnCode |= ErrorBaseTypes; } // testBinary() foreach (BinaryTestSize binTestCase in Enum.GetValues(typeof(BinaryTestSize))) { var binOut = PrepareTestData(true, binTestCase); Console.Write("testBinary({0} bytes)", binOut.Length); try { var binIn = await client.testBinaryAsync(binOut, MakeTimeoutToken()); Console.WriteLine(" = {0} bytes", binIn.Length); if (binIn.Length != binOut.Length) { Console.WriteLine("*** FAILED ***"); returnCode |= ErrorBaseTypes; } for (var ofs = 0; ofs < Math.Min(binIn.Length, binOut.Length); ++ofs) { if (binIn[ofs] != binOut[ofs]) { Console.WriteLine("*** FAILED ***"); returnCode |= ErrorBaseTypes; } } } catch (Thrift.TApplicationException ex) { Console.WriteLine("*** FAILED ***"); returnCode |= ErrorBaseTypes; Console.WriteLine(ex.Message + "\n" + ex.StackTrace); } } // CrazyNesting Console.WriteLine("Test CrazyNesting"); var one = new CrazyNesting(); var two = new CrazyNesting(); one.String_field = "crazy"; two.String_field = "crazy"; one.Binary_field = new byte[] { 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0xFF }; two.Binary_field = new byte[10] { 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0xFF }; if (typeof(CrazyNesting).GetMethod("Equals")?.DeclaringType == typeof(CrazyNesting)) { if (!one.Equals(two)) { Console.WriteLine("*** FAILED ***"); returnCode |= ErrorContainers; } } // TODO: Validate received message Console.Write("testStruct({\"Zero\", 1, -3, -5})"); var o = new Xtruct { String_thing = "Zero", Byte_thing = (sbyte)1, I32_thing = -3, I64_thing = -5 }; var i = await client.testStructAsync(o, MakeTimeoutToken()); Console.WriteLine(" = {\"" + i.String_thing + "\", " + i.Byte_thing + ", " + i.I32_thing + ", " + i.I64_thing + "}"); // TODO: Validate received message Console.Write("testNest({1, {\"Zero\", 1, -3, -5}, 5})"); var o2 = new Xtruct2 { Byte_thing = (sbyte)1, Struct_thing = o, I32_thing = 5 }; var i2 = await client.testNestAsync(o2, MakeTimeoutToken()); i = i2.Struct_thing; Console.WriteLine(" = {" + i2.Byte_thing + ", {\"" + i.String_thing + "\", " + i.Byte_thing + ", " + i.I32_thing + ", " + i.I64_thing + "}, " + i2.I32_thing + "}"); var mapout = new Dictionary <int, int>(); for (var j = 0; j < 5; j++) { mapout[j] = j - 10; } Console.Write("testMap({"); var first = true; foreach (var key in mapout.Keys) { if (first) { first = false; } else { Console.Write(", "); } Console.Write(key + " => " + mapout[key]); } Console.Write("})"); var mapin = await client.testMapAsync(mapout, MakeTimeoutToken()); Console.Write(" = {"); first = true; foreach (var key in mapin.Keys) { if (first) { first = false; } else { Console.Write(", "); } Console.Write(key + " => " + mapin[key]); } Console.WriteLine("}"); // TODO: Validate received message var listout = new List <int>(); for (var j = -2; j < 3; j++) { listout.Add(j); } Console.Write("testList({"); first = true; foreach (var j in listout) { if (first) { first = false; } else { Console.Write(", "); } Console.Write(j); } Console.Write("})"); var listin = await client.testListAsync(listout, MakeTimeoutToken()); Console.Write(" = {"); first = true; foreach (var j in listin) { if (first) { first = false; } else { Console.Write(", "); } Console.Write(j); } Console.WriteLine("}"); //set // TODO: Validate received message var setout = new THashSet <int>(); for (var j = -2; j < 3; j++) { setout.Add(j); } Console.Write("testSet({"); first = true; foreach (int j in setout) { if (first) { first = false; } else { Console.Write(", "); } Console.Write(j); } Console.Write("})"); var setin = await client.testSetAsync(setout, MakeTimeoutToken()); Console.Write(" = {"); first = true; foreach (int j in setin) { if (first) { first = false; } else { Console.Write(", "); } Console.Write(j); } Console.WriteLine("}"); Console.Write("testEnum(ONE)"); var ret = await client.testEnumAsync(Numberz.ONE, MakeTimeoutToken()); Console.WriteLine(" = " + ret); if (Numberz.ONE != ret) { Console.WriteLine("*** FAILED ***"); returnCode |= ErrorStructs; } Console.Write("testEnum(TWO)"); ret = await client.testEnumAsync(Numberz.TWO, MakeTimeoutToken()); Console.WriteLine(" = " + ret); if (Numberz.TWO != ret) { Console.WriteLine("*** FAILED ***"); returnCode |= ErrorStructs; } Console.Write("testEnum(THREE)"); ret = await client.testEnumAsync(Numberz.THREE, MakeTimeoutToken()); Console.WriteLine(" = " + ret); if (Numberz.THREE != ret) { Console.WriteLine("*** FAILED ***"); returnCode |= ErrorStructs; } Console.Write("testEnum(FIVE)"); ret = await client.testEnumAsync(Numberz.FIVE, MakeTimeoutToken()); Console.WriteLine(" = " + ret); if (Numberz.FIVE != ret) { Console.WriteLine("*** FAILED ***"); returnCode |= ErrorStructs; } Console.Write("testEnum(EIGHT)"); ret = await client.testEnumAsync(Numberz.EIGHT, MakeTimeoutToken()); Console.WriteLine(" = " + ret); if (Numberz.EIGHT != ret) { Console.WriteLine("*** FAILED ***"); returnCode |= ErrorStructs; } Console.Write("testTypedef(309858235082523)"); var uid = await client.testTypedefAsync(309858235082523L, MakeTimeoutToken()); Console.WriteLine(" = " + uid); if (309858235082523L != uid) { Console.WriteLine("*** FAILED ***"); returnCode |= ErrorStructs; } // TODO: Validate received message Console.Write("testMapMap(1)"); var mm = await client.testMapMapAsync(1, MakeTimeoutToken()); Console.Write(" = {"); foreach (var key in mm.Keys) { Console.Write(key + " => {"); var m2 = mm[key]; foreach (var k2 in m2.Keys) { Console.Write(k2 + " => " + m2[k2] + ", "); } Console.Write("}, "); } Console.WriteLine("}"); // TODO: Validate received message var insane = new Insanity { UserMap = new Dictionary <Numberz, long> { [Numberz.FIVE] = 5000L } }; var truck = new Xtruct { String_thing = "Truck", Byte_thing = (sbyte)8, I32_thing = 8, I64_thing = 8 }; insane.Xtructs = new List <Xtruct> { truck }; Console.Write("testInsanity()"); var whoa = await client.testInsanityAsync(insane, MakeTimeoutToken()); Console.Write(" = {"); foreach (var key in whoa.Keys) { var val = whoa[key]; Console.Write(key + " => {"); foreach (var k2 in val.Keys) { var v2 = val[k2]; Console.Write(k2 + " => {"); var userMap = v2.UserMap; Console.Write("{"); if (userMap != null) { foreach (var k3 in userMap.Keys) { Console.Write(k3 + " => " + userMap[k3] + ", "); } } else { Console.Write("null"); } Console.Write("}, "); var xtructs = v2.Xtructs; Console.Write("{"); if (xtructs != null) { foreach (var x in xtructs) { Console.Write("{\"" + x.String_thing + "\", " + x.Byte_thing + ", " + x.I32_thing + ", " + x.I32_thing + "}, "); } } else { Console.Write("null"); } Console.Write("}"); Console.Write("}, "); } Console.Write("}, "); } Console.WriteLine("}"); sbyte arg0 = 1; var arg1 = 2; var arg2 = long.MaxValue; var multiDict = new Dictionary <short, string> { [1] = "one" }; var tmpMultiDict = new List <string>(); foreach (var pair in multiDict) { tmpMultiDict.Add(pair.Key + " => " + pair.Value); } var arg4 = Numberz.FIVE; long arg5 = 5000000; Console.Write("Test Multi(" + arg0 + "," + arg1 + "," + arg2 + ",{" + string.Join(",", tmpMultiDict) + "}," + arg4 + "," + arg5 + ")"); var multiResponse = await client.testMultiAsync(arg0, arg1, arg2, multiDict, arg4, arg5, MakeTimeoutToken()); Console.Write(" = Xtruct(byte_thing:" + multiResponse.Byte_thing + ",String_thing:" + multiResponse.String_thing + ",i32_thing:" + multiResponse.I32_thing + ",i64_thing:" + multiResponse.I64_thing + ")\n"); try { Console.WriteLine("testException(\"Xception\")"); await client.testExceptionAsync("Xception", MakeTimeoutToken()); Console.WriteLine("*** FAILED ***"); returnCode |= ErrorExceptions; } catch (Xception ex) { if (ex.ErrorCode != 1001 || ex.Message != "Xception") { Console.WriteLine("*** FAILED ***"); returnCode |= ErrorExceptions; } } catch (Exception ex) { Console.WriteLine("*** FAILED ***"); returnCode |= ErrorExceptions; Console.WriteLine(ex.Message + "\n" + ex.StackTrace); } try { Console.WriteLine("testException(\"TException\")"); await client.testExceptionAsync("TException", MakeTimeoutToken()); Console.WriteLine("*** FAILED ***"); returnCode |= ErrorExceptions; } catch (Thrift.TException) { // OK } catch (Exception ex) { Console.WriteLine("*** FAILED ***"); returnCode |= ErrorExceptions; Console.WriteLine(ex.Message + "\n" + ex.StackTrace); } try { Console.WriteLine("testException(\"ok\")"); await client.testExceptionAsync("ok", MakeTimeoutToken()); // OK } catch (Exception ex) { Console.WriteLine("*** FAILED ***"); returnCode |= ErrorExceptions; Console.WriteLine(ex.Message + "\n" + ex.StackTrace); } try { Console.WriteLine("testMultiException(\"Xception\", ...)"); await client.testMultiExceptionAsync("Xception", "ignore", MakeTimeoutToken()); Console.WriteLine("*** FAILED ***"); returnCode |= ErrorExceptions; } catch (Xception ex) { if (ex.ErrorCode != 1001 || ex.Message != "This is an Xception") { Console.WriteLine("*** FAILED ***"); returnCode |= ErrorExceptions; } } catch (Exception ex) { Console.WriteLine("*** FAILED ***"); returnCode |= ErrorExceptions; Console.WriteLine(ex.Message + "\n" + ex.StackTrace); } try { Console.WriteLine("testMultiException(\"Xception2\", ...)"); await client.testMultiExceptionAsync("Xception2", "ignore", MakeTimeoutToken()); Console.WriteLine("*** FAILED ***"); returnCode |= ErrorExceptions; } catch (Xception2 ex) { if (ex.ErrorCode != 2002 || ex.Struct_thing.String_thing != "This is an Xception2") { Console.WriteLine("*** FAILED ***"); returnCode |= ErrorExceptions; } } catch (Exception ex) { Console.WriteLine("*** FAILED ***"); returnCode |= ErrorExceptions; Console.WriteLine(ex.Message + "\n" + ex.StackTrace); } try { Console.WriteLine("testMultiException(\"success\", \"OK\")"); if ("OK" != (await client.testMultiExceptionAsync("success", "OK", MakeTimeoutToken())).String_thing) { Console.WriteLine("*** FAILED ***"); returnCode |= ErrorExceptions; } } catch (Exception ex) { Console.WriteLine("*** FAILED ***"); returnCode |= ErrorExceptions; Console.WriteLine(ex.Message + "\n" + ex.StackTrace); } Console.WriteLine("Test Oneway(1)"); var sw = new Stopwatch(); sw.Start(); await client.testOnewayAsync(1, MakeTimeoutToken()); sw.Stop(); if (sw.ElapsedMilliseconds > 1000) { Console.WriteLine("*** FAILED ***"); returnCode |= ErrorBaseTypes; } Console.Write("Test Calltime()"); var times = 50; sw.Reset(); sw.Start(); var token = MakeTimeoutToken(20000); for (var k = 0; k < times; ++k) { await client.testVoidAsync(token); } sw.Stop(); Console.WriteLine(" = {0} ms a testVoid() call", sw.ElapsedMilliseconds / times); return(returnCode); }