コード例 #1
0
        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));
                }
            }
        }
コード例 #2
0
        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)
            {
            }
        }
コード例 #3
0
ファイル: Wow64ApiSetTests.cs プロジェクト: zhuxb711/Vanara
 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));
 }
コード例 #4
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);
     }
 }
コード例 #5
0
 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,
コード例 #6
0
ファイル: SetupAPITests.cs プロジェクト: tajbender/Vanara
 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}");
         }
     }
 }
コード例 #7
0
 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));
 }
コード例 #8
0
ファイル: WinSaferTests.cs プロジェクト: zhuxb711/Vanara
 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));
     }
 }