Esempio n. 1
0
        public void Test_Common2()
        {
            GDMTree tree = new GDMTree();

            using (GDMFamilyRecord famRec = new GDMFamilyRecord(tree)) {
                Assert.IsNotNull(famRec);

                GDMIndividualRecord unkInd = new GDMIndividualRecord(null);
                unkInd.Sex = GDMSex.svUnknown;
                Assert.IsFalse(famRec.AddSpouse(unkInd));

                GDMIndividualRecord child1 = tree.CreateIndividual(); // for pointer need a proper object
                Assert.IsTrue(famRec.AddChild(child1));

                GDMIndividualRecord child2 = tree.CreateIndividual(); // for pointer need a proper object
                Assert.IsTrue(famRec.AddChild(child2));
                Assert.AreEqual(1, famRec.IndexOfChild(child2));

                famRec.DeleteChild(child1);
                Assert.AreEqual(-1, famRec.IndexOfChild(child1));

                string str = GKUtils.GetFamilyString(famRec, null, null);
                Assert.AreEqual("? - ?", str);

                str = GKUtils.GetFamilyString(famRec, "x", "x");
                Assert.AreEqual("x - x", str);

                Assert.AreEqual(0.0f, famRec.IsMatch(null, new MatchParams()));
                Assert.AreEqual(100.0f, famRec.IsMatch(famRec, new MatchParams()));

                // MoveTo test
                Assert.Throws(typeof(ArgumentException), () => {
                    famRec.MoveTo(null, false);
                });

                GDMCustomEvent evt = famRec.AddEvent(new GDMFamilyEvent(famRec, (int)GEDCOMTagType.MARR, "01 SEP 1981"));
                Assert.AreEqual(1, famRec.Events.Count);
                Assert.AreEqual(evt, famRec.FindEvent(GEDCOMTagType.MARR));

                using (GDMFamilyRecord famRec2 = new GDMFamilyRecord(tree)) {
                    Assert.AreEqual(0, famRec2.Events.Count);
                    Assert.AreEqual(null, famRec2.FindEvent(GEDCOMTagType.MARR));

                    famRec.MoveTo(famRec2, false);

                    Assert.AreEqual(1, famRec2.Events.Count);
                    Assert.AreEqual(evt, famRec2.FindEvent(GEDCOMTagType.MARR));
                }

                famRec.ResetOwner(tree);
                Assert.AreEqual(tree, famRec.GetTree());
            }
        }
