コード例 #1
0
        public void Persistence()
        {
            ILgWritingSystemFactory wsf = LgWritingSystemFactoryClass.Create();

            try
            {
                int wsEng = 1;
                int wsFrn = 2;
                int wsGer = 3;
                wsf.AddWritingSystem(wsEng, "en");
                wsf.AddWritingSystem(wsFrn, "fr");
                wsf.AddWritingSystem(wsGer, "de");
                InterlinLineChoices choices = new InterlinLineChoices(wsFrn, wsEng);
                MakeStandardState(choices);
                string persist = choices.Persist(wsf);
                choices = InterlinLineChoices.Restore(persist, wsf, wsFrn, wsEng);

                Assert.AreEqual(InterlinLineChoices.kflidWord, choices[0].Flid);
                Assert.AreEqual(InterlinLineChoices.kflidMorphemes, choices[1].Flid);
                Assert.AreEqual(InterlinLineChoices.kflidLexEntries, choices[2].Flid);
                Assert.AreEqual(InterlinLineChoices.kflidLexGloss, choices[3].Flid);
                Assert.AreEqual(InterlinLineChoices.kflidLexPos, choices[4].Flid);
                Assert.AreEqual(InterlinLineChoices.kflidWordGloss, choices[5].Flid);
                Assert.AreEqual(InterlinLineChoices.kflidWordPos, choices[6].Flid);
                Assert.AreEqual(InterlinLineChoices.kflidFreeTrans, choices[7].Flid);
                Assert.AreEqual(InterlinLineChoices.kflidLitTrans, choices[8].Flid);

                // Check writing systems assigned by default.
                Assert.AreEqual(wsFrn, choices[0].WritingSystem);
                Assert.AreEqual(wsEng, choices[5].WritingSystem);
                Assert.AreEqual(wsFrn, choices[2].WritingSystem);

                choices = new EditableInterlinLineChoices(0, wsEng);
                MakeStandardState(choices);
                choices.Add(InterlinLineChoices.kflidLexGloss, wsGer);
                Assert.AreEqual(InterlinLineChoices.kflidWord, choices[0].Flid);
                Assert.AreEqual(InterlinLineChoices.kflidMorphemes, choices[1].Flid);
                Assert.AreEqual(InterlinLineChoices.kflidLexEntries, choices[2].Flid);
                Assert.AreEqual(InterlinLineChoices.kflidLexGloss, choices[3].Flid);
                Assert.AreEqual(InterlinLineChoices.kflidLexGloss, choices[4].Flid);
                Assert.AreEqual(InterlinLineChoices.kflidLexPos, choices[5].Flid);
                Assert.AreEqual(InterlinLineChoices.kflidWordGloss, choices[6].Flid);
                Assert.AreEqual(InterlinLineChoices.kflidWordPos, choices[7].Flid);
                Assert.AreEqual(InterlinLineChoices.kflidFreeTrans, choices[8].Flid);
                Assert.AreEqual(InterlinLineChoices.kflidLitTrans, choices[9].Flid);

                Assert.AreEqual(wsGer, choices[4].WritingSystem);
            }
            finally
            {
                // we must shutdown and marshal this or else it could mess up other tests.
                wsf.Shutdown();
                System.Runtime.InteropServices.Marshal.ReleaseComObject(wsf);
            }
        }