예제 #1
0
 public void ChangingLangProjDefaultAnalysisWs_ChangesCacheDefaultAnalWs()
 {
     using (var cache = LcmCache.CreateCacheWithNewBlankLangProj(new TestProjectId(BackendProviderType.kMemoryOnly, null),
                                                                 "en", "fr", "en", m_ui, m_lcmDirectories, new LcmSettings()))
     {
         var wsEn = cache.DefaultAnalWs;
         Assert.That(cache.LangProject.DefaultAnalysisWritingSystem.Handle, Is.EqualTo(wsEn));
         CoreWritingSystemDefinition wsObjGerman = null;
         UndoableUnitOfWorkHelper.Do("undoit", "redoit", cache.ActionHandlerAccessor,
                                     () =>
         {
             WritingSystemServices.FindOrCreateWritingSystem(cache, TestDirectoryFinder.TemplateDirectory, "de", true, false, out wsObjGerman);
             Assert.That(cache.DefaultAnalWs, Is.EqualTo(wsEn));
             cache.LangProject.DefaultAnalysisWritingSystem = wsObjGerman;
             Assert.That(cache.DefaultAnalWs, Is.EqualTo(wsObjGerman.Handle));
         });
         UndoableUnitOfWorkHelper.Do("undoit", "redoit", cache.ActionHandlerAccessor,
                                     () =>
         {
             cache.LangProject.CurAnalysisWss = "en";
             Assert.That(cache.DefaultAnalWs, Is.EqualTo(wsEn));
         });
         cache.ActionHandlerAccessor.Undo();
         Assert.That(cache.DefaultAnalWs, Is.EqualTo(wsObjGerman.Handle));
         cache.ActionHandlerAccessor.Redo();
         Assert.That(cache.DefaultAnalWs, Is.EqualTo(wsEn));
     }
 }
예제 #2
0
 public void ChangingLangProjDefaultAnalysisWs_ChangesCacheDefaultAnalWs()
 {
     using (var threadHelper = new ThreadHelper())
         using (
             var cache = FdoCache.CreateCacheWithNewBlankLangProj(new TestProjectId(FDOBackendProviderType.kMemoryOnly, null),
                                                                  "en", "fr", "en", threadHelper))
         {
             var wsEn = cache.DefaultAnalWs;
             Assert.That(cache.LangProject.DefaultAnalysisWritingSystem.Handle, Is.EqualTo(wsEn));
             IWritingSystem wsObjGerman = null;
             UndoableUnitOfWorkHelper.Do("undoit", "redoit", cache.ActionHandlerAccessor,
                                         () =>
             {
                 WritingSystemServices.FindOrCreateWritingSystem(cache, "de", true, false, out wsObjGerman);
                 Assert.That(cache.DefaultAnalWs, Is.EqualTo(wsEn));
                 cache.LangProject.DefaultAnalysisWritingSystem = wsObjGerman;
                 Assert.That(cache.DefaultAnalWs, Is.EqualTo(wsObjGerman.Handle));
             });
             UndoableUnitOfWorkHelper.Do("undoit", "redoit", cache.ActionHandlerAccessor,
                                         () =>
             {
                 cache.LangProject.CurAnalysisWss = "en";
                 Assert.That(cache.DefaultAnalWs, Is.EqualTo(wsEn));
             });
             cache.ActionHandlerAccessor.Undo();
             Assert.That(cache.DefaultAnalWs, Is.EqualTo(wsObjGerman.Handle));
             cache.ActionHandlerAccessor.Redo();
             Assert.That(cache.DefaultAnalWs, Is.EqualTo(wsEn));
         }
 }
예제 #3
0
        /// <summary/>
        public void UpdateWritingSystemListField_RemovesWsCode()
        {
            int m_wsEn = Cache.WritingSystemFactory.GetWsFromStr("en");
            int m_wsFr = Cache.WritingSystemFactory.GetWsFromStr("fr");

            CoreWritingSystemDefinition enBlz;

            WritingSystemServices.FindOrCreateWritingSystem(Cache, null, "blz", false, false, out enBlz);

            var revIndex = Cache.ServiceLocator.GetInstance <IReversalIndexRepository>().FindOrCreateIndexForWs(m_wsEn);

            var entry1 = SenseOrEntryTests.CreateInterestingLexEntry(Cache);
            var msa1   = Cache.ServiceLocator.GetInstance <IMoStemMsaFactory>().Create();

            entry1.MorphoSyntaxAnalysesOC.Add(msa1);
            entry1.SensesOS.First().MorphoSyntaxAnalysisRA = msa1;

            var entry2 = SenseOrEntryTests.CreateInterestingLexEntry(Cache);
            var msa2   = Cache.ServiceLocator.GetInstance <IMoStemMsaFactory>().Create();

            entry2.MorphoSyntaxAnalysesOC.Add(msa2);
            entry2.SensesOS.First().MorphoSyntaxAnalysisRA = msa2;

            var testEntry = revIndex.FindOrCreateReversalEntry("first");

            testEntry.SensesRS.Add(entry1.SensesOS.First());
            testEntry.SensesRS.Add(entry2.SensesOS.First());

            testEntry.ReversalIndex.WritingSystem = "fr";
            testEntry.ReversalForm.set_String(m_wsFr, "fr");
            WritingSystemServices.UpdateWritingSystemFields(Cache, "fr", "blz");
            Assert.DoesNotThrow(() => WritingSystemServices.UpdateWritingSystemFields(Cache, "fr", null));
            Assert.That(testEntry.ReversalIndex.WritingSystem, Is.EqualTo("blz"));
            Assert.That(testEntry.ReversalIndex.ShortName, Is.EqualTo("Balantak"));
        }
예제 #4
0
        public void MergeWritingSystemWithStyleDefnForToWs_DoesNotConvertStyleDefinition()
        {
            CoreWritingSystemDefinition fromWs;

            WritingSystemServices.FindOrCreateWritingSystem(Cache, null, "en-NO", true, false, out fromWs);
            CoreWritingSystemDefinition toWs;

            WritingSystemServices.FindOrCreateWritingSystem(Cache, null, "en-SO", true, false, out toWs);
            EnsureAnalysisWs(new[] { fromWs, toWs });

            var style1 = Cache.ServiceLocator.GetInstance <IStStyleFactory>().Create();

            Cache.LangProject.StylesOC.Add(style1);
            var fontOverrides = new Dictionary <int, FontInfo>();
            var fontOverride  = new FontInfo();

            fontOverride.m_italic.ExplicitValue = true;
            fontOverrides[fromWs.Handle]        = fontOverride;
            fontOverride = new FontInfo();
            fontOverride.m_bold.ExplicitValue = true;
            fontOverrides[toWs.Handle]        = fontOverride;
            var bldr = TsStringUtils.MakePropsBldr();

            BaseStyleInfo.SaveFontOverridesToBuilder(fontOverrides, bldr);
            style1.Rules = bldr.GetTextProps();
            m_actionHandler.EndUndoTask();
            UndoableUnitOfWorkHelper.Do("doit", "undoit", m_actionHandler,
                                        () => WritingSystemServices.MergeWritingSystems(Cache, fromWs, toWs));
            var styleInfo    = new BaseStyleInfo(style1);
            var overrideInfo = styleInfo.OverrideCharacterStyleInfo(toWs.Handle);

            Assert.IsNotNull(overrideInfo);
            Assert.That(overrideInfo.Bold.Value, Is.True);
            Assert.That(overrideInfo.Italic.ValueIsSet, Is.False);
        }
예제 #5
0
        public void GetMagicStringAlt_TestFirstPronunciation()
        {
            CoreWritingSystemDefinition mluWs;

            WritingSystemServices.FindOrCreateWritingSystem(Cache, null, "mlu", false, false, out mluWs);
            var mluId = mluWs.Handle;
            CoreWritingSystemDefinition senWs;

            WritingSystemServices.FindOrCreateWritingSystem(Cache, null, "sen", false, false, out senWs);
            var senId = senWs.Handle;

            Cache.LangProject.CurrentPronunciationWritingSystems.Clear();
            Cache.LangProject.CurrentPronunciationWritingSystems.Add(mluWs);
            Cache.LangProject.CurrentPronunciationWritingSystems.Add(senWs);
            var entry = Cache.ServiceLocator.GetInstance <ILexEntryFactory>().Create();

            entry.CitationForm.set_String(mluId, TsStringUtils.MakeString("To'abaita", mluId));
            entry.CitationForm.set_String(senId, TsStringUtils.MakeString("Sena", senId));
            int wsId;

            //SUT magic gets first pronuciation when there is one.
            WritingSystemServices.GetMagicStringAlt(Cache, Cache.MainCacheAccessor,
                                                    WritingSystemServices.kwsFirstPronunciation, entry.Hvo, entry.CitationForm.Flid, false, out wsId);
            Assert.AreEqual(wsId, mluId, "Did not pull first pronuciation language first.");
            //SUT magic gets second pronuciation when the first is empty
            entry.CitationForm.set_String(mluId, TsStringUtils.EmptyString(mluId));             //wipe Sena
            WritingSystemServices.GetMagicStringAlt(Cache, Cache.MainCacheAccessor,
                                                    WritingSystemServices.kwsFirstPronunciation, entry.Hvo, entry.CitationForm.Flid, false, out wsId);
            Assert.AreEqual(wsId, senId, "Did not pull second pronuciation language when first was empty.");
        }