Esempio n. 2
0
        public void Test_Common()
        {
            GDMTree tree = new GDMTree();

            Assert.IsNotNull(tree);

            Assert.IsNotNull(tree.GetSubmitter());

            // Tests of event handlers
            tree.OnChange   += OnTreeChange;
            tree.OnChanging += OnTreeChanging;
            tree.OnProgress += OnTreeProgress;

            tree.BeginUpdate();
            Assert.IsTrue(tree.IsUpdated());

            GDMRecord rec;

            GDMIndividualRecord iRec = tree.CreateIndividual();

            Assert.IsNotNull(iRec, "CreateIndividual() != null");

            string xref = iRec.XRef;

            rec = tree.XRefIndex_Find(xref);
            Assert.IsNotNull(rec);
            Assert.AreEqual(xref, rec.XRef);

            string uid = iRec.UID;

            rec = tree.FindUID(uid);
            Assert.IsNotNull(rec);
            Assert.AreEqual(uid, rec.UID);
            Assert.IsNull(tree.FindUID(""));

            //
            GDMFamilyRecord famRec = tree.CreateFamily();

            Assert.IsNotNull(famRec, "CreateFamily() != null");

            //
            GDMNoteRecord noteRec = tree.CreateNote();

            Assert.IsNotNull(noteRec, "CreateNote() != null");

            //
            GDMRepositoryRecord repRec = tree.CreateRepository();

            Assert.IsNotNull(repRec, "CreateRepository() != null");

            //
            GDMSourceRecord srcRec = tree.CreateSource();

            Assert.IsNotNull(srcRec, "CreateSource() != null");

            //
            GDMMultimediaRecord mmRec = tree.CreateMultimedia();

            Assert.IsNotNull(mmRec, "CreateMultimedia() != null");

            //

            GDMRecord sbmrRec = tree.AddRecord(new GDMSubmitterRecord(tree));

            Assert.IsNotNull(sbmrRec, "sbmrRec != null");
            tree.NewXRef(sbmrRec);
            string submXRef = sbmrRec.XRef;

            //

            GDMSubmissionRecord submRec = tree.AddRecord(new GDMSubmissionRecord(tree)) as GDMSubmissionRecord;

            Assert.IsNotNull(submRec, "rec1 != null");
            tree.NewXRef(submRec);

            //
            GDMGroupRecord groupRec = tree.CreateGroup();

            Assert.IsNotNull(groupRec, "CreateGroup() != null");

            //
            GDMTaskRecord taskRec = tree.CreateTask();

            Assert.IsNotNull(taskRec, "CreateTask() != null");

            //
            GDMCommunicationRecord commRec = tree.CreateCommunication();

            Assert.IsNotNull(commRec, "CreateCommunication() != null");

            //
            GDMResearchRecord resRec = tree.CreateResearch();

            Assert.IsNotNull(resRec, "CreateResearch() != null");

            //
            GDMLocationRecord locRec = tree.CreateLocation();

            Assert.IsNotNull(locRec, "CreateLocation() != null");

            tree.EndUpdate();
            Assert.IsFalse(tree.IsUpdated());

            tree.OnChange   -= OnTreeChange;
            tree.OnChanging -= OnTreeChanging;
            tree.OnProgress -= OnTreeProgress;

            int       size  = 0;
            var       enum1 = tree.GetEnumerator(GDMRecordType.rtNone);
            GDMRecord rec1;

            enum1.Reset();
            while (enum1.MoveNext(out rec1))
            {
                size++;
            }
            Assert.AreEqual(14, size);

            for (int i = 0; i < tree.RecordsCount; i++)
            {
                GDMRecord rec2 = tree[i];
                Assert.IsNotNull(rec2);

                string    xref2 = rec2.XRef;
                GDMRecord rec3  = tree.XRefIndex_Find(xref2);
                Assert.IsNotNull(rec3);
                Assert.AreEqual(rec2, rec3);

                /*string uid = rec2.UID;
                 * GEDCOMRecord rec4 = tree.FindUID(uid);
                 * Assert.IsNotNull(rec4);
                 * Assert.AreEqual(rec2, rec4);*/

                int idx = tree.IndexOf(rec2);
                Assert.AreEqual(i, idx);
            }

            var recordsX = tree.GetRecords <GDMIndividualRecord>();

            Assert.IsNotNull(recordsX);
            Assert.AreEqual(1, recordsX.Count);

            int[] stats = tree.GetRecordStats();
            Assert.IsNotNull(stats);
            Assert.AreEqual(14, stats.Length);

            Assert.IsFalse(tree.IsEmpty);

            Assert.IsFalse(tree.DeleteFamilyRecord(null));
            Assert.IsTrue(tree.DeleteFamilyRecord(famRec));

            Assert.IsFalse(tree.DeleteNoteRecord(null));
            Assert.IsTrue(tree.DeleteNoteRecord(noteRec));

            Assert.IsFalse(tree.DeleteSourceRecord(null));
            Assert.IsTrue(tree.DeleteSourceRecord(srcRec));

            Assert.IsFalse(tree.DeleteGroupRecord(null));
            Assert.IsTrue(tree.DeleteGroupRecord(groupRec));

            Assert.IsFalse(tree.DeleteLocationRecord(null));
            Assert.IsTrue(tree.DeleteLocationRecord(locRec));

            Assert.IsFalse(tree.DeleteResearchRecord(null));
            Assert.IsTrue(tree.DeleteResearchRecord(resRec));

            Assert.IsFalse(tree.DeleteCommunicationRecord(null));
            Assert.IsTrue(tree.DeleteCommunicationRecord(commRec));

            Assert.IsFalse(tree.DeleteTaskRecord(null));
            Assert.IsTrue(tree.DeleteTaskRecord(taskRec));

            Assert.IsFalse(tree.DeleteMediaRecord(null));
            Assert.IsTrue(tree.DeleteMediaRecord(mmRec));

            Assert.IsFalse(tree.DeleteIndividualRecord(null));
            Assert.IsTrue(tree.DeleteIndividualRecord(iRec));

            Assert.IsFalse(tree.DeleteRepositoryRecord(null));
            Assert.IsTrue(tree.DeleteRepositoryRecord(repRec));

            tree.Clear();
            Assert.AreEqual(0, tree.RecordsCount);
            Assert.IsTrue(tree.IsEmpty);

            tree.State = GDMTreeState.osReady;
            Assert.AreEqual(GDMTreeState.osReady, tree.State);


            // Tests of GEDCOMTree.Extract()
            using (GDMTree tree2 = new GDMTree()) {
                GDMIndividualRecord iRec2 = tree.AddRecord(new GDMIndividualRecord(tree2)) as GDMIndividualRecord;
                Assert.IsNotNull(iRec2);
                tree2.NewXRef(iRec2);

                tree2.AddRecord(iRec2);
                int rIdx = tree2.IndexOf(iRec2);
                Assert.IsTrue(rIdx >= 0);
                GDMRecord extractedRec = tree2.Extract(rIdx);
                Assert.AreEqual(iRec2, extractedRec);
                Assert.IsTrue(tree2.IndexOf(iRec2) < 0);
            }
        }
