public bool NegTest2() { bool retVal = true; int randValue = 0; TestLibrary.TestFramework.BeginScenario("NegTest2: Call DangerousRelease twice with one call DangerousAddRef for valid handle"); try { randValue = TestLibrary.Generator.GetInt32(-55); SafeHandle handle = new MySafeValidHandle(new IntPtr(randValue)); bool success = false; // if this object gets finalized it will throw an exception on the finalizer thread GC.SuppressFinalize(handle); handle.DangerousAddRef(ref success); if (!success) { TestLibrary.TestFramework.LogInformation("WARNING: Calling DangerousAddRef returns false"); } handle.DangerousRelease(); handle.DangerousRelease(); } catch (Exception e) { TestLibrary.TestFramework.LogError("102.1", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation("WARNING: [LOCAL VARIABLES] randValue = " + randValue.ToString()); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return(retVal); }
public bool PosTest1() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest1: Call DangerousRelease after call DangerousAddRef for valid handle"); try { SafeHandle handle = new MySafeValidHandle(); bool success = false; handle.DangerousAddRef(ref success); if (!success) { TestLibrary.TestFramework.LogInformation("WARNING: Calling DangerousAddRef returns false"); } handle.DangerousRelease(); } catch (Exception e) { TestLibrary.TestFramework.LogError("001", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return(retVal); }
public bool PosTest3() { bool retVal = true; int randValue = 0; TestLibrary.TestFramework.BeginScenario("PosTest3: call Dispose on valid SafeHandle instance with false"); try { MySafeValidHandle handle = new MySafeValidHandle(); handle.DisposeWrap(false); randValue = TestLibrary.Generator.GetInt32(-55); handle = new MySafeValidHandle(new IntPtr(randValue)); handle.DisposeWrap(false); } catch (Exception e) { TestLibrary.TestFramework.LogError("003", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation("WARNING: [LOCAL VARIABLES] randValue = " + randValue); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return(retVal); }
public bool PosTest2() { bool retVal = true; int randValue = 0; TestLibrary.TestFramework.BeginScenario("PosTest2: Call DangerousRelease after call DangerousAddRef for valid handle"); try { randValue = TestLibrary.Generator.GetInt32(-55); SafeHandle handle = new MySafeValidHandle(new IntPtr(randValue)); bool success = false; handle.DangerousAddRef(ref success); if (!success) { TestLibrary.TestFramework.LogInformation("WARNING: Calling DangerousAddRef returns false"); } handle.DangerousRelease(); } catch (Exception e) { TestLibrary.TestFramework.LogError("002", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation("WARNING: [LOCAL VARIABLES] randValue = " + randValue.ToString()); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return(retVal); }
public bool PosTest1() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest1: Call DangerousAddRef on a valid handle"); try { SafeHandle handle = new MySafeValidHandle(); bool success = false; handle.DangerousAddRef(ref success); if (!success) { TestLibrary.TestFramework.LogInformation("success returns false after calling DangerousAddRef"); } } catch (Exception e) { TestLibrary.TestFramework.LogError("001", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }
public bool PosTest2() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest2: DangerousGetHandle should return handle value for valid safe handle"); try { int randValue = TestLibrary.Generator.GetInt32(-55); IntPtr desiredValue = new IntPtr(randValue); SafeHandle handle = new MySafeValidHandle(desiredValue); IntPtr handleValue = handle.DangerousGetHandle(); if (handleValue != desiredValue) { TestLibrary.TestFramework.LogError("002.1", "DangerousGetHandle returns wrong handle value for valid safe handle"); TestLibrary.TestFramework.LogInformation("WARNING: [LOCAL VARIABLES] handleValue = " + handleValue.ToString() + ", desiredValue = " + desiredValue.ToString()); retVal = false; } handleValue = handle.DangerousGetHandle(); if (handleValue != desiredValue) { TestLibrary.TestFramework.LogError("002.2", "DangerousGetHandle returns wrong handle value for valid safe handle"); TestLibrary.TestFramework.LogInformation("WARNING: [LOCAL VARIABLES] handleValue = " + handleValue.ToString() + ", desiredValue = " + desiredValue.ToString()); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("002.3", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return(retVal); }
public bool PosTest1() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest1: DangerousGetHandle should return handle value for valid safe handle"); try { SafeHandle handle = new MySafeValidHandle(); IntPtr handleValue = handle.DangerousGetHandle(); if (handleValue != IntPtr.Zero) { TestLibrary.TestFramework.LogError("001.1", "DangerousGetHandle returns wrong handle value for valid safe handle"); TestLibrary.TestFramework.LogInformation("WARNING: [LOCAL VARIABLES] handleValue = " + handleValue.ToString() + ", desiredValue = IntPtr.Zero"); retVal = false; } // Get it twice handleValue = handle.DangerousGetHandle(); if (handleValue != IntPtr.Zero) { TestLibrary.TestFramework.LogError("001.2", "DangerousGetHandle returns wrong handle value for valid safe handle"); TestLibrary.TestFramework.LogInformation("WARNING: [LOCAL VARIABLES] handleValue = " + handleValue.ToString() + ", desiredValue = IntPtr.Zero"); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("001.3", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return(retVal); }
public bool PosTest3() { bool retVal = true; int randValue = 0; TestLibrary.TestFramework.BeginScenario("PosTest3: call Dispose through IDispose interface"); try { SafeHandle handle = new MySafeInValidHandle(); IDisposable idisp = handle as IDisposable; idisp.Dispose(); randValue = TestLibrary.Generator.GetInt32(-55); handle = new MySafeInValidHandle(new IntPtr(randValue)); idisp = handle as IDisposable; idisp.Dispose(); handle = new MySafeValidHandle(); idisp = handle as IDisposable; idisp.Dispose(); randValue = TestLibrary.Generator.GetInt32(-55); handle = new MySafeValidHandle(new IntPtr(randValue)); idisp = handle as IDisposable; idisp.Dispose(); } catch (Exception e) { TestLibrary.TestFramework.LogError("003", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation("WARNING: [LOCAL VARIABLES] randValue = " + randValue); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return(retVal); }
public bool NegTest4() { bool retVal = true; int randValue = 0; TestLibrary.TestFramework.BeginScenario("NegTest3: Call Dispose twice"); try { randValue = TestLibrary.Generator.GetInt32(-55); MySafeValidHandle handle = new MySafeValidHandle(new IntPtr(randValue)); handle.DisposeWrap(false); handle.DisposeWrap(false); } catch (Exception e) { TestLibrary.TestFramework.LogError("104", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation("WARNING: [LOCAL VARIABLES] randValue = " + randValue); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return(retVal); }
public bool NegTest4() { bool retVal = true; int randValue = 0; TestLibrary.TestFramework.BeginScenario("NegTest3: Call Dispose twice"); try { randValue = TestLibrary.Generator.GetInt32(-55); MySafeValidHandle handle = new MySafeValidHandle(new IntPtr(randValue)); handle.DisposeWrap(false); handle.DisposeWrap(false); } catch (Exception e) { TestLibrary.TestFramework.LogError("104", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation("WARNING: [LOCAL VARIABLES] randValue = " + randValue); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }
public bool PosTest3() { bool retVal = true; int randValue = 0; TestLibrary.TestFramework.BeginScenario("PosTest3: call Dispose on valid SafeHandle instance with false"); try { MySafeValidHandle handle = new MySafeValidHandle(); handle.DisposeWrap(false); randValue = TestLibrary.Generator.GetInt32(-55); handle = new MySafeValidHandle(new IntPtr(randValue)); handle.DisposeWrap(false); } catch (Exception e) { TestLibrary.TestFramework.LogError("003", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation("WARNING: [LOCAL VARIABLES] randValue = " + randValue); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }
public bool PosTest3() { bool retVal = true; int randValue = 0; TestLibrary.TestFramework.BeginScenario("PosTest3: call Dispose through IDispose interface"); try { SafeHandle handle = new MySafeInValidHandle(); IDisposable idisp = handle as IDisposable; idisp.Dispose(); randValue = TestLibrary.Generator.GetInt32(-55); handle = new MySafeInValidHandle(new IntPtr(randValue)); idisp = handle as IDisposable; idisp.Dispose(); handle = new MySafeValidHandle(); idisp = handle as IDisposable; idisp.Dispose(); randValue = TestLibrary.Generator.GetInt32(-55); handle = new MySafeValidHandle(new IntPtr(randValue)); idisp = handle as IDisposable; idisp.Dispose(); } catch (Exception e) { TestLibrary.TestFramework.LogError("003", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation("WARNING: [LOCAL VARIABLES] randValue = " + randValue); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }
public bool NegTest2() { bool retVal = true; int randValue = 0; TestLibrary.TestFramework.BeginScenario("NegTest2: Call DangerousRelease twice with one call DangerousAddRef for valid handle"); try { randValue = TestLibrary.Generator.GetInt32(-55); SafeHandle handle = new MySafeValidHandle(new IntPtr(randValue)); bool success = false; // if this object gets finalized it will throw an exception on the finalizer thread GC.SuppressFinalize(handle); handle.DangerousAddRef(ref success); if (!success) { TestLibrary.TestFramework.LogInformation("WARNING: Calling DangerousAddRef returns false"); } handle.DangerousRelease(); handle.DangerousRelease(); } catch (Exception e) { TestLibrary.TestFramework.LogError("102.1", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation("WARNING: [LOCAL VARIABLES] randValue = " + randValue.ToString()); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }
public bool PosTest5() { bool retVal = true; int randValue = 0; TestLibrary.TestFramework.BeginScenario("PosTest5: Call DangerousAddRef after call DangerousRelease for valid handle"); try { randValue = TestLibrary.Generator.GetInt32(-55); SafeHandle handle = new MySafeValidHandle(new IntPtr(randValue)); bool success = false; handle.DangerousAddRef(ref success); if (!success) { TestLibrary.TestFramework.LogInformation("WARNING: Calling DangerousAddRef returns false"); } handle.DangerousRelease(); handle.DangerousAddRef(ref success); if (!success) { TestLibrary.TestFramework.LogError("005.1", "Calling DangerousAddRef returns false after calling DangerousRelease"); } handle.DangerousRelease(); } catch (Exception e) { TestLibrary.TestFramework.LogError("005.2", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation("WARNING: [LOCAL VARIABLES] randValue = " + randValue.ToString()); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }
public bool PosTest1() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest1: DangerousGetHandle should return handle value for valid safe handle"); try { SafeHandle handle = new MySafeValidHandle(); IntPtr handleValue = handle.DangerousGetHandle(); if (handleValue != IntPtr.Zero) { TestLibrary.TestFramework.LogError("001.1", "DangerousGetHandle returns wrong handle value for valid safe handle"); TestLibrary.TestFramework.LogInformation("WARNING: [LOCAL VARIABLES] handleValue = " + handleValue.ToString() + ", desiredValue = IntPtr.Zero"); retVal = false; } // Get it twice handleValue = handle.DangerousGetHandle(); if (handleValue != IntPtr.Zero) { TestLibrary.TestFramework.LogError("001.2", "DangerousGetHandle returns wrong handle value for valid safe handle"); TestLibrary.TestFramework.LogInformation("WARNING: [LOCAL VARIABLES] handleValue = " + handleValue.ToString() + ", desiredValue = IntPtr.Zero"); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("001.3", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }
public bool PosTest2() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest2: DangerousGetHandle should return handle value for valid safe handle"); try { int randValue = TestLibrary.Generator.GetInt32(-55); IntPtr desiredValue = new IntPtr(randValue); SafeHandle handle = new MySafeValidHandle(desiredValue); IntPtr handleValue = handle.DangerousGetHandle(); if (handleValue != desiredValue) { TestLibrary.TestFramework.LogError("002.1", "DangerousGetHandle returns wrong handle value for valid safe handle"); TestLibrary.TestFramework.LogInformation("WARNING: [LOCAL VARIABLES] handleValue = " + handleValue.ToString() + ", desiredValue = " + desiredValue.ToString()); retVal = false; } handleValue = handle.DangerousGetHandle(); if (handleValue != desiredValue) { TestLibrary.TestFramework.LogError("002.2", "DangerousGetHandle returns wrong handle value for valid safe handle"); TestLibrary.TestFramework.LogInformation("WARNING: [LOCAL VARIABLES] handleValue = " + handleValue.ToString() + ", desiredValue = " + desiredValue.ToString()); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("002.3", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }