mirror of
https://github.com/FabInfra/capnproto-dotnetcore_Runtime.git
synced 2025-03-12 23:01:44 +01:00
first ListSerializer TC
ListOfBitsSerializer stack overflow bugfix build script fix
This commit is contained in:
parent
68d4ad668e
commit
3877e2aca3
@ -24,6 +24,7 @@
|
|||||||
<Compile Include="..\Capnp.Net.Runtime.Tests\RpcSchemaTests.cs" Link="RpcSchemaTests.cs" />
|
<Compile Include="..\Capnp.Net.Runtime.Tests\RpcSchemaTests.cs" Link="RpcSchemaTests.cs" />
|
||||||
<Compile Include="..\Capnp.Net.Runtime.Tests\ScatteringStream.cs" Link="ScatteringStream.cs" />
|
<Compile Include="..\Capnp.Net.Runtime.Tests\ScatteringStream.cs" Link="ScatteringStream.cs" />
|
||||||
<Compile Include="..\Capnp.Net.Runtime.Tests\SegmentAllocatorTests.cs" Link="SegmentAllocatorTests.cs" />
|
<Compile Include="..\Capnp.Net.Runtime.Tests\SegmentAllocatorTests.cs" Link="SegmentAllocatorTests.cs" />
|
||||||
|
<Compile Include="..\Capnp.Net.Runtime.Tests\SerializationTests.cs" Link="SerializationTests.cs" />
|
||||||
<Compile Include="..\Capnp.Net.Runtime.Tests\TcpRpc.cs" Link="TcpRpc.cs" />
|
<Compile Include="..\Capnp.Net.Runtime.Tests\TcpRpc.cs" Link="TcpRpc.cs" />
|
||||||
<Compile Include="..\Capnp.Net.Runtime.Tests\TcpRpcAdvancedStuff.cs" Link="TcpRpcAdvancedStuff.cs" />
|
<Compile Include="..\Capnp.Net.Runtime.Tests\TcpRpcAdvancedStuff.cs" Link="TcpRpcAdvancedStuff.cs" />
|
||||||
<Compile Include="..\Capnp.Net.Runtime.Tests\TcpRpcInterop.cs" Link="TcpRpcInterop.cs" />
|
<Compile Include="..\Capnp.Net.Runtime.Tests\TcpRpcInterop.cs" Link="TcpRpcInterop.cs" />
|
||||||
|
@ -10,6 +10,8 @@
|
|||||||
<OutputType>Library</OutputType>
|
<OutputType>Library</OutputType>
|
||||||
|
|
||||||
<Configurations>Debug;Release</Configurations>
|
<Configurations>Debug;Release</Configurations>
|
||||||
|
|
||||||
|
<RootNamespace>Capnp.Net.Runtime.Tests</RootNamespace>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||||
|
63
Capnp.Net.Runtime.Tests/SerializationTests.cs
Normal file
63
Capnp.Net.Runtime.Tests/SerializationTests.cs
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Capnp.Net.Runtime.Tests
|
||||||
|
{
|
||||||
|
[TestClass]
|
||||||
|
[TestCategory("Coverage")]
|
||||||
|
public class SerializationTests
|
||||||
|
{
|
||||||
|
[TestMethod]
|
||||||
|
public void ListOfBits()
|
||||||
|
{
|
||||||
|
void CheckList(IEnumerable<bool> items)
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
foreach (bool bit in items)
|
||||||
|
{
|
||||||
|
if (i == 63 || i == 66 || i == 129)
|
||||||
|
Assert.IsTrue(bit);
|
||||||
|
else
|
||||||
|
Assert.IsFalse(bit);
|
||||||
|
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
Assert.AreEqual(130, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
var b = MessageBuilder.Create();
|
||||||
|
var list = b.CreateObject<ListOfBitsSerializer>();
|
||||||
|
Assert.ThrowsException<ArgumentOutOfRangeException>(() => list.Init(-1));
|
||||||
|
list.Init(130);
|
||||||
|
list[63] = true;
|
||||||
|
list[65] = true;
|
||||||
|
list[66] = true;
|
||||||
|
list[65] = false;
|
||||||
|
list[129] = true;
|
||||||
|
Assert.IsFalse(list[0]);
|
||||||
|
Assert.IsTrue(list[63]);
|
||||||
|
Assert.IsFalse(list[64]);
|
||||||
|
Assert.IsFalse(list[65]);
|
||||||
|
Assert.IsTrue(list[66]);
|
||||||
|
Assert.IsTrue(list[129]);
|
||||||
|
var list2 = b.CreateObject<ListOfBitsSerializer>();
|
||||||
|
list2.Init(null);
|
||||||
|
list2.Init(list);
|
||||||
|
Assert.IsFalse(list2[0]);
|
||||||
|
Assert.IsTrue(list2[63]);
|
||||||
|
Assert.IsFalse(list2[64]);
|
||||||
|
Assert.IsFalse(list2[65]);
|
||||||
|
Assert.IsTrue(list2[66]);
|
||||||
|
Assert.IsTrue(list2[129]);
|
||||||
|
CheckList(list2);
|
||||||
|
Assert.ThrowsException<InvalidOperationException>(() => list.Init(4));
|
||||||
|
DeserializerState d = list2;
|
||||||
|
var list3 = d.RequireList().CastBool();
|
||||||
|
CheckList(list3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -2,6 +2,7 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace Capnp
|
namespace Capnp
|
||||||
{
|
{
|
||||||
@ -10,6 +11,34 @@ namespace Capnp
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class ListOfBitsSerializer: SerializerState, IReadOnlyList<bool>
|
public class ListOfBitsSerializer: SerializerState, IReadOnlyList<bool>
|
||||||
{
|
{
|
||||||
|
class Enumerator : IEnumerator<bool>
|
||||||
|
{
|
||||||
|
readonly ListOfBitsSerializer _self;
|
||||||
|
int _pos = -1;
|
||||||
|
|
||||||
|
public Enumerator(ListOfBitsSerializer self)
|
||||||
|
{
|
||||||
|
_self = self;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Current => _pos >= 0 && _pos < _self.Count ? _self[_pos] : false;
|
||||||
|
|
||||||
|
object IEnumerator.Current => Current;
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool MoveNext()
|
||||||
|
{
|
||||||
|
return ++_pos < _self.Count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Reset()
|
||||||
|
{
|
||||||
|
_pos = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the element at given index.
|
/// Gets or sets the element at given index.
|
||||||
@ -91,8 +120,8 @@ namespace Capnp
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Implements <see cref="IEnumerable{Boolean}"/>
|
/// Implements <see cref="IEnumerable{Boolean}"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IEnumerator<bool> GetEnumerator() => (IEnumerator<bool>)this.ToArray().GetEnumerator();
|
public IEnumerator<bool> GetEnumerator() => new Enumerator(this);
|
||||||
|
|
||||||
IEnumerator IEnumerable.GetEnumerator() => this.ToArray().GetEnumerator();
|
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -64,7 +64,7 @@ namespace Capnp
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates an object and sets it as root object.
|
/// Creates an object and sets it as root object.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="TS">Serializer state specialization</typeparam>
|
/// <typeparam name="TS">Serializer state specialization (must be a struct)</typeparam>
|
||||||
/// <returns>Serializer state instance representing the new object</returns>
|
/// <returns>Serializer state instance representing the new object</returns>
|
||||||
public TS BuildRoot<TS>() where TS: SerializerState, new()
|
public TS BuildRoot<TS>() where TS: SerializerState, new()
|
||||||
{
|
{
|
||||||
@ -72,6 +72,9 @@ namespace Capnp
|
|||||||
throw new InvalidOperationException("Root already set");
|
throw new InvalidOperationException("Root already set");
|
||||||
|
|
||||||
var root = CreateObject<TS>();
|
var root = CreateObject<TS>();
|
||||||
|
if (root.Kind != ObjectKind.Struct)
|
||||||
|
throw new InvalidOperationException("Root object must be a struct");
|
||||||
|
|
||||||
Root = root;
|
Root = root;
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
@ -91,8 +91,7 @@ test_script:
|
|||||||
vstest.console /logger:Appveyor /inIsolation Capnp.Net.Runtime.Tests.Core21\bin\Release\netcoreapp2.1\Capnp.Net.Runtime.Tests.Core21.dll
|
vstest.console /logger:Appveyor /inIsolation Capnp.Net.Runtime.Tests.Core21\bin\Release\netcoreapp2.1\Capnp.Net.Runtime.Tests.Core21.dll
|
||||||
- ps: |
|
- ps: |
|
||||||
.\scripts\measure-coverage.ps1
|
.\scripts\measure-coverage.ps1
|
||||||
$coveralls = ".\tools\csmacnz.coveralls.exe"
|
csmacnz.Coveralls --reportgenerator -i coverage/report --repoToken $env:COVERALLS_REPO_TOKEN --commitId $env:APPVEYOR_REPO_COMMIT --commitBranch $env:APPVEYOR_REPO_BRANCH --commitAuthor $env:APPVEYOR_REPO_COMMIT_AUTHOR --commitEmail $env:APPVEYOR_REPO_COMMIT_AUTHOR_EMAIL --commitMessage $env:APPVEYOR_REPO_COMMIT_MESSAGE --jobId $env:APPVEYOR_JOB_ID
|
||||||
& $coveralls --reportgenerator -i coverage/report --repoToken $env:COVERALLS_REPO_TOKEN --commitId $env:APPVEYOR_REPO_COMMIT --commitBranch $env:APPVEYOR_REPO_BRANCH --commitAuthor $env:APPVEYOR_REPO_COMMIT_AUTHOR --commitEmail $env:APPVEYOR_REPO_COMMIT_AUTHOR_EMAIL --commitMessage $env:APPVEYOR_REPO_COMMIT_MESSAGE --jobId $env:APPVEYOR_JOB_ID
|
|
||||||
on_finish :
|
on_finish :
|
||||||
# any cleanup in here
|
# any cleanup in here
|
||||||
deploy:
|
deploy:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user