예제 #6
0
 public void ChangingLangProjDefaultVernWs_ChangesCacheDefaultVernWs()
 {
     using (
         var cache = FdoCache.CreateCacheWithNewBlankLangProj(new TestProjectId(FDOBackendProviderType.kMemoryOnly, null),
                                                              "en", "fr", "en", m_ui, FwDirectoryFinder.FdoDirectories, new FdoSettings()))
     {
         var wsFr = cache.DefaultVernWs;
         Assert.That(cache.LangProject.DefaultVernacularWritingSystem.Handle, Is.EqualTo(wsFr));
         IWritingSystem wsObjGerman = null;
         UndoableUnitOfWorkHelper.Do("undoit", "redoit", cache.ActionHandlerAccessor,
                                     () =>
         {
             WritingSystemServices.FindOrCreateWritingSystem(cache, FwDirectoryFinder.TemplateDirectory, "de", false, true, out wsObjGerman);
             Assert.That(cache.DefaultVernWs, Is.EqualTo(wsFr));
             cache.LangProject.DefaultVernacularWritingSystem = wsObjGerman;
             Assert.That(cache.DefaultVernWs, Is.EqualTo(wsObjGerman.Handle));
         });
         UndoableUnitOfWorkHelper.Do("undoit", "redoit", cache.ActionHandlerAccessor,
                                     () =>
         {
             cache.LangProject.CurVernWss = "fr";
             Assert.That(cache.DefaultVernWs, Is.EqualTo(wsFr));
         });
         cache.ActionHandlerAccessor.Undo();
         Assert.That(cache.DefaultVernWs, Is.EqualTo(wsObjGerman.Handle));
         cache.ActionHandlerAccessor.Redo();
         Assert.That(cache.DefaultVernWs, Is.EqualTo(wsFr));
     }
 }
예제 #7
0
 public void CollatorSort_DoesNotThrow()
 {
     Assert.DoesNotThrow(() =>
     {
         CoreWritingSystemDefinition fromWs;
         WritingSystemServices.FindOrCreateWritingSystem(Cache, null, "sen", false, true, out fromWs);
         Cache.LangProject.DefaultVernacularWritingSystem = fromWs;
         fromWs.DefaultCollation.Collator.GetSortKey("boom");
     });
 }
예제 #8
0
        public void ChangingLangProjDefaultPronunciationWs_ChangesCacheDefaultPronunciationWs()
        {
            using (var threadHelper = new ThreadHelper())
                using (
                    var cache = FdoCache.CreateCacheWithNewBlankLangProj(new TestProjectId(FDOBackendProviderType.kMemoryOnly, null),
                                                                         "en", "fr", "en", threadHelper))
                {
                    var wsFr = cache.DefaultPronunciationWs;
                    Assert.That(cache.LangProject.DefaultPronunciationWritingSystem.Handle, Is.EqualTo(wsFr));
                    IWritingSystem wsObjGerman  = null;
                    IWritingSystem wsObjSpanish = null;
                    UndoableUnitOfWorkHelper.Do("undoit", "redoit", cache.ActionHandlerAccessor,
                                                () =>
                    {
                        WritingSystemServices.FindOrCreateWritingSystem(cache, "de", false, true, out wsObjGerman);
                        Assert.That(cache.DefaultPronunciationWs, Is.EqualTo(wsFr));
                        cache.LangProject.DefaultVernacularWritingSystem = wsObjGerman;
                        cache.LangProject.CurrentPronunciationWritingSystems.Clear();
                        // Now it re-evaluates to the new default vernacular.
                        Assert.That(cache.DefaultPronunciationWs, Is.EqualTo(wsObjGerman.Handle));

                        // This no longer works..._IPA does not make a valid WS ID.
                        //IWritingSystem wsObjGermanIpa;
                        //WritingSystemServices.FindOrCreateWritingSystem(cache, "de__IPA", false, true, out wsObjGermanIpa);
                        //cache.LangProject.CurrentPronunciationWritingSystems.Clear();
                        //// Once there is an IPA one, we should prefer that
                        //Assert.That(cache.DefaultPronunciationWs, Is.EqualTo(wsObjGermanIpa.Handle));

                        // Unless we clear the list it does not regenerate.
                        WritingSystemServices.FindOrCreateWritingSystem(cache, "es", false, true, out wsObjSpanish);
                        // Once we've found a real pronunciation WS, changing the default vernacular should not change it.
                        Assert.That(cache.DefaultPronunciationWs, Is.EqualTo(wsObjGerman.Handle));
                    });
                    UndoableUnitOfWorkHelper.Do("undoit", "redoit", cache.ActionHandlerAccessor,
                                                () =>
                    {
                        cache.LangProject.CurPronunWss = "es";
                        Assert.That(cache.DefaultPronunciationWs, Is.EqualTo(wsObjSpanish.Handle));
                    });
                    cache.ActionHandlerAccessor.Undo();
                    Assert.That(cache.DefaultPronunciationWs, Is.EqualTo(wsObjGerman.Handle));
                    cache.ActionHandlerAccessor.Redo();
                    Assert.That(cache.DefaultPronunciationWs, Is.EqualTo(wsObjSpanish.Handle));
                }
        }
