Ejemplo n.º 1
0
		public void TestSetup()
		{
			Debug.Assert(m_testTeApp == null, "Why does it have something in m_testTeApp here?");
			Unpacker.UnPackParatextTestProjects();
			m_regData = Unpacker.PrepareRegistryForPTData();
			m_teSubKey = Registry.CurrentUser.CreateSubKey(@"Software\SIL\FieldWorks\Translation Editor");

			// save the width of the style pane, only if it already has a value
			// Tests will fail if the style pane is showing, so we turn it off.
			object keyValue = m_teSubKey.GetValue("DraftStyleAreaWidth");
			if (keyValue != null)
			{
				m_draftAreaStyleWidth = (int)keyValue;
				m_teSubKey.SetValue("DraftStyleAreaWidth", 0);
			}

			// TeApp derives from FwApp
			// Make sure the registry thinks the last time an attempt was made to open TE
			// was successful. Otherwise, the welcome dialog shows up in the middle of tests.
			RegistryBoolSetting successfulStartup = new RegistryBoolSetting(FwSubKey.TE, "OpenSuccessful", true);
			successfulStartup.Value = true;

			// TODO: Figure out what we need to pass into the app
			m_testTeApp = new TestTeApp(new string[0]);

			m_fMainWindowOpened = m_testTeApp.OpenMainWindow();
			Assert.AreEqual(1, m_testTeApp.MainWindows.Count);

			// Sidebar buttons get pressed as part of main window initialization;
			// wait for that initialization to finish before we proceed.
			while (DataUpdateMonitor.IsUpdateInProgress(
				((TestTeMainWnd)m_testTeApp.MainWindows[0]).Cache.MainCacheAccessor))
			{
				Application.DoEvents();
			}

			if (m_fMainWindowOpened)
			{
				m_firstMainWnd = (TestTeMainWnd)m_testTeApp.MainWindows[0];
				m_firstMainWnd.CreateDraftView();
				// Set the view to the DraftView
				m_firstMainWnd.SwitchActiveView(m_firstMainWnd.TheDraftViewWrapper);
				Application.DoEvents();

				m_firstDraftView = (TestTeDraftView)m_firstMainWnd.TheDraftView;
				m_firstDraftView.ActivateView();

				SelectionHelper helper = m_firstDraftView.SetInsertionPoint(0, 0, 0, 0, true);
				// helper.IhvoEndPara = -1;
				helper.SetSelection(m_firstDraftView, true, true);
				Application.DoEvents();
			}
		}
Ejemplo n.º 2
0
		public void TestTearDown()
		{
			// Close the footnote view if it was showing
			if (m_firstMainWnd.TheDraftViewWrapper.FootnoteViewShowing)
				m_firstMainWnd.TheDraftViewWrapper.HideFootnoteView();

			m_testTeApp.ExitAppplication();
			//m_firstMainWnd.Cache = null; // Bad idea, since it has been disposed.
			m_testTeApp.Dispose();
			m_testTeApp = null;

			m_regData.RestoreRegistryData();
			// restore the value we saved in Init
			if (m_draftAreaStyleWidth != -1)
				m_teSubKey.SetValue("DraftStyleAreaWidth", m_draftAreaStyleWidth);

			m_firstMainWnd = null; // The app should have disposed this.
			m_firstDraftView = null; // The app should have disposed this.

			//			// Cleanup (and Release?) the ICU memory mapping.
			//			SIL.FieldWorks.Common.Utils.Icu.Cleanup();
			m_teSubKey = null;
			m_regData = null;
		}
