Beispiel #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Verifies that all footnotes correspond to exactly one ORC in the vernacular
        /// Scripture and that they are in the same order as they occur in Scripture.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void VerifyNoOrphanedFootnotes()
        {
            ScrChecksDataSource scrData = new ScrChecksDataSource(Cache);

            foreach (IScrBook book in m_scr.ScriptureBooksOS)
            {
                IEnumerator <IStFootnote> footnotes = book.FootnotesOS.GetEnumerator();
                IStFootnote currentFootnote         = (footnotes.MoveNext() ? footnotes.Current : null);

                scrData.GetText(book.CanonicalNum, 0);
                foreach (ITextToken tok in scrData.TextTokens())
                {
                    if (tok.TextType == TextType.Note)
                    {
                        if (tok.IsNoteStart)
                        {
                            Assert.IsNotNull(currentFootnote, "No more footnotes were expected in " + book.BestUIName);
                            Assert.IsTrue(((IStTxtPara)currentFootnote.ParagraphsOS[0]).Contents.Text.StartsWith(tok.Text),
                                          "Footnote ORC does not match next footnote in sequence (mismatched text)");
                            Assert.AreEqual(currentFootnote.ParagraphsOS[0].StyleName, tok.ParaStyleName,
                                            "Footnote ORC does not match next footnote in sequence (mismatched style)");
                            currentFootnote = (footnotes.MoveNext() ? footnotes.Current : null);
                        }
                    }
                    else
                    {
                        Assert.IsFalse(tok.Text.Contains(StringUtils.kszObject));
                    }
                }
                Assert.IsNull(currentFootnote);
            }
        }
