mirror of https://github.com/dahall/Vanara.git
Added assembly for KtmW32.dll functions and supporting unit tests
parent
1f7c469a09
commit
83560454ab
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,51 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<Description>PInvoke API (methods, structures and constants imported from Windows KtmW32.dll.</Description>
|
||||
<Copyright>Copyright © 2017-2019</Copyright>
|
||||
<AssemblyTitle>$(AssemblyName)</AssemblyTitle>
|
||||
<VersionPrefix>3.0.0</VersionPrefix>
|
||||
<TargetFrameworks>net20;net35;net40;net45;netstandard2.0;netcoreapp2.0;netcoreapp2.1</TargetFrameworks>
|
||||
<AssemblyName>Vanara.PInvoke.KtmW32</AssemblyName>
|
||||
<PackageId>$(AssemblyName)</PackageId>
|
||||
<RootNamespace>Vanara.PInvoke</RootNamespace>
|
||||
<Authors>David Hall</Authors>
|
||||
<PackageProjectUrl>https://github.com/dahall/vanara</PackageProjectUrl>
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
<PackageIconUrl>https://raw.githubusercontent.com/dahall/Vanara/master/docs/icons/Vanara48x48.png</PackageIconUrl>
|
||||
<RepositoryUrl>https://github.com/dahall/vanara</RepositoryUrl>
|
||||
<RepositoryType>Git</RepositoryType>
|
||||
<PackageTags>pinvoke;vanara;net-extensions;interop;ktmw32;transactions</PackageTags>
|
||||
<NeutralLanguage>en-US</NeutralLanguage>
|
||||
<IncludeSource>true</IncludeSource>
|
||||
<IncludeSymbols>true</IncludeSymbols>
|
||||
<Company>GitHub Community</Company>
|
||||
<Product>Vanara</Product>
|
||||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
||||
<PackageReleaseNotes></PackageReleaseNotes>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
<AssemblyOriginatorKeyFile>..\..\Vanara.snk</AssemblyOriginatorKeyFile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Release'">
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
<ItemGroup Condition=" '$(TargetFramework)' == 'net20' ">
|
||||
<Reference Include="System" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition=" '$(TargetFramework)' == 'net35' ">
|
||||
<Reference Include="System" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition=" '$(TargetFramework)' == 'net40' ">
|
||||
<Reference Include="System" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">
|
||||
<Reference Include="System" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Core\Vanara.Core.csproj" />
|
||||
<ProjectReference Include="..\Kernel32\Vanara.PInvoke.Kernel32.csproj" />
|
||||
<ProjectReference Include="..\Shared\Vanara.PInvoke.Shared.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -42,6 +42,9 @@
|
|||
/// <summary>The kernel base</summary>
|
||||
public const string KernelBase = "kernelbase.dll";
|
||||
|
||||
/// <summary>The Kernel Transaction Manager (KTM)</summary>
|
||||
public const string Ktmw32 = "ktmw32.dll";
|
||||
|
||||
/// <summary>The MPR</summary>
|
||||
public const string Mpr = "mpr.dll";
|
||||
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="16.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{8BC51B6B-77FA-4571-8E1C-EA75ED4DCD56}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Vanara.PInvoke.Tests</RootNamespace>
|
||||
<AssemblyName>UnitTest.PInvoke.KtmW32</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="KtmW32Tests.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\Core\Vanara.Core.csproj">
|
||||
<Project>{241f73ee-9298-45c9-b869-a045dff94c03}</Project>
|
||||
<Name>Vanara.Core</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\..\PInvoke\Kernel32\Vanara.PInvoke.Kernel32.csproj">
|
||||
<Project>{842d436f-598c-47d7-b5aa-12399f8ccfe9}</Project>
|
||||
<Name>Vanara.PInvoke.Kernel32</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\..\PInvoke\KtmW32\Vanara.PInvoke.KtmW32.csproj">
|
||||
<Project>{c325c0a4-b8cf-442b-b393-c65fc9174045}</Project>
|
||||
<Name>Vanara.PInvoke.KtmW32</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\..\PInvoke\Shared\Vanara.PInvoke.Shared.csproj">
|
||||
<Project>{a5e519e9-feba-4fe3-93a5-b8269bef72f4}</Project>
|
||||
<Name>Vanara.PInvoke.Shared</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\CSharpRunner\Shared.csproj">
|
||||
<Project>{a96cff10-0967-429a-8700-4a86c97c5603}</Project>
|
||||
<Name>Shared</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NUnit">
|
||||
<Version>3.12.0</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="NUnit3TestAdapter">
|
||||
<Version>3.13.0</Version>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
|
@ -0,0 +1,163 @@
|
|||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Text;
|
||||
using Vanara.InteropServices;
|
||||
using static Vanara.PInvoke.Kernel32;
|
||||
using static Vanara.PInvoke.KtmW32;
|
||||
|
||||
namespace Vanara.PInvoke.Tests
|
||||
{
|
||||
[TestFixture()]
|
||||
public class KtmW32Tests
|
||||
{
|
||||
private const string txnDesc = "MyTransaction";
|
||||
|
||||
[Test]
|
||||
public void CommitTransactionAsyncTest()
|
||||
{
|
||||
using (var hTR = CreateTransaction(null, default, 0, 0, 0, 0, txnDesc))
|
||||
{
|
||||
Assert.That(hTR, ResultIs.ValidHandle);
|
||||
Assert.That(CommitTransactionAsync(hTR), ResultIs.Successful);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CommitTransactionTest()
|
||||
{
|
||||
using (var hTR = CreateTransaction(null, default, 0, 0, 0, 0, txnDesc))
|
||||
{
|
||||
Assert.That(hTR, ResultIs.ValidHandle);
|
||||
Assert.That(CommitTransaction(hTR), ResultIs.Successful);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public unsafe void CreateTMNVTest()
|
||||
{
|
||||
using (var tmp = new TempFile(null))
|
||||
using (var hTM = CreateTransactionManager(null, tmp.FullName))
|
||||
{
|
||||
Assert.That(hTM, ResultIs.ValidHandle);
|
||||
|
||||
Assert.That(RenameTransactionManager(tmp.FullName, Guid.NewGuid()), ResultIs.Failure);
|
||||
|
||||
Assert.That(RecoverTransactionManager(hTM), ResultIs.Successful);
|
||||
|
||||
using (var hTM2 = OpenTransactionManager(tmp.FullName, TransactionMgrAccess.TRANSACTIONMANAGER_ALL_ACCESS))
|
||||
Assert.That(hTM2, ResultIs.ValidHandle);
|
||||
|
||||
var rmId = Guid.NewGuid();
|
||||
using (var hRM = CreateResourceManager(null, rmId, 0, hTM, "MyRM"))
|
||||
{
|
||||
Assert.That(hRM, ResultIs.ValidHandle);
|
||||
|
||||
Assert.That(RecoverResourceManager(hRM), ResultIs.Successful);
|
||||
|
||||
using (var pTn = new SafeHGlobalHandle(4096))
|
||||
Assert.That(GetNotificationResourceManagerAsync(hRM, pTn, pTn.Size, out _, null), ResultIs.Failure);
|
||||
|
||||
using (var hRM2 = OpenResourceManager(ResourceManagerAccess.RESOURCEMANAGER_ALL_ACCESS, hTM, rmId))
|
||||
Assert.That(hRM2, ResultIs.ValidHandle);
|
||||
}
|
||||
|
||||
Assert.That(RollforwardTransactionManager(hTM, 255L), ResultIs.Successful);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CreateTMRMGetInfoTest()
|
||||
{
|
||||
using (var hTM = CreateTransactionManager(CreateOptions: CreateTrxnMgrOptions.TRANSACTION_MANAGER_VOLATILE))
|
||||
{
|
||||
Assert.That(hTM, ResultIs.ValidHandle);
|
||||
|
||||
Assert.That(GetCurrentClockTransactionManager(hTM, out var clock), ResultIs.Successful);
|
||||
TestContext.WriteLine($"TMClock=0x{clock:X}");
|
||||
|
||||
Assert.That(GetTransactionManagerId(hTM, out var tmguid), ResultIs.Successful);
|
||||
TestContext.WriteLine($"TMID={tmguid}");
|
||||
|
||||
using (var hTM2 = OpenTransactionManagerById(tmguid, TransactionMgrAccess.TRANSACTIONMANAGER_ALL_ACCESS))
|
||||
Assert.That(hTM2, ResultIs.ValidHandle);
|
||||
|
||||
Assert.That(RecoverTransactionManager(hTM), ResultIs.FailureCode(Win32Error.ERROR_TM_VOLATILE));
|
||||
|
||||
using (var hRM = CreateResourceManager(null, Guid.Empty, CreateRMOptions.RESOURCE_MANAGER_VOLATILE, hTM, null))
|
||||
{
|
||||
Assert.That(hRM, ResultIs.ValidHandle);
|
||||
|
||||
using (var pTn = new SafeHGlobalHandle(4096))
|
||||
Assert.That(GetNotificationResourceManager(hRM, pTn, pTn.Size, 10, out var req), ResultIs.FailureCode(Win32Error.WAIT_TIMEOUT));
|
||||
|
||||
Assert.That(RecoverResourceManager(hRM), ResultIs.FailureCode(Win32Error.ERROR_TM_VOLATILE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetSetTransactionInformationTest()
|
||||
{
|
||||
using (var hTR = CreateTransaction(null, default, 0, 0, 0, 0, txnDesc))
|
||||
{
|
||||
Assert.That(hTR, ResultIs.ValidHandle);
|
||||
|
||||
Assert.That(GetTransactionId(hTR, out var trguid), ResultIs.Successful);
|
||||
TestContext.WriteLine($"TrID={trguid}");
|
||||
|
||||
using (var hTR2 = OpenTransaction(TransactionAccess.TRANSACTION_ALL_ACCESS, trguid))
|
||||
Assert.That(hTR2, ResultIs.ValidHandle);
|
||||
|
||||
var sb = new StringBuilder(255);
|
||||
Assert.That(GetTransactionInformation(hTR, out var troutcome, default, default, out var trTO, 255, sb), ResultIs.Successful);
|
||||
TestContext.WriteLine($"TrInf={troutcome}, {trTO}, {sb}");
|
||||
|
||||
sb.Append("2");
|
||||
Assert.That(SetTransactionInformation(hTR, 0, 0, 5000, sb.ToString()), ResultIs.Successful);
|
||||
}
|
||||
}
|
||||
|
||||
// Despite hours of trying, I cannot successfully create an enlistment nor find working code on the internet. So, I'm punting and
|
||||
// just doing non-functional testing for all enlistment functions. -- Sigh --
|
||||
[Test]
|
||||
public void NonFunctionalTest()
|
||||
{
|
||||
Assert.That(CommitComplete(HENLISTMENT.NULL), ResultIs.Failure);
|
||||
Assert.That(CommitEnlistment(HENLISTMENT.NULL), ResultIs.Failure);
|
||||
Assert.That(CreateEnlistment(null, HRESMGR.NULL, HTRXN.NULL, 0).DangerousGetHandle(), Is.EqualTo((IntPtr)HFILE.INVALID_HANDLE_VALUE));
|
||||
Assert.That(GetEnlistmentId(HENLISTMENT.NULL, out _), ResultIs.Failure);
|
||||
Assert.That(GetEnlistmentRecoveryInformation(HENLISTMENT.NULL, 0, default, out _), ResultIs.Failure);
|
||||
Assert.That(OpenEnlistment(EnlistmentAccess.ENLISTMENT_ALL_ACCESS, HRESMGR.NULL, Guid.NewGuid()).DangerousGetHandle(), Is.EqualTo((IntPtr)HFILE.INVALID_HANDLE_VALUE));
|
||||
Assert.That(PrepareComplete(HENLISTMENT.NULL), ResultIs.Failure);
|
||||
Assert.That(PrepareEnlistment(HENLISTMENT.NULL, 0L), ResultIs.Failure);
|
||||
Assert.That(PrePrepareComplete(HENLISTMENT.NULL), ResultIs.Failure);
|
||||
Assert.That(PrePrepareEnlistment(HENLISTMENT.NULL, 0L), ResultIs.Failure);
|
||||
Assert.That(ReadOnlyEnlistment(HENLISTMENT.NULL), ResultIs.Failure);
|
||||
Assert.That(RecoverEnlistment(HENLISTMENT.NULL), ResultIs.Failure);
|
||||
Assert.That(RollbackComplete(HENLISTMENT.NULL, 0L), ResultIs.Failure);
|
||||
Assert.That(RollbackEnlistment(HENLISTMENT.NULL, 0L), ResultIs.Failure);
|
||||
Assert.That(SetEnlistmentRecoveryInformation(HENLISTMENT.NULL, 0, default), ResultIs.Failure);
|
||||
Assert.That(SinglePhaseReject(HENLISTMENT.NULL), ResultIs.Failure);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RollbackTransactionAsyncTest()
|
||||
{
|
||||
using (var hTR = CreateTransaction(null, default, 0, 0, 0, 0, txnDesc))
|
||||
{
|
||||
Assert.That(hTR, ResultIs.ValidHandle);
|
||||
Assert.That(RollbackTransactionAsync(hTR), ResultIs.Successful);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RollbackTransactionTest()
|
||||
{
|
||||
using (var hTR = CreateTransaction(null, default, 0, 0, 0, 0, txnDesc))
|
||||
{
|
||||
Assert.That(hTR, ResultIs.ValidHandle);
|
||||
Assert.That(RollbackTransaction(hTR), ResultIs.Successful);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
18
Vanara.sln
18
Vanara.sln
|
@ -161,6 +161,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Shared", "UnitTests\CSharpR
|
|||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vanara.PInvoke.Wer", "PInvoke\Wer\Vanara.PInvoke.Wer.csproj", "{FA58DCE9-60A6-4321-982C-37C0DACC371D}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vanara.PInvoke.KtmW32", "PInvoke\KtmW32\Vanara.PInvoke.KtmW32.csproj", "{C325C0A4-B8CF-442B-B393-C65FC9174045}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KtmW32", "UnitTests\PInvoke\KtmW32\KtmW32.csproj", "{632795F2-F552-4907-9373-4929CB9ACE09}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug (no Unit Tests)|Any CPU = Debug (no Unit Tests)|Any CPU
|
||||
|
@ -521,6 +525,18 @@ Global
|
|||
{FA58DCE9-60A6-4321-982C-37C0DACC371D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{FA58DCE9-60A6-4321-982C-37C0DACC371D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{FA58DCE9-60A6-4321-982C-37C0DACC371D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{C325C0A4-B8CF-442B-B393-C65FC9174045}.Debug (no Unit Tests)|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C325C0A4-B8CF-442B-B393-C65FC9174045}.Debug (no Unit Tests)|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C325C0A4-B8CF-442B-B393-C65FC9174045}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C325C0A4-B8CF-442B-B393-C65FC9174045}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C325C0A4-B8CF-442B-B393-C65FC9174045}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C325C0A4-B8CF-442B-B393-C65FC9174045}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{632795F2-F552-4907-9373-4929CB9ACE09}.Debug (no Unit Tests)|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{632795F2-F552-4907-9373-4929CB9ACE09}.Debug (no Unit Tests)|Any CPU.Build.0 = Debug|Any CPU
|
||||
{632795F2-F552-4907-9373-4929CB9ACE09}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{632795F2-F552-4907-9373-4929CB9ACE09}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{632795F2-F552-4907-9373-4929CB9ACE09}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{632795F2-F552-4907-9373-4929CB9ACE09}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -591,6 +607,8 @@ Global
|
|||
{3EDE955E-50DE-4E1D-97E8-31E4E6A83E7D} = {212ABBD0-B724-4CFA-9D6D-E3891547FA90}
|
||||
{A96CFF10-0967-429A-8700-4A86C97C5603} = {3EC6B40D-71D3-4E59-A0E0-544EC605FE11}
|
||||
{FA58DCE9-60A6-4321-982C-37C0DACC371D} = {212ABBD0-B724-4CFA-9D6D-E3891547FA90}
|
||||
{C325C0A4-B8CF-442B-B393-C65FC9174045} = {212ABBD0-B724-4CFA-9D6D-E3891547FA90}
|
||||
{632795F2-F552-4907-9373-4929CB9ACE09} = {385CAD2D-0A5E-4F80-927B-D5499D126B90}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {543FAC75-2AF1-4EF1-9609-B242B63FEED4}
|
||||
|
|
Loading…
Reference in New Issue