// Returns true if the expected result is right // Returns false if the expected result is wrong public bool PosTest2() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest2: the parameter string is null."); try { string expectValue = null; OutOfMemoryException myException = new OutOfMemoryException(expectValue); if (myException == null) { TestLibrary.TestFramework.LogError("002.1", "OutOfMemoryException instance can not create correctly."); retVal = false; } if (myException.Message == expectValue) { TestLibrary.TestFramework.LogError("002.2", "the Message should return the default value."); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("002.0", "Unexpected exception: " + e); retVal = false; } return retVal; }
// Returns true if the expected result is right // Returns false if the expected result is wrong public bool PosTest1() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest1: Create a new instance of OutOfMemoryException."); try { string expectValue = "HELLO"; OutOfMemoryException myException = new OutOfMemoryException(expectValue); if (myException == null) { TestLibrary.TestFramework.LogError("001.1", "OutOfMemoryException instance can not create correctly."); retVal = false; } if (myException.Message != expectValue) { TestLibrary.TestFramework.LogError("001.2", "the Message should return " + expectValue); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("001.0", "Unexpected exception: " + e); retVal = false; } return retVal; }
public void StripTargetInvocationExceptionAndAggregateException() { _client.AddWrapperExceptions(typeof(AggregateException)); OutOfMemoryException exception2 = new OutOfMemoryException("Ran out of Int64s"); AggregateException innerWrapper = new AggregateException(_exception, exception2); TargetInvocationException wrapper = new TargetInvocationException(innerWrapper); List <Exception> exceptions = _client.ExposeStripWrapperExceptions(wrapper).ToList(); Assert.AreEqual(2, exceptions.Count); Assert.Contains(_exception, exceptions); Assert.Contains(exception2, exceptions); }
public static byte[] AllocateByteArray(int size) { byte[] numArray; try { numArray = new byte[size]; } catch (OutOfMemoryException outOfMemoryException1) { OutOfMemoryException outOfMemoryException = outOfMemoryException1; throw Fx.Exception.AsError(new InsufficientMemoryException(InternalSR.BufferAllocationFailed(size), outOfMemoryException)); } return(numArray); }
public static char[] AllocateCharArray(int size) { char[] chrArray; try { chrArray = new char[size]; } catch (OutOfMemoryException outOfMemoryException1) { OutOfMemoryException outOfMemoryException = outOfMemoryException1; throw Fx.Exception.AsError(new InsufficientMemoryException(InternalSR.BufferAllocationFailed(size * 2), outOfMemoryException)); } return(chrArray); }
public void ReleaseCore(int count) { Debug.Assert(count > 0); for (int i = 0; i < count; i++) { if (!Interop.Kernel32.PostQueuedCompletionStatus(_completionPort, 1, UIntPtr.Zero, IntPtr.Zero)) { int lastError = Marshal.GetLastWin32Error(); var exception = new OutOfMemoryException(); exception.HResult = lastError; throw exception; } } }
public void CreateCityModelTestThrowsOutOfMemoryException351() { using (PexPConsoleInContext.Create()) { OutOfMemoryException outOfMemoryException; CityModel cityModel; outOfMemoryException = new OutOfMemoryException(); IPexChoiceRecorder choices = PexChoose.Replay.Setup(); choices.NextSegment(1).DefaultSession .At(3, "line", "-0") .At(4, "throw", (object)outOfMemoryException); CityModelBuilder s0 = new CityModelBuilder(); cityModel = this.CreateCityModelTest(s0, (string)null); } }
public void getInputNumberTestThrowsOutOfMemoryException17() { using (PexPConsoleInContext.Create()) { Manager manager; OutOfMemoryException outOfMemoryException; int i; manager = new Manager((string)null, (string)null, (string)null); outOfMemoryException = new OutOfMemoryException(); IPexChoiceRecorder choices = PexChoose.Replay.Setup(); choices.NextSegment(2).DefaultSession .At(1, "throw", (object)outOfMemoryException); i = this.getInputNumberTest(manager); } }
public void ReportException_MultipleClasses_TelemetryIsAllowed_ChainsSameDataToAll() { SetupMultipleTelemetryClasses(); Exception expectedException = new OutOfMemoryException(); _telemetrySink.HasUserOptedIntoTelemetry = true; _telemetryMock1.Setup(x => x.ReportException(expectedException)); _telemetryMock2.Setup(x => x.ReportException(expectedException)); _telemetrySink.ReportException(expectedException); _telemetryMock1.VerifyAll(); _telemetryMock2.VerifyAll(); }
public void ReflectionTypeLoadExceptionSupport() { FileNotFoundException ex1 = new FileNotFoundException(); OutOfMemoryException ex2 = new OutOfMemoryException(); ReflectionTypeLoadException wrapper = new ReflectionTypeLoadException(new Type[] { typeof(FakeRaygunClient), typeof(WrapperException) }, new Exception[] { ex1, ex2 }); RaygunErrorMessage message = RaygunErrorMessageBuilder.Build(wrapper); Assert.AreEqual(2, message.InnerErrors.Count()); Assert.AreEqual("System.IO.FileNotFoundException", message.InnerErrors[0].ClassName); Assert.AreEqual("System.OutOfMemoryException", message.InnerErrors[1].ClassName); Assert.IsTrue(message.InnerErrors[0].Data["Type"].ToString().Contains("FakeRaygunClient")); Assert.IsTrue(message.InnerErrors[1].Data["Type"].ToString().Contains("WrapperException")); }
private bool WaitCore(int timeoutMilliseconds) { bool waitResult = Interop.Kernel32.SleepConditionVariableCS(ref _conditionVariable, ref _criticalSection, timeoutMilliseconds); if (!waitResult) { int lastError = Marshal.GetLastWin32Error(); if (lastError != Interop.Errors.ERROR_TIMEOUT) { var exception = new OutOfMemoryException(); exception.HResult = lastError; throw exception; } } return(waitResult); }
public void StripNestedAggregateExceptions() { _client.AddWrapperExceptions(typeof(AggregateException)); OutOfMemoryException exception2 = new OutOfMemoryException("Ran out of Int64s"); NotSupportedException exception3 = new NotSupportedException("Forgot to implement this method"); AggregateException innerWrapper = new AggregateException(_exception, exception2); AggregateException wrapper = new AggregateException(innerWrapper, exception3); List <Exception> exceptions = _client.ExposeStripWrapperExceptions(wrapper).ToList(); Assert.AreEqual(3, exceptions.Count); Assert.Contains(_exception, exceptions); Assert.Contains(exception2, exceptions); Assert.Contains(exception3, exceptions); }
public int Release(int count) { Debug.Assert(count > 0); for (int i = 0; i < count; i++) { if (!Interop.Kernel32.PostQueuedCompletionStatus(_completionPort, 1, UIntPtr.Zero, IntPtr.Zero)) { var lastError = Marshal.GetLastWin32Error(); var exception = new OutOfMemoryException(); exception.HResult = lastError; throw exception; } } return(0); // TODO: Track actual signal count to calculate this }
public void ReportException_TelemetryIsAllowed_MultipleClasses_TelemetryThrowsException_DoesNotReportSecondException() { SetupMultipleTelemetryClasses(); Exception expectedException = new OutOfMemoryException(); Exception unexpectedException = new InvalidOperationException(); _telemetrySink.HasUserOptedIntoTelemetry = true; _telemetryMock1.Setup(x => x.ReportException(expectedException)) .Throws(unexpectedException); _telemetryMock2.Setup(x => x.ReportException(expectedException)); _telemetrySink.ReportException(expectedException); _telemetryMock1.VerifyAll(); _telemetryMock2.VerifyAll(); }
private static byte *ThrowFailedToAllocate(long size, ThreadStats thread, OutOfMemoryException e) { long allocated = 0; foreach (var threadAllocationsValue in AllThreadStats) { allocated += threadAllocationsValue.TotalAllocated; } var managed = MemoryInformation.GetManagedMemoryInBytes(); var unmanagedMemory = MemoryInformation.GetUnManagedAllocationsInBytes(); throw new OutOfMemoryException($"Failed to allocate additional {new Size(size, SizeUnit.Bytes)} " + $"to already allocated {new Size(thread.TotalAllocated, SizeUnit.Bytes)} by this thread. " + $"Total allocated by all threads: {new Size(allocated, SizeUnit.Bytes)}, " + $"Managed memory: {new Size(managed, SizeUnit.Bytes)}, " + $"Un-managed memory: {new Size(unmanagedMemory, SizeUnit.Bytes)}", e); }
public LowLevelLifoSemaphore(int initialSignalCount, int maximumSignalCount) { Debug.Assert(initialSignalCount >= 0, "Windows LowLevelLifoSemaphore does not support a negative signal count"); // TODO: Track actual signal count to enable this Debug.Assert(maximumSignalCount > 0); Debug.Assert(initialSignalCount <= maximumSignalCount); _completionPort = Interop.Kernel32.CreateIoCompletionPort(new IntPtr(-1), IntPtr.Zero, UIntPtr.Zero, maximumSignalCount); if (_completionPort == IntPtr.Zero) { var error = Marshal.GetLastWin32Error(); var exception = new OutOfMemoryException(); exception.HResult = error; throw exception; } Release(initialSignalCount); }
public static byte[] AllocateByteArray(int size) { byte[] numArray; try { numArray = new byte[size]; } catch (OutOfMemoryException outOfMemoryException1) { OutOfMemoryException outOfMemoryException = outOfMemoryException1; ExceptionTrace exception = Fx.Exception; string bufferAllocationFailed = Resources.BufferAllocationFailed; object[] objArray = new object[] { size }; throw exception.AsError(new InsufficientMemoryException(Microsoft.ServiceBus.SR.GetString(bufferAllocationFailed, objArray), outOfMemoryException), null); } return(numArray); }
public void PublishTelemetryEvent_PropertyBag_TelemetryAllowed_ThrowsOnPublish_ReportsException() { Exception expectedExpection = new OutOfMemoryException(); PropertyBag expectedPropertyBag = new Dictionary <string, string> { { PropertyName1, Value2 }, { PropertyName2, Value1 }, }; _telemetrySink.IsTelemetryAllowed = true; _telemetryMock.Setup(x => x.PublishEvent(EventName2, expectedPropertyBag)) .Throws(expectedExpection); _telemetryMock.Setup(x => x.ReportException(expectedExpection)); _telemetrySink.PublishTelemetryEvent(EventName2, expectedPropertyBag); _telemetryMock.VerifyAll(); }
public void CreateCityModelTestThrowsOutOfMemoryException409() { using (PexPConsoleInContext.Create()) { OutOfMemoryException outOfMemoryException; CityModel cityModel; outOfMemoryException = new OutOfMemoryException(); IPexChoiceRecorder choices = PexChoose.Replay.Setup(); choices.NextSegment(1).DefaultSession .At(0, "peeked", (object)true) .At(1, "peek", (object)' ') .At(3, "line", "") .At(6, "line", "") .At(7, "throw", (object)outOfMemoryException); CityModelBuilder s0 = new CityModelBuilder(); cityModel = this.CreateCityModelTest(s0, ""); } }
public DataQueuePacket(int packetlen) { try { // 栈是从高地址到底地址存储数据,但结构体和数组应该当作一个整体,其内部地址是由低到高增长。 // 然而实际并非完全如此,上面这句话并不严谨,详见:https://www.zhihu.com/question/36103513 SDL_DataQueuePacket p;// 这里是由低到高 packetlen += Marshal.SizeOf <SDL_DataQueuePacket>() - (int)( (size_t)(&p.data) - (size_t)(&p.datalen)); data = (byte *)Marshal.AllocHGlobal(packetlen); } catch (OutOfMemoryException e) { data = null; err = e; } }
/// <summary> /// Convert Object from FilePath into a sequence of byte /// </summary> /// <param name="filePath"></param> /// <returns>Byte array value of the file</returns> public static byte[] FileToByte(string filePath) { using (var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read)) { try { byte[] buffer = new byte[fs.Length]; int bytesRead = fs.Read(buffer, 0, buffer.Length); return(buffer); } catch (OutOfMemoryException ex) { OutOfMemoryException memoryEx = new OutOfMemoryException("File is too huge to process", ex); throw memoryEx; } } }
public void Reference_Type_Homogenizer_Does_Not_Affect_Instances_Of_Unsupported_Types() { var homogenizer = new ToUpperCaseHomogenizer(); homogenizer .Homogenize(24) .Should() .Be(24); homogenizer .Homogenize(3.141592684d) .Should() .Be(3.141592684d); DateTimeOffset now = DateTimeOffset.Now; homogenizer .Homogenize(now) .Should() .Be(now); var instance = new OutOfMemoryException(); homogenizer .Homogenize(instance) .Should() .Be(instance); uint?anotherInstance = uint.MaxValue; homogenizer .Homogenize(anotherInstance) .Should() .Be(uint.MaxValue); ArgumentNullException nullValue = null; homogenizer .Homogenize(nullValue) .Should() .BeNull(); decimal?anotherNullValue = null; homogenizer .Homogenize(anotherNullValue) .Should() .BeNull(); }
public void AddOrUpdateContextProperty_MultipleClasses_TelemetryIsAllowed_TelemetryThrowsException_ReportsExceptionToAll() { SetupMultipleTelemetryClasses(); Exception expectedExpection = new OutOfMemoryException(); _telemetrySink.HasUserOptedIntoTelemetry = true; _telemetryMock1.Setup(x => x.AddOrUpdateContextProperty(PropertyName2, Value2)) .Throws(expectedExpection); _telemetryMock2.Setup(x => x.AddOrUpdateContextProperty(PropertyName2, Value2)); _telemetryMock1.Setup(x => x.ReportException(expectedExpection)); _telemetryMock2.Setup(x => x.ReportException(expectedExpection)); _telemetrySink.AddOrUpdateContextProperty(PropertyName2, Value2); _telemetryMock1.VerifyAll(); _telemetryMock2.VerifyAll(); }
public void ErrorOnBeginReadLine(Action <TestProcess, Exception> modifier) { var notifications = new List <Notification <string> >(); var error = new OutOfMemoryException(); using var subscription = TestSpawn(SpawnOptions, notifications, s => $"out: {s}", s => $"err: {s}", p => modifier(p, error)); Assert.That(notifications, Is.EqualTo(new[] { Notification.CreateOnError <string>(error) })); var process = subscription.Tag; Assert.That(process.KillCalled, Is.True); }
public void GetEnumerator_IteratesInfinitely() { // Arrange IEnumerableImposter ienumerableImposter = new IEnumerableImposter(); OutOfMemoryException outOfMemoryException = null; // Act try { new List <int>(ienumerableImposter); } catch (OutOfMemoryException ex) { outOfMemoryException = ex; } // Assert Assert.IsNotNull(outOfMemoryException); }
internal static void Initialize(UIntPtr os_commit_size, UIntPtr heap_commit_size) { PageManager.os_commit_size = os_commit_size; PageManager.heap_commit_size = heap_commit_size; // unusedMemoryBlocks = new UnusedBlockHeader [32] unusedMemoryBlocks = (UnusedBlockHeader[]) BootstrapMemory.Allocate(typeof(UnusedBlockHeader[]), 32); // outOfMemoryException = new OutOfMemoryException(); outOfMemoryException = (OutOfMemoryException) BootstrapMemory.Allocate(typeof(OutOfMemoryException)); #if SINGULARITY_KERNEL #if USE_SPINLOCK Lock = new SpinLock(SpinLock.Types.PageManager); #endif avoidDirtyPages = true; #else avoidDirtyPages = false; #endif }
// Returns true if the expected result is right // Returns false if the expected result is wrong public bool PosTest1() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest1: Create a new instance of OutOfMemoryException."); try { OutOfMemoryException myException = new OutOfMemoryException(); if (myException == null) { TestLibrary.TestFramework.LogError("001.1", "OutOfMemoryException instance can not create correctly."); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("001.0", "Unexpected exception: " + e); retVal = false; } return retVal; }
public void Method1() { throw new Exception(); // Noncompliant {{'System.Exception' should not be thrown by user code.}} // ^^^^^^^^^ throw new ApplicationException(); // Noncompliant {{'System.ApplicationException' should not be thrown by user code.}} // ^^^^^^^^^^^^^^^^^^^^ throw new SystemException(); // Noncompliant {{'System.SystemException' should not be thrown by user code.}} // ^^^^^^^^^^^^^^^ throw new ExecutionEngineException(); // Noncompliant {{'System.ExecutionEngineException' should not be thrown by user code.}} // ^^^^^^^^^^^^^^^^^^^^^^^^ throw new IndexOutOfRangeException(); // Noncompliant {{'System.IndexOutOfRangeException' should not be thrown by user code.}} // ^^^^^^^^^^^^^^^^^^^^^^^^ throw new NullReferenceException(); // Noncompliant {{'System.NullReferenceException' should not be thrown by user code.}} // ^^^^^^^^^^^^^^^^^^^^^^ throw new OutOfMemoryException(); // Noncompliant {{'System.OutOfMemoryException' should not be thrown by user code.}} // ^^^^^^^^^^^^^^^^^^^^ var e = new OutOfMemoryException(); // Noncompliant {{'System.OutOfMemoryException' should not be thrown by user code.}} // ^^^^^^^^^^^^^^^^^^^^ throw new ArgumentNullException(); // Compliant OutOfMemoryException e = (OutOfMemoryException) new ArgumentException(); // Compliant try { var a = new int[0]; Console.WriteLine(a[1]); // Throw exception } catch (IndexOutOfRangeException) { throw; // Compliant } }
public void Test() { string s1 = ""; lock (s1) { } //NonComplaint lock ("Hello") { } //NonComplaint var o1 = new OutOfMemoryException(); lock (o1) { } //NonComplaint var o2 = new StackOverflowException(); lock (o2) { } //NonComplaint var o3 = new ExecutionEngineException(); lock (o3) { } //NonComplaint lock (System.Threading.Thread.CurrentThread) { } //NonComplaint lock (typeof(LockTest2)) { } //NonComplaint System.Reflection.MemberInfo mi = null; lock (mi) { } //NonComplaint System.Reflection.ConstructorInfo ci = null; lock (ci) { } //NonComplaint System.Reflection.ParameterInfo pi = null; lock (pi) { } //NonComplaint int[] values = { 1, 2, 3 }; lock (values) { } //NonComplaint System.Reflection.MemberInfo[] values1 = null; lock (values1) { } lock (this) { } //NonComplaint }
// Returns true if the expected result is right // Returns false if the expected result is wrong public bool PosTest1() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest1: Create a new instance of OutOfMemoryException."); try { OutOfMemoryException myException = new OutOfMemoryException(); if (myException == null) { TestLibrary.TestFramework.LogError("001.1", "OutOfMemoryException instance can not create correctly."); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("001.0", "Unexpected exception: " + e); retVal = false; } return(retVal); }
public static List <TestCaseData> ThrowsOrPassesSource() { var exception1 = new ArgumentException(); var exception2 = new OutOfMemoryException(); var exception3 = new FieldAccessException(); var exception4 = new NotImplementedException(); return(new List <TestCaseData> { new TestCaseData(new List <Exception> { exception1, exception2, exception3, exception4 }), new TestCaseData(new List <Exception> { null, null, null, null }), new TestCaseData(new List <Exception> { null, exception1, null, exception2 }), new TestCaseData(new List <Exception> { exception1, null, exception2, null }) }); }
public void ErrorOnBeginErrorReadLineWithSomeOutputDataReceived() { var notifications = new List <Notification <string> >(); var error = new OutOfMemoryException(); using var subscription = TestSpawn(SpawnOptions, notifications, s => $"out: {s}", s => $"err: {s}", p => p.EnteringBeginOutputReadLine += (_, _) => p.FireOutputDataReceived("foobar"), p => p.BeginErrorReadLineException = error); Assert.That(notifications, Is.EqualTo(new[] { Notification.CreateOnNext("out: foobar"), Notification.CreateOnError <string>(error) })); var process = subscription.Tag; Assert.That(process.KillCalled, Is.True); }
public static List <List <object> > ThrowsOrReturnsSource() { var exception1 = new ArgumentException(); var exception2 = new OutOfMemoryException(); var exception3 = new FieldAccessException(); var exception4 = new NotImplementedException(); return(new List <List <object> >() { new List <object> { exception1, exception2, exception3, exception4 }, new List <object> { "1", "2", "3", "4" }, new List <object> { null, null, null, null }, new List <object> { exception1, "1", null, null, "2", exception2 } }); }