Beispiel #2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Creates the scripture checks and updates the annotation definitions by checking
        /// that for each check we have a corresponding annotation definition in the database.
        /// </summary>
        /// <param name="dataSource">The data source.</param>
        /// ------------------------------------------------------------------------------------
        private static SortedList <ScrCheckKey, IScriptureCheck> InstantiateChecks(
            ScrChecksDataSource dataSource)
        {
            FdoCache cache = dataSource.Cache;

            SortedList <ScrCheckKey, IScriptureCheck> scriptureChecks =
                new SortedList <ScrCheckKey, IScriptureCheck>();

            using (new SuppressSubTasks(cache))
            {
                Dictionary <Guid, ICmAnnotationDefn> errorTypes =
                    new Dictionary <Guid, ICmAnnotationDefn>();

                ICmAnnotationDefn annDefnChkError = new CmAnnotationDefn(cache,
                                                                         LangProject.kguidAnnCheckingError);

                foreach (ICmAnnotationDefn errorType in annDefnChkError.SubPossibilitiesOS)
                {
                    errorTypes[errorType.Guid] = errorType;
                }

                foreach (Type type in s_scrCheckList)
                {
                    IScriptureCheck scrCheck =
                        (IScriptureCheck)Activator.CreateInstance(type, dataSource);

                    if (scrCheck == null)
                    {
                        continue;
                    }

                    // Get the localized version of the check name
                    string scrCheckName = GetCheckProperty(ScrFdoResources.ResourceManager,
                                                           scrCheck.CheckId, "Name", scrCheck.CheckName);
                    scriptureChecks.Add(new ScrCheckKey(scrCheck.RelativeOrder, scrCheckName), scrCheck);

                    ICmAnnotationDefn chkType;
                    if (!errorTypes.TryGetValue(scrCheck.CheckId, out chkType))
                    {
                        chkType = new CmAnnotationDefn();
                        annDefnChkError.SubPossibilitiesOS.Append(chkType);
                        chkType.Guid        = scrCheck.CheckId;
                        chkType.IsProtected = true;
                        chkType.Name.UserDefaultWritingSystem = scrCheckName;
                        chkType.Description.UserDefaultWritingSystem.UnderlyingTsString =
                            StringUtils.MakeTss(scrCheck.Description, cache.DefaultUserWs);
                        chkType.HelpId = scrCheck.CheckName.Replace(' ', '_');
                        InheritAttributes(annDefnChkError, chkType);
                    }
                    else if (chkType.Name.UserDefaultWritingSystem != scrCheckName)
                    {
                        // Store the localized version of the check name as the current UI name.
                        chkType.Name.UserDefaultWritingSystem = scrCheckName;
                    }
                }
            }
            return(scriptureChecks);
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Reads the current TE scripture project.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private List <TextTokenSubstring> ReadTEScripture()
        {
            var scrDataSource = new ScrChecksDataSource(m_cache, DirectoryFinder.TeStylesPath);

            scrDataSource.LoadException += scrDataSource_LoadException;

            Assembly asm = Assembly.LoadFile(m_scrChecksDllFile);

            if (asm == null)
            {
                return(null);
            }
            Type type = asm.GetType("SILUBS.ScriptureChecks." + m_checkToRun);

            var scrCharInventoryBldr = Activator.CreateInstance(type, scrDataSource) as IScrCheckInventory;

            if (scrCharInventoryBldr == null)
            {
                return(null);
            }

            var tokens = new List <ITextToken>();
            var scr    = m_cache.LangProject.TranslatedScriptureOA;

            if (scr == null || scr.ScriptureBooksOS.Count == 0)
            {
                return(null);
            }

            foreach (var book in scr.ScriptureBooksOS)
            {
                if (scrDataSource.GetText(book.CanonicalNum, 0))
                {
                    tokens.AddRange(scrDataSource.TextTokens());
                }
            }

            foreach (KeyValuePair <string, string> kvp in m_chkParams)
            {
                scrDataSource.SetParameterValue(kvp.Key, kvp.Value);
            }

            scrDataSource.SetParameterValue("PreferredLocale", string.Empty);

            if (tokens.Count == 0)
            {
                return(null);
            }

            return(GetTokenSubstrings(scrCharInventoryBldr, tokens));
        }
Beispiel #4
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Reads the current TE scripture project.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private List <TextTokenSubstring> ReadTEScripture()
        {
            var scrDataSource = new ScrChecksDataSource(m_cache, ResourceHelper.GetResourceString("kstidPunctCheckWhitespaceChar"),
                                                        FwDirectoryFinder.LegacyWordformingCharOverridesFile, FwDirectoryFinder.TeStylesPath);

            scrDataSource.LoadException += scrDataSource_LoadException;

            IScrCheckInventory scrCharInventoryBldr = CreateScrCharInventoryBldr(FwDirectoryFinder.BasicEditorialChecksDll,
                                                                                 scrDataSource, m_checkToRun == CheckType.Punctuation ?
                                                                                 "SILUBS.ScriptureChecks.PunctuationCheck" : "SILUBS.ScriptureChecks.CharactersCheck");

            var tokens = new List <ITextToken>();
            var scr    = m_cache.LangProject.TranslatedScriptureOA;

            if (scr == null || scr.ScriptureBooksOS.Count == 0)
            {
                return(null);
            }

            foreach (var book in scr.ScriptureBooksOS)
            {
                if (scrDataSource.GetText(book.CanonicalNum, 0))
                {
                    tokens.AddRange(scrDataSource.TextTokens());
                }
            }

            foreach (KeyValuePair <string, string> kvp in m_chkParams)
            {
                scrDataSource.SetParameterValue(kvp.Key, kvp.Value);
            }

            scrDataSource.SetParameterValue("PreferredLocale", string.Empty);

            return(tokens.Count == 0 ? null : GetTokenSubstrings(scrCharInventoryBldr, tokens));
        }
		public override void Initialize()
		{
			base.Initialize();
			m_dataSource = new ScrChecksDataSource(Cache);
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Verifies that all footnotes correspond to exactly one ORC in the vernacular
		/// Scripture and that they are in the same order as they occur in Scripture.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private void VerifyNoOrphanedFootnotes()
		{
			ScrChecksDataSource scrData = new ScrChecksDataSource(Cache, ResourceHelper.GetResourceString("kstidPunctCheckWhitespaceChar"), FwDirectoryFinder.LegacyWordformingCharOverridesFile);
			foreach (IScrBook book in m_scr.ScriptureBooksOS)
			{
				using (IEnumerator<IScrFootnote> footnotes = book.FootnotesOS.GetEnumerator())
				{
					IStFootnote currentFootnote = (footnotes.MoveNext() ? footnotes.Current : null);

					scrData.GetText(book.CanonicalNum, 0);
					foreach (ITextToken tok in scrData.TextTokens())
					{
						if (tok.TextType == TextType.Note)
						{
							if (tok.IsNoteStart)
							{
								Assert.IsNotNull(currentFootnote, "No more footnotes were expected in " + book.BestUIName);
								Assert.IsTrue(((IStTxtPara)currentFootnote.ParagraphsOS[0]).Contents.Text.StartsWith(tok.Text),
									"Footnote ORC does not match next footnote in sequence (mismatched text)");
								Assert.AreEqual(currentFootnote.ParagraphsOS[0].StyleName, tok.ParaStyleName,
									"Footnote ORC does not match next footnote in sequence (mismatched style)");
								currentFootnote = (footnotes.MoveNext() ? footnotes.Current : null);
							}
						}
						else
						{
							Assert.IsFalse(tok.Text.Contains(StringUtils.kszObject));
						}
					}
					Assert.IsNull(currentFootnote);
				}
			}
		}
Beispiel #7
0
		public void RecordError_PictureCaptionToken()
		{
			ScrChecksDataSource dataSource = new ScrChecksDataSource(Cache);
			ScrCheckingToken tok = new DummyPictureCheckingToken(m_scr, Cache.DefaultUserWs, "en");

			Dictionary<int, Dictionary<Guid, ScrCheckRunResult>> bkChkFailedLst =
				new Dictionary<int, Dictionary<Guid, ScrCheckRunResult>>();
			bkChkFailedLst[tok.StartRef.Book] = new Dictionary<Guid, ScrCheckRunResult>();
			bkChkFailedLst[tok.StartRef.Book][kCheckId1] = ScrCheckRunResult.NoInconsistencies;
			ReflectionHelper.SetField(dataSource, "m_bookChecksFailed", bkChkFailedLst);

			TextTokenSubstring tts = new TextTokenSubstring(tok, 15, 9, "Weird bilingual picture caption");
			dataSource.RecordError(new RecordErrorEventArgs(tts, kCheckId1));
			IScrBookAnnotations annotations = m_scr.BookAnnotationsOS[tok.StartRef.Book - 1];
			IScrScriptureNote note = annotations.NotesOS[0];
			Assert.IsNotNull(note);
			Assert.AreEqual(NoteType.CheckingError, note.AnnotationType);
			Assert.AreEqual(m_scr, note.BeginObjectRA);
			Assert.AreEqual(m_scr, note.EndObjectRA);
			Assert.AreEqual(15, note.BeginOffset);
			Assert.AreEqual(24, note.EndOffset);
			Assert.AreEqual(0, note.CategoriesRS.Count);
			Assert.AreEqual(1, note.QuoteOA.ParagraphsOS.Count);
			ITsStrFactory factory = TsStrFactoryClass.Create();
			ITsString tssQuote = factory.MakeString("in Monroe", Cache.DefaultUserWs);
			AssertEx.AreTsStringsEqual(tssQuote, ((StTxtPara)note.QuoteOA.ParagraphsOS[0]).Contents.UnderlyingTsString);
			Assert.AreEqual(1, note.DiscussionOA.ParagraphsOS.Count);
			Assert.AreEqual("Weird bilingual picture caption", ((StTxtPara)note.DiscussionOA.ParagraphsOS[0]).Contents.Text);
			Assert.AreEqual(NoteStatus.Open, note.ResolutionStatus);
			VerifyEmptyStJournalText(note.RecommendationOA);
			VerifyEmptyStJournalText(note.ResolutionOA);
			Assert.AreEqual((int)CmPicture.CmPictureTags.kflidCaption, note.Flid);
			Assert.AreEqual(Cache.DefaultVernWs, note.WsSelector);
			Assert.AreEqual(01003034, note.BeginRef);
			Assert.AreEqual(01003034, note.EndRef);
			Assert.AreEqual(Cache.LangProject.DefaultComputerAgent, note.SourceRA);
		}
Beispiel #8
0
		public void GetTextTokens_EmptyTsStringWithMissingWs()
		{
			ScrChecksDataSource dataSource = new ScrChecksDataSource(Cache);
			int iExodus = 2;
			IScrBook exodus = m_scrInMemoryCache.AddBookToMockedScripture(iExodus, "Exodus");
			m_scrInMemoryCache.AddTitleToMockedBook(exodus.Hvo, "Exodus");
			IScrSection section = m_scrInMemoryCache.AddIntroSectionToMockedBook(exodus.Hvo);

			// Make the heading paragraph empty, and with no writing system set
			CacheBase cachebase = m_inMemoryCache.CacheAccessor;
			StTxtPara paraIntroSectHead = new StTxtPara(Cache, cachebase.NewHvo(StTxtPara.kClassId));
			cachebase.AppendToFdoVector(section.HeadingOAHvo,
				(int)StText.StTextTags.kflidParagraphs, paraIntroSectHead.Hvo);
			cachebase.SetBasicProps(paraIntroSectHead.Hvo, section.HeadingOAHvo, (int)StTxtPara.kClassId,
				(int)StText.StTextTags.kflidParagraphs, 1);
			ITsPropsFactory propFact = TsPropsFactoryClass.Create();
			paraIntroSectHead.StyleRules = propFact.MakeProps(ScrStyleNames.IntroSectionHead, 0, 0);
			ITsStrBldr strBldr = TsStrBldrClass.Create();
			strBldr.Replace(0, 0, "", null);
			paraIntroSectHead.Contents.UnderlyingTsString = strBldr.GetString();
			cachebase.SetGuid(paraIntroSectHead.Hvo, (int)CmObjectFields.kflidCmObject_Guid, Guid.NewGuid());

			// Set up the intro section contents
			StTxtPara paraIntroSectContent = m_scrInMemoryCache.AddParaToMockedText(section.ContentOAHvo,
				ScrStyleNames.IntroParagraph);
			m_scrInMemoryCache.AddRunToMockedPara(paraIntroSectContent, "There's not much to say, really.", null);
			section.AdjustReferences();

			Assert.IsTrue(dataSource.GetText(iExodus, 0));
			IEnumerator<ITextToken> tokens = dataSource.TextTokens().GetEnumerator();
			VerifyToken(tokens, "Exodus", ScrStyleNames.MainBookTitle, string.Empty, exodus.TitleOA.ParagraphsOS[0]);
			BCVRef expectedRef = new BCVRef(iExodus, 1, 0);
			VerifyToken(tokens, string.Empty, ScrStyleNames.IntroSectionHead, string.Empty, expectedRef, expectedRef,
				true, TextType.Other, null, paraIntroSectHead, (int)StTxtPara.StTxtParaTags.kflidContents);
			VerifyToken(tokens, "There's not much to say, really.", ScrStyleNames.IntroParagraph, string.Empty, paraIntroSectContent);
			Assert.IsFalse(tokens.MoveNext());
		}
Beispiel #9
0
		public void GetTextTokens_LastChapter()
		{
			ScrChecksDataSource dataSource = new ScrChecksDataSource(Cache);
			m_scrInMemoryCache.AddBookToMockedScripture(1, "Genesis");
			int iExodus = 2;
			IScrBook exodus = m_scrInMemoryCache.AddBookToMockedScripture(iExodus, "Exodus");
			m_scrInMemoryCache.AddTitleToMockedBook(exodus.Hvo, "Exodus");

			IScrSection section = m_scrInMemoryCache.AddSectionToMockedBook(exodus.Hvo);
			m_scrInMemoryCache.AddSectionHeadParaToSection(section.Hvo, "Head1", ScrStyleNames.SectionHead);
			StTxtPara para = m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo, ScrStyleNames.NormalParagraph);
			m_scrInMemoryCache.AddRunToMockedPara(para, "1", ScrStyleNames.ChapterNumber);
			m_scrInMemoryCache.AddRunToMockedPara(para, "Chapter 1 Verse 1 Text", null);
			section.AdjustReferences();

			section = m_scrInMemoryCache.AddSectionToMockedBook(exodus.Hvo);
			StTxtPara paraSectHead2 = m_scrInMemoryCache.AddSectionHeadParaToSection(section.Hvo, "Head2", ScrStyleNames.SectionHead);
			StTxtPara paraSect2Content1 = m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo, ScrStyleNames.NormalParagraph);
			m_scrInMemoryCache.AddRunToMockedPara(paraSect2Content1, "2", ScrStyleNames.ChapterNumber);
			m_scrInMemoryCache.AddRunToMockedPara(paraSect2Content1, "Chapter 2 Verse 1 Text", null);
			m_scrInMemoryCache.AddRunToMockedPara(paraSect2Content1, "2", ScrStyleNames.VerseNumber);
			m_scrInMemoryCache.AddRunToMockedPara(paraSect2Content1, "Chapter 2 Verse 2 Text ", null);
			StTxtPara paraSect2Content2 = m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo, "Line 1");
			m_scrInMemoryCache.AddRunToMockedPara(paraSect2Content2, "Selah", ScrStyleNames.Interlude);
			section.AdjustReferences();

			Assert.IsTrue(dataSource.GetText(iExodus, 2));
			IEnumerator<ITextToken> tokens = dataSource.TextTokens().GetEnumerator();
			BCVRef expectedRef = new BCVRef(iExodus, 2, 1);
			VerifyToken(tokens, "Head2", ScrStyleNames.SectionHead, string.Empty, expectedRef, true, TextType.Other, paraSectHead2);
			expectedRef.Chapter = 2;
			VerifyToken(tokens, "2", ScrStyleNames.NormalParagraph, ScrStyleNames.ChapterNumber, expectedRef, true, TextType.ChapterNumber, paraSect2Content1);
			VerifyToken(tokens, "Chapter 2 Verse 1 Text", ScrStyleNames.NormalParagraph, string.Empty, expectedRef, false, TextType.Verse, paraSect2Content1);
			expectedRef.Verse = 2;
			VerifyToken(tokens, "2", ScrStyleNames.NormalParagraph, ScrStyleNames.VerseNumber, expectedRef, false, TextType.VerseNumber, paraSect2Content1);
			VerifyToken(tokens, "Chapter 2 Verse 2 Text ", ScrStyleNames.NormalParagraph, string.Empty, expectedRef, false, TextType.Verse, paraSect2Content1);
			VerifyToken(tokens, "Selah", "Line 1", ScrStyleNames.Interlude, expectedRef, true, TextType.Verse, paraSect2Content2);
			Assert.IsFalse(tokens.MoveNext());
		}
