Exemple #1
0
        GetHyperlinksInFolder_changeOfPlatform_helper(string origPathSetInDatabase,
                                                      string newPlatformStyleLookupPath, string newPlatformStyleResultToVerify)
        {
            // When running on Windows, call "foreign"="Linux" and "current"="Windows".
            // When running on Linux, call "foreign"="Windows" and "current"="Linux".

            var entry = MakeEntry("kick", "hit with foot");
            // Foreign-style path is set by a foreign-platform FieldWorks
            var        link      = origPathSetInDatabase;
            ITsString  tss       = TsStringUtils.MakeString("This here is a link", Cache.DefaultAnalWs);
            ITsStrBldr bldr      = tss.GetBldr();
            var        linkStyle = MakeStyle("testStyle");

            StringServices.MarkTextInBldrAsHyperlink(bldr, 5, 9, link, linkStyle);
            entry.LiteralMeaning.AnalysisDefaultWritingSystem = bldr.GetString();

            // Now current-platform FieldWorks opens and reads the database created by a
            // foreign-platform FieldWorks, and needs to respond to currentOS-style path lookups
            // that match foreign-style stored paths.
            var hyperlinkInfo = StringServices.GetHyperlinksInFolder(Cache, newPlatformStyleLookupPath);

            // There should be one hyperlink, and with the proper path.
            Assert.That(hyperlinkInfo, Has.Count.EqualTo(1),
                        "Should have found hyperlink despite different platform style path being used during lookup");
            var relPath = newPlatformStyleResultToVerify;

            VerifyHyperlinkInfo(hyperlinkInfo, entry, LexEntryTags.kflidLiteralMeaning, Cache.DefaultAnalWs, 5, 9, relPath);
            return(new Tuple <List <StringServices.LinkOccurrence>, ILexEntry>(hyperlinkInfo, entry));
        }
Exemple #2
0
        /// <summary>
        /// Helper method for FixHyperlinkFolder_linkTextSameAsLink_isUpdated and
        /// FixHyperlinkFolder_linkTextSameAsLinkDespiteChangeOfPlatform_linkTextIsUpdated.
        /// </summary>
        private void FixHyperlinkFolder_linkTextSameAsLink_helper(string origPathSetInDatabase,
                                                                  string lookupPath, string lookupResultToVerify, string pathToRebaseFrom,
                                                                  string pathToRebaseTo, string rebasedPathToVerify)
        {
            var entry = MakeEntry("kick", "hit with foot");

            var       link          = origPathSetInDatabase;
            ITsString paragraph     = TsStringUtils.MakeString("abc" + link + "def", Cache.DefaultAnalWs);
            var       linkBeginning = "abc".Length;
            var       linkEnding    = linkBeginning + link.Length;
            var       bldr          = paragraph.GetBldr();
            var       linkStyle     = MakeStyle("testStyle");

            StringServices.MarkTextInBldrAsHyperlink(bldr, linkBeginning, linkEnding, link, linkStyle);
            entry.LiteralMeaning.AnalysisDefaultWritingSystem = bldr.GetString();

            var hyperlinkInfo = StringServices.GetHyperlinksInFolder(Cache, lookupPath);

            // There should be one hyperlink, and with the proper path.
            Assert.That(hyperlinkInfo, Has.Count.EqualTo(1), "Mistake in unit test");
            var relPath = lookupResultToVerify;

            VerifyHyperlinkInfo(hyperlinkInfo, entry, LexEntryTags.kflidLiteralMeaning,
                                Cache.DefaultAnalWs, linkBeginning, linkEnding, relPath);
            VerifyObjData(entry.LiteralMeaning.AnalysisDefaultWritingSystem, linkBeginning,
                          linkEnding, link);

            // Update links
            StringServices.FixHyperlinkFolder(hyperlinkInfo, pathToRebaseFrom, pathToRebaseTo);
            VerifyHyperlinkInfo(hyperlinkInfo, entry, LexEntryTags.kflidLiteralMeaning,
                                Cache.DefaultAnalWs, linkBeginning, linkEnding, lookupResultToVerify);

            // Check that link text was updated, not just its link

            VerifyObjData(entry.LiteralMeaning.AnalysisDefaultWritingSystem, linkBeginning,
                          linkBeginning + rebasedPathToVerify.Length, rebasedPathToVerify);

            var       linkInfo   = hyperlinkInfo.First();
            var       obj        = linkInfo.Object;
            var       domainData = obj.Cache.DomainDataByFlid;
            ITsString updatedParagraph;

            if (linkInfo.Ws == 0)
            {
                updatedParagraph = domainData.get_StringProp(obj.Hvo, linkInfo.Flid);
            }
            else
            {
                updatedParagraph = domainData.get_MultiStringAlt(obj.Hvo, linkInfo.Flid, linkInfo.Ws);
            }
            Assert.That(updatedParagraph.Text, Is.EqualTo("abc" + rebasedPathToVerify + "def"),
                        "Link text was not updated properly");
        }
