/// ------------------------------------------------------------------------------------ /// <summary> /// A helper method for book merger tests- /// Verifies the contents of the given difference /// for types: missing/added paragraphs. /// </summary> /// <param name="diff">the given Difference</param> /// <param name="start">The verse ref start.</param> /// <param name="end">The verse ref end.</param> /// <param name="type">Type of the diff.</param> /// <param name="paraAdded">The paragraph added.</param> /// <param name="paraDest">the destination paragraph</param> /// <param name="ichDest">The character index in the destination paragraph, /// where the added items could be inserted in the other book.</param> /// ------------------------------------------------------------------------------------ public static void VerifyParaAddedDiff(Difference diff, BCVRef start, BCVRef end, DifferenceType type, StTxtPara paraAdded, StTxtPara paraDest, int ichDest) { Assert.AreEqual(start, diff.RefStart); Assert.AreEqual(end, diff.RefEnd); Assert.AreEqual(type, diff.DiffType); switch (type) { case DifferenceType.ParagraphAddedToCurrent: Assert.IsNull(diff.HvosSectionsRev); Assert.AreEqual(paraAdded.Hvo, diff.HvoCurr); Assert.AreEqual(0, diff.IchMinCurr); Assert.AreEqual(paraAdded.Contents.Length, diff.IchLimCurr); Assert.AreEqual(paraDest.Hvo, diff.HvoRev); Assert.AreEqual(ichDest, diff.IchMinRev); Assert.AreEqual(ichDest, diff.IchLimRev); Assert.IsNull(diff.StyleNameCurr); Assert.IsNull(diff.StyleNameRev); break; case DifferenceType.ParagraphMissingInCurrent: Assert.IsNull(diff.HvosSectionsRev); Assert.AreEqual(paraDest.Hvo, diff.HvoCurr); Assert.AreEqual(ichDest, diff.IchMinCurr); Assert.AreEqual(ichDest, diff.IchLimCurr); Assert.AreEqual(paraAdded.Hvo, diff.HvoRev); Assert.AreEqual(0, diff.IchMinRev); Assert.AreEqual(paraAdded.Contents.Length, diff.IchLimRev); Assert.IsNull(diff.StyleNameCurr); Assert.IsNull(diff.StyleNameRev); break; } }
public void FootnoteTranslationTest() { // get an existing footnote IScrBook book = m_scr.ScriptureBooksOS[1]; // book of James IStFootnote footnote = book.FootnotesOS[0]; StTxtPara para = (StTxtPara)footnote.ParagraphsOS[0]; // add a translation to the footnote ICmTranslation translation = para.GetOrCreateBT(); translation.Translation.AnalysisDefaultWritingSystem.UnderlyingTsString = TsStringHelper.MakeTSS("abcde", m_fdoCache.DefaultAnalWs); FwStyleSheet styleSheet = new FwStyleSheet(); styleSheet.Init(m_fdoCache, m_scr.Hvo, (int)Scripture.ScriptureTags.kflidStyles); // Prepare the test by creating a footnote view using (DummyFootnoteView footnoteView = new DummyFootnoteView(m_fdoCache, true)) { footnoteView.StyleSheet = styleSheet; footnoteView.Visible = false; // We don't actually want to show it, but we need to force the view to create the root // box and lay it out so that various test stuff can happen properly. footnoteView.MakeRoot(); footnoteView.CallLayout(); // Select the footnote marker and some characters of the footnote paragraph footnoteView.RootBox.MakeSimpleSel(true, true, false, true); SelectionHelper selHelper = SelectionHelper.GetSelectionInfo(null, footnoteView); // Now the real test: IVwSelection sel = footnoteView.RootBox.Selection.GrowToWord(); ITsString tss; sel.GetSelectionString(out tss, string.Empty); Assert.AreEqual("abcde", tss.Text); } }
public void IsDataLossDifference_SectionAdded() { // Create a Current with two sections IScrSection sectionCur1 = m_scrInMemoryCache.AddSectionToMockedBook(m_genesis.Hvo); m_scrInMemoryCache.AddSectionHeadParaToSection(sectionCur1.Hvo, "Section 1", ScrStyleNames.SectionHead); StTxtPara para1Cur = AddPara(sectionCur1); AddVerse(para1Cur, 1, 0, "Verse one."); sectionCur1.AdjustReferences(); IScrSection sectionCur2 = m_scrInMemoryCache.AddSectionToMockedBook(m_genesis.Hvo); m_scrInMemoryCache.AddSectionHeadParaToSection(sectionCur2.Hvo, "Section 2", ScrStyleNames.SectionHead); StTxtPara para2Cur = AddPara(sectionCur2); AddVerse(para2Cur, 0, 2, "Verse two."); sectionCur2.AdjustReferences(); // Create a Revision with only one section IScrSection sectionRev1 = m_scrInMemoryCache.AddSectionToMockedBook(m_genesisRevision.Hvo); m_scrInMemoryCache.AddSectionHeadParaToSection(sectionRev1.Hvo, "Section 1", ScrStyleNames.SectionHead); StTxtPara para1Rev = AddPara(sectionRev1); AddVerse(para1Rev, 1, 0, "Verse one."); sectionRev1.AdjustReferences(); m_bookMerger.DetectDifferences(null); // We expect that we would have one difference: a SectionAdded difference which should be // a data loss difference. Assert.AreEqual(1, m_bookMerger.Differences.Count); Difference diff = m_bookMerger.Differences.MoveFirst(); Assert.AreEqual(DifferenceType.SectionAddedToCurrent, diff.DiffType); Assert.IsTrue(m_bookMerger.IsDataLossDifference(diff)); }
public void AdjustReferences_InvalidVerseNumberInMiddle() { CheckDisposed(); // add section and paragraph IScrSection section = m_scrInMemoryCache.AddSectionToMockedBook(m_matthew.Hvo); StTxtPara para = m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo, ScrStyleNames.NormalParagraph); m_scrInMemoryCache.AddRunToMockedPara(para, "1", ScrStyleNames.ChapterNumber); m_scrInMemoryCache.AddRunToMockedPara(para, "1", ScrStyleNames.VerseNumber); m_scrInMemoryCache.AddRunToMockedPara(para, "some text", null); m_scrInMemoryCache.AddRunToMockedPara(para, "155", ScrStyleNames.VerseNumber); m_scrInMemoryCache.AddRunToMockedPara(para, "some text", null); m_scrInMemoryCache.AddRunToMockedPara(para, "3", ScrStyleNames.VerseNumber); m_scrInMemoryCache.AddRunToMockedPara(para, "some text", null); section.AdjustReferences(); // Check the section references and squawk if wrong VerifySectionRefs(section, 40001001, 40001003, 40001001, 40001003); }
public void ExportNotationParagraphs_Basic() { IScrSection section = m_scrInMemoryCache.AddSectionToMockedBook(m_book.Hvo); StTxtPara para = m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo, ScrStyleNames.NormalParagraph); IScrScriptureNote note = m_scrInMemoryCache.AddAnnotation(para, new BCVRef(01001001), NoteType.Translator, "This is some basic text."); TsStringAccessor tssaDisc = ((StTxtPara)note.DiscussionOA.ParagraphsOS[0]).Contents; StringWriter stream = new StringWriter(); XmlTextWriter writer = new XmlTextWriter(stream); m_exporter = new ExportXml(null, Cache, null, ExportWhat.AllBooks, 0, 0, 0, "ExportNotationParagraphs_Basic"); ReflectionHelper.SetField(m_exporter, "m_writer", writer); ReflectionHelper.CallMethod(m_exporter, "ExportNotationParagraphs", note.DiscussionOA, "notationDiscussion"); Assert.AreEqual("<notationDiscussion><para xml:lang=\"en\">" + "<span>This is some basic text.</span>" + "</para></notationDiscussion>", stream.ToString()); }
public void ReplaceAll_InBackTranslation() { CheckDisposed(); InitializeForReplaceAll(); // Replace "BT" with "back translation" int wsBt = Cache.DefaultAnalWs; m_pattern.Pattern = m_strFactory.MakeString("BT", wsBt); m_pattern.ReplaceWith = m_strFactory.MakeString("Back Translation", Cache.DefaultAnalWs); int hvoRoot; IVwViewConstructor vc; int frag; IVwStylesheet styleSheet; m_btDraftView.RootBox.GetRootObject(out hvoRoot, out vc, out frag, out styleSheet); ReplaceAllCollectorEnv collectorEnv = new ReplaceAllCollectorEnv(vc, Cache.MainCacheAccessor, hvoRoot, frag, m_pattern, null); int nReplaces = collectorEnv.ReplaceAll(); // Get back translation from Exodus after Replace All. StTxtPara headingPara1 = (StTxtPara)m_exodus.SectionsOS[0].HeadingOA.ParagraphsOS[0]; ITsString btHeading1 = headingPara1.GetBT().Translation.GetAlternative(wsBt).UnderlyingTsString; StTxtPara contentPara1 = (StTxtPara)m_exodus.SectionsOS[0].ContentOA.ParagraphsOS[0]; ITsString btContent1 = contentPara1.GetBT().Translation.GetAlternative(wsBt).UnderlyingTsString; StTxtPara headingPara2 = (StTxtPara)m_exodus.SectionsOS[1].HeadingOA.ParagraphsOS[0]; ITsString btHeading2 = headingPara2.GetBT().Translation.GetAlternative(wsBt).UnderlyingTsString; StTxtPara contentPara2 = (StTxtPara)m_exodus.SectionsOS[1].ContentOA.ParagraphsOS[0]; ITsString btContent2 = contentPara2.GetBT().Translation.GetAlternative(wsBt).UnderlyingTsString; // Confirm that "BT" was replaced with "Back Translation" Assert.AreEqual(4, nReplaces); Assert.AreEqual("Back Translation Heading 1", btHeading1.Text); Assert.AreEqual("Back Translation Intro text", btContent1.Text); Assert.AreEqual("Back Translation Heading 2", btHeading2.Text); Assert.AreEqual("11Back Translation Verse one", btContent2.Text); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Bring the paragraph difference into view in the diff view. /// </summary> /// <param name="hvoPara">hvo of paragraph containing the difference</param> /// <param name="ichMin">starting character position of the difference</param> /// ------------------------------------------------------------------------------------ public void ScrollToParaDiff(int hvoPara, int ichMin) { CheckDisposed(); StTxtPara para = new StTxtPara(m_fdoCache, hvoPara); int iPara = para.IndexInOwner; StText text = new StText(m_fdoCache, para.OwnerHVO); if (m_fdoCache.GetClassOfObject(text.OwnerHVO) == ScrSection.kClassId) { int tag = text.OwningFlid == (int)ScrSection.ScrSectionTags.kflidHeading ? (int)ScrSection.ScrSectionTags.kflidHeading : (int)ScrSection.ScrSectionTags.kflidContent; ScrSection section = new ScrSection(m_fdoCache, text.OwnerHVO); SetInsertionPoint(tag, 0, section.IndexInBook, iPara, ichMin, false); } else { SetInsertionPoint((int)ScrBook.ScrBookTags.kflidTitle, 0, 0, iPara, ichMin, false); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Makes a selection from one paragraph to another paragraph. /// NOTE: This selects the entirety of both paragraphs. /// </summary> /// <param name="para1">The first paragraph.</param> /// <param name="para2">The last paragraph.</param> /// <param name="view">DraftView or FootnoteView</param> /// ------------------------------------------------------------------------------------ private SelectionHelper MakeSelection(StTxtPara para1, StTxtPara para2, IVwRootSite view) { Debug.Assert(view != null); Debug.Assert(para1.OwningFlid == (int)StText.StTextTags.kflidParagraphs); Debug.Assert(para2.OwningFlid == (int)StText.StTextTags.kflidParagraphs); SelectionHelper helper = new SelectionHelper(); StText text1 = new StText(m_fdoCache, para1.OwnerHVO); StText text2 = new StText(m_fdoCache, para2.OwnerHVO); // build the anchor part of the selection SetupSelectionFor(helper, text1, para1, SelectionHelper.SelLimitType.Anchor, (FwRootSite)view); // build the end part of the selection SetupSelectionFor(helper, text2, para2, SelectionHelper.SelLimitType.End, (FwRootSite)view); helper.IchAnchor = 0; helper.IchEnd = para2.Contents.Length; return(helper); }
public void AdjustReferences_ImportSimulation() { CheckDisposed(); // add section and paragraph IScrSection section1 = m_scrInMemoryCache.AddSectionToMockedBook(m_matthew.Hvo); StTxtPara para = m_scrInMemoryCache.AddParaToMockedSectionContent(section1.Hvo, ScrStyleNames.NormalParagraph); m_scrInMemoryCache.AddRunToMockedPara(para, "4", ScrStyleNames.ChapterNumber); m_scrInMemoryCache.AddRunToMockedPara(para, "3", ScrStyleNames.VerseNumber); m_scrInMemoryCache.AddRunToMockedPara(para, "some text", null); m_scrInMemoryCache.AddRunToMockedPara(para, "4", ScrStyleNames.VerseNumber); m_scrInMemoryCache.AddRunToMockedPara(para, "some text", null); m_scrInMemoryCache.AddRunToMockedPara(para, "5", ScrStyleNames.VerseNumber); m_scrInMemoryCache.AddRunToMockedPara(para, "some text", null); section1.AdjustReferences(); // make a second section without a chapter number IScrSection section2 = m_scrInMemoryCache.AddSectionToMockedBook(m_matthew.Hvo); para = m_scrInMemoryCache.AddParaToMockedSectionContent(section2.Hvo, ScrStyleNames.NormalParagraph); m_scrInMemoryCache.AddRunToMockedPara(para, "6", ScrStyleNames.VerseNumber); m_scrInMemoryCache.AddRunToMockedPara(para, "some text", null); m_scrInMemoryCache.AddRunToMockedPara(para, "7", ScrStyleNames.VerseNumber); m_scrInMemoryCache.AddRunToMockedPara(para, "some text", null); m_scrInMemoryCache.AddRunToMockedPara(para, "8", ScrStyleNames.VerseNumber); m_scrInMemoryCache.AddRunToMockedPara(para, "some text", null); section2.AdjustReferences(); // Check the section references and squawk if wrong VerifySectionRefs(section1, 40004003, 40004005, 40004003, 40004005); // Check the section references and squawk if wrong VerifySectionRefs(section2, 40004006, 40004008, 40004006, 40004008); }
public void IncludeCommentedErrors() { IScrScriptureNote note1 = m_scrInMemoryCache.AddAnnotation( (StTxtPara)m_genesis.SectionsOS[0].ContentOA.ParagraphsOS[0], 01001001, NoteType.CheckingError); note1.ResolutionStatus = NoteStatus.Open; StTxtPara para1 = m_scrInMemoryCache.AddParaToMockedText(note1.ResolutionOAHvo, ScrStyleNames.NormalParagraph); para1.Contents.Text = "This is my comment."; IScrScriptureNote note2 = m_scrInMemoryCache.AddAnnotation( (StTxtPara)m_genesis.SectionsOS[0].ContentOA.ParagraphsOS[0], 01001002, NoteType.CheckingError); note2.ResolutionStatus = NoteStatus.Closed; StTxtPara para2 = m_scrInMemoryCache.AddParaToMockedText(note2.ResolutionOAHvo, ScrStyleNames.NormalParagraph); para2.Contents.Text = "This is my comment."; Assert.IsTrue(m_filter.MatchesCriteria(note1.Hvo)); Assert.IsTrue(m_filter.MatchesCriteria(note2.Hvo)); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Gets the section index and paragraph index for the specified object, when this /// method assumes is an StTxtPara. /// </summary> /// <param name="obj">An ICmObject associated with an annotation (i.e. the annotation's /// BeginObjectRA) which is assumed to be an StTxtPara.</param> /// <param name="iNewNoteSection">The index of the section, or -1 if the index cannot /// be determined.</param> /// <param name="iNewNotePara">The index of paragraph, or int.MaxValue if the index /// cannot be determined.</param> /// ------------------------------------------------------------------------------------ private void GetLocationInfoForObj(ICmObject obj, out int iNewNoteSection, out int iNewNotePara) { iNewNoteSection = -1; iNewNotePara = int.MaxValue; if (obj is StTxtPara) { StTxtPara para = (StTxtPara)obj; iNewNotePara = para.IndexInOwner; ScrSection section = ScrSection.GetSectionFromParagraph(para); if (section != null) { iNewNoteSection = section.IndexInBook; } } else if (obj is CmTranslation) { CmTranslation trans = (CmTranslation)obj; Debug.Assert(trans.Owner is StTxtPara); GetLocationInfoForObj(trans.Owner, out iNewNoteSection, out iNewNotePara); } }
public void RemoveOwnedObjectsForString_FootnotesWithBT() { CheckDisposed(); StTxtPara para = (StTxtPara)m_currentText.ParagraphsOS[0]; // Add footnotes to existing paragraph. StFootnote footnote1 = m_inMemoryCache.AddFootnote(m_currentFootnotesOS, para, 6, "Footnote1"); StFootnote footnote2 = m_inMemoryCache.AddFootnote(m_currentFootnotesOS, para, 10, "Footnote2"); Assert.AreEqual(2, m_currentFootnotesOS.Count); // add two back translations of the para and footnotes ICmTranslation trans; int[] wsBt = new int[] { InMemoryFdoCache.s_wsHvos.En, InMemoryFdoCache.s_wsHvos.De }; foreach (int ws in wsBt) { // add back translation of the para trans = m_inMemoryCache.AddBtToMockedParagraph(para, ws); m_inMemoryCache.AddRunToMockedTrans(trans, ws, "BT of test paragraph", null); // add BT footnotes m_inMemoryCache.AddFootnoteORCtoTrans(trans, 2, ws, footnote1, "BT of footnote1"); m_inMemoryCache.AddFootnoteORCtoTrans(trans, 6, ws, footnote2, "BT of footnote2"); Assert.AreEqual("BT" + StringUtils.kchObject + " of" + StringUtils.kchObject + " test paragraph", trans.Translation.GetAlternative(ws).Text); // confirm that ORCs were inserted in BTs } para.RemoveOwnedObjectsForString(5, 12); Assert.AreEqual(0, m_currentFootnotesOS.Count); // We expect that the ORCs would have also been removed from both back translations. trans = para.GetBT() as CmTranslation; Assert.IsNotNull(trans); foreach (int ws in wsBt) { Assert.AreEqual("BT of test paragraph", trans.Translation.GetAlternative(ws).Text); } }
public void ChangeParagraphToSectionHead_EndOfSection() { CheckDisposed(); IScrSection section = m_scrInMemoryCache.AddSectionToMockedBook(m_matthew.Hvo); m_scrInMemoryCache.AddSectionHeadParaToSection(section.Hvo, "This is the heading", ScrStyleNames.SectionHead); m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo, ScrStyleNames.NormalParagraph); m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo, ScrStyleNames.NormalParagraph); StTxtPara para = m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo, ScrStyleNames.NormalParagraph); m_scrInMemoryCache.AddRunToMockedPara(para, "6", ScrStyleNames.VerseNumber); m_scrInMemoryCache.AddRunToMockedPara(para, "Content of paragraph 2", null); section.AdjustReferences(); ScrSection secHelp = new ScrSection(Cache, section.Hvo); IScrSection newSecHelp = secHelp.ChangeParagraphToSectionHead(2, 1); // verify that the new section has one content paragraph and one heading paragraph. Assert.AreEqual(1, newSecHelp.ContentOA.ParagraphsOS.Count); Assert.AreEqual(1, newSecHelp.HeadingOA.ParagraphsOS.Count); // verify that the text of the old paragraph is now in the new section head // and that the new section content paragraph is empty and has normal paragraph // style. StTxtPara newSecPara = (StTxtPara)newSecHelp.ContentOA.ParagraphsOS[0]; Assert.IsTrue(StStyle.IsStyle(newSecPara.StyleRules, ScrStyleNames.NormalParagraph)); Assert.IsFalse(StStyle.IsStyle(newSecPara.Contents.UnderlyingTsString.get_Properties(0), ScrStyleNames.NormalParagraph)); Assert.IsNull(newSecPara.Contents.Text); StTxtPara newSecHeadPara = (StTxtPara)newSecHelp.HeadingOA.ParagraphsOS[0]; Assert.AreEqual(para.Contents.Text, newSecHeadPara.Contents.Text); }
public void InsertNote_RangeSelInMultiVersePara() { CheckDisposed(); IScrBook philemon = m_scrInMemoryCache.AddBookToMockedScripture(57, "Philemon"); IScrSection section = m_scrInMemoryCache.AddSectionToMockedBook(philemon.Hvo); StTxtPara para1 = m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo, ScrStyleNames.IntroParagraph); m_scrInMemoryCache.AddRunToMockedPara(para1, "1", ScrStyleNames.ChapterNumber); m_scrInMemoryCache.AddRunToMockedPara(para1, "1", ScrStyleNames.VerseNumber); m_scrInMemoryCache.AddRunToMockedPara(para1, "This is text", null); m_scrInMemoryCache.AddRunToMockedPara(para1, "2", ScrStyleNames.VerseNumber); m_scrInMemoryCache.AddRunToMockedPara(para1, "This is text", null); StTxtPara para2 = m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo, ScrStyleNames.IntroParagraph); m_scrInMemoryCache.AddRunToMockedPara(para2, "3", ScrStyleNames.VerseNumber); m_scrInMemoryCache.AddRunToMockedPara(para2, "This is text", null); section.AdjustReferences(); CreateAndCheckAnnotation(para1.Hvo, para2.Hvo, 57001001, 57001003, 0, 0, string.Empty); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Gets the writing system and direction to use for the given paragraph (depending on /// the value of <see cref="BaseDirectionOnParaContents"/>, this can be based on the /// paragraph itself or simply derived from the VC). /// </summary> /// <param name="hvoPara">The HVO of the paragraph.</param> /// <param name="fIsRightToLeftPara">flag indicating whether direction is right to left. /// </param> /// <param name="wsPara">The writing system.</param> /// ------------------------------------------------------------------------------------ protected void GetWsAndDirectionForPara(int hvoPara, out bool fIsRightToLeftPara, out int wsPara) { fIsRightToLeftPara = RightToLeft; wsPara = DefaultWs; if (BaseDirectionOnParaContents) { // we'll infer the direction of the paragraph from the ws of the first run (offset 0). wsPara = StTxtPara.GetWsAtParaOffset(m_cache, hvoPara, 0); if (wsPara <= 0) { wsPara = DefaultWs; } else { IWritingSystem wsObj = m_cache.LanguageWritingSystemFactoryAccessor.get_EngineOrNull(wsPara); if (wsObj != null) { fIsRightToLeftPara = wsObj.RightToLeft; } } } }
public void TrimTrailingSpaceTwiceWithTwoSpacesAtEnd() { CheckDisposed(); // create an StTxtPara using (StTxtParaBldr bldr = new StTxtParaBldr(Cache)) { IParaStylePropsProxy proxy = new DummyProxy("Whatever"); bldr.ParaStylePropsProxy = proxy; ITsTextProps textProps = StyleUtils.CharStyleTextProps(null, m_wsArbitrary); bldr.AppendRun("My run ", textProps); Assert.AreEqual(8, bldr.Length); // trim the space off the end bldr.TrimTrailingSpaceInPara(); Assert.AreEqual(7, bldr.Length); bldr.TrimTrailingSpaceInPara(); Assert.AreEqual(6, bldr.Length); StTxtPara para = bldr.CreateParagraph(m_text.Hvo, 1); // verify paragraph contents AssertEx.RunIsCorrect(para.Contents.UnderlyingTsString, 0, "My run", null, m_wsArbitrary); } // Dispose() frees ICU resources. }
public override void Exit() { CheckDisposed(); m_vc.Dispose(); m_vc = null; m_section = null; m_para1 = null; m_para2 = null; m_para3 = null; if (Marshal.IsComObject(m_pattern)) { Marshal.ReleaseComObject(m_pattern); } m_pattern = null; if (Marshal.IsComObject(m_strFactory)) { Marshal.ReleaseComObject(m_strFactory); } m_strFactory = null; base.Exit(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Create minimal test data required for every test. /// </summary> /// ------------------------------------------------------------------------------------ protected override void CreateTestData() { base.CreateTestData(); m_inMemoryCache.InitializeWritingSystemEncodings(); m_inMemoryCache.InitializeLexDb(); m_helper = new DiscourseTestHelper(Cache); m_firstPara = m_helper.FirstPara; m_stText = m_firstPara.Owner as StText; //// We want a real action handler so we can test Undo/Redo. //m_originalHandler = m_inMemoryCache.Cache.ActionHandlerAccessor; //((NewFdoCache)(m_inMemoryCache.Cache)).ActionHandler = ActionHandlerClass.Create(); //// Make the key annotationdefns. ICmPossibilityList defns = Cache.LangProject.AnnotationDefsOA; if (defns == null) { defns = new CmPossibilityList(); Cache.LangProject.AnnotationDefsOA = defns; } MakeAnnDefn(defns, LangProject.kguidAnnWordformInContext); MakeAnnDefn(defns, LangProject.kguidConstituentChartRow); MakeAnnDefn(defns, LangProject.kguidConstituentChartAnnotation); }
public void AdjustReferences_ChapterWithImpliedVerseOne() { CheckDisposed(); // add section and paragraph IScrSection section1 = m_scrInMemoryCache.AddSectionToMockedBook(m_matthew.Hvo); StTxtPara para = m_scrInMemoryCache.AddParaToMockedSectionContent(section1.Hvo, ScrStyleNames.NormalParagraph); m_scrInMemoryCache.AddRunToMockedPara(para, "4", ScrStyleNames.ChapterNumber); // add text of implied verse one m_scrInMemoryCache.AddRunToMockedPara(para, "some text", null); m_scrInMemoryCache.AddRunToMockedPara(para, "3", ScrStyleNames.VerseNumber); m_scrInMemoryCache.AddRunToMockedPara(para, "some text", null); m_scrInMemoryCache.AddRunToMockedPara(para, "4", ScrStyleNames.VerseNumber); m_scrInMemoryCache.AddRunToMockedPara(para, "some text", null); m_scrInMemoryCache.AddRunToMockedPara(para, "5", ScrStyleNames.VerseNumber); m_scrInMemoryCache.AddRunToMockedPara(para, "some text", null); section1.AdjustReferences(); // We expect that the refs begin with the implied verse 1. VerifySectionRefs(section1, 40004001, 40004005, 40004001, 40004005); }
public void NoUserPromptForContentPara() { CheckDisposed(); // Set up empty content paragraph IScrSection section = m_inMemoryCache.AddSectionToMockedBook(m_book.Hvo); StTxtPara para = m_inMemoryCache.AddParaToMockedSectionContent(section.Hvo, ScrStyleNames.NormalParagraph); section.AdjustReferences(); m_vwenvMock.ExpectNoCall("NoteDependency", new string[] { typeof(int[]).FullName, typeof(int[]).FullName, typeInt }); m_vwenvMock.ExpectNoCall("AddProp", new string[] { typeInt, typeof(IVwViewConstructor).FullName, typeInt }); DummyTeStVc stVc = new DummyTeStVc(m_inMemoryCache.Cache, m_inMemoryCache.Cache.DefaultVernWs); bool fTextAdded = stVc.CallInsertUserPrompt((IVwEnv)m_vwenvMock.MockInstance, para.Hvo); Assert.IsFalse(fTextAdded, "User prompt was added to empty content para"); m_vwenvMock.Verify(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Creates a book with 2 sections with the following layout: /// bookName /// Heading 1 /// (1)1Verse one. /// Heading 2 /// (2)1Verse one.2Verse two. /// (3)1Verse one. /// 2This is a pretty long... /// .. /// 11This is a pretty long... /// /// /// Numbers in () are chapter numbers. /// </summary> /// <returns>the book for testing</returns> /// ------------------------------------------------------------------------------------ private IScrBook CreateBook(int nBookNumber, string bookName) { IScrBook book; IScrSection section; book = CreateSmallBook(nBookNumber, bookName, out section); for (int i = 0; i < 10; i++) { StTxtPara para = m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo, ScrStyleNames.NormalParagraph); m_scrInMemoryCache.AddRunToMockedPara(para, (i + 2).ToString(), ScrStyleNames.VerseNumber); m_scrInMemoryCache.AddRunToMockedPara(para, "This is a pretty long paragraph that doesn't say much " + "that would be worth saying if it wouldn't be for these test. In these tests " + "we simply need some long paragraphs with a lot of text so that we hopefully " + "fill more than one page full of text. Let's just pretend this is something " + "useful and let's hope we have enough text now so that we can stop here.", null); } section.AdjustReferences(); return(book); }
public void InsertVerseNumber_BegOfSection() { CheckDisposed(); // Remove the formatting on the verse number so it doesn't interfere with the test. m_draftView.SelectRangeOfChars(1, 12, 0, 0, 2); m_draftView.EditingHelper.RemoveCharFormattingWithUndo(); // set the IP at the beginning of the section that was James 4:11 m_draftView.SetInsertionPoint(1, 12, 0, 0, true); // insert verse num 11 at the IP m_draftView.InsertVerseNumber(); ScrBook book = (ScrBook)m_cache.LangProject.TranslatedScriptureOA.ScriptureBooksOS[1]; StTxtPara para = (StTxtPara)((ScrSection)book.SectionsOS[12]).ContentOA.ParagraphsOS[0]; ITsString tss = para.Contents.UnderlyingTsString; Assert.AreEqual(4, tss.RunCount); AssertEx.RunIsCorrect(tss, 0, "11", "Verse Number", m_cache.DefaultVernWs); Assert.AreEqual("11Do not criticize", para.Contents.UnderlyingTsString.get_RunText(1).Substring(0, 18)); Assert.AreEqual(StyleUtils.CharStyleTextProps(null, m_cache.DefaultVernWs), para.Contents.UnderlyingTsString.get_Properties(1)); }
public void AdjustReferences_LastVerseBeforeFirst() { CheckDisposed(); // add section and paragraph IScrSection section1 = m_scrInMemoryCache.AddSectionToMockedBook(m_matthew.Hvo); StTxtPara para1 = m_scrInMemoryCache.AddParaToMockedSectionContent(section1.Hvo, ScrStyleNames.NormalParagraph); m_scrInMemoryCache.AddRunToMockedPara(para1, "1", ScrStyleNames.ChapterNumber); m_scrInMemoryCache.AddRunToMockedPara(para1, "1", ScrStyleNames.VerseNumber); m_scrInMemoryCache.AddRunToMockedPara(para1, "some text", null); m_scrInMemoryCache.AddRunToMockedPara(para1, "2", ScrStyleNames.VerseNumber); m_scrInMemoryCache.AddRunToMockedPara(para1, "some text", null); m_scrInMemoryCache.AddRunToMockedPara(para1, "3", ScrStyleNames.VerseNumber); m_scrInMemoryCache.AddRunToMockedPara(para1, "some text", null); section1.AdjustReferences(); // need 2 sections because we need a section without a chapter number IScrSection section2 = m_scrInMemoryCache.AddSectionToMockedBook(m_matthew.Hvo); StTxtPara para2 = m_scrInMemoryCache.AddParaToMockedSectionContent(section2.Hvo, ScrStyleNames.NormalParagraph); m_scrInMemoryCache.AddRunToMockedPara(para2, "4", ScrStyleNames.VerseNumber); m_scrInMemoryCache.AddRunToMockedPara(para2, "some text", null); m_scrInMemoryCache.AddRunToMockedPara(para2, "5", ScrStyleNames.VerseNumber); m_scrInMemoryCache.AddRunToMockedPara(para2, "some text", null); m_scrInMemoryCache.AddRunToMockedPara(para2, "3", ScrStyleNames.VerseNumber); m_scrInMemoryCache.AddRunToMockedPara(para2, "some text", null); section2.AdjustReferences(); // Check the section references and squawk if wrong VerifySectionRefs(section2, 40001004, 40001003, 40001003, 40001005); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Creates the small book. /// </summary> /// <param name="nBookNumber">The book number.</param> /// <param name="bookName">Name of the book.</param> /// <param name="section2">The section2.</param> /// ------------------------------------------------------------------------------------ private IScrBook CreateSmallBook(int nBookNumber, string bookName, out IScrSection section2) { IScrBook book = m_scrInMemoryCache.AddBookToMockedScripture(nBookNumber, bookName); m_scrInMemoryCache.AddTitleToMockedBook(book.Hvo, bookName); IScrSection section1 = m_scrInMemoryCache.AddSectionToMockedBook(book.Hvo); m_scrInMemoryCache.AddSectionHeadParaToSection(section1.Hvo, "Heading 1", ScrStyleNames.SectionHead); StTxtPara para11 = m_scrInMemoryCache.AddParaToMockedSectionContent(section1.Hvo, ScrStyleNames.NormalParagraph); m_scrInMemoryCache.AddRunToMockedPara(para11, "1", ScrStyleNames.ChapterNumber); m_scrInMemoryCache.AddRunToMockedPara(para11, "1", ScrStyleNames.VerseNumber); m_scrInMemoryCache.AddRunToMockedPara(para11, "Verse one.", null); section1.AdjustReferences(); section2 = m_scrInMemoryCache.AddSectionToMockedBook(book.Hvo); m_scrInMemoryCache.AddSectionHeadParaToSection(section2.Hvo, "Heading 2", ScrStyleNames.SectionHead); StTxtPara para21 = m_scrInMemoryCache.AddParaToMockedSectionContent(section2.Hvo, ScrStyleNames.NormalParagraph); m_scrInMemoryCache.AddRunToMockedPara(para21, "2", ScrStyleNames.ChapterNumber); m_scrInMemoryCache.AddRunToMockedPara(para21, "1", ScrStyleNames.VerseNumber); m_scrInMemoryCache.AddRunToMockedPara(para21, "Verse one.", null); m_scrInMemoryCache.AddRunToMockedPara(para21, "2", ScrStyleNames.VerseNumber); m_scrInMemoryCache.AddRunToMockedPara(para21, "Verse two.", null); StTxtPara para22 = m_scrInMemoryCache.AddParaToMockedSectionContent(section2.Hvo, ScrStyleNames.NormalParagraph); m_scrInMemoryCache.AddRunToMockedPara(para22, "3", ScrStyleNames.ChapterNumber); m_scrInMemoryCache.AddRunToMockedPara(para22, "1", ScrStyleNames.VerseNumber); m_scrInMemoryCache.AddRunToMockedPara(para22, "Verse one.", null); return(book); }
public void CreateOwnedObjects_Picture() { CheckDisposed(); StTxtPara para = (StTxtPara)m_currentText.ParagraphsOS[0]; ITsString tss = para.Contents.UnderlyingTsString; ITsStrFactory factory = TsStrFactoryClass.Create(); using (DummyFileMaker fileMaker = new DummyFileMaker("junk.jpg", true)) { CmPicture pict = new CmPicture(Cache, fileMaker.Filename, factory.MakeString("Test picture", Cache.DefaultVernWs), StringUtils.LocalPictures); pict.InsertORCAt(tss, 0, para.Hvo, (int)StTxtPara.StTxtParaTags.kflidContents, 0); tss = para.Contents.UnderlyingTsString; int cchOrigStringLength = tss.Length; NMock.DynamicMock mockIObjectMetaInfoProvider = new DynamicMock(typeof(IObjectMetaInfoProvider)); mockIObjectMetaInfoProvider.Strict = true; mockIObjectMetaInfoProvider.ExpectAndReturn(1, "PictureFolder", StringUtils.LocalPictures); para.CreateOwnedObjects(0, 1, (IObjectMetaInfoProvider)mockIObjectMetaInfoProvider.MockInstance); mockIObjectMetaInfoProvider.Verify(); tss = para.Contents.UnderlyingTsString; Assert.AreEqual(cchOrigStringLength, tss.Length); string sObjData = tss.get_Properties(0).GetStrPropValue((int)FwTextPropType.ktptObjData); Guid guid = MiscUtils.GetGuidFromObjData(sObjData.Substring(1)); byte odt = Convert.ToByte(sObjData[0]); Assert.AreEqual((byte)FwObjDataTypes.kodtGuidMoveableObjDisp, odt); Assert.IsTrue(Cache.GetGuidFromId(pict.Hvo) != guid, "New guid was not inserted"); } }
public void GetAnnotationLocationInfo_BTLongerThanVern() { CheckDisposed(); int wsBt = Cache.DefaultAnalWs; // Add a section IScrSection section = m_scr.ScriptureBooksOS[0].SectionsOS[1]; StTxtPara para = (StTxtPara)section.ContentOA.ParagraphsOS[0]; CmTranslation transPara1 = (CmTranslation)para.GetOrCreateBT(); // The text "11BT Verse one" is already added, but we add a couple more verses... m_scrInMemoryCache.AddRunToMockedTrans(transPara1, wsBt, ". ", null); m_scrInMemoryCache.AddRunToMockedTrans(transPara1, wsBt, "2", ScrStyleNames.VerseNumber); m_scrInMemoryCache.AddRunToMockedTrans(transPara1, wsBt, "BT verse two. ", null); section.AdjustReferences(); // Set up a simple selection in the first back translation paragraph. m_btDraftView.SelectRangeOfChars(0, 1, 0, 0, 25); CmObject topObj, bottomObj; int wsSelector; int startOffset, endOffset; ITsString tssQuote; BCVRef startRef, endRef; m_btDraftView.TeEditingHelper.GetAnnotationLocationInfo(out topObj, out bottomObj, out wsSelector, out startOffset, out endOffset, out tssQuote, out startRef, out endRef); Assert.AreEqual(transPara1.Hvo, topObj.Hvo); Assert.AreEqual(transPara1.Hvo, bottomObj.Hvo); Assert.AreEqual(wsBt, wsSelector); Assert.AreEqual(0, startOffset); Assert.AreEqual(25, endOffset); Assert.AreEqual(new BCVRef(2, 1, 1), startRef); Assert.AreEqual(new BCVRef(2, 1, 2), endRef); Assert.AreEqual("BT Verse one. BT verse", tssQuote.Text); }
/// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// ------------------------------------------------------------------------------------ protected override void CreateTestData() { m_stylesheet = new FwStyleSheet(); m_stylesheet.Init(Cache, m_scr.Hvo, (int)Scripture.ScriptureTags.kflidStyles); m_exodus = m_scrInMemoryCache.AddBookToMockedScripture(2, "Exodus"); m_scrInMemoryCache.AddTitleToMockedBook(m_exodus.Hvo, "Exodus"); IScrSection section = m_scrInMemoryCache.AddSectionToMockedBook(m_exodus.Hvo); m_scrInMemoryCache.AddSectionHeadParaToSection(section.Hvo, "Section Heading", ScrStyleNames.SectionHead); StTxtPara para = m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo, ScrStyleNames.NormalParagraph); m_scrInMemoryCache.AddRunToMockedPara(para, "1", ScrStyleNames.ChapterNumber); m_scrInMemoryCache.AddRunToMockedPara(para, "1", ScrStyleNames.VerseNumber); m_scrInMemoryCache.AddRunToMockedPara(para, "Verse one. ", null); m_scrInMemoryCache.AddRunToMockedPara(para, "2", ScrStyleNames.VerseNumber); m_scrInMemoryCache.AddRunToMockedPara(para, "Verse two.", null); m_scrInMemoryCache.AddRunToMockedPara(para, "3", ScrStyleNames.VerseNumber); m_scrInMemoryCache.AddRunToMockedPara(para, "Verse three.", null); m_scrInMemoryCache.AddRunToMockedPara(para, "4", ScrStyleNames.VerseNumber); m_scrInMemoryCache.AddRunToMockedPara(para, "Verse four. ", null); m_scrInMemoryCache.AddRunToMockedPara(para, "5", ScrStyleNames.VerseNumber); m_scrInMemoryCache.AddRunToMockedPara(para, "Verse five.", null); m_scrInMemoryCache.AddRunToMockedPara(para, "6", ScrStyleNames.VerseNumber); m_scrInMemoryCache.AddRunToMockedPara(para, "Verse six. ", null); m_scrInMemoryCache.AddRunToMockedPara(para, "7", ScrStyleNames.VerseNumber); m_scrInMemoryCache.AddRunToMockedPara(para, "Verse seven.", null); m_scrInMemoryCache.AddRunToMockedPara(para, "8", ScrStyleNames.VerseNumber); m_scrInMemoryCache.AddRunToMockedPara(para, "Verse seven.", null); m_scrInMemoryCache.AddRunToMockedPara(para, "9", ScrStyleNames.VerseNumber); m_scrInMemoryCache.AddRunToMockedPara(para, "Verse seven.", null); m_scrInMemoryCache.AddRunToMockedPara(para, "10", ScrStyleNames.VerseNumber); m_scrInMemoryCache.AddRunToMockedPara(para, "Verse seven.", null); section.AdjustReferences(); }
public void PageElementsDontOverlap_OneFootnote() { // Add a footnote in the first book, first section, first paragraph IScripture scr = Cache.LangProject.TranslatedScriptureOA; ScrBook genesis = (ScrBook)scr.ScriptureBooksOS[0]; IScrSection section = (IScrSection)genesis.SectionsOS[0]; StFootnote footnote = m_scrInMemoryCache.AddFootnote(genesis, (StTxtPara)section.ContentOA.ParagraphsOS[0], 2); StTxtPara para = m_scrInMemoryCache.AddParaToMockedText(footnote.Hvo, ScrStyleNames.NormalFootnoteParagraph); m_scrInMemoryCache.AddRunToMockedPara(para, "Another footnote", 0); m_pub.CreatePages(); m_pub.PrepareToDrawPages(0, m_pub.AutoScrollMinSize.Height * 2); Page firstPage = m_pub.Pages[0]; int cFoonotesOnThisPage = (int)m_division.m_testPageFootnoteInfo[firstPage.Handle]; Assert.AreEqual(1, cFoonotesOnThisPage, "Should display one footnote on first page"); // None of the page elements on the first page should intersect CheckThatPageElementsDontOverlap(firstPage); }
public void InsertVerseNumber_AfterChapterNumber() { CheckDisposed(); // Remove the formatting on the verse number so it doesn't interfere with the test. m_draftView.SelectRangeOfChars(1, 11, 0, 1, 2); m_draftView.EditingHelper.RemoveCharFormattingWithUndo(); // Set the IP right after the chapter number in James 4:1 m_draftView.SetInsertionPoint(1, 11, 0, 1, true); // insert verse num 1 at the IP m_draftView.InsertVerseNumber(); ScrBook book = (ScrBook)m_cache.LangProject.TranslatedScriptureOA.ScriptureBooksOS[1]; StTxtPara para = (StTxtPara)((ScrSection)book.SectionsOS[11]).ContentOA.ParagraphsOS[0]; ITsString tss = para.Contents.UnderlyingTsString; Assert.AreEqual(15, tss.RunCount); AssertEx.RunIsCorrect(tss, 0, "4", "Chapter Number", m_cache.DefaultVernWs); AssertEx.RunIsCorrect(tss, 1, "1", "Verse Number", m_cache.DefaultVernWs); Assert.AreEqual("1Where do all the fights", para.Contents.UnderlyingTsString.get_RunText(2).Substring(0, 24)); Assert.AreEqual(StyleUtils.CharStyleTextProps(null, m_cache.DefaultVernWs), para.Contents.UnderlyingTsString.get_Properties(2)); }
public void InsertVerseNumber_MidPara() { CheckDisposed(); // set the IP in middle of Phm 1:8 m_draftView.SetInsertionPoint(0, 3, 2, 8, true); // insert verse num at the IP m_draftView.InsertVerseNumber(); //verify verse num 9 was properly inserted ScrBook book = (ScrBook)m_cache.LangProject.TranslatedScriptureOA.ScriptureBooksOS[0]; StTxtPara para = (StTxtPara)((ScrSection)book.SectionsOS[3]).ContentOA.ParagraphsOS[2]; ITsString tss = para.Contents.UnderlyingTsString; Assert.AreEqual(20, tss.RunCount); AssertEx.RunIsCorrect(tss, 1, "Aussi, ", null, m_cache.DefaultVernWs); AssertEx.RunIsCorrect(tss, 2, "9", "Verse Number", m_cache.DefaultVernWs); Assert.AreEqual("bien que", para.Contents.UnderlyingTsString.get_RunText(3).Substring(0, 8)); Assert.AreEqual(StyleUtils.CharStyleTextProps(null, m_cache.DefaultVernWs), para.Contents.UnderlyingTsString.get_Properties(3)); }