Beispiel #10
0
		public void GetTextTokens_FirstChapter()
		{
			int iExodus = 2;
			IScrBook exodus = m_scrInMemoryCache.AddBookToMockedScripture(iExodus, "Exodus");
			m_scrInMemoryCache.AddTitleToMockedBook(exodus.Hvo, "Exodus");

			ScrChecksDataSource dataSource = new ScrChecksDataSource(Cache);
			IScrSection section = m_scrInMemoryCache.AddIntroSectionToMockedBook(exodus.Hvo);
			StTxtPara para = m_scrInMemoryCache.AddParaToMockedText(section.HeadingOAHvo,
				ScrStyleNames.IntroSectionHead);
			m_scrInMemoryCache.AddRunToMockedPara(para, "Everything you wanted to know about Exodus but were afraid to ask", null);
			para = m_scrInMemoryCache.AddParaToMockedText(section.ContentOAHvo,
				ScrStyleNames.IntroParagraph);
			m_scrInMemoryCache.AddRunToMockedPara(para, "There's not much to say, really.", null);
			section.AdjustReferences();

			section = m_scrInMemoryCache.AddSectionToMockedBook(exodus.Hvo);
			StTxtPara paraSectHead1 = m_scrInMemoryCache.AddSectionHeadParaToSection(section.Hvo, "Head1", ScrStyleNames.SectionHead);
			StTxtPara paraSect1Content = m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo, ScrStyleNames.NormalParagraph);
			m_scrInMemoryCache.AddRunToMockedPara(paraSect1Content, "1", ScrStyleNames.ChapterNumber);
			m_scrInMemoryCache.AddRunToMockedPara(paraSect1Content, "1", ScrStyleNames.VerseNumber);
			m_scrInMemoryCache.AddRunToMockedPara(paraSect1Content, "Chapter 1 Verse 1 Text", null);
			section.AdjustReferences();

			section = m_scrInMemoryCache.AddSectionToMockedBook(exodus.Hvo);
			m_scrInMemoryCache.AddSectionHeadParaToSection(section.Hvo, "Head2", ScrStyleNames.SectionHead);
			para = m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo, ScrStyleNames.NormalParagraph);
			m_scrInMemoryCache.AddRunToMockedPara(para, "2", ScrStyleNames.ChapterNumber);
			m_scrInMemoryCache.AddRunToMockedPara(para, "Chapter 2 Verse 1 Text", null);
			section.AdjustReferences();

			Assert.IsTrue(dataSource.GetText(iExodus, 1));
			IEnumerator<ITextToken> tokens = dataSource.TextTokens().GetEnumerator();
			BCVRef expectedRef = new BCVRef(iExodus, 1, 1);
			VerifyToken(tokens, "Head1", ScrStyleNames.SectionHead, string.Empty, expectedRef, true, TextType.Other, paraSectHead1);
			expectedRef = new BCVRef(iExodus, 1, 1);
			VerifyToken(tokens, "1", ScrStyleNames.NormalParagraph, ScrStyleNames.ChapterNumber, expectedRef, true, TextType.ChapterNumber, paraSect1Content);
			VerifyToken(tokens, "1", ScrStyleNames.NormalParagraph, ScrStyleNames.VerseNumber, expectedRef, false, TextType.VerseNumber, paraSect1Content);
			VerifyToken(tokens, "Chapter 1 Verse 1 Text", "Paragraph", string.Empty, expectedRef, false, TextType.Verse, paraSect1Content);
			Assert.IsFalse(tokens.MoveNext());
		}
Beispiel #11
0
		public void GetTextTokens_Chapter0()
		{
			ScrChecksDataSource dataSource = new ScrChecksDataSource(Cache);
			int iExodus = 2;
			IScrBook exodus = m_scrInMemoryCache.AddBookToMockedScripture(iExodus, "Exodus");
			m_scrInMemoryCache.AddTitleToMockedBook(exodus.Hvo, "Exodus");

			IScrSection section = m_scrInMemoryCache.AddSectionToMockedBook(exodus.Hvo);
			StTxtPara paraSectHead0 = m_scrInMemoryCache.AddSectionHeadParaToSection(section.Hvo, "Heading", ScrStyleNames.SectionHead);
			StTxtPara paraSect0Content = m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo, ScrStyleNames.NormalParagraph);
			m_scrInMemoryCache.AddRunToMockedPara(paraSect0Content, "0", ScrStyleNames.ChapterNumber);

			Assert.IsTrue(dataSource.GetText(iExodus, 0));
			IEnumerator<ITextToken> tokens = dataSource.TextTokens().GetEnumerator();
			VerifyToken(tokens, "Exodus", ScrStyleNames.MainBookTitle, string.Empty, exodus.TitleOA.ParagraphsOS[0]);

			// Skip the next token (the section head).
			tokens.MoveNext();

			// The chapter number should be the next token, and trying to get it shouldn't crash TE.
			tokens.MoveNext();
			ScrCheckingToken token = tokens.Current as ScrCheckingToken;
			Assert.AreEqual("0", token.Text);
			Assert.AreEqual(TextType.ChapterNumber, token.TextType);
		}
Beispiel #12
0
		public void RecordError_NearDuplicate_DifferByCheck()
		{
			ScrChecksDataSource dataSource = new ScrChecksDataSource(Cache);
			ICmAnnotationDefn annDefnChkError = new CmAnnotationDefn(Cache,
				LangProject.kguidAnnCheckingError);
			CmAnnotationDefn errorCheck1 = new CmAnnotationDefn();
			annDefnChkError.SubPossibilitiesOS.Append(errorCheck1);
			errorCheck1.Guid = Guid.NewGuid();
			errorCheck1.Name.UserDefaultWritingSystem = "Type 1";

			CmAnnotationDefn errorCheck2 = new CmAnnotationDefn();
			annDefnChkError.SubPossibilitiesOS.Append(errorCheck2);
			errorCheck2.Guid = Guid.NewGuid();
			errorCheck2.Name.UserDefaultWritingSystem = "Type 2";

			DummyEditorialCheck check1 = new DummyEditorialCheck(errorCheck1.Guid);
			ScrCheckingToken tok = new DummyParaCheckingToken(m_scr, Cache.DefaultVernWs, 0);
			check1.m_ErrorsToReport.Add(new DummyEditorialCheck.DummyError(tok, 5, 8, "General Error"));

			m_scrInMemoryCache.AddBookToMockedScripture(tok.StartRef.Book, "My Favorite Book");

			dataSource.GetText(tok.StartRef.Book, 0);
			dataSource.RunCheck(check1);
			IScrBookAnnotations annotations = m_scr.BookAnnotationsOS[tok.StartRef.Book - 1];
			Assert.AreEqual(1, annotations.NotesOS.Count,
				"Check 1 should add 1 error annotation");
			IScrScriptureNote origErrorAnnotation = annotations.NotesOS[0];

			DummyEditorialCheck check2 = new DummyEditorialCheck(errorCheck2.Guid);
			check2.m_ErrorsToReport.Add(new DummyEditorialCheck.DummyError(tok, 5, 8, "General Error"));

			dataSource.RunCheck(check2);
			Assert.AreEqual(2, annotations.NotesOS.Count,
				"Check 2 should add another error annotation.");
			Assert.IsTrue(annotations.NotesOS.Contains(origErrorAnnotation));
		}