Esempio n. 3
0
        public void Test_IndiMathes()
        {
            GDMTree tree = new GDMTree();

            Assert.IsNotNull(tree);

            GDMIndividualRecord ind1, ind2;
            GDMCustomEvent      ev1, ev2;
            GDMDateValue        dtVal1, dtVal2;

            ind1     = tree.CreateIndividual();
            ind1.Sex = GDMSex.svMale;
            GDMPersonalName pn = ind1.AddPersonalName(new GDMPersonalName(ind1));

            pn.SetNameParts("Ivan Ivanov", "Fedoroff", "");

            ind2     = tree.CreateIndividual();
            ind2.Sex = GDMSex.svMale;
            pn       = ind2.AddPersonalName(new GDMPersonalName(ind2));
            pn.SetNameParts("Ivan Ivanovich", "Fedoroff", "");

            ev1    = new GDMIndividualEvent(ind1, (int)GEDCOMTagType.BIRT, "");
            dtVal1 = ev1.Date;
            ind1.AddEvent(ev1);

            ev2    = new GDMIndividualEvent(ind2, (int)GEDCOMTagType.BIRT, "");
            dtVal2 = ev2.Date;
            ind2.AddEvent(ev2);

            float       res;
            MatchParams mParams;

            mParams.NamesIndistinctThreshold = 1.0f;
            mParams.DatesCheck       = true;
            mParams.YearsInaccuracy  = 0;
            mParams.CheckEventPlaces = false;

            // null
            res = dtVal1.IsMatch(null, mParams);
            Assert.AreEqual(0.0f, res);

            // null
            res = ev1.IsMatch(null, mParams);
            Assert.AreEqual(0.0f, res);

            // dtVal1 -> dtVal2, delta = 0
            dtVal1.SetDateTime(DateTime.Parse("10.10.2013"));
            dtVal2.SetDateTime(DateTime.Parse("10.10.2013"));
            res = dtVal1.IsMatch(dtVal2, mParams);
            Assert.AreEqual(100.0f, res);

            // ev1 -> ev2, delta = 0
            res = ev1.IsMatch(ev2, mParams);
            Assert.AreEqual(100.0f, res);

            // dtVal1 -> dtVal2, delta = 3
            mParams.YearsInaccuracy = 3;

            dtVal2.SetDateTime(DateTime.Parse("10.10.2015"));
            res = dtVal1.IsMatch(dtVal2, mParams);
            Assert.AreEqual(100.0f, res);

            // ev1 -> ev2, delta = 3
            res = ev1.IsMatch(ev2, mParams);
            Assert.AreEqual(100.0f, res);

            dtVal2.SetDateTime(DateTime.Parse("10.10.2009"));
            res = dtVal1.IsMatch(dtVal2, mParams);
            Assert.AreEqual(0.0f, res);

            // ev1 -> ev2, delta = 3
            res = ev1.IsMatch(ev2, mParams);
            Assert.AreEqual(0.0f, res);

            // //

            res = ind1.IsMatch(null, mParams);
            Assert.AreEqual(0.0f, res);

            res = ind1.IsMatch(ind2, mParams);
            Assert.AreEqual(0.0f, res);

            // Ivanov - Ivanov(ich) : 3 chars of difference -> 0.88
            mParams.NamesIndistinctThreshold = 0.85f;
            mParams.YearsInaccuracy          = 4;

            res = ind1.IsMatch(ind2, mParams);
            Assert.AreEqual(100.0f, res);
        }