Ejemplo n.º 3
0
		public void CursorPosInSamePlaceAfterCloseAndOpen()
		{
			// Set the insertion point to the 3rd paragraph of 3rd section.
			SelectionHelper selHelper1 = m_firstDraftView.SetInsertionPoint(0, 3, 3, 100, true);
			int tag3 = selHelper1.LevelInfo[3].tag;
			int ihvo3 = selHelper1.LevelInfo[3].ihvo;
			int tag2 = selHelper1.LevelInfo[2].tag;
			int ihvo2 = selHelper1.LevelInfo[2].ihvo;
			int tag1 = selHelper1.LevelInfo[1].tag;
			int ihvo1 = selHelper1.LevelInfo[1].ihvo;
			int tag0 = selHelper1.LevelInfo[0].tag;
			int numberOfLevels = selHelper1.NumberOfLevels;

			// close the main window
			// This will dispose it, so we have to remember the
			// relevant information about selections, above.
			m_firstMainWnd.Close();

			// re-open the main window
			m_testTeApp.OpenMainWindow();
			TestTeMainWnd newMainWnd = (TestTeMainWnd)m_testTeApp.MainWindows[0];
			newMainWnd.CreateDraftView();
			newMainWnd.SwitchActiveView(newMainWnd.TheDraftViewWrapper);
			// We also have to reset this member variable,
			// or the teardown code will try and use the old disposed one.
			m_firstMainWnd = newMainWnd;
			TestTeDraftView newDraftView = (TestTeDraftView)newMainWnd.TheDraftView;
			// We also have to reset this member variable,
			// or the teardown code will try and use the old disposed one.
			m_firstDraftView = newDraftView;

			SelectionHelper selHelper2 = SelectionHelper.GetSelectionInfo(null, newDraftView);

			// Verify the IPs are in the same book, section, and that the ip is in the
			// first paragraph
			Assert.AreEqual(numberOfLevels, selHelper2.NumberOfLevels);

			Assert.AreEqual(tag3, selHelper2.LevelInfo[3].tag);
			Assert.AreEqual(ihvo3, selHelper2.LevelInfo[3].ihvo);
			Assert.AreEqual(tag2, selHelper2.LevelInfo[2].tag);
			Assert.AreEqual(ihvo2, selHelper2.LevelInfo[2].ihvo);
			Assert.AreEqual(tag1, selHelper2.LevelInfo[1].tag);
			Assert.AreEqual(ihvo1, selHelper2.LevelInfo[1].ihvo);
			Assert.AreEqual(tag0, selHelper2.LevelInfo[0].tag);
			Assert.AreEqual(0, selHelper2.LevelInfo[0].ihvo);
			// Verify the IP is in the correct location.
			Assert.AreEqual(0, selHelper2.IchAnchor);
			Assert.AreEqual(0, selHelper2.IchEnd);
		}
Ejemplo n.º 4
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Creates the control based on the create info.
		/// </summary>
		/// <param name="sender">The caller.</param>
		/// <param name="createInfo">The create info previously specified by the client.</param>
		/// <returns>The newly created control.</returns>
		/// ------------------------------------------------------------------------------------
		protected override Control CreateControl(object sender, object createInfo)
		{
			CheckDisposed();
			if (createInfo is DraftViewCreateInfo)
			{
				DraftViewCreateInfo info = (DraftViewCreateInfo)createInfo;
				TestTeDraftView draftView = new TestTeDraftView(m_cache, Handle.ToInt32());
				draftView.Name = info.Name;
				draftView.Editable = info.IsEditable;
				draftView.TheViewWrapper = sender as ViewWrapper;
				return draftView;
			}
			return base.CreateControl(sender, createInfo);
		}
Ejemplo n.º 5
0
		public void Init()
		{
			if (m_fMainWindowOpened)
			{
				if (m_testTeApp == null)
					StartTestApp();

				m_firstMainWnd = (TestTeMainWnd)m_testTeApp.MainWindows[0];
				if (m_firstMainWnd.ClientWindows.Count == 0)
					m_firstMainWnd.CreateDraftView();

				// Set the view to the DraftView
				m_firstMainWnd.SwitchActiveView(m_firstMainWnd.TheDraftViewWrapper);
				Application.DoEvents();

				m_firstDraftView = (TestTeDraftView)m_firstMainWnd.TheDraftView;
				m_firstDraftView.ActivateView();

				SelectionHelper helper = m_firstDraftView.SetInsertionPoint(0, 0, 0, 0, true);
				// helper.IhvoEndPara = -1;
				helper.SetSelection(m_firstDraftView, true, true);
				Application.DoEvents();
			}
		}