Beispiel #13
0
		public void RunCheck_CorrectedErrorGetsDeleted()
		{
			ScrChecksDataSource dataSource = new ScrChecksDataSource(Cache);
			DummyEditorialCheck check = new DummyEditorialCheck(kCheckId1);
			ScrCheckingToken tok = new DummyParaCheckingToken(m_scr, Cache.DefaultVernWs, 0);
			check.m_ErrorsToReport.Add(new DummyEditorialCheck.DummyError(tok, 5, 8, "Lousy message"));

			m_scrInMemoryCache.AddBookToMockedScripture(tok.StartRef.Book, "My Favorite Book");

			dataSource.GetText(tok.StartRef.Book, 0);
			dataSource.RunCheck(check);
			IScrBookAnnotations annotations = m_scr.BookAnnotationsOS[tok.StartRef.Book - 1];
			Assert.AreEqual(1, annotations.NotesOS.Count,
				"First run of check should add 1 error annotation");
			IScrScriptureNote origErrorAnnotation = annotations.NotesOS[0];
			Assert.AreEqual("Lousy message",
				((StTxtPara)origErrorAnnotation.DiscussionOA.ParagraphsOS[0]).Contents.Text);

			check.m_ErrorsToReport.Clear();
			check.m_ErrorsToReport.Add(new DummyEditorialCheck.DummyError(tok, 5, 8, "Goofy message"));
			dataSource.RunCheck(check);
			Assert.AreEqual(1, annotations.NotesOS.Count,
				"Second run of check should delete the 'fixed' error annotation and add another error annotation.");
			IScrScriptureNote newErrorAnnotation = annotations.NotesOS[0];
			Assert.AreNotEqual(origErrorAnnotation, newErrorAnnotation);
			Assert.AreEqual("Goofy message",
				((StTxtPara)newErrorAnnotation.DiscussionOA.ParagraphsOS[0]).Contents.Text);
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Creates the scripture checks and updates the annotation definitions by checking
		/// that for each check we have a corresponding annotation definition in the database.
		/// </summary>
		/// <param name="dataSource">The data source.</param>
		/// ------------------------------------------------------------------------------------
		private static SortedList<ScrCheckKey, IScriptureCheck> InstantiateChecks(
			ScrChecksDataSource dataSource)
		{
			FdoCache cache = dataSource.Cache;

			SortedList<ScrCheckKey, IScriptureCheck> scriptureChecks =
				new SortedList<ScrCheckKey, IScriptureCheck>();

			using (new SuppressSubTasks(cache))
			{
				Dictionary<Guid, ICmAnnotationDefn> errorTypes =
					new Dictionary<Guid, ICmAnnotationDefn>();

				ICmAnnotationDefn annDefnChkError = new CmAnnotationDefn(cache,
					LangProject.kguidAnnCheckingError);

				foreach (ICmAnnotationDefn errorType in annDefnChkError.SubPossibilitiesOS)
					errorTypes[errorType.Guid] = errorType;

				foreach (Type type in s_scrCheckList)
				{
					IScriptureCheck scrCheck =
						(IScriptureCheck)Activator.CreateInstance(type, dataSource);

					if (scrCheck == null)
						continue;

					// Get the localized version of the check name
					string scrCheckName = GetCheckProperty(ScrFdoResources.ResourceManager,
						scrCheck.CheckId, "Name", scrCheck.CheckName);
					scriptureChecks.Add(new ScrCheckKey(scrCheck.RelativeOrder, scrCheckName), scrCheck);

					ICmAnnotationDefn chkType;
					if (!errorTypes.TryGetValue(scrCheck.CheckId, out chkType))
					{
						chkType = new CmAnnotationDefn();
						annDefnChkError.SubPossibilitiesOS.Append(chkType);
						chkType.Guid = scrCheck.CheckId;
						chkType.IsProtected = true;
						chkType.Name.UserDefaultWritingSystem = scrCheckName;
						chkType.Description.UserDefaultWritingSystem.UnderlyingTsString =
							StringUtils.MakeTss(scrCheck.Description, cache.DefaultUserWs);
						chkType.HelpId = scrCheck.CheckName.Replace(' ', '_');
						InheritAttributes(annDefnChkError, chkType);
					}
					else if (chkType.Name.UserDefaultWritingSystem != scrCheckName)
					{
						// Store the localized version of the check name as the current UI name.
						chkType.Name.UserDefaultWritingSystem = scrCheckName;
					}
				}
			}
			return scriptureChecks;
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Gets the installed list of scripture checks.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public static SortedList<ScrCheckKey, IScriptureCheck> GetChecks(ScrChecksDataSource dataSource)
		{
			LoadAvailableChecks();

			return InstantiateChecks(dataSource);
		}
Beispiel #16
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Reads the current TE scripture project.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private List<TextTokenSubstring> ReadTEScripture()
		{
			var scrDataSource = new ScrChecksDataSource(m_cache, ResourceHelper.GetResourceString("kstidPunctCheckWhitespaceChar"),
				FwDirectoryFinder.LegacyWordformingCharOverridesFile, FwDirectoryFinder.TeStylesPath);

			scrDataSource.LoadException += scrDataSource_LoadException;

			IScrCheckInventory scrCharInventoryBldr = CreateScrCharInventoryBldr(FwDirectoryFinder.BasicEditorialChecksDll,
				scrDataSource, m_checkToRun == CheckType.Punctuation ?
				"SILUBS.ScriptureChecks.PunctuationCheck" : "SILUBS.ScriptureChecks.CharactersCheck");

			var tokens = new List<ITextToken>();
			var scr = m_cache.LangProject.TranslatedScriptureOA;
			if (scr == null || scr.ScriptureBooksOS.Count == 0)
				return null;

			foreach (var book in scr.ScriptureBooksOS)
			{
				if (scrDataSource.GetText(book.CanonicalNum, 0))
					tokens.AddRange(scrDataSource.TextTokens());
			}

			foreach (KeyValuePair<string, string> kvp in m_chkParams)
				scrDataSource.SetParameterValue(kvp.Key, kvp.Value);

			scrDataSource.SetParameterValue("PreferredLocale", string.Empty);

			return tokens.Count == 0 ? null : GetTokenSubstrings(scrCharInventoryBldr, tokens);
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initializes a new instance of the <see cref="T:EditorialChecksControl"/> class.
		/// </summary>
		/// <param name="cache">The cache.</param>
		/// <param name="app">The app.</param>
		/// <param name="bookFilter">The book filter.</param>
		/// <param name="sCaption">The caption to use when this control is displayed as a
		/// floating window</param>
		/// <param name="sProject">The name of the current project</param>
		/// <param name="tmAdapter">TMAdapter for the main window</param>
		/// <param name="helpTopicProvider">The help topic provider.</param>
		/// ------------------------------------------------------------------------------------
		public EditorialChecksControl(FdoCache cache, IApp app, FilteredScrBooks bookFilter,
			string sCaption, string sProject, ITMAdapter tmAdapter,
			IHelpTopicProvider helpTopicProvider)
			: base(sCaption, sProject)
		{
			InitializeComponent();

			lblCheckName.Text = string.Empty;

			m_dxButtonGap = m_btnApplyFilter.Left - m_btnRunChecks.Right;
			m_dyButtonGap = pnlButtons.Padding.Top;
			m_buttonPanelHeight1 = pnlButtons.Height;
			m_buttonPanelHeight2 = m_buttonPanelHeight1 + m_btnRunChecks.Height + m_dyButtonGap;
			m_buttonPanelHeight3 = m_buttonPanelHeight2 + m_btnRunChecks.Height + m_dyButtonGap;

			m_helpTopicProvider = helpTopicProvider;
			m_app = app;
			// It's important to subscribe to this event after the previous three
			// heights are saved. Therefore, this event should not be subscribed
			// to in designer (i.e. InitializeComponent()). This fixes TE-6653.
			pnlButtons.ClientSizeChanged += pnlButtons_ClientSizeChanged;

			m_cache = cache;
			m_chkDataSource = new ScrChecksDataSource(cache, FwDirectoryFinder.TeStylesPath, FwDirectoryFinder.LegacyWordformingCharOverridesFile);

			m_bookFilter = bookFilter;
			m_bookFilter.FilterChanged += OnBookFilterChanged;
			CreateCheckingToolbar(tmAdapter);
			m_nodeTip = new ToolTip();

			m_ComboBox.HideDropDownWhenComboTextChanges = false;

			// Set the minimum allowable with for the
			// control will be based on the widest button.
			int minWidth = m_btnRunChecks.Width;
			minWidth = Math.Max(minWidth, m_btnApplyFilter.Width);
			MinimumSize = new Size(Math.Max(minWidth, m_btnHelp.Width), MinimumSize.Height);

			if (tmAdapter != null)
			{
				if (tmAdapter.MessageMediator != null)
					tmAdapter.MessageMediator.AddColleague(this);

				tmAdapter.SetContextMenuForControl(this, "cmnuEditorialChecksTree");
			}
		}
Beispiel #18
0
 public override void TestSetup()
 {
     base.TestSetup();
     m_dataSource = new ScrChecksDataSource(Cache, DirectoryFinder.TeStylesPath);
 }
Beispiel #19
0
		public void RecordError_NearDuplicate_DifferOnlyByParaHvo()
		{
			IScrBook book = m_scrInMemoryCache.AddBookToMockedScripture(1, "My Favorite Book");

			BCVRef reference = new BCVRef(1, 2, 3);

			ScrChecksDataSource dataSource = new ScrChecksDataSource(Cache);
			DummyEditorialCheck check = new DummyEditorialCheck(kCheckId1);
			ScrCheckingToken tok = new DummyParaCheckingToken(book,
				Cache.DefaultVernWs, 0, reference, reference);
			check.m_ErrorsToReport.Add(new DummyEditorialCheck.DummyError(tok, 5, 8, "Message"));

			dataSource.GetText(tok.StartRef.Book, 0);
			dataSource.RunCheck(check);

			IScrBookAnnotations annotations = m_scr.BookAnnotationsOS[tok.StartRef.Book - 1];
			Assert.AreEqual(1, annotations.NotesOS.Count,
				"First run of check should add 1 error annotation");
			IScrScriptureNote origErrorAnnotation = annotations.NotesOS[0];

			IScrDraft draft = m_scr.ArchivedDraftsOC.Add(new ScrDraft());
			draft.BooksOS.Append(book);

			Assert.AreEqual(0, m_scr.ScriptureBooksOS.Count);

			check.m_ErrorsToReport.Clear();
			IScrBook newBook = m_scrInMemoryCache.AddBookToMockedScripture(1, "My Favorite Book");

			tok = new DummyParaCheckingToken(newBook, Cache.DefaultVernWs, 0, reference, reference);
			check.m_ErrorsToReport.Add(new DummyEditorialCheck.DummyError(tok, 5, 8, "Message"));
			dataSource.RunCheck(check);
			Assert.AreEqual(1, annotations.NotesOS.Count,
				"Second run of check should add another error annotation.");
			Assert.IsTrue(annotations.NotesOS.Contains(origErrorAnnotation));
			Assert.AreEqual(newBook.Hvo, annotations.NotesOS[0].BeginObjectRAHvo);
			Assert.AreEqual(newBook.Hvo, annotations.NotesOS[0].EndObjectRAHvo);
			Assert.AreEqual(reference, annotations.NotesOS[0].BeginRef);
			Assert.AreEqual(reference, annotations.NotesOS[0].EndRef);
			Assert.AreEqual(5, annotations.NotesOS[0].BeginOffset);
			Assert.AreEqual(13, annotations.NotesOS[0].EndOffset);
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initializes a new instance of the <see cref="EditorialChecksControl"/> class.
		/// </summary>
		/// <param name="cache">The cache.</param>
		/// <param name="bookFilter">The book filter.</param>
		/// <param name="sCaption">The caption to use when this control is displayed as a
		/// floating window</param>
		/// <param name="sProject">The name of the current project</param>
		/// <param name="tmAdapter">TMAdapter for the main window</param>
		/// ------------------------------------------------------------------------------------
		public EditorialChecksControl(FdoCache cache, FilteredScrBooks bookFilter,
			string sCaption, string sProject, ITMAdapter tmAdapter)
			: base(sCaption, sProject)
		{
			InitializeComponent();

			lblCheckName.Text = string.Empty;

			m_dxButtonGap = m_btnApplyFilter.Left - m_btnRunChecks.Right;
			m_dyButtonGap = pnlButtons.Padding.Top;
			m_buttonPanelHeight1 = pnlButtons.Height;
			m_buttonPanelHeight2 = m_buttonPanelHeight1 + m_btnRunChecks.Height + m_dyButtonGap;
			m_buttonPanelHeight3 = m_buttonPanelHeight2 + m_btnRunChecks.Height + m_dyButtonGap;

			// It's important to subscribe to this event after the previous three
			// heights are saved. Therefore, this event should not be subscribed
			// to in designer (i.e. InitializeComponent()). This fixes TE-6653.
			pnlButtons.ClientSizeChanged += pnlButtons_ClientSizeChanged;

			m_cache = cache;
			m_chkDataSource = new ScrChecksDataSource(cache);

			m_bookFilter = bookFilter;
			m_bookFilter.CheckFilteredBooks();
			m_bookFilter.FilterChanged += OnBookFilterChanged;
			Content = pnlOuter;
			CreateCheckingToolbar(tmAdapter);
			m_nodeTip = new ToolTip();

			m_ComboBox.HideDropDownWhenComboTextChanges = false;

			// Set the minimum allowable with for the
			// control will be based on the widest button.
			int minWidth = m_btnRunChecks.Width;
			minWidth = Math.Max(minWidth, m_btnApplyFilter.Width);
			MinimumSize = new Size(Math.Max(minWidth, m_btnHelp.Width), MinimumSize.Height);

			m_chkHelpIds = new Dictionary<Guid, string>();
			m_chkHelpIds[StandardCheckIds.kguidCharacters] = "khtpScrChecksCharacters";
			m_chkHelpIds[StandardCheckIds.kguidChapterVerse] = "khtpScrChecksChapterVerse";
			m_chkHelpIds[StandardCheckIds.kguidMixedCapitalization] = "khtpScrChecksMixedCapitalization";
			m_chkHelpIds[StandardCheckIds.kguidRepeatedWords] = "khtpScrChecksRepeatedWords";
			m_chkHelpIds[StandardCheckIds.kguidMatchedPairs] = "khtpScrChecksMatchingPunctPairs";
			m_chkHelpIds[StandardCheckIds.kguidPunctuation] = "khtpScrChecksPunctuationPatterns";
			m_chkHelpIds[StandardCheckIds.kguidQuotations] = "khtpScrChecksQuotationMarks";
			m_chkHelpIds[StandardCheckIds.kguidCapitalization] = "khtpScrChecksCapitalization";

			if (tmAdapter != null)
			{
				if (tmAdapter.MessageMediator != null)
					tmAdapter.MessageMediator.AddColleague(this);

				tmAdapter.SetContextMenuForControl(this, "cmnuEditorialChecksTree");
			}
		}
Beispiel #21
0
		public void RecordError_NearDuplicate_DifferByCitedText()
		{
			ScrChecksDataSource dataSource = new ScrChecksDataSource(Cache);
			DummyEditorialCheck check = new DummyEditorialCheck(kCheckId1);
			ScrCheckingToken tok = new DummyParaCheckingToken(m_scr, Cache.DefaultVernWs, 0);
			check.m_ErrorsToReport.Add(new DummyEditorialCheck.DummyError(tok, 0, 4, "Message"));

			m_scrInMemoryCache.AddBookToMockedScripture(tok.StartRef.Book, "My Favorite Book");

			dataSource.GetText(tok.StartRef.Book, 0);
			dataSource.RunCheck(check);
			IScrBookAnnotations annotations = m_scr.BookAnnotationsOS[tok.StartRef.Book - 1];
			Assert.AreEqual(1, annotations.NotesOS.Count,
				"First run of check should add 1 error annotation");
			IScrScriptureNote origErrorAnnotation = annotations.NotesOS[0];

			check.m_ErrorsToReport.Add(new DummyEditorialCheck.DummyError(tok, 5, 8, "Message"));
			dataSource.RunCheck(check);
			Assert.AreEqual(2, annotations.NotesOS.Count,
				"Second run of check should add another error annotation.");
			Assert.IsTrue(annotations.NotesOS.Contains(origErrorAnnotation));
		}
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Gets the installed list of scripture checks.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public static SortedList <ScrCheckKey, IScriptureCheck> GetChecks(ScrChecksDataSource dataSource)
        {
            LoadAvailableChecks();

            return(InstantiateChecks(dataSource));
        }
Beispiel #23
0
		public void GetTextTokens_WholeBook()
		{
			ScrChecksDataSource dataSource = new ScrChecksDataSource(Cache);
			m_scrInMemoryCache.AddBookToMockedScripture(1, "Genesis");
			int iExodus = 2;
			IScrBook exodus = m_scrInMemoryCache.AddBookToMockedScripture(iExodus, "Exodus");
			m_scrInMemoryCache.AddTitleToMockedBook(exodus.Hvo, "Exodus");

			IScrSection section = m_scrInMemoryCache.AddIntroSectionToMockedBook(exodus.Hvo);
			StTxtPara paraIntroSectHead = m_scrInMemoryCache.AddParaToMockedText(section.HeadingOAHvo,
				ScrStyleNames.IntroSectionHead);
			m_scrInMemoryCache.AddRunToMockedPara(paraIntroSectHead, "Everything you wanted to know about Exodus but were afraid to ask", null);
			StTxtPara paraIntroSectContent = m_scrInMemoryCache.AddParaToMockedText(section.ContentOAHvo,
				ScrStyleNames.IntroParagraph);
			m_scrInMemoryCache.AddRunToMockedPara(paraIntroSectContent, "There's not much to say, really.", null);
			section.AdjustReferences();

			section = m_scrInMemoryCache.AddSectionToMockedBook(exodus.Hvo);
			StTxtPara paraSectHead1 = m_scrInMemoryCache.AddSectionHeadParaToSection(section.Hvo, "Head1", ScrStyleNames.SectionHead);
			StTxtPara paraSect1Content = m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo, ScrStyleNames.NormalParagraph);
			m_scrInMemoryCache.AddRunToMockedPara(paraSect1Content, "1", ScrStyleNames.ChapterNumber);
			m_scrInMemoryCache.AddRunToMockedPara(paraSect1Content, "1", ScrStyleNames.VerseNumber);
			m_scrInMemoryCache.AddRunToMockedPara(paraSect1Content, "Chapter 1 Verse 1 Text", null);
			section.AdjustReferences();

			section = m_scrInMemoryCache.AddSectionToMockedBook(exodus.Hvo);
			StTxtPara paraSectHead2 = m_scrInMemoryCache.AddSectionHeadParaToSection(section.Hvo, "Head2", ScrStyleNames.SectionHead);
			StTxtPara paraSect2Content1 = m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo, ScrStyleNames.NormalParagraph);
			m_scrInMemoryCache.AddRunToMockedPara(paraSect2Content1, "2", ScrStyleNames.ChapterNumber);
			m_scrInMemoryCache.AddRunToMockedPara(paraSect2Content1, "Chapter 2 Verse 1 Text", null);
			m_scrInMemoryCache.AddRunToMockedPara(paraSect2Content1, "2", ScrStyleNames.VerseNumber);
			m_scrInMemoryCache.AddRunToMockedPara(paraSect2Content1, "Chapter 2 Verse 2 Text ", null);
			m_scrInMemoryCache.AddRunToMockedPara(paraSect2Content1, "Wow!", "Emphasis");
			StTxtPara paraSect2Content2 = m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo, "Line 1");
			m_scrInMemoryCache.AddRunToMockedPara(paraSect2Content2, "Selah", ScrStyleNames.Interlude);
			StFootnote footnote = m_scrInMemoryCache.AddFootnote(exodus, paraSect2Content2, 5, "This is the text of the footnote");
			m_scrInMemoryCache.AddRunToMockedPara((StTxtPara)footnote.ParagraphsOS[0], "Favorite", Cache.DefaultUserWs);
			m_scrInMemoryCache.AddRunToMockedPara(paraSect2Content2, " or say, \"la\".", null);
			CmPicture pict;
			using (DummyFileMaker filemaker = new DummyFileMaker("junk.jpg", true))
			{
				ITsStrFactory factory = TsStrFactoryClass.Create();
				pict = new CmPicture(Cache, filemaker.Filename,
					factory.MakeString("Test picture caption", Cache.DefaultVernWs),
					StringUtils.LocalPictures);
				ITsStrBldr bldr = paraSect2Content2.Contents.UnderlyingTsString.GetBldr();
				pict.AppendPicture(Cache.DefaultVernWs, bldr);
				paraSect2Content2.Contents.UnderlyingTsString = bldr.GetString();
			}
			section.AdjustReferences();

			Assert.IsTrue(dataSource.GetText(iExodus, 0));
			IEnumerator<ITextToken> tokens = dataSource.TextTokens().GetEnumerator();
			VerifyToken(tokens, "Exodus", ScrStyleNames.MainBookTitle, string.Empty, exodus.TitleOA.ParagraphsOS[0]);
			VerifyToken(tokens, "Everything you wanted to know about Exodus but were afraid to ask", ScrStyleNames.IntroSectionHead, string.Empty, paraIntroSectHead);
			VerifyToken(tokens, "There's not much to say, really.", ScrStyleNames.IntroParagraph, string.Empty, paraIntroSectContent);
			BCVRef expectedRef = new BCVRef(iExodus, 1, 1);
			VerifyToken(tokens, "Head1", ScrStyleNames.SectionHead, string.Empty, expectedRef, true, TextType.Other, paraSectHead1);
			VerifyToken(tokens, "1", ScrStyleNames.NormalParagraph, ScrStyleNames.ChapterNumber, expectedRef, true, TextType.ChapterNumber, paraSect1Content);
			VerifyToken(tokens, "1", ScrStyleNames.NormalParagraph, ScrStyleNames.VerseNumber, expectedRef, false, TextType.VerseNumber, paraSect1Content);
			VerifyToken(tokens, "Chapter 1 Verse 1 Text", "Paragraph", string.Empty, expectedRef, false, TextType.Verse, paraSect1Content);
			expectedRef.Chapter = 2;
			VerifyToken(tokens, "Head2", ScrStyleNames.SectionHead, string.Empty, expectedRef, true, TextType.Other, paraSectHead2);
			VerifyToken(tokens, "2", ScrStyleNames.NormalParagraph, ScrStyleNames.ChapterNumber, expectedRef, true, TextType.ChapterNumber, paraSect2Content1);
			VerifyToken(tokens, "Chapter 2 Verse 1 Text", ScrStyleNames.NormalParagraph, string.Empty, expectedRef, false, TextType.Verse, paraSect2Content1);
			expectedRef.Verse = 2;
			VerifyToken(tokens, "2", ScrStyleNames.NormalParagraph, ScrStyleNames.VerseNumber, expectedRef, false, TextType.VerseNumber, paraSect2Content1);
			VerifyToken(tokens, "Chapter 2 Verse 2 Text ", ScrStyleNames.NormalParagraph, string.Empty, expectedRef, false, TextType.Verse, paraSect2Content1);
			VerifyToken(tokens, "Wow!", ScrStyleNames.NormalParagraph, ScrStyleNames.Emphasis, expectedRef, false, TextType.Verse, paraSect2Content1);
			VerifyToken(tokens, "Selah", "Line 1", ScrStyleNames.Interlude, expectedRef, true, TextType.Verse, paraSect2Content2);
			VerifyToken(tokens, "This is the text of the footnote", ScrStyleNames.NormalFootnoteParagraph, string.Empty,
				expectedRef, true, TextType.Note, footnote.ParagraphsOS[0]);
			VerifyToken(tokens, "Favorite", ScrStyleNames.NormalFootnoteParagraph, string.Empty, expectedRef,
				expectedRef, false, TextType.Note, "en", footnote.ParagraphsOS[0], (int)StTxtPara.StTxtParaTags.kflidContents);
			VerifyToken(tokens, " or say, \"la\".", "Line 1", string.Empty, expectedRef, false, TextType.Verse, paraSect2Content2);
			VerifyToken(tokens, "Test picture caption", ScrStyleNames.Figure, string.Empty, expectedRef, expectedRef, true, TextType.PictureCaption, null,
				pict, (int)CmPicture.CmPictureTags.kflidCaption);
			Assert.IsFalse(tokens.MoveNext());
		}
Beispiel #24
0
 public override void TestSetup()
 {
     base.TestSetup();
     m_dataSource = new ScrChecksDataSource(Cache, ResourceHelper.GetResourceString("kstidPunctCheckWhitespaceChar"),
                                            FwDirectoryFinder.LegacyWordformingCharOverridesFile, FwDirectoryFinder.TeStylesPath);
 }
Beispiel #25
0
		public void GetTextTokens_DifferentWritingSystem()
		{
			// Set valid characters for each writing system to a different set of three characters.
			// The set of valid characters will be 'ABC' for the first writing system, 'DEF' for
			// the second and so on.
			ILgWritingSystemFactory lgwsf = m_inMemoryCache.Cache.LanguageWritingSystemFactoryAccessor;
			int cWs = lgwsf.NumberOfWs;
			ArrayPtr rgWs = MarshalEx.ArrayToNative(cWs, typeof(int));
			lgwsf.GetWritingSystems(rgWs, cWs);
			int[] hvoWsArray = (int[])MarshalEx.NativeToArray(rgWs, cWs, typeof(int));
			List<string> validChars = new List<string>();
			int iWs = 0;
			int numValidChars = 3;
			for (iWs = 0; iWs < cWs; iWs++)
			{
				IWritingSystem ws = lgwsf.get_EngineOrNull(hvoWsArray[iWs]);
				StringBuilder strBldr = new StringBuilder();
				for (int iChar = 0; iChar < numValidChars; iChar++)
				{
					strBldr.Append(Encoding.ASCII.GetString(
						new byte[] { (byte)(65 + numValidChars * iWs + iChar) }));
					strBldr.Append(" ");
				}
				validChars.Add(strBldr.ToString());
				ws.ValidChars = validChars[iWs];
			}

			// Set up (minimal) Scripture data.
			int iExodus = 2;
			IScrBook exodus = m_scrInMemoryCache.AddBookToMockedScripture(iExodus, "Exodus");
			m_scrInMemoryCache.AddTitleToMockedBook(exodus.Hvo, "Exodus");

			// Get the text (and set the valid characters for each writing system).
			ScrChecksDataSource dataSource = new ScrChecksDataSource(Cache);
			dataSource.GetText(iExodus, 1);

			// Now confirm that the valid characters for the writing systems were set correctly.
			for (iWs = 0; iWs < cWs; iWs++)
			{
				IWritingSystem ws = lgwsf.get_EngineOrNull(hvoWsArray[iWs]);
				string validCharsParam = (ws.WritingSystem == Cache.DefaultVernWs) ?
					"ValidCharacters" : "ValidCharacters_" + lgwsf.GetStrFromWs(hvoWsArray[iWs]);
				Assert.AreEqual(validChars[iWs].TrimEnd(' '), dataSource.GetParameterValue(validCharsParam));
			}
		}
		public override void TestSetup()
		{
			base.TestSetup();
			m_dataSource = new ScrChecksDataSource(Cache, ResourceHelper.GetResourceString("kstidPunctCheckWhitespaceChar"),
				FwDirectoryFinder.LegacyWordformingCharOverridesFile, FwDirectoryFinder.TeStylesPath);
		}
Beispiel #27
0
		public void GetTextTokens_ChapterStartsAndEndsMidSection()
		{

			ScrChecksDataSource dataSource = new ScrChecksDataSource(Cache);
			m_scrInMemoryCache.AddBookToMockedScripture(1, "Genesis");
			int iExodus = 2;
			IScrBook exodus = m_scrInMemoryCache.AddBookToMockedScripture(iExodus, "Exodus");
			m_scrInMemoryCache.AddTitleToMockedBook(exodus.Hvo, "Exodus");

			// Section 1 starts with Chapter 1
			IScrSection section = m_scrInMemoryCache.AddSectionToMockedBook(exodus.Hvo);
			m_scrInMemoryCache.AddSectionHeadParaToSection(section.Hvo, "Head1", 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, "Chapter 1 Verse 1 Text", null);
			section.AdjustReferences();

			// Section 2 starts with Chapter 1, but also contains the start of Chapter 2
			section = m_scrInMemoryCache.AddSectionToMockedBook(exodus.Hvo);
			m_scrInMemoryCache.AddSectionHeadParaToSection(section.Hvo, "Head2", ScrStyleNames.SectionHead);
			para = m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo, ScrStyleNames.NormalParagraph);
			m_scrInMemoryCache.AddRunToMockedPara(para, "2", ScrStyleNames.VerseNumber);
			m_scrInMemoryCache.AddRunToMockedPara(para, "Chapter 1 Verse 2 Text", null);
			StTxtPara paraSect2Content2 = m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo, ScrStyleNames.NormalParagraph);
			m_scrInMemoryCache.AddRunToMockedPara(paraSect2Content2, "3", ScrStyleNames.VerseNumber);
			m_scrInMemoryCache.AddRunToMockedPara(paraSect2Content2, "Chapter 1 Verse 3 Text ", null);
			m_scrInMemoryCache.AddRunToMockedPara(paraSect2Content2, "2", ScrStyleNames.ChapterNumber);
			m_scrInMemoryCache.AddRunToMockedPara(paraSect2Content2, "1", ScrStyleNames.VerseNumber);
			m_scrInMemoryCache.AddRunToMockedPara(paraSect2Content2, "Chapter 2 Verse 1 Text", null);
			section.AdjustReferences();

			// Section 3 starts with Chapter 2, but also contains the start of Chapter 3
			section = m_scrInMemoryCache.AddSectionToMockedBook(exodus.Hvo);
			StTxtPara paraSectHead3 = m_scrInMemoryCache.AddSectionHeadParaToSection(section.Hvo, "Head3", ScrStyleNames.SectionHead);
			StTxtPara paraSect3Content = m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo, ScrStyleNames.NormalParagraph);
			m_scrInMemoryCache.AddRunToMockedPara(paraSect3Content, "More Chapter 2 Verse 1 Text ", null);
			m_scrInMemoryCache.AddRunToMockedPara(paraSect3Content, "2", ScrStyleNames.VerseNumber);
			m_scrInMemoryCache.AddRunToMockedPara(paraSect3Content, "Chapter 2 Verse 2 Text ", null);
			m_scrInMemoryCache.AddRunToMockedPara(paraSect3Content, "3", ScrStyleNames.ChapterNumber);
			m_scrInMemoryCache.AddRunToMockedPara(paraSect3Content, "Chapter 3 Verse 1 Text", null);
			section.AdjustReferences();

			Assert.IsTrue(dataSource.GetText(iExodus, 2));
			IEnumerator<ITextToken> tokens = dataSource.TextTokens().GetEnumerator();
			BCVRef expectedRef = new BCVRef(iExodus, 2, 1);
			VerifyToken(tokens, "2", ScrStyleNames.NormalParagraph, ScrStyleNames.ChapterNumber, expectedRef, false, TextType.ChapterNumber, paraSect2Content2);
			VerifyToken(tokens, "1", ScrStyleNames.NormalParagraph, ScrStyleNames.VerseNumber, expectedRef, false, TextType.VerseNumber, paraSect2Content2);
			VerifyToken(tokens, "Chapter 2 Verse 1 Text", ScrStyleNames.NormalParagraph, string.Empty, expectedRef, false, TextType.Verse, paraSect2Content2);
			VerifyToken(tokens, "Head3", ScrStyleNames.SectionHead, string.Empty, expectedRef, true, TextType.Other, paraSectHead3);
			VerifyToken(tokens, "More Chapter 2 Verse 1 Text ", ScrStyleNames.NormalParagraph, string.Empty, expectedRef, true, TextType.Verse, paraSect3Content);
			expectedRef.Verse = 2;
			VerifyToken(tokens, "2", ScrStyleNames.NormalParagraph, ScrStyleNames.VerseNumber, expectedRef, false, TextType.VerseNumber, paraSect3Content);
			VerifyToken(tokens, "Chapter 2 Verse 2 Text ", ScrStyleNames.NormalParagraph, string.Empty, expectedRef, false, TextType.Verse, paraSect3Content);
			Assert.IsFalse(tokens.MoveNext());
		}
