mirror of
https://github.com/zap-proto/cs.git
synced 2026-10-30 15:05:32 +00:00
Finishes the in-flight capnp→ZAP rebrand on this branch. The prior commits
renamed identifiers/namespaces/files/projects (Capnp.Net.Runtime→Zap.Net.Runtime,
CapnpC→ZapC, .capnp→.zap) but left the human-readable brand name "Cap'n Proto"
throughout doc-comments, .csproj/.nuspec descriptions, README, MSBuild .xaml
rule display names, and the generated XML doc. This completes brand neutrality:
- Replace 154 "Cap'n Proto" / 4 "Cap'n-Proto" / 1 "Cap'n'p" prose occurrences
with "ZAP" across 32 first-party files (runtime, generator, zapc-csharp,
MSBuild integration, chocolatey nuspecs, README, docs, XML doc).
- Revert the LICENSE provenance URL to the real upstream fork
(c80k/capnproto-dotnetcore) — upstream-fork license headers must stay.
- Canonicalize project/repo URLs to github.com/zap-proto/cs (were fabricated
c80k/zap-dotnetcore) in csproj/nuspec/VERIFICATION/README badges.
- Canonicalize docs URLs zap-protocol(.github.io|/zap-cs|/zap-cpp-core)
→ zap-proto.dev / github.com/zap-proto/{cs,cpp-core}.
- Collapse redundant "zap \"ZAP\"" PackageTags to "zap".
Verified consistent (no toolchain on host): every .sln/.csproj ProjectReference
resolves; all namespaces are Zap*/ZapC*; MSBuild task chain
(GenerateZapFileCodeBehindTask, ZapFiles ItemGroup, _ZapcCsharp_TaskAssembly)
is uniformly renamed; props/targets/xaml/coverage/chocolatey carry no capnp.
Deliberately preserved as upstream-derived test data (not first-party source):
upstream Cap'n Proto schema fixtures (rpc.zap, rpc-twoparty.zap, json.zap,
rpc-csharp.zap), golden compiler-error outputs (errors.txt), and the
machine-generated DO-NOT-EDIT test.zap.{c++,h}. Their "Cap'n Proto" strings are
the literal output of the external schema compiler the compat test matches.
209 lines
6.5 KiB
C#
209 lines
6.5 KiB
C#
using Zap.Net.Runtime.Tests.GenImpls;
|
|
using Zap.Rpc;
|
|
using Zap.Util;
|
|
using Zap_test.Zap.Test;
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Zap.Net.Runtime.Tests
|
|
{
|
|
[TestClass]
|
|
[TestCategory("Coverage")]
|
|
public class ImpatientTests
|
|
{
|
|
[TestMethod]
|
|
public async Task Unwrap()
|
|
{
|
|
var impl = new TestInterfaceImpl2();
|
|
Assert.AreEqual(impl, await impl.Unwrap<ITestInterface>());
|
|
using (var proxy = Proxy.Share<ITestInterface>(impl))
|
|
using (var reso = ((Proxy)proxy).GetResolvedCapability<ITestInterface>())
|
|
{
|
|
|
|
Assert.AreEqual(((Proxy)proxy).ConsumedCap, ((Proxy)reso).ConsumedCap);
|
|
}
|
|
Assert.IsNull(await default(ITestInterface).Unwrap());
|
|
var tcs = new TaskCompletionSource<ITestInterface>();
|
|
tcs.SetResult(null);
|
|
Assert.IsNull(await tcs.Task.Eager(true).Unwrap());
|
|
var excepted = Task.FromException<ITestInterface>(new InvalidTimeZoneException("So annoying"));
|
|
await Assert.ThrowsExceptionAsync<RpcException>(async () => await excepted.Eager(true).Unwrap());
|
|
}
|
|
|
|
[TestMethod]
|
|
public async Task MaybeTailCall3()
|
|
{
|
|
bool flag = false;
|
|
|
|
SerializerState Fn(int a, int b, int c)
|
|
{
|
|
Assert.AreEqual(0, a);
|
|
Assert.AreEqual(1, b);
|
|
Assert.AreEqual(2, c);
|
|
flag = true;
|
|
return null;
|
|
}
|
|
|
|
var t = Task.FromResult((0, 1, 2));
|
|
await Impatient.MaybeTailCall(t, Fn);
|
|
Assert.IsTrue(flag);
|
|
}
|
|
|
|
[TestMethod]
|
|
public async Task MaybeTailCall4()
|
|
{
|
|
bool flag = false;
|
|
|
|
SerializerState Fn(int a, int b, int c, int d)
|
|
{
|
|
Assert.AreEqual(0, a);
|
|
Assert.AreEqual(1, b);
|
|
Assert.AreEqual(2, c);
|
|
Assert.AreEqual(3, d);
|
|
flag = true;
|
|
return null;
|
|
}
|
|
|
|
var t = Task.FromResult((0, 1, 2, 3));
|
|
await Impatient.MaybeTailCall(t, Fn);
|
|
Assert.IsTrue(flag);
|
|
}
|
|
|
|
[TestMethod]
|
|
public async Task MaybeTailCall5()
|
|
{
|
|
bool flag = false;
|
|
|
|
SerializerState Fn(int a, int b, int c, int d, int e)
|
|
{
|
|
Assert.AreEqual(0, a);
|
|
Assert.AreEqual(1, b);
|
|
Assert.AreEqual(2, c);
|
|
Assert.AreEqual(3, d);
|
|
Assert.AreEqual(4, e);
|
|
flag = true;
|
|
return null;
|
|
}
|
|
|
|
var t = Task.FromResult((0, 1, 2, 3, 4));
|
|
await Impatient.MaybeTailCall(t, Fn);
|
|
Assert.IsTrue(flag);
|
|
}
|
|
|
|
[TestMethod]
|
|
public async Task MaybeTailCall6()
|
|
{
|
|
bool flag = false;
|
|
|
|
SerializerState Fn(int a, int b, int c, int d, int e, int f)
|
|
{
|
|
Assert.AreEqual(0, a);
|
|
Assert.AreEqual(1, b);
|
|
Assert.AreEqual(2, c);
|
|
Assert.AreEqual(3, d);
|
|
Assert.AreEqual(4, e);
|
|
Assert.AreEqual(5, f);
|
|
flag = true;
|
|
return null;
|
|
}
|
|
|
|
var t = Task.FromResult((0, 1, 2, 3, 4, 5));
|
|
await Impatient.MaybeTailCall(t, Fn);
|
|
Assert.IsTrue(flag);
|
|
}
|
|
|
|
[TestMethod]
|
|
public async Task MaybeTailCall7()
|
|
{
|
|
bool flag = false;
|
|
|
|
SerializerState Fn(int a, int b, int c, int d, int e, int f, int g)
|
|
{
|
|
Assert.AreEqual(0, a);
|
|
Assert.AreEqual(1, b);
|
|
Assert.AreEqual(2, c);
|
|
Assert.AreEqual(3, d);
|
|
Assert.AreEqual(4, e);
|
|
Assert.AreEqual(5, f);
|
|
Assert.AreEqual(6, g);
|
|
flag = true;
|
|
return null;
|
|
}
|
|
|
|
var t = Task.FromResult((0, 1, 2, 3, 4, 5, 6));
|
|
await Impatient.MaybeTailCall(t, Fn);
|
|
Assert.IsTrue(flag);
|
|
}
|
|
|
|
class PromisedAnswerMock : IPromisedAnswer
|
|
{
|
|
readonly TaskCompletionSource<DeserializerState> _tcs = new TaskCompletionSource<DeserializerState>();
|
|
public StrictlyOrderedAwaitTask<DeserializerState> WhenReturned { get; }
|
|
|
|
public PromisedAnswerMock()
|
|
{
|
|
WhenReturned = _tcs.Task.EnforceAwaitOrder();
|
|
}
|
|
|
|
public bool IsTailCall => false;
|
|
|
|
public ConsumedCapability Access(MemberAccessPath access)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public ConsumedCapability Access(MemberAccessPath access, Task<IDisposable> proxyTask)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
}
|
|
}
|
|
|
|
[TestMethod]
|
|
public void ObsoleteGetAnswer()
|
|
{
|
|
#pragma warning disable CS0618
|
|
var answer = new PromisedAnswerMock();
|
|
Assert.ThrowsException<ArgumentException>(() => Impatient.GetAnswer(Task.FromResult(new object())));
|
|
var t = Impatient.MakePipelineAware(answer, _ => _);
|
|
Assert.AreEqual(answer, Impatient.GetAnswer(t));
|
|
#pragma warning restore CS0618
|
|
}
|
|
|
|
[TestMethod]
|
|
public async Task Access()
|
|
{
|
|
var answer = new PromisedAnswerMock();
|
|
async Task AwaitReturn() => await answer.WhenReturned;
|
|
var cap = Impatient.Access(AwaitReturn(), new MemberAccessPath(), Task.FromResult<IDisposable>(new TestInterfaceImpl2()));
|
|
using (var proxy = new BareProxy(cap))
|
|
{
|
|
await proxy.WhenResolved;
|
|
}
|
|
}
|
|
|
|
[TestMethod]
|
|
public void ObsoletePseudoEager()
|
|
{
|
|
#pragma warning disable CS0618
|
|
var task = Task.FromResult<ITestInterface>(new TestInterfaceImpl2());
|
|
Assert.IsTrue(task.PseudoEager() is Proxy proxy && proxy.WhenResolved.IsCompleted);
|
|
#pragma warning restore CS0618
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Eager()
|
|
{
|
|
var task = Task.FromResult<ITestInterface>(new TestInterfaceImpl2());
|
|
Assert.ThrowsException<ArgumentException>(() => task.Eager(false));
|
|
Assert.ThrowsException<ArgumentException>(() => task.Eager());
|
|
}
|
|
}
|
|
}
|