예제 #9
0
        public void GetMagicStringAlt_TestFirstAnaly()
        {
            CoreWritingSystemDefinition frWs;

            WritingSystemServices.FindOrCreateWritingSystem(Cache, null, "fr", false, false, out frWs);
            var frId = frWs.Handle;
            CoreWritingSystemDefinition enWs;

            WritingSystemServices.FindOrCreateWritingSystem(Cache, null, "en", false, false, out enWs);
            var enId = enWs.Handle;
            CoreWritingSystemDefinition ptWs;

            WritingSystemServices.FindOrCreateWritingSystem(Cache, null, "pt", false, false, out ptWs);
            var ptId = ptWs.Handle;

            Cache.LangProject.CurrentAnalysisWritingSystems.Clear();
            Cache.LangProject.AddToCurrentAnalysisWritingSystems(frWs);
            Cache.LangProject.AddToCurrentAnalysisWritingSystems(enWs);
            Cache.LangProject.AnalysisWritingSystems.Add(ptWs);
            var entry = Cache.ServiceLocator.GetInstance <ILexEntryFactory>().Create();
            var sense = Cache.ServiceLocator.GetInstance <ILexSenseFactory>().Create();

            entry.SensesOS.Add(sense);
            sense.Definition.set_String(frId, TsStringUtils.MakeString("fr", frId));
            sense.Definition.set_String(enId, TsStringUtils.MakeString("en", enId));
            sense.Definition.set_String(ptId, TsStringUtils.MakeString("pt", ptId));
            int wsId;

            //SUT magic gets first analysis when there is one.
            WritingSystemServices.GetMagicStringAlt(Cache, Cache.MainCacheAccessor,
                                                    WritingSystemServices.kwsFirstAnal, sense.Hvo, sense.Definition.Flid, false, out wsId);
            Assert.AreEqual(wsId, frId, "Did not pull first analysis language first.");
            //SUT magic gets second analysis when the first is empty
            sense.Definition.set_String(frId, TsStringUtils.EmptyString(frId));             //wipe french
            WritingSystemServices.GetMagicStringAlt(Cache, Cache.MainCacheAccessor,
                                                    WritingSystemServices.kwsFirstAnal, sense.Hvo, sense.Definition.Flid, false, out wsId);
            Assert.AreEqual(wsId, enId, "Did not pull second analysis language when first was empty.");
            //SUT magic gets non current analysis when all current analysis languages are empty
            sense.Definition.set_String(enId, TsStringUtils.EmptyString(enId));             //wipe english
            WritingSystemServices.GetMagicStringAlt(Cache, Cache.MainCacheAccessor,
                                                    WritingSystemServices.kwsFirstAnal, sense.Hvo, sense.Definition.Flid, false, out wsId);
            Assert.AreEqual(wsId, ptId, "Did not pull from non current analysis language when all current languages were empty.");
        }
예제 #10
0
            private ITsString NameOfWs(int ws)
            {
                m_wsLabel = ws;
                var            sWs = m_cache.WritingSystemFactory.GetStrFromWs(ws);
                IWritingSystem wsys;

                WritingSystemServices.FindOrCreateWritingSystem(m_cache, FwDirectoryFinder.TemplateDirectory, sWs, false, false, out wsys);
                var result = wsys.Abbreviation;

                if (string.IsNullOrEmpty(result))
                {
                    result = "??";
                }
                ITsStrBldr tsb = TsStrBldrClass.Create();

                tsb.Replace(0, 0, result, WritingSystemServices.AbbreviationTextProperties);
                tsb.SetIntPropValues(0, tsb.Length, (int)FwTextPropType.ktptWs, 0, m_wsEn);
                return(tsb.GetString());
            }