Beispiel #28
0
		public void RecordError_DuplicateAfterAdjustingReference()
		{
			ScrChecksDataSource dataSource = new ScrChecksDataSource(Cache);
			DummyEditorialCheck check = new DummyEditorialCheck(kCheckId1);
			ScrCheckingToken tok = new DummyParaCheckingToken(m_scr, Cache.DefaultVernWs, 0);
			tok.MissingStartRef = new BCVRef(tok.StartRef);
			tok.MissingStartRef.Verse++;
			tok.MissingEndRef = new BCVRef(tok.MissingStartRef);
			tok.MissingEndRef.Verse++; // this simulates missing two verses
			check.m_ErrorsToReport.Add(new DummyEditorialCheck.DummyError(tok, 1, 1, "3"));

			m_scrInMemoryCache.AddBookToMockedScripture(tok.StartRef.Book, "My Favorite Book");

			dataSource.GetText(tok.StartRef.Book, 0);
			dataSource.RunCheck(check);
			IScrBookAnnotations annotations = m_scr.BookAnnotationsOS[tok.StartRef.Book - 1];
			Assert.AreEqual(1, annotations.NotesOS.Count,
				"First run of check should add error annotation");

			annotations.NotesOS[0].ResolutionStatus = NoteStatus.Closed;

			// Need a new token because the one above has already gotten changed.
			tok = new DummyParaCheckingToken(m_scr, Cache.DefaultVernWs, 0);
			tok.MissingStartRef = new BCVRef(tok.StartRef);
			tok.MissingStartRef.Verse++;
			tok.MissingEndRef = new BCVRef(tok.MissingStartRef);
			tok.MissingEndRef.Verse++; // this simulates missing two verses
			check.m_ErrorsToReport.Clear();
			check.m_ErrorsToReport.Add(new DummyEditorialCheck.DummyError(tok, 1, 1, "3"));

			dataSource.RunCheck(check);
			Assert.AreEqual(1, annotations.NotesOS.Count,
				"Second run of check shouldn't create a duplicate.");
			Assert.AreEqual(NoteStatus.Closed, annotations.NotesOS[0].ResolutionStatus,
				"Annotation should still be resolved/closed (ignored).");
		}