Esempio n. 4
0
        public void Test_Common()
        {
            GDMTree tree = new GDMTree();

            Assert.IsNotNull(tree);

            GDMIndividualRecord indiv = tree.CreateIndividual();

            Assert.IsNotNull(indiv);

            GDMFamilyRecord famRec = tree.CreateFamily();

            Assert.IsNotNull(famRec);

            famRec.Restriction = GDMRestriction.rnLocked;
            Assert.AreEqual(GDMRestriction.rnLocked, famRec.Restriction);

            famRec.AddChild(indiv);
            Assert.AreEqual(0, famRec.IndexOfChild(indiv));

            famRec.Husband.Value = tree.CreateIndividual();
            famRec.Wife.Value    = tree.CreateIndividual();

            using (GDMFamilyRecord fam2 = tree.CreateFamily()) {
                Assert.Throws(typeof(ArgumentException), () => {
                    fam2.Assign(null);
                });

                fam2.Assign(famRec);

                string buf = TestUtils.GetTagStreamText(fam2, 0);
                Assert.AreEqual("0 @F2@ FAM\r\n" +
                                "1 RESN locked\r\n" +
                                "1 HUSB @I2@\r\n" +
                                "1 WIFE @I3@\r\n" +
                                "1 CHIL @I1@\r\n", buf);
            }

            // Integrity test
            GDMChildToFamilyLink childLink = indiv.ChildToFamilyLinks[0];

            Assert.IsNotNull(childLink.Family);

            famRec.RemoveChild(indiv);
            Assert.AreEqual(-1, famRec.IndexOfChild(indiv));

            //

            Assert.Throws(typeof(ArgumentException), () => {
                famRec.AddEvent(new GDMIndividualEvent(null));
            });

            famRec.ReplaceXRefs(new GDMXRefReplacer());

            //

            famRec.Husband.Value = indiv;
            Assert.AreEqual(indiv, famRec.Husband.Individual);
            famRec.Husband.Value = null;

            //

            famRec.Wife.Value = indiv;
            Assert.AreEqual(indiv, famRec.Wife.Individual);
            famRec.Wife.Value = null;

            //

            indiv.Sex = GDMSex.svMale;
            famRec.AddSpouse(indiv);
            Assert.AreEqual(0, indiv.IndexOfSpouse(famRec));
            Test_GDMSpouseToFamilyLink(indiv.SpouseToFamilyLinks[0]);
            Assert.IsNull(famRec.GetSpouseBy(indiv));
            famRec.RemoveSpouse(indiv);

            indiv.Sex = GDMSex.svFemale;
            famRec.AddSpouse(indiv);
            Assert.AreEqual(0, indiv.IndexOfSpouse(famRec));
            Test_GDMSpouseToFamilyLink(indiv.SpouseToFamilyLinks[0]);
            Assert.IsNull(famRec.GetSpouseBy(indiv));
            famRec.RemoveSpouse(indiv);

            //

            famRec.SortChilds();

            //

            famRec.AddChild(null);
            famRec.RemoveChild(null);
            famRec.AddSpouse(null);
            famRec.RemoveSpouse(null);

            //
            famRec.AddSpouse(indiv);

            famRec.AddChild(tree.CreateIndividual());
            famRec.AddChild(tree.CreateIndividual());
            famRec.AddChild(tree.CreateIndividual());
            Assert.AreEqual(3, famRec.Children.Count);

            Assert.IsFalse(famRec.IsEmpty());
            famRec.Clear();
            Assert.IsTrue(famRec.IsEmpty());
        }