예제 #11
0
        public void MergeWritingSystem_ConvertsMultiStrings()
        {
            var entry1 = Cache.ServiceLocator.GetInstance <ILexEntryFactory>().Create();
            CoreWritingSystemDefinition fromWs;

            WritingSystemServices.FindOrCreateWritingSystem(Cache, null, "en-NO", true, false, out fromWs);
            CoreWritingSystemDefinition toWs;

            WritingSystemServices.FindOrCreateWritingSystem(Cache, null, "en-SO", true, false, out toWs);
            EnsureAnalysisWs(new [] { fromWs, toWs });
            var sense1 = Cache.ServiceLocator.GetInstance <ILexSenseFactory>().Create();

            entry1.SensesOS.Add(sense1);
            // Sense1 should be dirty: it has a gloss in the changing WS.
            sense1.Gloss.set_String(fromWs.Handle, TsStringUtils.MakeString("whatever", fromWs.Handle));
            m_actionHandler.EndUndoTask();
            UndoableUnitOfWorkHelper.Do("doit", "undoit", m_actionHandler,
                                        () => WritingSystemServices.MergeWritingSystems(Cache, fromWs, toWs));
            Assert.That(sense1.Gloss.get_String(toWs.Handle).Text, Is.EqualTo("whatever"));
        }
        public void GetMagicStringAlt_TestFirstVern()
        {
            IWritingSystem mluWs;

            WritingSystemServices.FindOrCreateWritingSystem(Cache, null, "mlu", false, false, out mluWs);
            var            mluId = mluWs.Handle;
            IWritingSystem senWs;

            WritingSystemServices.FindOrCreateWritingSystem(Cache, null, "sen", false, false, out senWs);
            var            senId = senWs.Handle;
            IWritingSystem sekWs;

            WritingSystemServices.FindOrCreateWritingSystem(Cache, null, "sek", false, false, out sekWs);
            var sekId = sekWs.Handle;

            Cache.LangProject.CurrentVernacularWritingSystems.Clear();
            Cache.LangProject.AddToCurrentVernacularWritingSystems(mluWs);
            Cache.LangProject.AddToCurrentVernacularWritingSystems(senWs);
            Cache.LangProject.VernacularWritingSystems.Add(sekWs);
            var entry = Cache.ServiceLocator.GetInstance <ILexEntryFactory>().Create();

            entry.CitationForm.set_String(mluId, Cache.TsStrFactory.MakeString("To'abaita", mluId));
            entry.CitationForm.set_String(senId, Cache.TsStrFactory.MakeString("Sena", senId));
            entry.CitationForm.set_String(sekId, Cache.TsStrFactory.MakeString("Sekani", sekId));
            int wsId;

            //SUT magic gets first vernacular when there is one.
            WritingSystemServices.GetMagicStringAlt(Cache, Cache.MainCacheAccessor,
                                                    WritingSystemServices.kwsFirstVern, entry.Hvo, entry.CitationForm.Flid, false, out wsId);
            Assert.AreEqual(wsId, mluId, "Did not pull first vernacular language first.");
            //SUT magic gets second vernacular when the first is empty
            entry.CitationForm.set_String(mluId, Cache.TsStrFactory.MakeString("", mluId));             //wipe Sena
            WritingSystemServices.GetMagicStringAlt(Cache, Cache.MainCacheAccessor,
                                                    WritingSystemServices.kwsFirstVern, entry.Hvo, entry.CitationForm.Flid, false, out wsId);
            Assert.AreEqual(wsId, senId, "Did not pull second vernacular language when first was empty.");
            //SUT magic gets non current vernacular when all current vernacular languages are empty
            entry.CitationForm.set_String(senId, Cache.TsStrFactory.MakeString("", senId));             //wipe To'abaita
            WritingSystemServices.GetMagicStringAlt(Cache, Cache.MainCacheAccessor,
                                                    WritingSystemServices.kwsFirstVernOrAnal, entry.Hvo, entry.CitationForm.Flid, false, out wsId);
            Assert.AreEqual(wsId, sekId, "Did not pull from non current vernacular language when all current languages were empty.");
        }
