diff options
Diffstat (limited to 'test/netstd/Server/TestServer.cs')
-rw-r--r-- | test/netstd/Server/TestServer.cs | 153 |
1 files changed, 83 insertions, 70 deletions
diff --git a/test/netstd/Server/TestServer.cs b/test/netstd/Server/TestServer.cs index 515a299f8..86072b0a7 100644 --- a/test/netstd/Server/TestServer.cs +++ b/test/netstd/Server/TestServer.cs @@ -229,10 +229,10 @@ namespace ThriftTest return Task.CompletedTask; } - public Task<string> testString(string thing, CancellationToken cancellationToken) + public Task<string> testString(string? thing, CancellationToken cancellationToken) { - logger.Invoke("testString({0})", thing); - return Task.FromResult(thing); + logger.Invoke("testString({0})", thing ?? "<null>"); + return Task.FromResult(thing ?? string.Empty); } public Task<bool> testBool(bool thing, CancellationToken cancellationToken) @@ -265,117 +265,129 @@ namespace ThriftTest return Task.FromResult(thing); } - public Task<byte[]> testBinary(byte[] thing, CancellationToken cancellationToken) + public Task<byte[]> testBinary(byte[]? thing, CancellationToken cancellationToken) { - logger.Invoke("testBinary({0} bytes)", thing.Length); - return Task.FromResult(thing); + logger.Invoke("testBinary({0} bytes)", thing?.Length ?? 0); + return Task.FromResult(thing ?? Array.Empty<byte>()); } - public Task<Xtruct> testStruct(Xtruct thing, CancellationToken cancellationToken) + public Task<Xtruct> testStruct(Xtruct? thing, CancellationToken cancellationToken) { - logger.Invoke("testStruct({{\"{0}\", {1}, {2}, {3}}})", thing.String_thing, thing.Byte_thing, thing.I32_thing, thing.I64_thing); - return Task.FromResult(thing); + logger.Invoke("testStruct({{\"{0}\", {1}, {2}, {3}}})", thing?.String_thing ?? "<null>", thing?.Byte_thing ?? 0, thing?.I32_thing ?? 0, thing?.I64_thing ?? 0); + return Task.FromResult(thing ?? new Xtruct()); // null returns are not allowed in Thrift } - public Task<Xtruct2> testNest(Xtruct2 nest, CancellationToken cancellationToken) + public Task<Xtruct2> testNest(Xtruct2? nest, CancellationToken cancellationToken) { - var thing = nest.Struct_thing; + var thing = nest?.Struct_thing; logger.Invoke("testNest({{{0}, {{\"{1}\", {2}, {3}, {4}, {5}}}}})", - nest.Byte_thing, - thing.String_thing, - thing.Byte_thing, - thing.I32_thing, - thing.I64_thing, - nest.I32_thing); - return Task.FromResult(nest); + nest?.Byte_thing ?? 0, + thing?.String_thing ?? "<null>", + thing?.Byte_thing ?? 0, + thing?.I32_thing ?? 0, + thing?.I64_thing ?? 0, + nest?.I32_thing ?? 0); + return Task.FromResult(nest ?? new Xtruct2()); // null returns are not allowed in Thrift } - public Task<Dictionary<int, int>> testMap(Dictionary<int, int> thing, CancellationToken cancellationToken) + public Task<Dictionary<int, int>> testMap(Dictionary<int, int>? thing, CancellationToken cancellationToken) { sb.Clear(); sb.Append("testMap({{"); - var first = true; - foreach (var key in thing.Keys) + if (thing != null) { - if (first) - { - first = false; - } - else + var first = true; + foreach (var key in thing.Keys) { - sb.Append(", "); + if (first) + { + first = false; + } + else + { + sb.Append(", "); + } + sb.AppendFormat("{0} => {1}", key, thing[key]); } - sb.AppendFormat("{0} => {1}", key, thing[key]); } sb.Append("}})"); logger.Invoke(sb.ToString()); - return Task.FromResult(thing); + return Task.FromResult(thing ?? new Dictionary<int, int>()); // null returns are not allowed in Thrift } - public Task<Dictionary<string, string>> testStringMap(Dictionary<string, string> thing, CancellationToken cancellationToken) + public Task<Dictionary<string, string>> testStringMap(Dictionary<string, string>? thing, CancellationToken cancellationToken) { sb.Clear(); sb.Append("testStringMap({{"); - var first = true; - foreach (var key in thing.Keys) + if (thing != null) { - if (first) - { - first = false; - } - else + var first = true; + foreach (var key in thing.Keys) { - sb.Append(", "); + if (first) + { + first = false; + } + else + { + sb.Append(", "); + } + sb.AppendFormat("{0} => {1}", key, thing[key]); } - sb.AppendFormat("{0} => {1}", key, thing[key]); } sb.Append("}})"); logger.Invoke(sb.ToString()); - return Task.FromResult(thing); + return Task.FromResult(thing ?? new Dictionary<string, string>()); // null returns are not allowed in Thrift } - public Task<THashSet<int>> testSet(THashSet<int> thing, CancellationToken cancellationToken) + public Task<HashSet<int>> testSet(HashSet<int>? thing, CancellationToken cancellationToken) { sb.Clear(); sb.Append("testSet({{"); - var first = true; - foreach (int elem in thing) + if (thing != null) { - if (first) - { - first = false; - } - else + var first = true; + foreach (int elem in thing) { - sb.Append(", "); + if (first) + { + first = false; + } + else + { + sb.Append(", "); + } + sb.AppendFormat("{0}", elem); } - sb.AppendFormat("{0}", elem); } sb.Append("}})"); logger.Invoke(sb.ToString()); - return Task.FromResult(thing); + return Task.FromResult(thing ?? new HashSet<int>()); // null returns are not allowed in Thrift } - public Task<List<int>> testList(List<int> thing, CancellationToken cancellationToken) + public Task<List<int>> testList(List<int>? thing, CancellationToken cancellationToken) { sb.Clear(); sb.Append("testList({{"); - var first = true; - foreach (var elem in thing) + if (thing != null) { - if (first) + var first = true; + foreach (var elem in thing) { - first = false; + if (first) + { + first = false; + } + else + { + sb.Append(", "); + } + sb.AppendFormat("{0}", elem); } - else - { - sb.Append(", "); - } - sb.AppendFormat("{0}", elem); } sb.Append("}})"); logger.Invoke(sb.ToString()); - return Task.FromResult(thing); + return Task.FromResult(thing ?? new List<int>()); // null returns are not allowed in Thrift } public Task<Numberz> testEnum(Numberz thing, CancellationToken cancellationToken) @@ -409,7 +421,7 @@ namespace ThriftTest return Task.FromResult(mapmap); } - public Task<Dictionary<long, Dictionary<Numberz, Insanity>>> testInsanity(Insanity argument, CancellationToken cancellationToken) + public Task<Dictionary<long, Dictionary<Numberz, Insanity>>> testInsanity(Insanity? argument, CancellationToken cancellationToken) { logger.Invoke("testInsanity()"); @@ -428,8 +440,9 @@ namespace ThriftTest var first_map = new Dictionary<Numberz, Insanity>(); var second_map = new Dictionary<Numberz, Insanity>(); ; - first_map[Numberz.TWO] = argument; - first_map[Numberz.THREE] = argument; + // null dict keys/values are not allowed in Thrift + first_map[Numberz.TWO] = argument ?? new Insanity(); + first_map[Numberz.THREE] = argument ?? new Insanity(); second_map[Numberz.SIX] = new Insanity(); @@ -442,7 +455,7 @@ namespace ThriftTest return Task.FromResult(insane); } - public Task<Xtruct> testMulti(sbyte arg0, int arg1, long arg2, Dictionary<short, string> arg3, Numberz arg4, long arg5, + public Task<Xtruct> testMulti(sbyte arg0, int arg1, long arg2, Dictionary<short, string>? arg3, Numberz arg4, long arg5, CancellationToken cancellationToken) { logger.Invoke("testMulti()"); @@ -455,9 +468,9 @@ namespace ThriftTest return Task.FromResult(hello); } - public Task testException(string arg, CancellationToken cancellationToken) + public Task testException(string? arg, CancellationToken cancellationToken) { - logger.Invoke("testException({0})", arg); + logger.Invoke("testException({0})", arg ?? "<null>"); if (arg == "Xception") { var x = new Xception @@ -474,9 +487,9 @@ namespace ThriftTest return Task.CompletedTask; } - public Task<Xtruct> testMultiException(string arg0, string arg1, CancellationToken cancellationToken) + public Task<Xtruct> testMultiException(string? arg0, string? arg1, CancellationToken cancellationToken) { - logger.Invoke("testMultiException({0}, {1})", arg0, arg1); + logger.Invoke("testMultiException({0}, {1})", arg0 ?? "<null>", arg1 ?? "<null>"); if (arg0 == "Xception") { var x = new Xception |