From: Steve Brokenshire Date: Sun, 27 Dec 2015 03:15:42 +0000 (+0000) Subject: Added source code, headers and unit testing to the XML vCard Property for ContactData... X-Git-Tag: release-0.09~209 X-Git-Url: http://Server1/repobrowser/?a=commitdiff_plain;h=db50ff1e15d18ad7e4451279f91086cc4d6050c5;p=xestiaab%2F.git Added source code, headers and unit testing to the XML vCard Property for ContactDataObject. --- diff --git a/source/contacteditor/ContactDataObject.cpp b/source/contacteditor/ContactDataObject.cpp index 4dad1f9..b9035ed 100644 --- a/source/contacteditor/ContactDataObject.cpp +++ b/source/contacteditor/ContactDataObject.cpp @@ -108,6 +108,7 @@ ContactLoadStatus ContactDataObject::LoadFile(wxString Filename){ int KeyCount = 0; int VendorCount = 0; int XTokenCount = 0; + int XMLCount = 0; wxString ContactLine; wxString PropertyLine; wxString PropertySeg1; @@ -220,6 +221,11 @@ ContactLoadStatus ContactDataObject::LoadFile(wxString Filename){ ProcessSource(PropertySeg1, PropertySeg2, &SourceCount); SourceCount++; + } else if (Property == wxT("XML")){ + + ProcessXML(PropertySeg1, PropertySeg2, &XMLCount); + XMLCount++; + } else if (Property == wxT("MEMBER")){ ProcessMember(PropertySeg1, PropertySeg2, &GroupCount); @@ -593,6 +599,54 @@ void ContactDataObject::ProcessSource(wxString PropertySeg1, wxString PropertySe } +void ContactDataObject::ProcessXML(wxString PropertySeg1, wxString PropertySeg2, int *XMLCount){ + + std::map SplitPoints; + std::map SplitLength; + + int intPrevValue = 5; + int intPref = 0; + int intType = 0; + + SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue); + + intPrevValue = 4; + + wxString PropertyName; + wxString PropertyValue; + wxString PropertyData; + wxString PropertyTokens; + std::map::iterator SLiter; + bool FirstToken = TRUE; + + for (std::map::iterator intiter = SplitPoints.begin(); + intiter != SplitPoints.end(); ++intiter){ + + SLiter = SplitLength.find(intiter->first); + + PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second)); + + wxStringTokenizer PropertyElement (PropertyData, wxT("=")); + PropertyName = PropertyElement.GetNextToken(); + PropertyValue = PropertyElement.GetNextToken(); + + intPrevValue = intiter->second; + + CaptureString(&PropertyValue, FALSE); + + if (PropertyName == wxT("ALTID")){ + + XMLListAltID.erase(*XMLCount); + XMLListAltID.insert(std::make_pair(*XMLCount, PropertyValue)); + + } + + } + + XMLList.insert(std::make_pair(*XMLCount, PropertySeg2)); + +} + void ContactDataObject::ProcessMember(wxString PropertySeg1, wxString PropertySeg2, int *GroupCount){ std::map SplitPoints; diff --git a/source/contacteditor/ContactDataObject.h b/source/contacteditor/ContactDataObject.h index 1186e21..0c788dd 100644 --- a/source/contacteditor/ContactDataObject.h +++ b/source/contacteditor/ContactDataObject.h @@ -56,6 +56,7 @@ class ContactDataObject{ void ProcessKind(wxString KindData); void ProcessSource(wxString PropertySeg1, wxString PropertySeg2, int *SourceCount); + void ProcessXML(wxString PropertySeg1, wxString PropertySeg2, int *XMLCount); void ProcessMember(wxString PropertySeg1, wxString PropertySeg2, int *GroupCount); void ProcessFN(wxString PropertySeg1, wxString PropertySeg2, int *FNCount); void ProcessN(wxString PropertySeg1, wxString PropertySeg2); @@ -125,6 +126,9 @@ class ContactDataObject{ std::map SourceListTokens; std::map SourceListMediatype; std::map SourceListPref; + + std::map XMLList; + std::map XMLListAltID; /* We don't use these at the moment but we want to keep them for compatability reasons */ diff --git a/source/tests/LoadCheck-Load4.vcf b/source/tests/LoadCheck-Load4.vcf index 575f55c..afa0e9a 100644 --- a/source/tests/LoadCheck-Load4.vcf +++ b/source/tests/LoadCheck-Load4.vcf @@ -2,6 +2,12 @@ BEGIN:VCARD VERSION:4.0 UID:903588-9082374-989120310-AAFECDBCDF KIND:individual +XML:Example Page 1 +XML;ALTID=3:Example Page 2 +XML;ALTID=5:Example Page 3 SOURCE;ALTID=74;PID=71;PREF=72;MEDIATYPE=text/plain;STATUS=FEED:http://examp le.com/source/sourcea.vcf SOURCE;TYPE=home;ALTID=84;PID=81;MEDIATYPE=text/plainpaper;STATUS=ONLINE;PRE diff --git a/source/tests/xestiaab_contactload.h b/source/tests/xestiaab_contactload.h index e2217a1..1f910d2 100644 --- a/source/tests/xestiaab_contactload.h +++ b/source/tests/xestiaab_contactload.h @@ -307,6 +307,38 @@ TEST(ContactLoad, SourceTests){ } +TEST(ContactLoad, XMLTest){ + + ContactDataObject TestFile; + + // Check that the vCard 4.0 file loads OK. + + ASSERT_EQ(CONTACTLOAD_OK, TestFile.LoadFile("LoadCheck-Load4.vcf")); + + std::map::iterator TestFileIter; + std::map::iterator TestFileIntIter; + + // Start with the first XML property. + + // Start with a general source address. + + TestFileIter = TestFile.XMLList.find(0); + ASSERT_NE(TestFile.XMLList.end(), TestFileIter); + ASSERT_EQ("Example Page 1", TestFileIter->second); + + TestFileIter = TestFile.XMLList.find(1); + ASSERT_NE(TestFile.XMLList.end(), TestFileIter); + ASSERT_EQ("Example Page 2", TestFileIter->second); + + TestFileIter = TestFile.XMLList.find(2); + ASSERT_NE(TestFile.XMLList.end(), TestFileIter); + ASSERT_EQ("Example Page 3", TestFileIter->second); + +} + TEST(ContactLoad, NicknameTests){ ContactDataObject TestFile;