예제 #13
0
        public void DeleteWritingSystem()
        {
            CoreWritingSystemDefinition wsBlz;

            WritingSystemServices.FindOrCreateWritingSystem(Cache, null, "blz", false, false, out wsBlz);

            var revIndex = Cache.ServiceLocator.GetInstance <IReversalIndexRepository>().FindOrCreateIndexForWs(wsBlz.Handle);

            Cache.LangProject.LexDbOA.ReversalIndexesOC.Add(revIndex);
            var entry1 = SenseOrEntryTests.CreateInterestingLexEntry(Cache);

            var testEntry = revIndex.FindOrCreateReversalEntry("first");

            testEntry.SensesRS.Add(entry1.SensesOS.First());

            testEntry.ReversalIndex.WritingSystem = "blz";
            testEntry.ReversalForm.set_String(wsBlz.Handle, "blz");
            Assert.That(testEntry.ReversalIndex.WritingSystem, Is.EqualTo("blz"));
            WritingSystemServices.DeleteWritingSystem(Cache, wsBlz);
            Assert.IsFalse(testEntry.IsValidObject);
            Assert.IsFalse(Cache.LangProject.LexDbOA.ReversalIndexesOC.Contains(revIndex));
        }
예제 #14
0
        public void GetMagicStringAlt_TestVernInPara()
        {
            // set up project writing systems
            Cache.LangProject.CurrentVernacularWritingSystems.Clear();
            Cache.LangProject.CurrentAnalysisWritingSystems.Clear();
            CoreWritingSystemDefinition mluWs, senWs, engWs;

            WritingSystemServices.FindOrCreateWritingSystem(Cache, null, "mlu", false, true, out mluWs);
            WritingSystemServices.FindOrCreateWritingSystem(Cache, null, "sen", false, true, out senWs);
            WritingSystemServices.FindOrCreateWritingSystem(Cache, null, "en", true, false, out engWs);
            Cache.LangProject.AddToCurrentVernacularWritingSystems(mluWs);
            Cache.LangProject.AddToCurrentVernacularWritingSystems(senWs);
            Cache.LangProject.AddToCurrentAnalysisWritingSystems(engWs);
            var mluId = mluWs.Handle;
            var senId = senWs.Handle;
            var engId = engWs.Handle;

            // set up a paragraph that starts with Anal and ends with Vern
            var tssf = new TsStrFactory();
            var tssb = tssf.GetBldr();

            tssb.Append(tssf.MakeString("Analysis ", engId));
            tssb.Append(tssf.MakeString("Vernacular ", senId));
            tssb.Append(tssf.MakeString("Other Vernacular ", mluId));
            var paraBldr = Cache.ServiceLocator.GetInstance <StTxtParaBldr>();
            var stText   = Cache.ServiceLocator.GetInstance <IStTextFactory>().Create();

            Cache.ServiceLocator.GetInstance <ITextFactory>().Create().ContentsOA = stText;            // needed to put a Cache in stText
            var para = paraBldr.CreateParagraph(stText);

            para.Contents = tssb.GetString();

            // SUT
            int wsId;

            WritingSystemServices.GetMagicStringAlt(Cache, Cache.MainCacheAccessor, WritingSystemServices.kwsVernInParagraph, para.Hvo, 0, false, out wsId);
            Assert.AreEqual(senId, wsId, "The first vernacular WS in the para is 'sen'");
        }
예제 #15
0
        public void MergeWritingSystem_ConvertsLiftResidue()
        {
            CoreWritingSystemDefinition fromWs;

            WritingSystemServices.FindOrCreateWritingSystem(Cache, null, "en-NO", true, false, out fromWs);
            CoreWritingSystemDefinition toWs;

            WritingSystemServices.FindOrCreateWritingSystem(Cache, null, "en-SO", true, false, out toWs);
            EnsureAnalysisWs(new[] { fromWs, toWs });

            var entry1 = Cache.ServiceLocator.GetInstance <ILexEntryFactory>().Create();

            entry1.LiftResidue =
                "<lift-residue id=\"aj1_8ef13061-21ae-480f-b3a9-6b694e1ec3c4\" dateCreated=\"2005-11-09T02:57:45Z\" dateModified=\"2010-07-03T08:15:00Z\"><field type=\"Source Language\">"
                + "<form lang=\"en\"><text>Proto-Tai</text></form>"
                + "<form lang=\"en-NO\"><text>¥ポ¥ᄃヒ¥マᄚ│ᆵᆳ</text></form>"
                + "</field>"
                + "</lift-residue>";

            m_actionHandler.EndUndoTask();
            UndoableUnitOfWorkHelper.Do("doit", "undoit", m_actionHandler,
                                        () => WritingSystemServices.MergeWritingSystems(Cache, fromWs, toWs));
            Assert.That(entry1.LiftResidue.Contains("lang=\"en-SO\""));
        }
