private void AddAllOccurrences(RespellUndoAction action, List <int> occurrences) { foreach (int hvo in occurrences) { action.AddOccurrence(hvo); } }
public void ApplyTwo() { RespellUndoAction action = new RespellUndoAction(Cache, "axx", "ayyy"); action.AddOccurrence(m_para2Occurrences[1]); action.AddOccurrence(m_para2Occurrences[2]); action.DoIt(); VerifyDoneStateApplyTwo(); Assert.IsTrue(m_fdoCache.CanUndo, "undo should be possible after respelling"); UndoResult ures; m_fdoCache.Undo(out ures); VerifyStartingState(); m_fdoCache.Redo(out ures); VerifyDoneStateApplyTwo(); }
public void PreserveCase() { Assert.AreEqual(6, m_axxOccurrences.Count); int ich2ndOcc = Cache.GetIntProperty(m_para1Occurrences[1], kflidBeginOffset); RespellUndoAction action = new RespellUndoAction(Cache, "axx", "ayyy"); action.AddOccurrence(m_para1Occurrences[0]); action.AddOccurrence(m_para1Occurrences[1]); action.SetupPreviews(tagPrecedingContext, tagPreview, tagAdjustedBegin, tagAdjustedEnd, tagEnabled, m_axxOccurrences); Assert.AreEqual("Axx", Cache.GetTsStringProperty(m_para1Occurrences[0], tagPrecedingContext).Text, "Old value at start without preserve case"); Assert.AreEqual("ayyy simplexx testxx withxx axx", Cache.GetTsStringProperty(m_para1Occurrences[1], tagPrecedingContext).Text, "Preceding context without preserve case has LC"); action.PreserveCase = true; action.UpdatePreviews(); Assert.AreEqual("Axx", Cache.GetTsStringProperty(m_para1Occurrences[0], tagPrecedingContext).Text, "Old value at start with preserver case"); Assert.AreEqual("Ayyy simplexx testxx withxx axx", Cache.GetTsStringProperty(m_para1Occurrences[1], tagPrecedingContext).Text, "Preceding context with preserve case has UC"); }
public void ApplyTwoAndCopyAnalyses() { MakeMonoAnalyses(); MakeMultiAnalyses(); // Makes one more analysis, which (having no human approval) should NOT get copied. m_wfAxx.AnalysesOC.Add(new WfiAnalysis()); m_cAnalyses++; RespellUndoAction action = new RespellUndoAction(Cache, "axx", "ayyy"); action.AddOccurrence(m_para2Occurrences[1]); action.AddOccurrence(m_para2Occurrences[2]); action.CopyAnalyses = true; action.DoIt(); VerifyDoneStateApplyTwoAndCopyAnalyses(); Assert.IsTrue(m_fdoCache.CanUndo, "undo should be possible after respelling"); UndoResult ures; m_fdoCache.Undo(out ures); VerifyStartingState(); m_fdoCache.Redo(out ures); VerifyDoneStateApplyTwoAndCopyAnalyses(); }
public void Previews() { Assert.AreEqual(6, m_axxOccurrences.Count); int ich2ndOcc = Cache.GetIntProperty(m_para2Occurrences[1], kflidBeginOffset); int ich3rdOcc = Cache.GetIntProperty(m_para2Occurrences[2], kflidBeginOffset); RespellUndoAction action = new RespellUndoAction(Cache, "axx", "ayyy"); action.AddOccurrence(m_para2Occurrences[1]); action.AddOccurrence(m_para2Occurrences[2]); action.SetupPreviews(tagPrecedingContext, tagPreview, tagAdjustedBegin, tagAdjustedEnd, tagEnabled, m_axxOccurrences); Assert.AreEqual(m_para1.Contents.Text, Cache.GetTsStringProperty(m_para1Occurrences[1], tagPrecedingContext).Text, "Unselected occurrences should have unchanged previews"); Assert.AreEqual(0, Cache.GetIntProperty(m_para1Occurrences[0], tagAdjustedBegin), "Unselected occurrences should still have adjustedBegin set"); Assert.AreEqual(3, Cache.GetIntProperty(m_para1Occurrences[0], tagAdjustedEnd), "Unselected occurrences should still have adjustedEnd set"); AssertTextProp(m_para1Occurrences[0], tagPrecedingContext, 0, RespellUndoAction.SecondaryTextProp, -1, "prop should not be set on unchanged occurrence"); Assert.AreEqual("axx sentencexx axx", Cache.GetTsStringProperty(m_para2Occurrences[1], tagPrecedingContext).Text, "First occurrence should have only part of para 2"); Assert.AreEqual(ich2ndOcc, Cache.GetIntProperty(m_para2Occurrences[1], tagAdjustedBegin), "First occurrence in para has no begin adjustment"); Assert.AreEqual(ich2ndOcc + 3, Cache.GetIntProperty(m_para2Occurrences[1], tagAdjustedEnd), "First occurrence in para has no end adjustment"); Assert.AreEqual("ayyy havingxx ayyy lotxx ofxx axx", Cache.GetTsStringProperty(m_para2Occurrences[1], tagPreview).Text, "First occurrence should have correct following context"); AssertTextProp(m_para2Occurrences[1], tagPrecedingContext, 0, RespellUndoAction.SecondaryTextProp, -1, "prop should not be set on unchanged occurrence- 2"); AssertTextProp(m_para2Occurrences[1], tagPrecedingContext, 5, RespellUndoAction.SecondaryTextProp, -1, "prop should not be set on other words"); AssertTextProp(m_para2Occurrences[1], tagPreview, "ayyy havingxx ".Length, RespellUndoAction.SecondaryTextProp, RespellUndoAction.SecondaryTextVal, "prop should be set on changed occurrence in Preview"); AssertTextProp(m_para2Occurrences[1], tagPreview, "ayyy havingxx ".Length - 1, RespellUndoAction.SecondaryTextProp, -1, "prop should not be set on other text in Preview"); AssertTextProp(m_para2Occurrences[1], tagPreview, "ayyy havingxx ".Length + 4, RespellUndoAction.SecondaryTextProp, -1, "prop should not be set on other text in Preview"); AssertTextProp(m_para2Occurrences[1], tagPreview, "ayyy havingxx ayyy lotxx ofxx a".Length, RespellUndoAction.SecondaryTextProp, -1, "prop should not be set on unchanged occurrence in Preview"); AssertTextProp(m_para2Occurrences[1], tagPreview, 0, (int)FwTextPropType.ktptBold, (int)FwTextToggleVal.kttvForceOn, "bold should be set at start of preview"); AssertTextProp(m_para2Occurrences[1], tagPreview, 4, (int)FwTextPropType.ktptBold, -1, "bold should not be set except on changed word"); // no longer action responsibility. Assert.IsTrue(Cache.GetIntProperty(m_para2Occurrences[1], tagEnabled) != 0); Assert.AreEqual("axx sentencexx ayyy havingxx axx", Cache.GetTsStringProperty(m_para2Occurrences[2], tagPrecedingContext).Text, "Second occurrence should have more of para 2 with first occurrence corrected"); Assert.AreEqual(ich3rdOcc + 1, Cache.GetIntProperty(m_para2Occurrences[2], tagAdjustedBegin), "Second occurrence in para has begin adjustment"); Assert.AreEqual(ich3rdOcc + 1 + 3, Cache.GetIntProperty(m_para2Occurrences[2], tagAdjustedEnd), "Second occurrence in para has end adjustment"); Assert.AreEqual("ayyy lotxx ofxx axx", Cache.GetTsStringProperty(m_para2Occurrences[2], tagPreview).Text, "Second occurrence should have correct following context"); AssertTextProp(m_para2Occurrences[2], tagPrecedingContext, 0, RespellUndoAction.SecondaryTextProp, -1, "prop should not be set on unchanged occurrence- 3"); AssertTextProp(m_para2Occurrences[2], tagPrecedingContext, "axx sentencexx a".Length, RespellUndoAction.SecondaryTextProp, RespellUndoAction.SecondaryTextVal, "prop should be set on changed occurrence in preceding context"); AssertTextProp(m_para2Occurrences[2], tagPrecedingContext, "axx sentencexx".Length, RespellUndoAction.SecondaryTextProp, -1, "prop should not be set on other text in preceding context"); AssertTextProp(m_para2Occurrences[2], tagPrecedingContext, "axx sentencexx ayyy".Length, RespellUndoAction.SecondaryTextProp, -1, "prop should not be set on other text in preceding context - 2"); AssertTextProp(m_para2Occurrences[2], tagPreview, 0, (int)FwTextPropType.ktptBold, (int)FwTextToggleVal.kttvForceOn, "bold should be set at start of preview - 2"); AssertTextProp(m_para2Occurrences[2], tagPreview, 4, (int)FwTextPropType.ktptBold, -1, "bold should not be set except on changed word - 2"); Assert.AreEqual("axx sentencexx ayyy havingxx ayyy lotxx ofxx axx", Cache.GetTsStringProperty(m_para2Occurrences[3], tagPrecedingContext).Text, "Unselected occurrences should have full-length preview"); Assert.AreEqual("axx sentencexx axx havingxx axx lotxx ofxx ".Length + 2, Cache.GetIntProperty(m_para2Occurrences[3], tagAdjustedBegin), "Unselected occurrences after changed ones should have adjusted begin"); Assert.AreEqual("axx sentencexx axx havingxx axx lotxx ofxx ".Length + 2 + 3, Cache.GetIntProperty(m_para2Occurrences[3], tagAdjustedEnd), "Unselected occurrences after changed ones should have adjustedEnd set"); //----------------------------------------------------------------------------------- // This is rather a 'greedy' test, but tests on the real database are expensive. // Now we want to try changing the status of an occurrence to see whether it updates correctly. action.UpdatePreview(m_para2Occurrences[0], true); Assert.AreEqual("axx", Cache.GetTsStringProperty(m_para2Occurrences[0], tagPrecedingContext).Text, "Newly selected item at start of sentence has null preceding context"); Assert.AreEqual("ayyy sentencexx ayyy havingxx ayyy lotxx ofxx axx", Cache.GetTsStringProperty(m_para2Occurrences[0], tagPreview).Text, "After select at start occ(0) should have correct preview"); AssertTextProp(m_para2Occurrences[0], tagPreview, 0, (int)FwTextPropType.ktptBold, (int)FwTextToggleVal.kttvForceOn, "After select at start occ(0) bold should be set at start of preview"); AssertTextProp(m_para2Occurrences[0], tagPreview, 4, (int)FwTextPropType.ktptBold, -1, "After select at start occ(0) bold should not be set except on changed word"); Assert.AreEqual("ayyy sentencexx axx", Cache.GetTsStringProperty(m_para2Occurrences[1], tagPrecedingContext).Text, "After select at start occ(1) should have new preceding context."); Assert.AreEqual(ich2ndOcc + 1, Cache.GetIntProperty(m_para2Occurrences[1], tagAdjustedBegin), "After select at start occ(1) should have changed begin adjustment"); Assert.AreEqual(ich2ndOcc + 4, Cache.GetIntProperty(m_para2Occurrences[1], tagAdjustedEnd), "After select at start occ(1) should have changed end adjustment"); Assert.AreEqual("ayyy havingxx ayyy lotxx ofxx axx", Cache.GetTsStringProperty(m_para2Occurrences[1], tagPreview).Text, "After select at start occ(1) should have correct following context"); AssertTextProp(m_para2Occurrences[1], tagPrecedingContext, 0, RespellUndoAction.SecondaryTextProp, RespellUndoAction.SecondaryTextVal, "after select at start prop should be set on initial (new) occurrence"); AssertTextProp(m_para2Occurrences[1], tagPrecedingContext, 5, RespellUndoAction.SecondaryTextProp, -1, "after select at start prop should not be set on other words"); AssertTextProp(m_para2Occurrences[1], tagPreview, "ayyy havingxx ".Length, RespellUndoAction.SecondaryTextProp, RespellUndoAction.SecondaryTextVal, "after select at start prop should be set on changed occurrence in Preview"); AssertTextProp(m_para2Occurrences[1], tagPreview, "ayyy havingxx ".Length - 1, RespellUndoAction.SecondaryTextProp, -1, "after select at start prop should not be set on other text in Preview"); // no longer action responsibilty. Assert.IsTrue(Cache.GetIntProperty(m_para2Occurrences[1], tagEnabled) != 0); Assert.AreEqual(ich3rdOcc + 2, Cache.GetIntProperty(m_para2Occurrences[2], tagAdjustedBegin), "After one change occ(2) should have appropriate begin adjustment"); Assert.AreEqual(ich3rdOcc + 2 + 3, Cache.GetIntProperty(m_para2Occurrences[2], tagAdjustedEnd), "After one change occ(2) should have appropriate end adjustment"); //------------------------------------------------------------------------ // And now try turning one off. action.UpdatePreview(m_para2Occurrences[1], false); Assert.AreEqual("ayyy sentencexx axx havingxx ayyy lotxx ofxx axx", Cache.GetTsStringProperty(m_para2Occurrences[1], tagPrecedingContext).Text, "Turned-off occurrence should have full-length preview"); Assert.AreEqual("ayyy sentencexx ".Length, Cache.GetIntProperty(m_para2Occurrences[1], tagAdjustedBegin), "Turned-off occurrence should still have adjusted begin"); Assert.AreEqual("ayyy sentencexx axx havingxx axx", Cache.GetTsStringProperty(m_para2Occurrences[2], tagPrecedingContext).Text, "After two changes occ(2) should have appropriate preceding context"); Assert.AreEqual(ich3rdOcc + 1, Cache.GetIntProperty(m_para2Occurrences[2], tagAdjustedBegin), "After two changes occ(2) should have appropriate begin adjustment"); Assert.AreEqual(ich3rdOcc + 1 + 3, Cache.GetIntProperty(m_para2Occurrences[2], tagAdjustedEnd), "After two changes occ(2) should have appropriate end adjustment"); }