Beispiel #29
0
		public void RecordError_ParaContentsToken_SecondRun()
		{
			ScrChecksDataSource dataSource = new ScrChecksDataSource(Cache);
			ScrCheckingToken tok = new DummyParaCheckingToken(m_scr, Cache.DefaultVernWs, 10);

			Dictionary<int, Dictionary<Guid, ScrCheckRunResult>> bkChkFailedLst =
				new Dictionary<int, Dictionary<Guid, ScrCheckRunResult>>();
			bkChkFailedLst[tok.StartRef.Book] = new Dictionary<Guid, ScrCheckRunResult>();
			bkChkFailedLst[tok.StartRef.Book][kCheckId1] = ScrCheckRunResult.NoInconsistencies;
			ReflectionHelper.SetField(dataSource, "m_bookChecksFailed", bkChkFailedLst);

			TextTokenSubstring tts = new TextTokenSubstring(tok, 5, 8, "Lousy message");
			dataSource.RecordError(new RecordErrorEventArgs(tts, kCheckId1));
			IScrBookAnnotations annotations = m_scr.BookAnnotationsOS[tok.StartRef.Book - 1];
			IScrScriptureNote note = annotations.NotesOS[0];
			Assert.IsNotNull(note);
			Assert.AreEqual(NoteType.CheckingError, note.AnnotationType);
			Assert.AreEqual(m_scr, note.BeginObjectRA);
			Assert.AreEqual(m_scr, note.EndObjectRA);
			Assert.AreEqual(15, note.BeginOffset);
			Assert.AreEqual(23, note.EndOffset);
			Assert.AreEqual(0, note.CategoriesRS.Count);
			Assert.AreEqual(1, note.QuoteOA.ParagraphsOS.Count);
			ITsStrFactory factory = TsStrFactoryClass.Create();
			ITsString tssQuote = factory.MakeString("is lousy", Cache.DefaultVernWs);
			AssertEx.AreTsStringsEqual(tssQuote, ((StTxtPara)note.QuoteOA.ParagraphsOS[0]).Contents.UnderlyingTsString);
			Assert.AreEqual(1, note.DiscussionOA.ParagraphsOS.Count);
			Assert.AreEqual("Lousy message", ((StTxtPara)note.DiscussionOA.ParagraphsOS[0]).Contents.Text);
			Assert.AreEqual(NoteStatus.Open, note.ResolutionStatus);
			VerifyEmptyStJournalText(note.RecommendationOA);
			VerifyEmptyStJournalText(note.ResolutionOA);
			Assert.AreEqual((int)StTxtPara.StTxtParaTags.kflidContents, note.Flid);
			// TODO: Test this for an annotation on a CmPicture: Assert.AreEqual(0, note.WsSelector);
			Assert.AreEqual(01003034, note.BeginRef);
			Assert.AreEqual(01003034, note.EndRef);
			// TODO: Assert.AreEqual(???, note.SourceRA);
		}
