/// <summary/> public override void BeforeTest(TestDetails testDetails) { base.BeforeTest(testDetails); m_activationContext = new ActivationContextHelper("FieldWorks.Tests.manifest"); m_currentActivation = m_activationContext.Activate(); m_debugProcs = new DebugProcs(); if (!Platform.IsWindows) { try { using (var process = System.Diagnostics.Process.GetCurrentProcess()) { // try to change PTRACE option so that unmanaged call stacks show more useful // information. Since Ubuntu 10.10 a normal user is no longer allowed to use // PTRACE. This prevents call stacks and assertions from working properly. // However, we can set a flag on the currently running process to allow // it. See also the similar code in Generic/ModuleEntry.cpp prctl(PR_SET_PTRACER, (IntPtr)process.Id, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); } } catch (Exception e) { // just ignore any errors we get } } }
public virtual void FixtureSetup() { m_debugProcs = new DebugProcs(); try { Common.COMInterfaces.Icu.InitIcuDataDir(); } catch (Exception e) { Console.WriteLine(e.Message); } Icu.Wrapper.ConfineIcuVersions(54); #if __MonoCS__ try { using (var process = System.Diagnostics.Process.GetCurrentProcess()) { // try to change PTRACE option so that unmanaged call stacks show more useful // information. Since Ubuntu 10.10 a normal user is no longer allowed to use // PTRACE. This prevents call stacks and assertions from working properly. // However, we can set a flag on the currently running process to allow // it. See also the similar code in Generic/ModuleEntry.cpp prctl(PR_SET_PTRACER, (IntPtr)process.Id, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); } } catch (Exception e) { // just ignore any errors we get } #endif }
/// ------------------------------------------------------------------------------------ /// <summary> /// Executes in two distinct scenarios. /// /// 1. If disposing is true, the method has been called directly /// or indirectly by a user's code via the Dispose method. /// Both managed and unmanaged resources can be disposed. /// /// 2. If disposing is false, the method has been called by the /// runtime from inside the finalizer and you should not reference (access) /// other managed objects, as they already have been garbage collected. /// Only unmanaged resources can be disposed. /// </summary> /// <param name="disposing"></param> /// <remarks> /// If any exceptions are thrown, that is fine. /// If the method is being done in a finalizer, it will be ignored. /// If it is thrown by client code calling Dispose, /// it needs to be handled by fixing the bug. /// /// If subclasses override this method, they should call the base implementation. /// </remarks> /// ------------------------------------------------------------------------------------ protected virtual void Dispose(bool disposing) { //Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************"); // Must not be run more than once. if (IsDisposed) { return; } // FWC-16: we have to call CoFreeUnusedLibraries. This causes sqlnclir.dll to get // unloaded. If we don't do this we get a deadlock after the fixture teardown // because we're running STA. CoFreeUnusedLibraries(); if (disposing) { // Dispose managed resources here. if (m_DebugProcs != null) { m_DebugProcs.Dispose(); } } // Dispose unmanaged resources here, whether disposing is true or false. m_DebugProcs = null; m_isDisposed = true; }
public virtual void FixtureSetup() { #if false CheckDisposed(); #else /* We need to document cases where this needs to be worried about. * I (RandyR) don't understand how this can happen, if the nunit framework * creates a test class instance, calls this method, runs all its tests, * calls the TestFictureTeardown code (Dispose), * and then turns loose of the test class instance. * * If the above is what happens, then how can it be called twice? * If the class can indeed be reused, and this method called more than once, * in what contexts does it happen? * * Until we can nail down that context, * let's see if we can live with the more rigid approach. * * Followup observation: * I (RandyR) saw in some acceptance tests (UndoRedoTests) that a test TearDown * method had called this method, as well as the Dispose method, as a way * to be sure the next was set up correcly. That is not good! * I fixed that class to not override this method or the Dispose method, * but to just do all the setup/teardown stuff between each test. */ // Answer (TimS/EberhardB): NUnit doesn't create a new instance each time // a test fixture is run. Therefore we have to resurrect the instance, otherwise // we can't run tests twice in NUnit-GUI. // ENHANCE: We think our use of doing a Dispose in the TestFixtureTearDown is wrong, // since FixtureSetUp and FixtureTearDown go together, so FixtureTearDown should // clean the things that FixtureSetUp created (or that might be left over from // running the tests). if (m_isDisposed) { // in case we're running the same test twice we have to reset the m_isDisposed // flag, otherwise in FixtureTearDown we think that Dispose was already called. m_isDisposed = false; GC.ReRegisterForFinalize(this); } #if false // This should already be disposed if we run this test fixture twice. if (m_DebugProcs != null) { m_DebugProcs.Dispose(); } #endif #endif m_DebugProcs = new DebugProcs(); try { StringUtils.InitIcuDataDir(); } catch (Exception e) { Console.WriteLine(e.Message); } }
public virtual void FixtureTeardown() { // FWC-16: we have to call CoFreeUnusedLibraries. This causes sqlnclir.dll to get // unloaded. If we don't do this we get a deadlock after the fixture teardown // because we're running STA. CoFreeUnusedLibraries(); m_debugProcs.Dispose(); m_debugProcs = null; }
/// <summary> /// Executes in two distinct scenarios. /// /// 1. If disposing is true, the method has been called directly /// or indirectly by a user's code via the Dispose method. /// Both managed and unmanaged resources can be disposed. /// /// 2. If disposing is false, the method has been called by the /// runtime from inside the finalizer and you should not reference (access) /// other managed objects, as they already have been garbage collected. /// Only unmanaged resources can be disposed. /// </summary> /// <param name="disposing"></param> /// <remarks> /// If any exceptions are thrown, that is fine. /// If the method is being done in a finalizer, it will be ignored. /// If it is thrown by client code calling Dispose, /// it needs to be handled by fixing the bug. /// /// If subclasses override this method, they should call the base implementation. /// </remarks> protected virtual void Dispose(bool disposing) { System.Diagnostics.Debug.WriteLineIf(!disposing, "****** Missing Dispose() call for " + GetType().Name + ". ****** "); // Must not be run more than once. if (IsDisposed || BeingDisposed) return; BeingDisposed = true; if (disposing) { UpdateAppRuntimeCounter(); Logger.WriteEvent("Disposing app: " + GetType().Name); RegistrySettings.FirstTimeAppHasBeenRun = false; // Dispose managed resources here. List<IFwMainWnd> mainWnds = new List<IFwMainWnd>(m_rgMainWindows); // Use another array, since m_rgMainWindows may change. m_rgMainWindows.Clear(); // In fact, just clear the main array, so the windows won't have to worry so much. foreach (IFwMainWnd mainWnd in mainWnds) { if (mainWnd is Form) { Form wnd = (Form)mainWnd; wnd.Closing -= OnClosingWindow; wnd.Closed -= OnWindowClosed; wnd.Activated -= fwMainWindow_Activated; wnd.HandleDestroyed -= fwMainWindow_HandleDestroyed; wnd.Dispose(); } else if (mainWnd is IDisposable) ((IDisposable)mainWnd).Dispose(); } if (m_findReplaceDlg != null) m_findReplaceDlg.Dispose(); #if DEBUG if (m_debugProcs != null) m_debugProcs.Dispose(); #endif ResourceHelper.ShutdownHelper(); if (m_registrySettings != null) m_registrySettings.Dispose(); Application.EnterThreadModal -= Application_EnterThreadModal; Application.LeaveThreadModal -= Application_LeaveThreadModal; Application.RemoveMessageFilter(this); PictureHolder.Dispose(); } // Dispose unmanaged resources here, whether disposing is true or false. m_rgMainWindows = null; m_activeMainWindow = null; m_registrySettings = null; m_findPattern = null; m_findReplaceDlg = null; m_suppressedCacheInfo = null; m_refreshView = null; PictureHolder = null; #if DEBUG m_debugProcs = null; #endif IsDisposed = true; BeingDisposed = false; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Constructor for FwApp /// </summary> /// <param name="fwManager">The FieldWorks manager for dealing with FieldWorks-level /// stuff.</param> /// <param name="helpTopicProvider">An application-specific help topic provider.</param> /// ------------------------------------------------------------------------------------ protected FwApp(IFieldWorksManager fwManager, IHelpTopicProvider helpTopicProvider) { PictureHolder = new PictureHolder(); m_fwManager = fwManager; m_helpTopicProvider = helpTopicProvider; #if DEBUG m_debugProcs = new DebugProcs(); #endif m_registrySettings = new FwRegistrySettings(this); m_registrySettings.LatestAppStartupTime = DateTime.Now.ToUniversalTime().Ticks.ToString(); m_registrySettings.AddErrorReportingInfo(); Application.EnterThreadModal += Application_EnterThreadModal; Application.LeaveThreadModal += Application_LeaveThreadModal; Application.AddMessageFilter(this); }