test & fix

This commit is contained in:
Christian Köllner 2020-04-16 07:57:26 +02:00
parent 5d0f24cdab
commit af6dcec8f7
5 changed files with 38 additions and 5 deletions

View File

@ -842,12 +842,16 @@ namespace Capnp.Net.Runtime.Tests
data[0] = p; data[0] = p;
Assert.ThrowsException<DeserializationException>(() => DeserializerState.CreateRoot(wf)); Assert.ThrowsException<DeserializationException>(() => DeserializerState.CreateRoot(wf));
p.SetFarPointer(0, 0, false); p.SetFarPointer(0, 0, false);
data[0] = p;
Assert.ThrowsException<DeserializationException>(() => DeserializerState.CreateRoot(wf)); Assert.ThrowsException<DeserializationException>(() => DeserializerState.CreateRoot(wf));
p.SetFarPointer(1, 0, false); p.SetFarPointer(1, 0, false);
data[0] = p;
Assert.ThrowsException<DeserializationException>(() => DeserializerState.CreateRoot(wf)); Assert.ThrowsException<DeserializationException>(() => DeserializerState.CreateRoot(wf));
p.SetFarPointer(0, 1, false); p.SetFarPointer(0, 1, false);
data[0] = p;
Assert.ThrowsException<DeserializationException>(() => DeserializerState.CreateRoot(wf)); Assert.ThrowsException<DeserializationException>(() => DeserializerState.CreateRoot(wf));
p.SetFarPointer(0, 0, true); p.SetFarPointer(0, 0, true);
data[0] = p;
Assert.ThrowsException<DeserializationException>(() => DeserializerState.CreateRoot(wf)); Assert.ThrowsException<DeserializationException>(() => DeserializerState.CreateRoot(wf));
var data2 = new ulong[3]; var data2 = new ulong[3];

View File

@ -18,6 +18,12 @@ namespace Capnp.Net.Runtime.Tests
{ {
var impl = new TestInterfaceImpl2(); var impl = new TestInterfaceImpl2();
Assert.AreEqual(impl, await impl.Unwrap<ITestInterface>()); 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()); Assert.IsNull(await default(ITestInterface).Unwrap());
var tcs = new TaskCompletionSource<ITestInterface>(); var tcs = new TaskCompletionSource<ITestInterface>();
tcs.SetResult(null); tcs.SetResult(null);

View File

@ -226,5 +226,22 @@ namespace Capnp.Net.Runtime.Tests
Assert.IsTrue(Task.WaitAll(new Task[] { w1, w2 }, MediumNonDbgTimeout)); Assert.IsTrue(Task.WaitAll(new Task[] { w1, w2 }, MediumNonDbgTimeout));
} }
} }
[TestMethod]
public void DisposedProxy()
{
var b = new BareProxy();
Assert.ThrowsException<ArgumentNullException>(() => b.Bind(null));
var impl = new TestInterfaceImpl2();
var proxy = Proxy.Share<ITestInterface>(impl);
var p = (Proxy)proxy;
Assert.ThrowsException<InvalidOperationException>(() => p.Bind(p.ConsumedCap));
Assert.IsFalse(p.IsDisposed);
proxy.Dispose();
Assert.IsTrue(p.IsDisposed);
Assert.ThrowsException<ObjectDisposedException>(() => p.ConsumedCap);
var t = proxy.Foo(123, true);
Assert.IsTrue(Assert.ThrowsExceptionAsync<ObjectDisposedException>(() => t).Wait(MediumNonDbgTimeout));
}
} }
} }

View File

@ -29,7 +29,7 @@
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<DefineConstants>DebugFinalizers</DefineConstants> <DefineConstants></DefineConstants>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|netstandard2.0|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|netstandard2.0|AnyCPU'">

View File

@ -329,10 +329,13 @@ namespace Capnp
case PointerKind.Far: case PointerKind.Far:
if (pointer.TargetSegmentIndex >= Segments.Count)
throw new DeserializationException("Error decoding pointer: Invalid target segment index");
CurrentSegmentIndex = pointer.TargetSegmentIndex;
if (pointer.IsDoubleFar) if (pointer.IsDoubleFar)
{ {
CurrentSegmentIndex = pointer.TargetSegmentIndex;
if (pointer.LandingPadOffset >= CurrentSegment.Length - 1) if (pointer.LandingPadOffset >= CurrentSegment.Length - 1)
throw new DeserializationException("Error decoding double-far pointer: exceeds segment bounds"); throw new DeserializationException("Error decoding double-far pointer: exceeds segment bounds");
@ -353,9 +356,12 @@ namespace Capnp
} }
else else
{ {
CurrentSegmentIndex = pointer.TargetSegmentIndex;
Offset = 0; Offset = 0;
offset = pointer.LandingPadOffset; offset = pointer.LandingPadOffset;
if (pointer.LandingPadOffset >= CurrentSegment.Length)
throw new DeserializationException("Error decoding pointer: exceeds segment bounds");
pointer = CurrentSegment[pointer.LandingPadOffset]; pointer = CurrentSegment[pointer.LandingPadOffset];
} }
continue; continue;
@ -701,7 +707,7 @@ namespace Capnp
{ {
foreach (var cap in Caps) foreach (var cap in Caps)
{ {
cap?.Release(); cap.Release();
} }
Caps = null; Caps = null;