Beispiel #30
0
		public void RecordError_Duplicate_SameErrorTwiceInVerse()
		{
			ScrChecksDataSource dataSource = new ScrChecksDataSource(Cache);
			DummyEditorialCheck check = new DummyEditorialCheck(kCheckId1);
			ScrCheckingToken tok = new DummyParaCheckingToken(m_scr, Cache.DefaultVernWs, 0);
			check.m_ErrorsToReport.Add(new DummyEditorialCheck.DummyError(tok, 5, 2, "Lousy message"));
			tok = new DummyParaCheckingToken(m_scr, m_inMemoryCache.Cache.DefaultVernWs, 0);
			check.m_ErrorsToReport.Add(new DummyEditorialCheck.DummyError(tok, 26, 2, "Lousy message"));

			m_scrInMemoryCache.AddBookToMockedScripture(tok.StartRef.Book, "My Favorite Book");

			dataSource.GetText(tok.StartRef.Book, 0);
			dataSource.RunCheck(check);
			IScrBookAnnotations annotations = m_scr.BookAnnotationsOS[tok.StartRef.Book - 1];
			Assert.AreEqual(2, annotations.NotesOS.Count,
				"First run of check should add two error annotations");
			Assert.AreEqual(5, annotations.NotesOS[0].BeginOffset);
			Assert.AreEqual(26, annotations.NotesOS[1].BeginOffset);
			Assert.AreEqual(28, annotations.NotesOS[1].EndOffset);

			// Change the offset of the second error (but the text is still the same at that ich, so the
			// error's key will be the same).
			check.m_ErrorsToReport[1].m_ichStart = 37;

			dataSource.RunCheck(check);
			Assert.AreEqual(2, annotations.NotesOS.Count,
				"Second run of check shouldn't create a duplicate.");
			Assert.AreEqual(5, annotations.NotesOS[0].BeginOffset,
				"Offset of first annotation shouldn't change.");
			Assert.AreEqual(37, annotations.NotesOS[1].BeginOffset,
				"Begin offset of second annotation should get updated.");
			Assert.AreEqual(39, annotations.NotesOS[1].EndOffset,
				"End offset of second annotation should get updated.");
		}