Ejemplo n.º 6
0
		/// <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 override void Dispose(bool disposing)
		{
			//Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************");
			// Must not be run more than once.
			if (IsDisposed)
				return;

			if (disposing)
			{
				// Dispose managed resources here.
				if (m_testTeApp != null)
				{
					m_testTeApp.ExitAppplication();
					m_testTeApp.Dispose();
				}
				if (m_regData != null)
					m_regData.RestoreRegistryData();
				// restore the value we saved in Init
				if (m_draftAreaStyleWidth != -1)
					m_teSubKey.SetValue("DraftStyleAreaWidth", m_draftAreaStyleWidth);
			}

			// Dispose unmanaged resources here, whether disposing is true or false.
			m_firstMainWnd = null; // The app should have disposed this.
			m_firstDraftView = null; // The app should have disposed this.
			m_testTeApp = null;

			// This used to be done by the dispose of the FwFindReplaceDlg control, but doing it
			// that often is wrong, because other instances of the control (or other controls)
			// may have the default WSF open. However, later tests depend on ShutDown writing
			// stuff out.
#if !__MonoCS__
			ILgWritingSystemFactory wsf = LgWritingSystemFactoryClass.Create();
#else
			// TODO-Linux: above code hangs - FIXME
			// Currently doing without the Invoke - see FwKernel.cs LgWritingSystemFactoryClass.Create.
			ILgWritingSystemFactory wsf = new LgWritingSystemFactory();
#endif
			wsf.Shutdown();
			Marshal.ReleaseComObject(wsf);
			wsf = null;
			//			// Cleanup (and Release?) the ICU memory mapping.
			//			SIL.FieldWorks.Common.Utils.Icu.Cleanup();
			m_DefParaCharsStyle = null;
			m_teSubKey = null;
			m_regData = null;

			base.Dispose(disposing);
		}
Ejemplo n.º 7
0
		public void Init()
		{
			CheckDisposed();

			if (m_fMainWindowOpened)
			{
				m_firstMainWnd = (TestTeMainWnd)m_testTeApp.MainWindows[0];
				// Set the view to the DraftView
				m_firstMainWnd.SelectScriptureDraftView();
				Application.DoEvents();

				m_firstDraftView = (TestTeDraftView)m_firstMainWnd.TheDraftView;
				m_firstDraftView.ActivateView();

				SelectionHelper helper = m_firstDraftView.SetInsertionPoint(0, 0, 0, 0, true);
				// helper.IhvoEndPara = -1;
				helper.SetSelection(m_firstDraftView, true, true);

				if (!m_firstMainWnd.Cache.DatabaseAccessor.IsTransactionOpen())
					m_firstMainWnd.Cache.DatabaseAccessor.BeginTrans();
				m_firstMainWnd.Cache.BeginUndoTask("Undo TeAppTest", "Redo TeAppTest");
			}
		}
Ejemplo n.º 8
0
        public void Init()
        {
            CheckDisposed();
            if (m_fMainWindowOpened)
            {
                m_firstMainWnd = (TestTeMainWnd)m_testTeApp.MainWindows[0];
                // reload the styles from the database (test may have inserted new styles!)
                m_firstMainWnd.Synchronize(new SyncInfo(SyncMsg.ksyncStyle, 0, 0));
                // Set the view to the DraftView
                m_firstMainWnd.SelectScriptureDraftView();
                Application.DoEvents();

                // insert book tests create filters - turn them off to prevent interaction
                // between tests
                m_firstMainWnd.TurnOffAllFilters();

                m_firstDraftView = (TestTeDraftView)m_firstMainWnd.TheDraftView;
                m_firstDraftView.ActivateView();

                SelectionHelper helper = m_firstDraftView.SetInsertionPoint(0, 0, 0, 0, true);
                // helper.IhvoEndPara = -1;
                helper.SetSelection(m_firstDraftView, true, true);

                // we don't want to open a transaction!
            }
        }
Ejemplo n.º 9
0
        public void Init()
        {
            CheckDisposed();

            Unpacker.UnPackParatextTestProjects();
            m_regData = Unpacker.PrepareRegistryForPTData();

            // TeApp derives from FwApp
            m_testTeApp = new TestTeApp(new string[] {
                "-c", m_sSvrName,			// ComputerName (aka the SQL server)
                "-proj", m_ProjName,		// ProjectName
                "-db", m_sDbName});			// DatabaseName

            m_fMainWindowOpened = m_testTeApp.OpenMainWindow();

            if (m_fMainWindowOpened)
            {
                m_firstMainWnd = (TestTeMainWnd)m_testTeApp.MainWindows[0];
                // reload the styles from the database (test may have inserted new styles!)
                m_firstMainWnd.Synchronize(new SyncInfo(SyncMsg.ksyncStyle, 0, 0));
                // Set the view to the DraftView
                m_firstMainWnd.SelectScriptureDraftView();
                Application.DoEvents();

                // insert book tests create filters - turn them off to prevent interaction
                // between tests
                m_firstMainWnd.TurnOffAllFilters();

                m_firstDraftView = (TestTeDraftView)m_firstMainWnd.TheDraftView;
                m_firstDraftView.ActivateView();

                SelectionHelper helper = m_firstDraftView.SetInsertionPoint(0, 0, 0, 0, true);
                // helper.IhvoEndPara = -1;
                helper.SetSelection(m_firstDraftView, true, true);

                // we don't want to open a transaction!
            }
        }