From 6cd8a887c1e346fef41e94e6593248246cf3c729 Mon Sep 17 00:00:00 2001 From: Steve Brokenshire Date: Mon, 28 Dec 2015 01:23:12 +0000 Subject: [PATCH] Added source code, headers and unit tests for the CLIENTPIDMAP vCard Property for ClientDataObject. --- source/contacteditor/ContactDataObject.cpp | 90 ++++++++++++++++++++++ source/contacteditor/ContactDataObject.h | 4 + source/tests/LoadCheck-Load4.vcf | 4 + source/tests/xestiaab_contactload.h | 38 +++++++++ 4 files changed, 136 insertions(+) diff --git a/source/contacteditor/ContactDataObject.cpp b/source/contacteditor/ContactDataObject.cpp index 66f4259..ffca460 100644 --- a/source/contacteditor/ContactDataObject.cpp +++ b/source/contacteditor/ContactDataObject.cpp @@ -110,6 +110,7 @@ ContactLoadStatus ContactDataObject::LoadFile(wxString Filename){ int VendorCount = 0; int XTokenCount = 0; int XMLCount = 0; + int ClientPIDCount = 0; wxString ContactLine; wxString PropertyLine; wxString PropertySeg1; @@ -247,6 +248,11 @@ ContactLoadStatus ContactDataObject::LoadFile(wxString Filename){ ProcessN(PropertySeg1, PropertySeg2); NameProcessed = TRUE; + } else if (Property == wxT("CLIENTPIDMAP")){ + + ProcessClientPIDMap(PropertySeg1, PropertySeg2, &ClientPIDCount); + ClientPIDCount++; + } else if (Property == wxT("NICKNAME")){ ProcessNickname(PropertySeg1, PropertySeg2, &NicknameCount); @@ -1092,6 +1098,90 @@ void ContactDataObject::ProcessN(wxString PropertySeg1, wxString PropertySeg2){ } +void ContactDataObject::ProcessClientPIDMap(wxString PropertySeg1, wxString PropertySeg2, int *ClientPIDCount){ + + size_t intPropertyLen = PropertySeg1.Len(); + std::map SplitPoints; + std::map SplitLength; + std::map::iterator SLiter; + wxString PropertyData; + wxString PropertyName; + wxString PropertyValue; + wxString PropertyTokens; + bool FirstToken = TRUE; + int intSplitsFound = 0; + int intSplitSize = 0; + int intPrevValue = 14; + int intPref = 0; + int intType = 0; + + SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue); + + intPrevValue = 13; + + 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; + + // Process properties. + + size_t intPropertyValueLen = PropertyValue.Len(); + + if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){ + + PropertyValue.Trim(); + PropertyValue.RemoveLast(); + + } + + if (PropertyValue.Mid(0, 1) == wxT("\"")){ + + PropertyValue.Remove(0, 1); + + } + + CaptureString(&PropertyValue, FALSE); + + if (PropertyName.IsEmpty() || PropertyName.IsEmpty()){ + + continue; + + } + + if (FirstToken == TRUE){ + + PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue); + FirstToken = FALSE; + + } else { + + PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue); + + } + + } + + CaptureString(&PropertySeg2, FALSE); + + ClientPIDList.insert(std::make_pair(*ClientPIDCount, PropertySeg2)); + + if (!PropertyTokens.IsEmpty()){ + + ClientPIDListTokens.insert(std::make_pair(*ClientPIDCount, PropertyTokens)); + + } + +} + void ContactDataObject::ProcessNickname(wxString PropertySeg1, wxString PropertySeg2, int *NicknameCount){ std::map SplitPoints; diff --git a/source/contacteditor/ContactDataObject.h b/source/contacteditor/ContactDataObject.h index 3179f56..4cf459d 100644 --- a/source/contacteditor/ContactDataObject.h +++ b/source/contacteditor/ContactDataObject.h @@ -61,6 +61,7 @@ class ContactDataObject{ void ProcessMember(wxString PropertySeg1, wxString PropertySeg2, int *GroupCount); void ProcessFN(wxString PropertySeg1, wxString PropertySeg2, int *FNCount); void ProcessN(wxString PropertySeg1, wxString PropertySeg2); + void ProcessClientPIDMap(wxString PropertySeg1, wxString PropertySeg2, int *ClientPIDCount); void ProcessNickname(wxString PropertySeg1, wxString PropertySeg2, int *NicknameCount); void ProcessGender(wxString PropertySeg1, wxString PropertySeg2); void ProcessBirthday(wxString PropertySeg1, wxString PropertySeg2); @@ -133,6 +134,9 @@ class ContactDataObject{ std::map XMLList; std::map XMLListAltID; + std::map ClientPIDList; + std::map ClientPIDListTokens; + /* 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 90cd129..31462b0 100644 --- a/source/tests/LoadCheck-Load4.vcf +++ b/source/tests/LoadCheck-Load4.vcf @@ -3,6 +3,10 @@ VERSION:4.0 UID:903588-9082374-989120310-AAFECDBCDF KIND:individual REV;TEST=YES;DATA=NO;MORE=MAYBE:20151227T033000Z +CLIENTPIDMAP:1;urn;uuid:aaaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa +CLIENTPIDMAP:2;urn;uuid:ccccccccc-cccc-cccc-cccc-cccccccccccc +CLIENTPIDMAP;MEEP=MOO;WOOP=WOO:3;urn;uuid:bbbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbb + bbb XML:Example Page 1 XML;ALTID=3:::iterator TestFileIter; + + // Test the first Client PID Map. + + TestFileIter = TestFile.ClientPIDList.find(0); + ASSERT_NE(TestFile.ClientPIDList.end(), TestFileIter); + ASSERT_EQ("1;urn;uuid:aaaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", TestFileIter->second); + + TestFileIter = TestFile.ClientPIDListTokens.find(0); + ASSERT_EQ(TestFile.ClientPIDListTokens.end(), TestFileIter); + + // Test the second Client PID Map. + + TestFileIter = TestFile.ClientPIDList.find(1); + ASSERT_NE(TestFile.ClientPIDList.end(), TestFileIter); + ASSERT_EQ("2;urn;uuid:ccccccccc-cccc-cccc-cccc-cccccccccccc", TestFileIter->second); + + TestFileIter = TestFile.ClientPIDListTokens.find(1); + ASSERT_EQ(TestFile.ClientPIDListTokens.end(), TestFileIter); + + // Test the third Client PID Map. + + TestFileIter = TestFile.ClientPIDListTokens.find(2); + ASSERT_NE(TestFile.ClientPIDListTokens.end(), TestFileIter); + ASSERT_EQ("MEEP=MOO;WOOP=WOO", TestFileIter->second); + + TestFileIter = TestFile.ClientPIDList.find(2); + ASSERT_NE(TestFile.ClientPIDList.end(), TestFileIter); + ASSERT_EQ("3;urn;uuid:bbbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb", TestFileIter->second); + +} + TEST(ContactLoad, RevisionTests){ ContactDataObject TestFile; -- 2.39.2