예제 #16
0
        public void UpdateWritingSystemTag_MarksObjectsAsDirty()
        {
            var entry0 = Cache.ServiceLocator.GetInstance <ILexEntryFactory>().Create();
            CoreWritingSystemDefinition newWs;

            WritingSystemServices.FindOrCreateWritingSystem(Cache, null, "en-NO", true, false, out newWs);
            // A string property NOT using the WS we will change.
            entry0.ImportResidue = TsStringUtils.MakeString("hello", Cache.DefaultAnalWs);
            // A multilingual one using the WS.
            entry0.LiteralMeaning.set_String(Cache.DefaultAnalWs, TsStringUtils.MakeString("whatever", Cache.DefaultAnalWs));

            var entry1 = Cache.ServiceLocator.GetInstance <ILexEntryFactory>().Create();
            var sense1 = Cache.ServiceLocator.GetInstance <ILexSenseFactory>().Create();

            entry1.SensesOS.Add(sense1);
            // Sense1 should be dirty: it has a gloss in the changing WS.
            sense1.Gloss.set_String(newWs.Handle, TsStringUtils.MakeString("whatever", newWs.Handle));

            // Entry2 should be dirty: it has a string property with a run in the changing WS.
            var entry2 = Cache.ServiceLocator.GetInstance <ILexEntryFactory>().Create();
            var bldr   = TsStringUtils.MakeString("abc ", Cache.DefaultAnalWs).GetBldr();

            bldr.ReplaceTsString(bldr.Length, bldr.Length, TsStringUtils.MakeString("def", newWs.Handle));
            var stringWithNewWs = bldr.GetString();

            entry2.ImportResidue = stringWithNewWs;

            // Sense3 should be dirty: it has a multistring string property with a run in the changing WS.
            var entry3 = Cache.ServiceLocator.GetInstance <ILexEntryFactory>().Create();
            var sense3 = Cache.ServiceLocator.GetInstance <ILexSenseFactory>().Create();

            entry3.SensesOS.Add(sense3);
            sense3.Definition.set_String(Cache.DefaultAnalWs, stringWithNewWs);

            Cache.LangProject.AnalysisWss = "en en-SU";

            m_actionHandler.EndUndoTask();
            var undoManager = Cache.ServiceLocator.GetInstance <IUndoStackManager>();

            undoManager.Save();             // makes everything non-dirty.

            var newbies   = new HashSet <ICmObjectId>();
            var dirtballs = new HashSet <ICmObjectOrSurrogate>(new ObjectSurrogateEquater());
            var goners    = new HashSet <ICmObjectId>();

            Assert.That(dirtballs.Count, Is.EqualTo(0));             // After save nothing should be dirty.

            var uowServices = Cache.ServiceLocator.GetInstance <IUnitOfWorkService>();

            uowServices.GatherChanges(newbies, dirtballs, goners);

            UndoableUnitOfWorkHelper.Do("doit", "undoit", m_actionHandler,
                                        () => WritingSystemServices.UpdateWritingSystemId(Cache, newWs, "en-SU"));

            newbies   = new HashSet <ICmObjectId>();
            dirtballs = new HashSet <ICmObjectOrSurrogate>(new ObjectSurrogateEquater());
            goners    = new HashSet <ICmObjectId>();

            uowServices.GatherChanges(newbies, dirtballs, goners);

            Assert.That(dirtballs.Contains((ICmObjectOrSurrogate)sense1));
            Assert.That(!dirtballs.Contains((ICmObjectOrSurrogate)entry0));             // make sure the implementation doesn't just dirty everything.
            Assert.That(dirtballs.Contains((ICmObjectOrSurrogate)entry2));
            Assert.That(dirtballs.Contains((ICmObjectOrSurrogate)sense3));
            Assert.That(Cache.LangProject.AnalysisWss, Is.EqualTo("en en-NO"), "should have updated WS lists");
        }
