public void MergeOwningAtomic() { CheckDisposed(); // 23 LexEntry.Pronunciation:LexPronunciation ILexEntry lmeKeeper = m_entriesCol.Add(new LexEntry()); ILexEntry lmeSrc = m_entriesCol.Add(new LexEntry()); // Merge content into null target. lmeSrc.LexemeFormOA = new MoStemAllomorph(); lmeKeeper.MergeObject(lmeSrc); //Assert.IsNull(lmeSrc.LexemeFormOA); // Try to merge content into content. lmeKeeper.LexemeFormOA = new MoStemAllomorph(); int hvoKeeper = lmeKeeper.LexemeFormOAHvo; lmeSrc = m_entriesCol.Add(new LexEntry()); lmeSrc.LexemeFormOA = new MoStemAllomorph(); int hvoSrc = lmeSrc.LexemeFormOAHvo; lmeKeeper.MergeObject(lmeSrc); Assert.AreEqual(hvoKeeper, lmeKeeper.LexemeFormOAHvo); //Assert.AreEqual(hvoSrc, lmeSrc.LexemeFormOAHvo); // Try to merge null into content. lmeKeeper.LexemeFormOA = new MoStemAllomorph(); hvoKeeper = lmeKeeper.LexemeFormOAHvo; lmeSrc = m_entriesCol.Add(new LexEntry()); lmeSrc.LexemeFormOA = null; lmeKeeper.MergeObject(lmeSrc); Assert.AreEqual(hvoKeeper, lmeKeeper.LexemeFormOAHvo); }
public void MergeOwningCollection() { CheckDisposed(); // 25 LexEntry.MorphoSyntaxAnalyses ILexEntry lmeKeeper = m_entriesCol.Add(new LexEntry()); ILexEntry lmeSrc = m_entriesCol.Add(new LexEntry()); FdoOwningSequence<ICmPossibility> posSeq = Cache.LangProject.PartsOfSpeechOA.PossibilitiesOS; posSeq.Append(new PartOfSpeech()); posSeq.Append(new PartOfSpeech()); // Merge content into null. IMoStemMsa msaSrc = (IMoStemMsa)lmeSrc.MorphoSyntaxAnalysesOC.Add(new MoStemMsa()); msaSrc.PartOfSpeechRA = (IPartOfSpeech)posSeq[0]; lmeKeeper.MergeObject(lmeSrc); Assert.AreEqual(1, lmeKeeper.MorphoSyntaxAnalysesOC.Count); Assert.AreEqual(msaSrc.Hvo, lmeKeeper.MorphoSyntaxAnalysesOC.HvoArray[0]); // Merge content into content. lmeSrc = m_entriesCol.Add(new LexEntry()); IMoStemMsa msaSrc2 = (IMoStemMsa)lmeSrc.MorphoSyntaxAnalysesOC.Add(new MoStemMsa()); msaSrc2.PartOfSpeechRA = (IPartOfSpeech)posSeq[1]; lmeKeeper.MergeObject(lmeSrc); Assert.AreEqual(2, lmeKeeper.MorphoSyntaxAnalysesOC.Count); }
public void MergeAppendAtomic() { CheckDisposed(); int engWs = Cache.LanguageEncodings.GetWsFromIcuLocale("en"); ILexEntry lmeKeeper = m_entriesCol.Add(new LexEntry()); MoStemAllomorph amKeeper = new MoStemAllomorph(); lmeKeeper.LexemeFormOA = amKeeper; ILexEntry lmeSrc = m_entriesCol.Add(new LexEntry()); MoStemAllomorph amSrc = new MoStemAllomorph(); lmeSrc.LexemeFormOA = amSrc; string oldForm = "old form"; string newForm = "new form"; amKeeper.Form.SetAlternative(oldForm, engWs); amSrc.Form.SetAlternative(newForm, engWs); lmeKeeper.MergeObject(lmeSrc, true); Assert.AreEqual(oldForm + ' ' + newForm, amKeeper.Form.GetAlternative(engWs)); // Nothing should happen if the child objects are of different types. MoAffixAllomorph maa = new MoAffixAllomorph(); lmeSrc = m_entriesCol.Add(new LexEntry()); lmeSrc.LexemeFormOA = maa; maa.Form.SetAlternative(newForm, engWs); amKeeper.Form.SetAlternative(oldForm, engWs); lmeKeeper.MergeObject(lmeSrc, true); Assert.AreEqual(oldForm, amKeeper.Form.GetAlternative(engWs)); }
public void MergeTimes() { CheckDisposed(); // Use LexEntry.DateModified. ILexEntry lmeKeeper = m_entriesCol.Add(new LexEntry()); ILexEntry lmeSrc = m_entriesCol.Add(new LexEntry()); // We have to change something else - otherwise the merge won't change any data. lmeKeeper.ExcludeAsHeadword = false; lmeSrc.ExcludeAsHeadword = true; // This one gets set to 'now' in the MergeObject method, // so we don't know what it will end up being, except newer than lmeSrc.DateModified. lmeKeeper.DateModified = new DateTime(2005, 3, 31, 15, 50, 0); lmeSrc.DateModified = new DateTime(2005, 3, 31, 15, 59, 59); DateTime srcTime = lmeSrc.DateModified; lmeKeeper.MergeObject(lmeSrc); Assert.IsTrue(lmeKeeper.DateModified > srcTime, "Wrong modified time for DateModified (T-#1)."); lmeSrc = m_entriesCol.Add(new LexEntry()); lmeSrc.DateModified = new DateTime(2005, 3, 31, 15, 50, 0); DateTime mod = lmeSrc.DateModified; lmeKeeper.DateModified = new DateTime(2005, 3, 31, 15, 59, 59); lmeKeeper.MergeObject(lmeSrc); Assert.IsTrue(lmeKeeper.DateModified > mod, "Wrong modified time for DateModified (T-#2)."); lmeSrc = m_entriesCol.Add(new LexEntry()); DateTime dt = new DateTime(2005, 3, 31, 15, 59, 59); lmeSrc.DateCreated = DateTime.Now; lmeKeeper.DateCreated = new DateTime(2005, 3, 31, 15, 59, 59); lmeKeeper.MergeObject(lmeSrc); Assert.IsTrue(lmeKeeper.DateCreated.Equals(dt), "Wrong created time for DateModified (T-#3)."); }
public void MergeIntegers() { CheckDisposed(); // Use LexEntry.HomographNumber. ILexEntry lmeKeeper = m_entriesCol.Add(new LexEntry()); ILexEntry lmeSrc = m_entriesCol.Add(new LexEntry()); lmeKeeper.HomographNumber = 0; lmeSrc.HomographNumber = 1; lmeKeeper.MergeObject(lmeSrc); Assert.AreEqual(1, lmeKeeper.HomographNumber); lmeKeeper.HomographNumber = 1; lmeSrc = m_entriesCol.Add(new LexEntry()); lmeSrc.HomographNumber = 2; lmeKeeper.MergeObject(lmeSrc); Assert.AreEqual(1, lmeKeeper.HomographNumber); lmeKeeper.HomographNumber = 1; lmeSrc = m_entriesCol.Add(new LexEntry()); lmeSrc.HomographNumber = 0; lmeKeeper.MergeObject(lmeSrc); Assert.AreEqual(1, lmeKeeper.HomographNumber); lmeKeeper.HomographNumber = 0; lmeSrc = m_entriesCol.Add(new LexEntry()); lmeSrc.HomographNumber = 0; lmeKeeper.MergeObject(lmeSrc); Assert.AreEqual(0, lmeKeeper.HomographNumber); }
public void MergeBooleans() { CheckDisposed(); // Use LexEntry.ExcludeAsHeadword ILexEntry lmeKeeper = m_entriesCol.Add(new LexEntry()); ILexEntry lmeSrc = m_entriesCol.Add(new LexEntry()); lmeKeeper.ExcludeAsHeadword = false; lmeSrc.ExcludeAsHeadword = false; lmeKeeper.MergeObject(lmeSrc); Assert.IsFalse(lmeKeeper.ExcludeAsHeadword); lmeKeeper.ExcludeAsHeadword = false; lmeSrc = m_entriesCol.Add(new LexEntry()); lmeSrc.ExcludeAsHeadword = true; lmeKeeper.MergeObject(lmeSrc); Assert.IsTrue(lmeKeeper.ExcludeAsHeadword); lmeKeeper.ExcludeAsHeadword = true; lmeSrc = m_entriesCol.Add(new LexEntry()); lmeSrc.ExcludeAsHeadword = true; lmeKeeper.MergeObject(lmeSrc); Assert.IsTrue(lmeKeeper.ExcludeAsHeadword); lmeKeeper.ExcludeAsHeadword = true; lmeSrc = m_entriesCol.Add(new LexEntry()); lmeSrc.ExcludeAsHeadword = false; lmeKeeper.MergeObject(lmeSrc); Assert.IsTrue(lmeKeeper.ExcludeAsHeadword); }
public void MergeMultiUnicode() { CheckDisposed(); // 16 LexEntry.CitationForm // 20 Not used in database. string eng = "dog"; string es = "perro"; int engWs = Cache.LanguageEncodings.GetWsFromIcuLocale("en"); int esWs = Cache.LanguageEncodings.GetWsFromIcuLocale("es"); ILexEntry lmeKeeper = m_entriesCol.Add(new LexEntry()); ILexEntry lmeSrc = m_entriesCol.Add(new LexEntry()); // Merge content into null alternatives lmeSrc.CitationForm.SetAlternative(eng, engWs); lmeKeeper.MergeObject(lmeSrc); Assert.AreEqual(lmeKeeper.CitationForm.GetAlternative(engWs), eng); // Try to merge empty string into null content. lmeKeeper.CitationForm.SetAlternative(null, engWs); lmeSrc = m_entriesCol.Add(new LexEntry()); lmeSrc.CitationForm.SetAlternative("", engWs); Assert.IsNull(lmeKeeper.CitationForm.GetAlternative(engWs)); // Merge content into empty string. lmeKeeper.CitationForm.SetAlternative("", engWs); // This actually sets the content to null, not an empty string. lmeSrc = m_entriesCol.Add(new LexEntry()); lmeSrc.CitationForm.SetAlternative(eng, engWs); lmeKeeper.MergeObject(lmeSrc); Assert.AreEqual(lmeKeeper.CitationForm.GetAlternative(engWs), eng); // Try to merge into existing content. lmeKeeper.CitationForm.SetAlternative(eng, engWs); lmeSrc = m_entriesCol.Add(new LexEntry()); lmeSrc.CitationForm.SetAlternative("cat", engWs); lmeKeeper.MergeObject(lmeSrc); Assert.AreEqual(lmeKeeper.CitationForm.GetAlternative(engWs), eng); // Make sure extant content isn't wrecked. lmeKeeper.CitationForm.SetAlternative(eng, engWs); lmeSrc = m_entriesCol.Add(new LexEntry()); lmeSrc.CitationForm.SetAlternative(es, esWs); lmeKeeper.MergeObject(lmeSrc); Assert.AreEqual(lmeKeeper.CitationForm.GetAlternative(engWs), eng); Assert.AreEqual(lmeKeeper.CitationForm.GetAlternative(esWs), es); }
private bool RunMergeEntryDialog(object argument, bool fLoseNoTextData) { ICmObject obj = m_mediator.PropertyTable.GetValue("ActiveClerkSelectedObject") as ICmObject; Debug.Assert(obj != null); if (obj == null) { return(false); // should never happen, but nothing we can do if it does! } FdoCache cache = (FdoCache)m_mediator.PropertyTable.GetValue("cache"); Debug.Assert(cache != null); Debug.Assert(cache == obj.Cache); ILexEntry currentEntry = obj as ILexEntry; if (currentEntry == null) { int hvoEntry = cache.GetOwnerOfObjectOfClass(obj.Hvo, LexEntry.kclsidLexEntry); if (hvoEntry != 0) { currentEntry = LexEntry.CreateFromDBObject(cache, hvoEntry); } } Debug.Assert(currentEntry != null); if (currentEntry == null) { return(false); } using (MergeEntryDlg dlg = new MergeEntryDlg()) { Debug.Assert(argument != null && argument is XCore.Command); dlg.SetDlgInfo(cache, m_mediator, currentEntry); if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { int entryID = dlg.SelectedID; ILexEntry survivor = LexEntry.CreateFromDBObject(cache, entryID); Debug.Assert(survivor != currentEntry); cache.BeginUndoTask(SIL.FieldWorks.LexText.Controls.LexTextControls.ksUndoMergeEntry, SIL.FieldWorks.LexText.Controls.LexTextControls.ksRedoMergeEntry); // If lexeme forms differ, make the source lexeme form an allomorph of the target entry. if (survivor.LexemeFormOA.Form.VernacularDefaultWritingSystem != currentEntry.LexemeFormOA.Form.VernacularDefaultWritingSystem) { survivor.AlternateFormsOS.Append(currentEntry.LexemeFormOA.Hvo); } survivor.MergeObject(currentEntry, fLoseNoTextData); cache.EndUndoTask(); survivor.DateModified = DateTime.Now; MessageBox.Show(null, SIL.FieldWorks.LexText.Controls.LexTextControls.ksEntriesHaveBeenMerged, SIL.FieldWorks.LexText.Controls.LexTextControls.ksMergeReport, MessageBoxButtons.OK, MessageBoxIcon.Information); m_mediator.SendMessage("JumpToRecord", entryID); } } return(true); }
public void MergeOwningSequence() { CheckDisposed(); // 27 LexEntry.Senses ILexEntry lmeKeeper = m_entriesCol.Add(new LexEntry()); ILexEntry lmeSrc = m_entriesCol.Add(new LexEntry()); // Merge content into null. lmeSrc.SensesOS.Append(new LexSense()); lmeKeeper.MergeObject(lmeSrc); Assert.AreEqual(1, lmeKeeper.SensesOS.Count); // Merge content into content. lmeSrc = m_entriesCol.Add(new LexEntry()); lmeSrc.SensesOS.Append(new LexSense()); lmeKeeper.MergeObject(lmeSrc); Assert.AreEqual(2, lmeKeeper.SensesOS.Count); // Merge null into content. lmeSrc = m_entriesCol.Add(new LexEntry()); lmeKeeper.MergeObject(lmeSrc); Assert.AreEqual(2, lmeKeeper.SensesOS.Count); }
public void MergeMultiStrings() { CheckDisposed(); // 14 Use LexEntry.Bibliography string eng = "English Bib. Info"; string es = "Inf. Bib. Esp."; int engWs = Cache.LanguageEncodings.GetWsFromIcuLocale("en"); int esWs = Cache.LanguageEncodings.GetWsFromIcuLocale("es"); ILexEntry lmeKeeper = m_entriesCol.Add(new LexEntry()); ILexEntry lmeSrc = m_entriesCol.Add(new LexEntry()); ITsPropsBldr propsBldr = TsPropsBldrClass.Create(); propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, engWs); ITsTextProps ttpEng = propsBldr.GetTextProps(); ITsStrBldr tsb = TsStrBldrClass.Create(); ITsString tssEmpty = tsb.GetString(); tsb.Replace(0, 0, eng, ttpEng); tsb.SetIntPropValues(7, 10, (int) FwTextPropType.ktptForeColor, (int)FwTextPropVar.ktpvDefault, 50); ITsString tssEng = tsb.GetString(); string append = "Append"; ITsStrBldr tsb2 = TsStrBldrClass.Create(); tsb2.Replace(0, 0, append, ttpEng); tsb2.SetIntPropValues(2, 4, (int) FwTextPropType.ktptForeColor, (int)FwTextPropVar.ktpvDefault, 500); ITsString tssAppend = tsb2.GetString(); // reuse the original tsb to get the concatenation with the append string. tsb.Replace(tsb.Length, tsb.Length, " ", null); tsb.ReplaceTsString(tsb.Length, tsb.Length, tssAppend); ITsString tssConcat = tsb.GetString(); ITsStrBldr tsb3 = TsStrBldrClass.Create(); tsb3.Replace(0, 0, es, ttpEng); tsb3.SetIntPropValues(5, 8, (int) FwTextPropType.ktptForeColor, (int)FwTextPropVar.ktpvDefault, 500); ITsString tssEs = tsb3.GetString(); // Merge content into null alternatives lmeSrc.Bibliography.GetAlternative(engWs).UnderlyingTsString = tssEng; lmeKeeper.MergeObject(lmeSrc); Assert.AreEqual(lmeKeeper.Bibliography.GetAlternative(engWs).UnderlyingTsString, tssEng); // Try to merge empty string into null content. lmeKeeper.Bibliography.SetAlternative("", engWs); lmeSrc = m_entriesCol.Add(new LexEntry()); lmeSrc.Bibliography.SetAlternative("", engWs); Assert.IsNull(lmeKeeper.Bibliography.GetAlternative(engWs).Text); // Merge content into empty string. lmeKeeper.Bibliography.SetAlternative("", engWs); // This actually sets the content to null, not an empty string. lmeSrc.Bibliography.GetAlternative(engWs).UnderlyingTsString = tssEng; lmeKeeper.MergeObject(lmeSrc); Assert.AreEqual(lmeKeeper.Bibliography.GetAlternative(engWs).UnderlyingTsString, tssEng); // Try to merge into existing content. lmeKeeper.Bibliography.GetAlternative(engWs).UnderlyingTsString = tssEng; lmeSrc = m_entriesCol.Add(new LexEntry()); lmeSrc.Bibliography.SetAlternative("Should fail to merge, blah.", engWs); lmeKeeper.MergeObject(lmeSrc); Assert.AreEqual(lmeKeeper.Bibliography.GetAlternative(engWs).UnderlyingTsString, tssEng); // Make sure extant content isn't wrecked. lmeKeeper.Bibliography.GetAlternative(engWs).UnderlyingTsString = tssEng; lmeSrc = m_entriesCol.Add(new LexEntry()); lmeSrc.Bibliography.GetAlternative(esWs).UnderlyingTsString = tssEs; lmeKeeper.MergeObject(lmeSrc); Assert.AreEqual(lmeKeeper.Bibliography.GetAlternative(engWs).UnderlyingTsString, tssEng); Assert.AreEqual(lmeKeeper.Bibliography.GetAlternative(esWs).UnderlyingTsString, tssEs); // Now tests involving concatenation. lmeKeeper.Bibliography.GetAlternative(engWs).UnderlyingTsString = tssEng; lmeSrc = m_entriesCol.Add(new LexEntry()); lmeSrc.Bibliography.SetAlternative(tssAppend, engWs); lmeKeeper.MergeObject(lmeSrc, true); AssertEqualTss(lmeKeeper.Bibliography.GetAlternative(engWs).UnderlyingTsString, tssConcat); // Don't concatenate if initial values are equal. lmeKeeper.Bibliography.GetAlternative(engWs).UnderlyingTsString = tssEng; lmeSrc = m_entriesCol.Add(new LexEntry()); lmeSrc.Bibliography.SetAlternative(tssEng, engWs); lmeKeeper.MergeObject(lmeSrc, true); AssertEqualTss(lmeKeeper.Bibliography.GetAlternative(engWs).UnderlyingTsString, tssEng); }