public ITsString WsLabel(FdoCache cache) { if (m_tssWsLabel == null) { ITsPropsFactory tpf = TsPropsFactoryClass.Create(); ITsTextProps ttp = tpf.MakeProps("Language Code", cache.DefaultUserWs, 0); ITsStrFactory tsf = TsStrFactoryClass.Create(); string label = null; if (m_ws == LangProject.kwsFirstAnal) { label = ITextStrings.ksBstAn; } else if (m_ws == LangProject.kwsVernInParagraph) { label = ITextStrings.ksBaselineAbbr; } else { LgWritingSystem wsAnalysis = new LgWritingSystem(cache, m_ws); label = wsAnalysis.Abbr.UserDefaultWritingSystem; } m_tssWsLabel = tsf.MakeStringWithPropsRgch(label, label.Length, ttp); } return(m_tssWsLabel); }
public void DisableCompareBtn() { // Add Revelation, archive it and then remove it. int hvoTitle; Assert.IsNull(ScrBook.FindBookByID(m_cache, 66), "Revelation should not be in the database. Restore the clean version of TestLangProj."); IScrBook revelation = ScrBook.CreateNewScrBook(66, m_scr, out hvoTitle); ITsPropsFactory propFact = TsPropsFactoryClass.Create(); ITsTextProps ttp = propFact.MakeProps(ScrStyleNames.NormalParagraph, m_cache.DefaultVernWs, 0); ScrSection.CreateScrSection(revelation, 0, "Text for section", ttp, false); AddArchive("Revelation Archive", new List <int>(new int[] { revelation.Hvo })); m_scr.ScriptureBooksOS.Remove(m_scr.ScriptureBooksOS[3]); DummySavedVersionsDialog dlg = new DummySavedVersionsDialog(m_cache); TreeView tree = dlg.ArchiveTree; // Select the archive node that was just added. tree.SelectedNode = tree.Nodes[0]; dlg.SimulateSelectEvent(); // Check to make sure the Compare to Current Version button is disabled Assert.IsFalse(dlg.ComparetoCurrentVersionBtn.Enabled, "The Compare to Current Version button should be disabled"); // Select a book node. tree.SelectedNode = tree.Nodes[0].Nodes[0]; dlg.SimulateSelectEvent(); // Check to make sure the Diff button is still disabled if we select Philemon // after it is removed from the DB. Assert.IsFalse(dlg.ComparetoCurrentVersionBtn.Enabled, "The Compare to Current Version button should still"); }
public void ConvertChapterVerseNumbersTest_EmptyChapterNumber() { CheckDisposed(); // Add paragraph with empty chapter number run. StTxtPara para = m_scrInMemoryCache.AddParaToMockedSectionContent(m_exodus.SectionsOS[0].Hvo, ScrStyleNames.ChapterNumber); ITsPropsFactory propFact = TsPropsFactoryClass.Create(); ITsTextProps ttpChapterNumber = propFact.MakeProps(ScrStyleNames.ChapterNumber, (int)InMemoryFdoCache.s_wsHvos.Fr, 0); ITsStrBldr bldr = para.Contents.UnderlyingTsString.GetBldr(); bldr.SetProperties(0, 0, ttpChapterNumber); para.Contents.UnderlyingTsString = bldr.GetString(); ScriptureProperties dlg = new ScriptureProperties(Cache, m_stylesheet, null, true); char bengaliZero = '\u09e6'; char bengaliNine = (char)((int)bengaliZero + 9); // test arabic->bengali when there is a paragraph with an empty chapter number run. // It should complete without crashing. ScriptDigitConversionTest(bengaliZero, bengaliNine, dlg); // test bengali->arabic ScriptDigitConversionTest('0', '9', dlg); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Gets the text from clipboard. /// </summary> /// <returns></returns> /// ------------------------------------------------------------------------------------ public ITsString CallGetTextFromClipboard() { CheckDisposed(); ITsPropsFactory propsFact = TsPropsFactoryClass.Create(); return(base.GetTextFromClipboard(null, false, propsFact.MakeProps("bla", 0, 0))); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Adds a run of text to the specified paragraph /// </summary> /// <param name="para"></param> /// <param name="runText"></param> /// <param name="ws"></param> /// ------------------------------------------------------------------------------------ public void AddRunToMockedPara(IStTxtPara para, string runText, int ws) { ITsPropsFactory propFact = TsPropsFactoryClass.Create(); ITsTextProps runStyle = propFact.MakeProps(null, ws, 0); ITsStrBldr bldr = para.Contents.GetBldr(); bldr.Replace(bldr.Length, bldr.Length, runText, runStyle); para.Contents = bldr.GetString(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Adds a run of text to the specified translation /// </summary> /// <param name="trans">The translation where the run of text will be appended.</param> /// <param name="btWS">The writing system of the back translation</param> /// <param name="runWS">The writing system of the run</param> /// <param name="runText">The run text.</param> /// <param name="runStyleName">Name of the run style.</param> /// ------------------------------------------------------------------------------------ protected void AddRunToMockedTrans(ICmTranslation trans, int btWS, int runWS, string runText, string runStyleName) { ITsPropsFactory propFact = TsPropsFactoryClass.Create(); ITsTextProps runProps = propFact.MakeProps(runStyleName, runWS, 0); ITsStrBldr bldr = trans.Translation.get_String(btWS).GetBldr(); bldr.Replace(bldr.Length, bldr.Length, runText, runProps); trans.Translation.set_String(btWS, bldr.GetString()); }
public void ConstructBasedOnStyleAndEffects() { IStStyle mainTitleStyle = AddTestStyle("Title Main", ContextValues.Title, StructureValues.Body, FunctionValues.Prose, false, Cache.LangProject.StylesOC); var props = TsPropsFactoryClass.Create().MakeProps("rubbish", Cache.DefaultAnalWs, 0); var sut = new BaseStyleInfo(mainTitleStyle, props); Assert.That(sut.Cache, Is.EqualTo(Cache)); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Adds a run of text to the specified paragraph /// </summary> /// <param name="hvoPara">HVO of the paragraph</param> /// <param name="runText">Text of the run to add</param> /// <param name="ws">writing system ID</param> /// ------------------------------------------------------------------------------------ public void AddRunToMockedPara(int hvoPara, string runText, int ws) { var propFact = TsPropsFactoryClass.Create(); var runStyle = propFact.MakeProps(null, ws, 0); ITsString contents = m_cache.get_StringProp(hvoPara, SimpleRootsiteTestsConstants.kflidParaContents); var bldr = contents.GetBldr(); bldr.Replace(bldr.Length, bldr.Length, runText, runStyle); m_cache.SetString(hvoPara, SimpleRootsiteTestsConstants.kflidParaContents, bldr.GetString()); }
public void TsStringsSame() { ITsStrBldr strBldr = TsStrBldrClass.Create(); strBldr.Replace(0, 0, "Test", TsPropsFactoryClass.Create().MakeProps(null, 5, 0)); string s; Assert.IsTrue(TsStringHelper.TsStringsAreEqual(strBldr.GetString(), strBldr.GetString(), out s)); }
public static ITsString WsLabel(FdoCache cache, int ws) { ITsPropsFactory tpf = TsPropsFactoryClass.Create(); ITsTextProps ttp = tpf.MakeProps("Language Code", cache.DefaultUserWs, 0); ILgWritingSystem wsObj = LgWritingSystem.CreateFromDBObject(cache, ws); ITsStrFactory tsf = TsStrFactoryClass.Create(); string sAbbr = wsObj.Abbr.UserDefaultWritingSystem; return(tsf.MakeStringWithPropsRgch(sAbbr, sAbbr.Length, ttp)); }
public void NullStringDiffersFromTsString() { ITsStrBldr strBldr = TsStrBldrClass.Create(); ITsPropsFactory propsFact = TsPropsFactoryClass.Create(); strBldr.Replace(0, 0, "Test", propsFact.MakeProps(null, 5, 0)); string s; Assert.IsFalse(TsStringHelper.TsStringsAreEqual(strBldr.GetString(), null, out s)); Assert.AreEqual("TsStrings differ." + Environment.NewLine + "\tExpected <Test>, but was <null>.", s, "Got incorrect explanation of difference"); }
public void UserPromptChangeWSWhenPasting() { CheckDisposed(); // Set up section head with an empty paragraph IScrSection section = m_inMemoryCache.AddSectionToMockedBook(m_book.Hvo); StTxtPara para = m_inMemoryCache.AddSectionHeadParaToSection(section.Hvo, "", ScrStyleNames.SectionHead); section.AdjustReferences(); Options.ShowEmptyParagraphPromptsSetting = true; DynamicMock rootb = new DynamicMock(typeof(IVwRootBox)); rootb.SetupResult("IsCompositionInProgress", false); DynamicMock vwsel = new DynamicMock(typeof(IVwSelection)); IVwRootBox mockRootbox = (IVwRootBox)rootb.MockInstance; vwsel.SetupResult("RootBox", mockRootbox); vwsel.SetupResult("CLevels", 4, typeof(bool)); vwsel.Ignore("AllTextSelInfo"); #if DEBUG vwsel.SetupResult("IsValid", true); #endif DummyTeStVc stVc = new DummyTeStVc(m_inMemoryCache.Cache, m_inMemoryCache.Cache.DefaultAnalWs, mockRootbox); // set up the text to paste - will be TE2ST with vernacular WS int ws = m_inMemoryCache.Cache.DefaultVernWs; ITsPropsFactory propFact = TsPropsFactoryClass.Create(); ITsTextProps ttp = propFact.MakeProps(null, ws, 0); ITsStrBldr bldr = TsStrBldrClass.Create(); bldr.ReplaceRgch(0, 0, "TEST", 4, ttp); ttp = propFact.MakeProps(ScrStyleNames.VerseNumber, ws, 0); bldr.ReplaceRgch(2, 2, "2", 1, ttp); ITsString tssVal = bldr.GetString(); // Now simulate the user pasting over the user prompt stVc.UpdateProp((IVwSelection)vwsel.MockInstance, para.Hvo, SimpleRootSite.kTagUserPrompt, 0, tssVal); // verify that the text is in the paragraph, that there is no longer a user // prompt, and that the ws changed but the character formatting survives. bldr = tssVal.GetBldr(); bldr.SetIntPropValues(0, 5, (int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, m_inMemoryCache.Cache.DefaultAnalWs); AssertEx.AreTsStringsEqual(bldr.GetString(), para.Contents.UnderlyingTsString); m_vwenvMock.Verify(); }
public void PasteParagraphsWithSameStyle() { // Add a title to the root object int hvoTitle = m_cache.MakeNewObject(SimpleRootsiteTestsConstants.kclsidStText, m_hvoRoot, SimpleRootsiteTestsConstants.kflidDocTitle, -2); int hvoTitlePara1 = m_cache.MakeNewObject(SimpleRootsiteTestsConstants.kclsidStTxtPara, hvoTitle, SimpleRootsiteTestsConstants.kflidTextParas, 0); ITsStrFactory tsStrFactory = TsStrFactoryClass.Create(); m_cache.CacheStringProp(hvoTitlePara1, SimpleRootsiteTestsConstants.kflidParaContents, tsStrFactory.MakeString("The First Book of the Law given by Moses", m_wsEng)); ITsPropsFactory fact = TsPropsFactoryClass.Create(); m_cache.SetUnknown(hvoTitlePara1, SimpleRootsiteTestsConstants.kflidParaProperties, fact.MakeProps("Title", m_wsEng, 0)); int hvoTitlePara2 = m_cache.MakeNewObject(SimpleRootsiteTestsConstants.kclsidStTxtPara, hvoTitle, SimpleRootsiteTestsConstants.kflidTextParas, 1); string secondParaContents = "and Aaron"; m_cache.CacheStringProp(hvoTitlePara2, SimpleRootsiteTestsConstants.kflidParaContents, tsStrFactory.MakeString(secondParaContents, m_wsEng)); m_cache.SetUnknown(hvoTitlePara2, SimpleRootsiteTestsConstants.kflidParaProperties, fact.MakeProps("Title", m_wsEng, 0)); ShowForm(SimpleViewVc.DisplayType.kTitle | SimpleViewVc.DisplayType.kUseParaProperties | SimpleViewVc.DisplayType.kOnlyDisplayContentsOnce); // Make a selection from the top of the view to the bottom. IVwSelection sel0 = m_basicView.RootBox.MakeSimpleSel(true, false, false, false); IVwSelection sel1 = m_basicView.RootBox.MakeSimpleSel(false, false, false, false); m_basicView.RootBox.MakeRangeSelection(sel0, sel1, true); // Copy the selection and then paste it at the start of the view. Assert.IsTrue(m_basicView.EditingHelper.CopySelection()); // Install a simple selection at the start of the view. m_basicView.RootBox.MakeSimpleSel(true, true, false, true); // This is a legal paste. m_basicView.EditingHelper.PasteClipboard(); // We expect the contents to change. Assert.AreEqual(4, m_cache.get_VecSize(hvoTitle, SimpleRootsiteTestsConstants.kflidTextParas)); Assert.AreEqual(hvoTitlePara2 + 1, m_cache.get_VecItem(hvoTitle, SimpleRootsiteTestsConstants.kflidTextParas, 0)); Assert.AreEqual(hvoTitlePara2 + 2, m_cache.get_VecItem(hvoTitle, SimpleRootsiteTestsConstants.kflidTextParas, 1)); Assert.AreEqual(hvoTitlePara1, m_cache.get_VecItem(hvoTitle, SimpleRootsiteTestsConstants.kflidTextParas, 2)); Assert.AreEqual(hvoTitlePara2, m_cache.get_VecItem(hvoTitle, SimpleRootsiteTestsConstants.kflidTextParas, 3)); Assert.IsNotNull(m_basicView.RequestedSelectionAtEndOfUow); // WANTTESTPORT: (Common) FWR-1649 Check properties of RequestedSelectionAtEndOfUow }
public void FindOrCreateStyle_HandlesConflictingUserStyles() { var userStyle = Cache.ServiceLocator.GetInstance <IStStyleFactory>().Create(); Cache.LangProject.StylesOC.Add(userStyle); const string styleName = "StyleName"; userStyle.Name = styleName; userStyle.Type = StyleType.kstParagraph; userStyle.Context = ContextValues.General; userStyle.Structure = StructureValues.Undefined; userStyle.Function = FunctionValues.Prose; userStyle.IsBuiltIn = false; userStyle.IsModified = true; userStyle.NextRA = userStyle; var propsFactory = TsPropsFactoryClass.Create(); var props1 = propsFactory.MakeProps("mystyle", Cache.DefaultAnalWs, 0); userStyle.Rules = props1; var userGuid = userStyle.Guid; var factoryGuid = Guid.NewGuid(); var sut = new TestAccessorForFindOrCreateStyle(Cache); sut.FindOrCreateStyle(styleName, StyleType.kstCharacter, ContextValues.General, StructureValues.Undefined, FunctionValues.Prose, factoryGuid); var userStyle1 = Cache.ServiceLocator.GetInstance <IStStyleRepository>().GetObject(userGuid); // will throw if not found Assert.That(userStyle1, Is.SameAs(userStyle)); Assert.That(userStyle1.IsValidObject, "should still be valid"); Assert.That(userStyle1.Name, Is.Not.EqualTo(styleName)); Assert.That(userStyle1.IsBuiltIn, Is.False, "User style built in"); Assert.That(userStyle1.IsModified, Is.True, "user style modified"); Assert.That(userStyle1.NextRA, Is.EqualTo(userStyle1), "should have kept the self-referential next style"); Assert.That(userStyle1.Rules, Is.EqualTo(props1)); Assert.That(userStyle1.Guid, Is.EqualTo(userGuid), "Should have maintained its GUID"); var factoryStyle = Cache.ServiceLocator.GetInstance <IStStyleRepository>().GetObject(factoryGuid); // will throw if not found Assert.That(factoryStyle.Name, Is.EqualTo(styleName)); Assert.That(factoryStyle.IsBuiltIn, Is.True, "factory style built in"); Assert.That(factoryStyle.IsModified, Is.False, "factory style modified"); Assert.That(factoryStyle.Owner, Is.Not.Null, "factory style owner"); Assert.That(factoryStyle.Guid, Is.EqualTo(factoryGuid), "Should have the factory-specifiied GUID"); }
public void TsStringsDifferByText() { ITsStrBldr strBldr = TsStrBldrClass.Create(); ITsPropsFactory propsFact = TsPropsFactoryClass.Create(); ITsTextProps props = propsFact.MakeProps(null, 5, 0); strBldr.Replace(0, 0, "Test", props); ITsString tssExpected = strBldr.GetString(); strBldr.Replace(0, 4, "Crud", props); string s; Assert.IsFalse(TsStringHelper.TsStringsAreEqual(tssExpected, strBldr.GetString(), out s)); Assert.AreEqual( "TsString text differs." + Environment.NewLine + "\tExpected <Test>, but was <Crud>.", s, "Got incorrect explanation of difference"); }
public void TsStringsDifferByRunCount() { ITsStrBldr strBldr = TsStrBldrClass.Create(); ITsPropsFactory propsFact = TsPropsFactoryClass.Create(); strBldr.Replace(0, 0, "Bad Test", propsFact.MakeProps(null, 5, 0)); ITsString tssExpected = strBldr.GetString(); strBldr.Replace(0, 3, "Bad", propsFact.MakeProps("Bogus", 5, 0)); string s; Assert.IsFalse(TsStringHelper.TsStringsAreEqual(tssExpected, strBldr.GetString(), out s)); Assert.AreEqual( string.Format("TsStrings have different number of runs.{0}\tExpected 1 runs, but was 2 runs.{0}\t" + "Expected run 1:<Bad Test>, but was:<Bad>{0}\t" + "Expected run 2:<>, but was:< Test>", Environment.NewLine), s, "Got incorrect explanation of difference"); }
public void PasteParagraphsWithDifferentStyles() { // Add a title to the root object int hvoTitle = m_cache.MakeNewObject(kclsidStText, m_hvoRoot, kflidDocTitle, -2); int hvoTitlePara1 = m_cache.MakeNewObject(kclsidStTxtPara, hvoTitle, kflidTextParas, 0); ITsStrFactory tsStrFactory = TsStrFactoryClass.Create(); m_cache.CacheStringProp(hvoTitlePara1, kflidParaContents, tsStrFactory.MakeString("The First Book of the Law given by Moses", m_wsEng)); ITsPropsFactory fact = TsPropsFactoryClass.Create(); m_cache.SetUnknown(hvoTitlePara1, kflidParaProperties, fact.MakeProps("Title", m_wsEng, 0)); int hvoTitlePara2 = m_cache.MakeNewObject(kclsidStTxtPara, hvoTitle, kflidTextParas, 1); string secondParaContents = "and Aaron"; m_cache.CacheStringProp(hvoTitlePara2, kflidParaContents, tsStrFactory.MakeString(secondParaContents, m_wsEng)); m_cache.SetUnknown(hvoTitlePara2, kflidParaProperties, fact.MakeProps("Conclusion", m_wsEng, 0)); ShowForm(SimpleViewVc.DisplayType.kTitle | SimpleViewVc.DisplayType.kUseParaProperties | SimpleViewVc.DisplayType.kOnlyDisplayContentsOnce); // Make a selection from the top of the view to the bottom. IVwSelection sel0 = m_basicView.RootBox.MakeSimpleSel(true, false, false, false); IVwSelection sel1 = m_basicView.RootBox.MakeSimpleSel(false, false, false, false); m_basicView.RootBox.MakeRangeSelection(sel0, sel1, true); // Copy the selection and then paste it at the start of the view. Assert.IsTrue(m_basicView.EditingHelper.CopySelection()); // Install a simple selection at the start of the view. m_basicView.RootBox.MakeSimpleSel(true, true, false, true); // This is an illegal paste, so the paste will fail. m_basicView.EditingHelper.PasteClipboard(); // We expect the contents to remain unchanged. Assert.AreEqual(2, m_cache.get_VecSize(hvoTitle, kflidTextParas)); Assert.IsNull(m_basicView.RequestedSelectionAtEndOfUow); }
/// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// ------------------------------------------------------------------------------------ protected override void OnFormClosing(FormClosingEventArgs e) { base.OnFormClosing(e); if (DialogResult == DialogResult.Cancel) { return; } FdoOwningSequence <IStPara> oldParas = m_error.ResolutionOA.ParagraphsOS; ITsString[] newParas = m_text.Paragraphs; // If there are fewer paragraphs in the new comment, then remove from the end // of the old comment the number paragraphs that is the difference between // the number of old and new paragraphs. if (newParas.Length < oldParas.Count) { for (int i = oldParas.Count - 1; i >= newParas.Length; i--) { oldParas.RemoveAt(i); } } for (int i = 0; i < newParas.Length; i++) { if (i < oldParas.Count) { // Reuse the old paragraph. ((StTxtPara)oldParas[i]).Contents.UnderlyingTsString = newParas[i]; } else { // Create a new paragraph StTxtPara newStPara = new StTxtPara(); oldParas.Append(newStPara); newStPara.Contents.UnderlyingTsString = newParas[i]; ITsPropsFactory tspf = TsPropsFactoryClass.Create(); newStPara.StyleRules = tspf.MakeProps(ScrStyleNames.Remark, m_text.CurrentWs, 0); } } }
private int SetupInitialText(string text) { int cParas = m_cache.get_VecSize(m_hvoRoot, SimpleRootsiteTestsConstants.kflidTextParas); ITsStrFactory tsStrFactory = TsStrFactoryClass.Create(); int hvoPara = m_cache.MakeNewObject(SimpleRootsiteTestsConstants.kclsidStTxtPara, m_hvoRoot, SimpleRootsiteTestsConstants.kflidTextParas, cParas); m_cache.CacheStringProp(hvoPara, SimpleRootsiteTestsConstants.kflidParaContents, tsStrFactory.MakeString(string.Empty, m_wsFrn)); var propFact = TsPropsFactoryClass.Create(); var runStyle = propFact.MakeProps(null, m_wsFrn, 0); ITsString contents = m_cache.get_StringProp(hvoPara, SimpleRootsiteTestsConstants.kflidParaContents); var bldr = contents.GetBldr(); bldr.Replace(bldr.Length, bldr.Length, text, runStyle); m_cache.SetString(hvoPara, SimpleRootsiteTestsConstants.kflidParaContents, bldr.GetString()); ShowThisForm(); m_basicView.Show(); m_basicView.RefreshDisplay(); m_basicView.Focus(); return(hvoPara); }
private ITsTextProps SetNumberTextProperties(int wsEng, XmlNode listDelimitNode) { ITsTextProps ttpNum; ITsPropsBldr tpb = TsPropsFactoryClass.Create().GetPropsBldr(); // TODO: find more appropriate writing system? tpb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, wsEng); string style = XmlUtils.GetOptionalAttributeValue(listDelimitNode, "numstyle", null); ApplyStyleToTsPropertyBuilder(tpb, style); string font = XmlUtils.GetOptionalAttributeValue(listDelimitNode, "numfont", null); if (!String.IsNullOrEmpty(font)) { tpb.SetStrPropValue((int)FwTextPropType.ktptFontFamily, font); } m_viewConstructor.MarkSource(tpb, listDelimitNode); ttpNum = tpb.GetTextProps(); return(ttpNum); }
/// <summary> /// Add to the current display (a paragraph should be open) a label followed by colon, in the standard style, /// that identifies a particular writing system from the current list. /// </summary> /// <param name="vwenv"></param> /// <param name="iws"></param> public void AddWsLabel(IVwEnv vwenv, int iws) { CheckDisposed(); if (m_tssColon == null) { ITsStrFactory tsf = TsStrFactoryClass.Create(); m_tssColon = tsf.MakeString(": ", m_lp.Cache.DefaultUserWs); } if (m_ttpLabelStyle == null) { ITsPropsFactory tpf = TsPropsFactoryClass.Create(); // Get a ttp invoking the style "Language Code" style for the writing system // which corresponds to the user's environment. m_ttpLabelStyle = tpf.MakeProps("Language Code", m_lp.Cache.DefaultUserWs, 0); } vwenv.Props = m_ttpLabelStyle; vwenv.OpenSpan(); vwenv.AddString(AnalysisWsLabels[iws]); vwenv.AddString(m_tssColon); vwenv.CloseSpan(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Verifies that the given run of the given ITsString contains the specified text and /// properties. /// </summary> /// <param name="tss">The ITsString to test</param> /// <param name="iRun">Zero-based run index to check</param> /// <param name="expectedText">Expected contents of run</param> /// <param name="expectedCharStyle">Expected character style name, or null if expecting /// default paragraph character props</param> /// <param name="expectedWs">Expected writing system for the run</param> /// <param name="fExpectNFD">Pass <c>true</c> to make sure that TSS is in normal /// form decomposed (which it probably should be if it has been saved to the DB); pass /// <c>false</c> if the string is not expected to be decomposed.</param> /// ------------------------------------------------------------------------------------ public static void RunIsCorrect(ITsString tss, int iRun, string expectedText, string expectedCharStyle, int expectedWs, bool fExpectNFD) { Assert.AreEqual(fExpectNFD, tss.get_IsNormalizedForm(FwNormalizationMode.knmNFD)); // If both strings are null then they're equal and there's nothing else to compare. if (expectedText == null) { Assert.IsNull(tss.Text); return; } // If both strings are 0-length, then they're equal; otherwise compare them. if (expectedText.Length == 0) { Assert.AreEqual(0, tss.Length); } else { // compare strings // apparently IndexOf performs Unicode normalization. if (expectedText.IndexOf(tss.get_RunText(iRun), StringComparison.Ordinal) != 0) { Assert.Fail("Run " + iRun + " text differs. Expected <" + expectedText + "> but was <" + tss.get_RunText(iRun) + ">"); } } ITsTextProps ttp1 = TsPropsFactoryClass.Create().MakeProps(expectedCharStyle, expectedWs, 0); ITsTextProps ttp2 = tss.get_Properties(iRun); string sWhy; if (!TsTextPropsHelper.PropsAreEqual(ttp1, ttp2, out sWhy)) { Assert.Fail(sWhy); } }
public void ConvertChapterVerseNumbersTest_EmptyChapterNumber() { // Add paragraph with empty chapter number run. IStTxtPara para = AddParaToMockedSectionContent(m_exodus.SectionsOS[0], ScrStyleNames.ChapterNumber); ITsPropsFactory propFact = TsPropsFactoryClass.Create(); ITsTextProps ttpChapterNumber = propFact.MakeProps(ScrStyleNames.ChapterNumber, Cache.ServiceLocator.WritingSystemManager.GetWsFromStr("fr"), 0); ITsStrBldr bldr = para.Contents.GetBldr(); bldr.SetProperties(0, 0, ttpChapterNumber); para.Contents = bldr.GetString(); using (ScriptureProperties dlg = new ScriptureProperties(Cache, m_stylesheet, null, true, null)) { char bengaliZero = '\u09e6'; char bengaliNine = (char)((int)bengaliZero + 9); // test arabic->bengali when there is a paragraph with an empty chapter number run. // It should complete without crashing. ScriptDigitConversionTest(bengaliZero, bengaliNine, dlg); // test bengali->arabic ScriptDigitConversionTest('0', '9', dlg); } }
public void UpdateUserPrompt_NormalBT_Pasting() { // Set up section head with an empty paragraph IScrSection section = AddSectionToMockedBook(m_book); IStTxtPara para = AddSectionHeadParaToSection(section, "", ScrStyleNames.SectionHead); int defAnalWs = Cache.DefaultAnalWs; IVwRootBox rootb; IVwSelection vwsel; IVwRootSite rootsite; SetUpResultsForUpdateUserPromptTests(5, "TE2ST", out rootb, out vwsel, out rootsite); DummyTeStVc stVc = new DummyTeStVc(Cache, defAnalWs, rootb); // set up the text to paste - will be TE2ST with vernacular WS ITsPropsFactory propFact = TsPropsFactoryClass.Create(); ITsTextProps ttp = propFact.MakeProps(null, defAnalWs, 0); ITsStrBldr bldr = TsStrBldrClass.Create(); bldr.ReplaceRgch(0, 0, "TEST", 4, ttp); ttp = propFact.MakeProps(ScrStyleNames.VerseNumber, defAnalWs, 0); bldr.ReplaceRgch(2, 2, "2", 1, ttp); ITsString tssPasted = bldr.GetString(); // Now simulate the user pasting over the user prompt ICmTranslation bt = para.GetOrCreateBT(); stVc.UpdateProp(vwsel, bt.Hvo, SimpleRootSite.kTagUserPrompt, CmTranslationTags.kflidTranslation, tssPasted); // Verify that the text is in the paragraph and that the character formatting survives. AssertEx.AreTsStringsEqual(tssPasted, bt.Translation.get_String(defAnalWs)); m_vwenvMock.VerifyAllExpectations(); VerifyArgsSentToRequestSelectionAtEndOfUow(rootsite, rootb, defAnalWs, 5, CmTranslationTags.kflidTranslation, "TE2ST"); }
public void FindOrCreateStyle_DoesNotCopyInvalidNextStyle() { var style1 = Cache.ServiceLocator.GetInstance <IStStyleFactory>().Create(); Cache.LangProject.StylesOC.Add(style1); var style2 = Cache.ServiceLocator.GetInstance <IStStyleFactory>().Create(); Cache.LangProject.StylesOC.Add(style2); style1.Name = "testA"; style1.Type = StyleType.kstParagraph; style1.Context = ContextValues.Text; style1.Structure = StructureValues.Body; style1.Function = FunctionValues.Prose; style1.IsBuiltIn = true; style1.IsModified = true; style1.NextRA = style1; var propsFactory = TsPropsFactoryClass.Create(); var props1 = propsFactory.MakeProps("mystyle", Cache.DefaultAnalWs, 0); style1.Rules = props1; style1.UserLevel = 5; style2.Name = "testB"; style2.Type = StyleType.kstParagraph; style2.Context = ContextValues.Text; style2.Structure = StructureValues.Body; style2.Function = FunctionValues.Prose; style2.IsBuiltIn = true; style2.IsModified = true; style2.NextRA = style1; style2.BasedOnRA = style1; // Now that we've created testB, change the category of testA. This creates a state that the system tries to prevent. // The 'next' style of a body style should not be a heading style. We catch this when setting NextRA, but not // when changing the Structure, since that normally never happens. style1.Structure = StructureValues.Heading; var factoryGuid1 = Guid.NewGuid(); var factoryGuid2 = Guid.NewGuid(); var sut = new TestAccessorForFindOrCreateStyle(Cache); sut.FindOrCreateStyle("testA", StyleType.kstParagraph, ContextValues.Text, StructureValues.Heading, FunctionValues.Prose, factoryGuid1); sut.FindOrCreateStyle("testB", StyleType.kstParagraph, ContextValues.Text, StructureValues.Body, FunctionValues.Prose, factoryGuid2); Assert.That(style1.IsValidObject, Is.False, "should have deleted original style in course of changing guid"); IStStyle newStyle1; Assert.That(Cache.ServiceLocator.GetInstance <IStStyleRepository>().TryGetObject(factoryGuid1, out newStyle1), Is.True, "should have created a new style with the specified guid"); Assert.That(newStyle1.Name, Is.EqualTo("testA")); Assert.That(newStyle1.IsBuiltIn, Is.True); Assert.That(newStyle1.IsModified, Is.True); Assert.That(newStyle1.NextRA, Is.EqualTo(newStyle1), "should have kept the self-referential next style"); Assert.That(newStyle1.Rules, Is.EqualTo(props1)); Assert.That(newStyle1.UserLevel, Is.EqualTo(5)); IStStyle newStyle2; Assert.That(Cache.ServiceLocator.GetInstance <IStStyleRepository>().TryGetObject(factoryGuid2, out newStyle2), Is.True, "should have created second new style with the specified guid"); Assert.That(newStyle2.Name, Is.EqualTo("testB")); Assert.That(newStyle2.IsBuiltIn, Is.True); Assert.That(newStyle2.IsModified, Is.True); Assert.That(newStyle2.NextRA, Is.Null, "should have cleared the invalid next style"); Assert.That(newStyle2.BasedOnRA, Is.EqualTo(newStyle1), "should have transferred the base style ref to the replacement"); }
public ITsTextProps GetStyleRgch(int cch, string _rgchName) { return(TsPropsFactoryClass.Create().MakeProps(null, 0, 0)); }
public void FindOrCreateStyle_CopiesAllProperties() { var style1 = Cache.ServiceLocator.GetInstance <IStStyleFactory>().Create(); Cache.LangProject.StylesOC.Add(style1); var style2 = Cache.ServiceLocator.GetInstance <IStStyleFactory>().Create(); Cache.LangProject.StylesOC.Add(style2); var style3 = Cache.ServiceLocator.GetInstance <IStStyleFactory>().Create(); Cache.LangProject.StylesOC.Add(style3); style1.Name = "testA"; style1.Type = StyleType.kstParagraph; style1.Context = ContextValues.General; style1.Structure = StructureValues.Undefined; style1.Function = FunctionValues.Prose; style1.IsBuiltIn = true; style1.IsModified = true; style1.NextRA = style1; var propsFactory = TsPropsFactoryClass.Create(); var props1 = propsFactory.MakeProps("mystyle", Cache.DefaultAnalWs, 0); style1.Rules = props1; style1.UserLevel = 5; style2.Name = "testB"; style2.Type = StyleType.kstParagraph; style2.Context = ContextValues.General; style2.Structure = StructureValues.Undefined; style2.Function = FunctionValues.Prose; style2.IsBuiltIn = true; style2.IsModified = true; style2.NextRA = style1; style2.BasedOnRA = style1; style3.Name = "testC"; style3.BasedOnRA = style2; var factoryGuid1 = Guid.NewGuid(); var factoryGuid2 = Guid.NewGuid(); var sut = new TestAccessorForFindOrCreateStyle(Cache); sut.FindOrCreateStyle("testA", StyleType.kstParagraph, ContextValues.General, StructureValues.Undefined, FunctionValues.Prose, factoryGuid1); sut.FindOrCreateStyle("testB", StyleType.kstParagraph, ContextValues.General, StructureValues.Undefined, FunctionValues.Prose, factoryGuid2); Assert.That(style1.IsValidObject, Is.False, "should have deleted original style in course of changing guid"); var newStyle1 = Cache.ServiceLocator.GetInstance <IStStyleRepository>().GetObject(factoryGuid1); // will throw if not found Assert.That(newStyle1.Name, Is.EqualTo("testA")); Assert.That(newStyle1.IsBuiltIn, Is.True); Assert.That(newStyle1.IsModified, Is.True); Assert.That(newStyle1.NextRA, Is.EqualTo(newStyle1), "should have kept the self-referential next style"); Assert.That(newStyle1.Rules, Is.EqualTo(props1)); Assert.That(newStyle1.UserLevel, Is.EqualTo(5)); var newStyle2 = Cache.ServiceLocator.GetInstance <IStStyleRepository>().GetObject(factoryGuid2); // will throw if not found Assert.That(newStyle2.Name, Is.EqualTo("testB")); Assert.That(newStyle2.IsBuiltIn, Is.True); Assert.That(newStyle2.IsModified, Is.True); Assert.That(newStyle2.NextRA, Is.EqualTo(newStyle1), "should have transferred the next style ref to the replacement"); Assert.That(newStyle2.BasedOnRA, Is.EqualTo(newStyle1), "should have transferred the base style ref to the replacement"); Assert.That(style3.BasedOnRA, Is.EqualTo(newStyle2), "should have transferred the base style ref to the replacement, even for style not processed"); }
public void DisableCompareBtn() { // Add Revelation, archive it and then remove it. IStText title; Assert.IsNull(m_scr.FindBook(66), "Revelation should not be in the database. Restore the clean version of TestLangProj."); IScrBook revelation = Cache.ServiceLocator.GetInstance <IScrBookFactory>().Create(66, out title); ITsPropsFactory propFact = TsPropsFactoryClass.Create(); ITsTextProps ttp = propFact.MakeProps(ScrStyleNames.NormalParagraph, Cache.DefaultVernWs, 0); Cache.ServiceLocator.GetInstance <IScrSectionFactory>().CreateScrSection(revelation, 0, "Text for section", ttp, false); AddArchive("Revelation Archive", new List <IScrBook>(new IScrBook[] { revelation })); m_scr.ScriptureBooksOS.Remove(revelation); using (DummySavedVersionsDialog dlg = new DummySavedVersionsDialog(Cache)) { TreeView tree = dlg.ArchiveTree; // Select the archive node that was just added. tree.SelectedNode = tree.Nodes[0]; dlg.SimulateSelectEvent(); // Check to make sure the Compare to Current Version button is disabled Assert.IsFalse(dlg.ComparetoCurrentVersionBtn.Enabled, "The Compare to Current Version button should be disabled"); TreeNode revNode = null; TreeNode phmNode = null; foreach (TreeNode node in tree.Nodes) { if (node.Nodes.Count > 0 && node.Nodes[0].Tag is IScrBook) { if (((IScrBook)node.Nodes[0].Tag).CanonicalNum == 66) { revNode = node.Nodes[0]; } if (((IScrBook)node.Nodes[0].Tag).CanonicalNum == 57) { phmNode = node.Nodes[0]; } } } Assert.IsNotNull(revNode, "there should be an archive where the first book is Revelation"); Assert.IsNotNull(phmNode, "there should be an archive where the first book is Philemon"); // Select a book node for Revelation. tree.SelectedNode = revNode; dlg.SimulateSelectEvent(); // Check to make sure the Diff button is still disabled if we select Revelation // after it is removed from the DB. Assert.IsTrue(tree.SelectedNode.Tag is IScrBook); var bookId = ((IScrBook)tree.SelectedNode.Tag).CanonicalNum; Assert.AreEqual(66, bookId); Assert.IsNull(m_scr.FindBook(bookId)); Assert.IsFalse(dlg.ComparetoCurrentVersionBtn.Enabled, "The Compare to Current Version button should still be disabled."); // However, the diff button should be enabled if we select Philemon in the second archive // since it is in our database. tree.SelectedNode = phmNode; // selecting Philemon dlg.SimulateSelectEvent(); Assert.IsTrue(dlg.ComparetoCurrentVersionBtn.Enabled, "The Compare to Current Version button should be enabled when Philemon is selected."); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// This is the main interesting method of displaying objects and fragments of them. /// Scripture Footnotes are displayed by displaying each footnote's reference and text. /// The text is displayed using the standard view constructor for StText. /// </summary> /// <param name="vwenv"></param> /// <param name="hvo"></param> /// <param name="frag"></param> /// ------------------------------------------------------------------------------------ public override void Display(IVwEnv vwenv, int hvo, int frag) { CheckDisposed(); switch (frag) { case (int)FootnoteFrags.kfrScripture: { vwenv.NoteDependency(new int[] { m_cache.LangProject.TranslatedScriptureOAHvo }, new int[] { (int)Scripture.ScriptureTags.kflidScriptureBooks }, 1); vwenv.AddLazyVecItems(BooksTag, this, (int)FootnoteFrags.kfrBook); break; } case (int)FootnoteFrags.kfrRootInPageSeq: { int tag = DummyVirtualHandler.InstallDummyHandler(m_cache.VwCacheDaAccessor, "Scripture", "FootnotesOnPage", (int)CellarModuleDefns.kcptReferenceSequence).Tag; // Get the list of footnotes to display int[] hvos = m_cache.GetVectorProperty(hvo, tag, true); if (hvos.Length > 0) { int ownerHvo = m_cache.GetOwnerOfObject(hvos[0]); // The ownerHvo should be the HVO of the book vwenv.NoteDependency(new int[] { ownerHvo }, new int[] { (int)ScrBook.ScrBookTags.kflidFootnotes }, 1); } vwenv.AddObjVec(tag, this, (int)FootnoteFrags.kfrAllFootnotesWithinPagePara); break; } case (int)FootnoteFrags.kfrFootnoteWithinPagePara: { // Note a dependency on the footnote options so that the footnote will // be refreshed when these are changed. int[] depHvos = { hvo }; int[] depTags = { StFootnote.ktagFootnoteOptions }; vwenv.NoteDependency(depHvos, depTags, 1); // Insert the marker and reference vwenv.AddObj(hvo, this, (int)StTextFrags.kfrFootnoteMarker); vwenv.AddObj(hvo, this, (int)StTextFrags.kfrFootnoteReference); // Insert (we hope only one) paragraph contents. vwenv.AddObjVecItems((int)StText.StTextTags.kflidParagraphs, this, (int)FootnoteFrags.kfrFootnoteParaWithinPagePara); break; } case (int)FootnoteFrags.kfrFootnoteParaWithinPagePara: { if (!InsertParaContentsUserPrompt(vwenv, hvo)) { // Display the text paragraph contents, or its user prompt. vwenv.AddStringProp((int)StTxtPara.StTxtParaTags.kflidContents, null); } break; } case (int)FootnoteFrags.kfrBook: { vwenv.OpenDiv(); vwenv.AddObjVecItems((int)ScrBook.ScrBookTags.kflidFootnotes, this, (int)StTextFrags.kfrFootnote); vwenv.CloseDiv(); break; } case (int)StTextFrags.kfrFootnoteMarker: { ScrFootnote footnote = new ScrFootnote(Cache, hvo); if (footnote.DisplayFootnoteMarker) { DisplayFootnoteMarker(vwenv, footnote); } break; } case (int)StTextFrags.kfrFootnoteReference: { ITsStrFactory tsStrFactory = TsStrFactoryClass.Create(); ITsPropsFactory tpf = TsPropsFactoryClass.Create(); ITsTextProps ttp = tpf.MakeProps(ScrStyleNames.FootnoteTargetRef, m_wsDefault, 0); ScrFootnote footnote = new ScrFootnote(m_cache, hvo); string footnoteRef = footnote.GetReference(m_wsDefault); ITsString tssRef = tsStrFactory.MakeStringWithPropsRgch(footnoteRef, footnoteRef.Length, ttp); vwenv.set_IntProperty((int)FwTextPropType.ktptEditable, (int)FwTextPropVar.ktpvEnum, (int)TptEditable.ktptNotEditable); vwenv.AddString(tssRef); break; } default: base.Display(vwenv, hvo, frag); break; } }