2020-07-31 03:22:33 +08:00
|
|
|
|
// 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.
|
|
|
|
|
|
2020-09-17 03:26:58 +08:00
|
|
|
|
using System;
|
2020-07-31 03:22:33 +08:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using interop;
|
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.Interop.Tests
|
|
|
|
|
{
|
|
|
|
|
[TestClass]
|
2020-09-17 03:26:58 +08:00
|
|
|
|
public class InteropTests : IDisposable
|
2020-07-31 03:22:33 +08:00
|
|
|
|
{
|
|
|
|
|
private const string ServerSidePipe = "\\\\.\\pipe\\serverside";
|
|
|
|
|
private const string ClientSidePipe = "\\\\.\\pipe\\clientside";
|
|
|
|
|
|
2020-09-17 03:26:58 +08:00
|
|
|
|
internal TwoWayPipeMessageIPCManaged ClientPipe { get; set; }
|
|
|
|
|
|
|
|
|
|
private bool disposedValue;
|
2020-07-31 03:22:33 +08:00
|
|
|
|
|
|
|
|
|
[TestInitialize]
|
|
|
|
|
public void Initialize()
|
|
|
|
|
{
|
2020-09-17 03:26:58 +08:00
|
|
|
|
ClientPipe = new TwoWayPipeMessageIPCManaged(ClientSidePipe, ServerSidePipe, null);
|
2020-07-31 03:22:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestCleanup]
|
|
|
|
|
public void Cleanup()
|
|
|
|
|
{
|
2020-09-17 03:26:58 +08:00
|
|
|
|
ClientPipe.End();
|
2020-07-31 03:22:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void TestSend()
|
|
|
|
|
{
|
|
|
|
|
var testString = "This string is a test\n";
|
2020-09-17 03:26:58 +08:00
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-31 03:22:33 +08:00
|
|
|
|
|
2020-09-17 03:26:58 +08:00
|
|
|
|
protected virtual void Dispose(bool disposing)
|
|
|
|
|
{
|
|
|
|
|
if (!disposedValue)
|
|
|
|
|
{
|
|
|
|
|
if (disposing)
|
2020-07-31 03:22:33 +08:00
|
|
|
|
{
|
2020-09-17 03:26:58 +08:00
|
|
|
|
ClientPipe.Dispose();
|
|
|
|
|
}
|
2020-07-31 03:22:33 +08:00
|
|
|
|
|
2020-09-17 03:26:58 +08:00
|
|
|
|
// TODO: free unmanaged resources (unmanaged objects) and override finalizer
|
|
|
|
|
// TODO: set large fields to null
|
|
|
|
|
disposedValue = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-31 03:22:33 +08:00
|
|
|
|
|
2020-09-17 03:26:58 +08:00
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
|
|
|
|
Dispose(disposing: true);
|
|
|
|
|
GC.SuppressFinalize(this);
|
2020-07-31 03:22:33 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|