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)); } } }
public void EnumerateTraceGuidsTest() { var memList = new List <SafeHGlobalHandle>(); var sz = Marshal.SizeOf <TRACE_GUID_PROPERTIES>(); var pprovs = new IntPtr[1]; memList.Add(new SafeHGlobalHandle(sz)); pprovs[0] = memList[0]; try { Assert.That(EnumerateTraceGuids(pprovs, 0, out var req), ResultIs.FailureCode(Win32Error.ERROR_MORE_DATA)); Array.Resize(ref pprovs, (int)req); for (int i = 1; i < req; i++) { memList.Add(new SafeHGlobalHandle(sz)); pprovs[i] = memList[i]; } Assert.That(EnumerateTraceGuids(pprovs, (uint)pprovs.Length, out req), ResultIs.Successful); } finally { for (int i = 0; i < memList.Count; i++) { TestContext.Write($"({i}) "); memList[i].ToStructure <TRACE_GUID_PROPERTIES>().WriteValues(); memList[i].Dispose(); } } }
public void EventTest() { var activId = Guid.Empty; Assert.That(EventActivityIdControl(EVENT_ACTIVITY_CTRL.EVENT_ACTIVITY_CTRL_CREATE_ID, ref activId), ResultIs.Successful); var provGuid = Guid.NewGuid(); Assert.That(EventRegister(provGuid, Callback, IntPtr.Zero, out var hReg), ResultIs.Successful); Assert.That(hReg.IsInvalid, Is.False); using (hReg) { var desc = new EVENT_DESCRIPTOR(0, 0, 0, 0, 0, 0, ulong.MaxValue); Assert.That(EventEnabled(hReg, desc), Is.False); Assert.That(EventProviderEnabled(hReg, 0, ulong.MaxValue), Is.False); using (var mem = SafeHGlobalHandle.CreateFromStructure((byte)1)) Assert.That(EventSetInformation(hReg, EVENT_INFO_CLASS.EventProviderUseDescriptorType, mem, 1U), ResultIs.FailureCode(Win32Error.ERROR_NOT_SUPPORTED)); Assert.That(EventWrite(hReg, desc, 0, null), ResultIs.FailureCode(Win32Error.ERROR_INVALID_PARAMETER)); Assert.That(EventWriteEx(hReg, desc, 0, 0, IntPtr.Zero, IntPtr.Zero, 0, null), ResultIs.FailureCode(Win32Error.ERROR_INVALID_PARAMETER)); Assert.That(EventWriteString(hReg, 0, ulong.MaxValue, "Dummy"), ResultIs.FailureCode(Win32Error.ERROR_INVALID_HANDLE)); Assert.That(EventWriteTransfer(hReg, desc, IntPtr.Zero, IntPtr.Zero, 0, null), ResultIs.FailureCode(Win32Error.ERROR_INVALID_PARAMETER)); } void Callback(in Guid SourceId, bool IsEnabled, byte Level, ulong MatchAnyKeyword, ulong MatchAllKeyword, IntPtr FilterData, IntPtr CallbackContext) { } }
public void GlobalAtomTest() { const string name = "Test"; var atom = GlobalAddAtom(name); Assert.That(atom, Is.Not.Zero); Assert.That(GlobalFindAtom(name), Is.EqualTo(atom)); Assert.That(GlobalGetAtomName(atom), Is.EqualTo(name)); Assert.That(GlobalDeleteAtom(atom), ResultIs.Value(ATOM.INVALID_ATOM)); }
public void AtomTest() { const string name = "Test"; Assert.That(InitAtomTable(7), ResultIs.Successful); var atom = AddAtom(name); Assert.That(atom, Is.Not.Zero); Assert.That(FindAtom(name), Is.EqualTo(atom)); Assert.That(GetAtomName(atom), Is.EqualTo(name)); Assert.That(DeleteAtom(atom), ResultIs.Value(ATOM.INVALID_ATOM)); }
public void HLocalTest() { HLOCAL hMem; Assert.That(hMem = LocalAlloc(LMEM.LHND, 256), ResultIs.ValidHandle); try { Assert.That(LocalFlags(hMem), ResultIs.Value(LMEM.LMEM_FIXED)); Assert.That(LocalSize(hMem), ResultIs.Value(new SizeT(256))); IntPtr ptr; Assert.That(ptr = LocalLock(hMem), ResultIs.ValidHandle); Assert.That(LocalHandle(ptr), ResultIs.Value(hMem)); Assert.That(LocalUnlock(hMem), ResultIs.Successful); Assert.That(hMem = LocalReAlloc(hMem, 128, 0), ResultIs.ValidHandle); } finally { Assert.That(LocalFree(hMem), ResultIs.Value(HLOCAL.NULL)); } }
public void Wow64DisableRevertWow64FsRedirectionTest() { Assert.That(Wow64DisableWow64FsRedirection(out var ptr), ResultIs.FailureCode(Win32Error.ERROR_INVALID_FUNCTION)); Assert.That(Wow64RevertWow64FsRedirection(ptr), ResultIs.FailureCode(Win32Error.ERROR_INVALID_FUNCTION)); }
public void GetSidSubAuthorityCountTest() { Assert.That(GetSidSubAuthorityCount(SafePSID.Everyone), ResultIs.Value(1)); }
public void GetSidSubAuthorityTest() { Assert.That(GetSidSubAuthority(SafePSID.Everyone, 0), ResultIs.Value(0)); }
public void AccessCheckAndAuditAlarmTest() { using (var pSD = AdvApi32Tests.GetSD(AdvApi32Tests.fn, AdvApi32Tests.AllSI)) { var gm = GENERIC_MAPPING.GenericFileMapping; ACCESS_MASK accessMask = ACCESS_MASK.GENERIC_READ; MapGenericMask(ref accessMask, gm); Assert.That(AccessCheckAndAuditAlarm(subSys, IntPtr.Zero, objType, null, pSD, accessMask, gm, false, out var access, out var status, out var gen), ResultIs.FailureCode(Win32Error.ERROR_NO_IMPERSONATION_TOKEN)); //Assert.That(access, Is.EqualTo((uint)FileAccess.FILE_GENERIC_READ)); //Assert.That(status, Is.True); } }
public void OpenThreadTokenTest() { Assert.That(OpenThreadToken(GetCurrentThread(), TokenAccess.TOKEN_QUERY | TokenAccess.TOKEN_ADJUST_PRIVILEGES, true, out var hTok), ResultIs.FailureCode(Win32Error.ERROR_NO_TOKEN)); Assert.That(OpenProcessToken(GetCurrentProcess(), TokenAccess.TOKEN_DUPLICATE, out var hPrTok), ResultIs.Successful); using (hPrTok) { Assert.That(DuplicateTokenEx(hPrTok, TokenAccess.TOKEN_IMPERSONATE | TokenAccess.TOKEN_QUERY | TokenAccess.TOKEN_ADJUST_PRIVILEGES,
public void SetupDiGetDevicePropertyKeysTest() { foreach (var did in SetupDiEnumDeviceInfo(hDevInfo)) { Assert.That(SetupDiGetDevicePropertyKeys(hDevInfo, did, null, 0, out var cnt), ResultIs.FailureCode(Win32Error.ERROR_INSUFFICIENT_BUFFER)); var arr = new DEVPROPKEY[cnt]; Assert.That(SetupDiGetDevicePropertyKeys(hDevInfo, did, arr, (uint)arr.Length, out _), ResultIs.Successful); foreach (var key in arr) { Assert.That(SetupDiGetDeviceProperty(hDevInfo, did, key, out var value), ResultIs.Successful); //var obj = value.GetType().IsArray ? string.Join(", ", ((IEnumerable)value).Cast<object>()) : // (value is System.Runtime.InteropServices.ComTypes.FILETIME ft ? (object)ft.ToDateTime() : value) //TestContext.WriteLine($"{key.fmtid},{key.pid} = {obj}"); } } }
public void SslGetServerIdentityTest() { // There is no useful documentation or samples on this function. Only checking that it is callable. using (var mem = new SafeHGlobalHandle(256)) Assert.That(SslGetServerIdentity(mem, mem.Size, out var pId, out var pSz), ResultIs.FailureCode(HRESULT.SEC_E_ILLEGAL_MESSAGE)); }
public void SaferRecordEventLogEntryTest() { Assert.That(SaferCreateLevel(SAFER_SCOPEID.SAFER_SCOPEID_USER, SAFER_LEVELID.SAFER_LEVELID_NORMALUSER, SAFER_LEVEL_CREATE_FLAGS.SAFER_LEVEL_OPEN, out var hLvl), ResultIs.Successful); using (hLvl) { // Not sure how to make this return success Assert.That(SaferRecordEventLogEntry(hLvl, @"C:\Windows\notepad.exe"), ResultIs.FailureCode(Win32Error.ERROR_NOT_FOUND)); } }