mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-21 07:17:56 +08:00
81 lines
2.2 KiB
C#
81 lines
2.2 KiB
C#
// Copyright (c) Microsoft Corporation
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
using System;
|
|
using System.Threading;
|
|
using interop;
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
namespace Microsoft.Interop.Tests
|
|
{
|
|
[TestClass]
|
|
public class InteropTests : IDisposable
|
|
{
|
|
private const string ServerSidePipe = "\\\\.\\pipe\\serverside";
|
|
private const string ClientSidePipe = "\\\\.\\pipe\\clientside";
|
|
|
|
internal TwoWayPipeMessageIPCManaged ClientPipe { get; set; }
|
|
|
|
private bool disposedValue;
|
|
|
|
[TestInitialize]
|
|
public void Initialize()
|
|
{
|
|
ClientPipe = new TwoWayPipeMessageIPCManaged(ClientSidePipe, ServerSidePipe, null);
|
|
}
|
|
|
|
[TestCleanup]
|
|
public void Cleanup()
|
|
{
|
|
ClientPipe.End();
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TestSend()
|
|
{
|
|
var testString = "This string is a test\n";
|
|
using (var reset = new AutoResetEvent(false))
|
|
{
|
|
using (var serverPipe = new TwoWayPipeMessageIPCManaged(
|
|
ServerSidePipe,
|
|
ClientSidePipe,
|
|
(string msg) =>
|
|
{
|
|
Assert.AreEqual(testString, msg);
|
|
reset.Set();
|
|
}))
|
|
{
|
|
serverPipe.Start();
|
|
ClientPipe.Start();
|
|
|
|
ClientPipe.Send(testString);
|
|
reset.WaitOne();
|
|
|
|
serverPipe.End();
|
|
}
|
|
}
|
|
}
|
|
|
|
protected virtual void Dispose(bool disposing)
|
|
{
|
|
if (!disposedValue)
|
|
{
|
|
if (disposing)
|
|
{
|
|
ClientPipe.Dispose();
|
|
}
|
|
|
|
disposedValue = true;
|
|
}
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
|
Dispose(disposing: true);
|
|
GC.SuppressFinalize(this);
|
|
}
|
|
}
|
|
}
|