Skip to content

Commit

Permalink
feat: cb loop csharp bindings (#587)
Browse files Browse the repository at this point in the history
* fix: make benchmarks compatable with windows

* double include

* fix valgrind ubuntu

* feat: cb loop csharp bindings

* clang

* address comments: basic usage and nullptr throw

---------

Co-authored-by: zwd-ms <71728747+zwd-ms@users.noreply.github.com>
  • Loading branch information
bassmang and zwd-ms authored Oct 9, 2023
1 parent cbcd282 commit c9f692d
Show file tree
Hide file tree
Showing 22 changed files with 1,514 additions and 154 deletions.
2 changes: 2 additions & 0 deletions bindings/cs/rl.net.cli.test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
set (RL_NET_CLI_TEST_SOURCES
CleanupContainer.cs
MockSender.cs
ReplayStepProviderTest.cs
SenderExtensibilityTest.cs
SenderExtensibilityCBLoopTest.cs
TempFileDisposable.cs
TestBase.cs
UnicodeTest.cs
Expand Down
70 changes: 70 additions & 0 deletions bindings/cs/rl.net.cli.test/MockSender.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using System;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Rl.Net;
using Rl.Net.Native;

namespace Rl.Net.Cli.Test
{
using SenderFactory = Func<IReadOnlyConfiguration, ErrorCallback, ISender>;
using BackgroundErrorCallback = Action<ApiStatus>;

internal class MockSender : ISender
{
public Action<ApiStatus> Init
{
get;
set;
}

public Action<SharedBuffer, ApiStatus> Send
{
get;
set;
}

void ISender.Init(ApiStatus status)
{
if (this.Init != null)
{
this.Init(status);
}
}

void ISender.Send(SharedBuffer buffer, ApiStatus status)
{
if (this.Send != null)
{
this.Send(buffer, status);
}
}
}


internal class MockAsyncSender : AsyncSender
{
public MockAsyncSender(ErrorCallback callback) : base(callback)
{
}

public new Func<SharedBuffer, BackgroundErrorCallback, Task> Send
{
get;
set;
}

protected override Task SendAsync(SharedBuffer buffer)
{
if (this.Send != null)
{
return this.Send(buffer, this.RaiseBackgroundError);
}

return Task.CompletedTask;
}
}
}
Loading

0 comments on commit c9f692d

Please sign in to comment.