Beispiel #31
0
		public void RecordError_Duplicate()
		{
			ScrChecksDataSource dataSource = new ScrChecksDataSource(Cache);
			DummyEditorialCheck check = new DummyEditorialCheck(kCheckId1);
			ScrCheckingToken tok = new DummyParaCheckingToken(m_scr, Cache.DefaultVernWs, 0);
			check.m_ErrorsToReport.Add(new DummyEditorialCheck.DummyError(tok, 5, 8, "Lousy message"));

			m_scrInMemoryCache.AddBookToMockedScripture(tok.StartRef.Book, "My Favorite Book");

			dataSource.GetText(tok.StartRef.Book, 0);
			dataSource.RunCheck(check);
			IScrBookAnnotations annotations = m_scr.BookAnnotationsOS[tok.StartRef.Book - 1];
			Assert.AreEqual(1, annotations.NotesOS.Count,
				"First run of check should add error annotation");

			dataSource.RunCheck(check);
			Assert.AreEqual(1, annotations.NotesOS.Count,
				"Second run of check shouldn't create a duplicate.");
		}
Beispiel #32
0
		public void RunCheck_ScrCheckRunRecordsWithFixedInconsistency()
		{
			ScrChecksDataSource dataSource = new ScrChecksDataSource(Cache);
			DummyEditorialCheck check = new DummyEditorialCheck(kCheckId1);
			ScrCheckingToken tok = new DummyParaCheckingToken(m_scr, Cache.DefaultVernWs, 0);
			check.m_ErrorsToReport.Add(new DummyEditorialCheck.DummyError(tok, 5, 2, "Verbification"));

			m_scrInMemoryCache.AddBookToMockedScripture(tok.StartRef.Book, "The Book of David");

			dataSource.GetText(tok.StartRef.Book, 0);
			dataSource.RunCheck(check);
			IScrBookAnnotations annotations = m_scr.BookAnnotationsOS[tok.StartRef.Book - 1];

			Assert.AreEqual(1, annotations.ChkHistRecsOC.Count);
			Assert.AreEqual(1, annotations.NotesOS.Count);

			ScrCheckRun scr =
				new ScrCheckRun(Cache, annotations.ChkHistRecsOC.HvoArray[0]);

			Assert.AreEqual(ScrCheckRunResult.Inconsistencies, scr.Result);
			Assert.AreEqual(NoteStatus.Open, annotations.NotesOS[0].ResolutionStatus);

			check.m_ErrorsToReport.Clear();
			dataSource.RunCheck(check);

			Assert.AreEqual(1, annotations.ChkHistRecsOC.Count);
			Assert.AreEqual(0, annotations.NotesOS.Count);

			scr = new ScrCheckRun(Cache, annotations.ChkHistRecsOC.HvoArray[0]);
			Assert.AreEqual(ScrCheckRunResult.NoInconsistencies, scr.Result);
		}
Beispiel #33
0
		public void RunCheck_ScrCheckRunRecordsWithOneBookTwoChecks()
		{
			ScrChecksDataSource dataSource = new ScrChecksDataSource(Cache);
			DummyEditorialCheck check1 = new DummyEditorialCheck(kCheckId1);
			ScrCheckingToken tok = new DummyParaCheckingToken(m_scr, Cache.DefaultVernWs, 0);
			check1.m_ErrorsToReport.Add(new DummyEditorialCheck.DummyError(tok, 5, 2, "Verbification"));
			tok = new DummyParaCheckingToken(m_scr, m_inMemoryCache.Cache.DefaultVernWs, 0);
			check1.m_ErrorsToReport.Add(new DummyEditorialCheck.DummyError(tok, 26, 2, "Verbification"));

			DummyEditorialCheck check2 = new DummyEditorialCheck(kCheckId2);
			check2.m_ErrorsToReport.Add(new DummyEditorialCheck.DummyError(tok, 5, 2, "Stupid Check"));
			tok = new DummyParaCheckingToken(m_scr, m_inMemoryCache.Cache.DefaultVernWs, 0);
			check2.m_ErrorsToReport.Add(new DummyEditorialCheck.DummyError(tok, 26, 2, "Stupid Check"));

			m_scrInMemoryCache.AddBookToMockedScripture(tok.StartRef.Book, "The Book of David");

			dataSource.GetText(tok.StartRef.Book, 0);
			dataSource.RunCheck(check1);
			dataSource.RunCheck(check2);
			IScrBookAnnotations annotations = m_scr.BookAnnotationsOS[tok.StartRef.Book - 1];

			Assert.AreEqual(2, annotations.ChkHistRecsOC.Count);
			Assert.AreEqual(4, annotations.NotesOS.Count);

			ScrCheckRun scr1 =
				new ScrCheckRun(Cache, annotations.ChkHistRecsOC.HvoArray[0]);
			ScrCheckRun scr2 =
				new ScrCheckRun(Cache, annotations.ChkHistRecsOC.HvoArray[1]);

			Assert.AreEqual(ScrCheckRunResult.Inconsistencies, scr1.Result);
			Assert.AreEqual(ScrCheckRunResult.Inconsistencies, scr2.Result);
			Assert.AreEqual(NoteStatus.Open, annotations.NotesOS[0].ResolutionStatus);
			Assert.AreEqual(NoteStatus.Open, annotations.NotesOS[1].ResolutionStatus);
			Assert.AreEqual(NoteStatus.Open, annotations.NotesOS[2].ResolutionStatus);
			Assert.AreEqual(NoteStatus.Open, annotations.NotesOS[3].ResolutionStatus);

			annotations.NotesOS[0].ResolutionStatus = NoteStatus.Closed;
			annotations.NotesOS[1].ResolutionStatus = NoteStatus.Closed;
			dataSource.RunCheck(check1);

			scr1 = new ScrCheckRun(Cache, annotations.ChkHistRecsOC.HvoArray[0]);
			scr2 = new ScrCheckRun(Cache, annotations.ChkHistRecsOC.HvoArray[1]);
			Assert.AreEqual(ScrCheckRunResult.IgnoredInconsistencies, scr1.Result);
			Assert.AreEqual(ScrCheckRunResult.Inconsistencies, scr2.Result);
		}
Beispiel #34
0
 public override void Initialize()
 {
     base.Initialize();
     m_dataSource = new ScrChecksDataSource(Cache);
 }