Exemple #3
0
        public void GetHyperlinksInFolder()
        {
            // Test cases cover multistring, regular string, two matches in same string, and a link that doesn't match.
            var        entry     = MakeEntry("kick", "hit with foot");
            var        link      = FileUtils.ChangeWindowsPathIfLinux(@"c:\testlangproj\linkedFiles\other\Myfile.wav");
            ITsString  tss       = TsStringUtils.MakeString("This here is a link", Cache.DefaultAnalWs);
            ITsStrBldr bldr      = tss.GetBldr();
            var        linkStyle = MakeStyle("testStyle");

            StringServices.MarkTextInBldrAsHyperlink(bldr, 5, 9, link, linkStyle);
            entry.LiteralMeaning.AnalysisDefaultWritingSystem = bldr.GetString();

            var para = MakeSimpleText("OneTwoSix");

            bldr = para.Contents.GetBldr();
            StringServices.MarkTextInBldrAsHyperlink(bldr, 0, 3, link, linkStyle);
            StringServices.MarkTextInBldrAsHyperlink(bldr, 3, 6, "This is a link but not matching", linkStyle);
            StringServices.MarkTextInBldrAsHyperlink(bldr, 6, 9, link, linkStyle);
            para.Contents = bldr.GetString();

            var para2 = MakeSimpleText("ab" + link + "cd" + link + "ef");

            bldr = para2.Contents.GetBldr();
            StringServices.MarkTextInBldrAsHyperlink(bldr, 2, link.Length + 2, link, linkStyle);
            StringServices.MarkTextInBldrAsHyperlink(bldr, 4 + link.Length, 4 + 2 * link.Length, link, linkStyle);
            para2.Contents = bldr.GetString();

            var hyperlinkInfo = StringServices.GetHyperlinksInFolder(Cache, FileUtils.ChangeWindowsPathIfLinux(@"c:\testlangproj\linkedFiles"));

            Assert.That(hyperlinkInfo, Has.Count.EqualTo(5), "should find all four matching links but not the other one");
            var relPath = FileUtils.ChangeWindowsPathIfLinux(@"other\Myfile.wav");

            VerifyHyperlinkInfo(hyperlinkInfo, entry, LexEntryTags.kflidLiteralMeaning, Cache.DefaultAnalWs, 5, 9, relPath);
            VerifyHyperlinkInfo(hyperlinkInfo, para, StTxtParaTags.kflidContents, 0, 0, 3, relPath);
            VerifyHyperlinkInfo(hyperlinkInfo, para, StTxtParaTags.kflidContents, 0, 6, 9, relPath);
            VerifyHyperlinkInfo(hyperlinkInfo, para2, StTxtParaTags.kflidContents, 0, 2, link.Length + 2, relPath);
            VerifyHyperlinkInfo(hyperlinkInfo, para2, StTxtParaTags.kflidContents, 0, 4 + link.Length, 4 + 2 * link.Length, relPath);

            StringServices.FixHyperlinkFolder(hyperlinkInfo, FileUtils.ChangeWindowsPathIfLinux(@"c:\testlangproj\linkedFiles"), FileUtils.ChangeWindowsPathIfLinux(@"c:\testlangproj\externalLinks"));
            var newText = FileUtils.ChangeWindowsPathIfLinux(@"c:\testlangproj\externalLinks\other\Myfile.wav");

            VerifyObjData(entry.LiteralMeaning.AnalysisDefaultWritingSystem, 5, 9, FileUtils.ChangeWindowsPathIfLinux(@"c:\testlangproj\externalLinks\other\Myfile.wav"));
            VerifyObjData(para.Contents, 0, 3, newText);
            VerifyObjData(para.Contents, 6, 9, newText);
            Assert.That(para2.Contents.Text, Is.EqualTo("ab" + newText + "cd" + newText + "ef"));
            VerifyObjData(para2.Contents, 2, newText.Length + 2, newText);
            VerifyObjData(para2.Contents, 4 + newText.Length, 4 + 2 * newText.Length, newText);
        }