예제 #17
0
        public void UpdateWritingSystemTag_ChangesWsContent()
        {
            var entry0 = Cache.ServiceLocator.GetInstance <ILexEntryFactory>().Create();
            CoreWritingSystemDefinition newWs;

            WritingSystemServices.FindOrCreateWritingSystem(Cache, null, "en-SU", true, false, out newWs);
            // A string property NOT using the WS we will change.
            entry0.ImportResidue = TsStringUtils.MakeString("hello", Cache.DefaultAnalWs);
            // A multilingual one using the WS.
            entry0.LiteralMeaning.set_String(Cache.DefaultAnalWs, TsStringUtils.MakeString("whatever", Cache.DefaultAnalWs));

            var entry1 = Cache.ServiceLocator.GetInstance <ILexEntryFactory>().Create();
            var sense1 = Cache.ServiceLocator.GetInstance <ILexSenseFactory>().Create();

            entry1.SensesOS.Add(sense1);
            // Sense1 should be dirty: it has a gloss in the changing WS.
            sense1.Gloss.set_String(newWs.Handle, TsStringUtils.MakeString("whatever", newWs.Handle));

            // Entry2 should be dirty: it has a string property with a run in the changing WS.
            var entry2 = Cache.ServiceLocator.GetInstance <ILexEntryFactory>().Create();
            var bldr   = TsStringUtils.MakeString("abc ", Cache.DefaultAnalWs).GetBldr();

            bldr.ReplaceTsString(bldr.Length, bldr.Length, TsStringUtils.MakeString("def", newWs.Handle));
            var stringWithNewWs = bldr.GetString();

            entry2.ImportResidue = stringWithNewWs;

            // Sense3 should be dirty: it has a multistring string property with a run in the changing WS.
            var entry3 = Cache.ServiceLocator.GetInstance <ILexEntryFactory>().Create();
            var sense3 = Cache.ServiceLocator.GetInstance <ILexSenseFactory>().Create();

            entry3.SensesOS.Add(sense3);
            var styledAndNormalRunInChangingWs = TsStringUtils.MakeString("changing", newWs.Handle);

            styledAndNormalRunInChangingWs.Insert(0, TsStringUtils.MakeString("8", newWs.Handle, "Verse Number"));
            sense3.Definition.set_String(newWs.Handle, styledAndNormalRunInChangingWs);

            Cache.LangProject.AnalysisWss = "en en-SU";
            // Add Free Translation in the changing ws
            var paraBldr = Cache.ServiceLocator.GetInstance <StTxtParaBldr>();
            var stText   = Cache.ServiceLocator.GetInstance <IStTextFactory>().Create();

            Cache.ServiceLocator.GetInstance <ITextFactory>().Create().ContentsOA = stText;            // needed to put a Cache in stText
            var para = paraBldr.CreateParagraph(stText);

            para.Contents = TsStringUtils.MakeString("vernacular", Cache.DefaultVernWs);
            para.SegmentsOS[0].FreeTranslation.set_String(newWs.Handle, "Free Willy!");
            m_actionHandler.EndUndoTask();
            var undoManager = Cache.ServiceLocator.GetInstance <IUndoStackManager>();

            undoManager.Save();             // makes everything non-dirty.

            var newbies   = new HashSet <ICmObjectId>();
            var dirtballs = new HashSet <ICmObjectOrSurrogate>(new ObjectSurrogateEquater());
            var goners    = new HashSet <ICmObjectId>();

            var uowServices = Cache.ServiceLocator.GetInstance <IUnitOfWorkService>();

            Assert.That(dirtballs.Count, Is.EqualTo(0));             // After save nothing should be dirty.

            uowServices.GatherChanges(newbies, dirtballs, goners);
            int oldWsHandle = newWs.Handle;
            var tempWs      = new CoreWritingSystemDefinition("en-GB");

            newWs.Copy(tempWs);
            Cache.ServiceLocator.GetInstance <WritingSystemManager>().Set(newWs);

            UndoableUnitOfWorkHelper.Do("doit", "undoit", m_actionHandler,
                                        () => WritingSystemServices.UpdateWritingSystemId(Cache, newWs, oldWsHandle, "en-SU"));

            newbies   = new HashSet <ICmObjectId>();
            dirtballs = new HashSet <ICmObjectOrSurrogate>(new ObjectSurrogateEquater());
            goners    = new HashSet <ICmObjectId>();

            uowServices.GatherChanges(newbies, dirtballs, goners);

            Assert.That(dirtballs.Contains((ICmObjectOrSurrogate)sense1));
            Assert.That(!dirtballs.Contains((ICmObjectOrSurrogate)entry0));             // make sure the implementation doesn't just dirty everything.
            Assert.That(dirtballs.Contains((ICmObjectOrSurrogate)entry2));
            Assert.That(dirtballs.Contains((ICmObjectOrSurrogate)sense3));
            Assert.That(dirtballs.Contains((ICmObjectOrSurrogate)para.SegmentsOS[0]));
            Assert.That(Cache.LangProject.AnalysisWss, Is.EqualTo("en en-GB"), "should have updated WS lists");
        }