From 5ab6af24eb42838438875f9c7af77210ccfa44a8 Mon Sep 17 00:00:00 2001 From: Steve Brokenshire Date: Fri, 11 Dec 2015 00:07:15 +0000 Subject: [PATCH] Added remaining property source code and unit tests for the FN vCard member for ContactDataObject. --- source/contacteditor/ContactDataObject.cpp | 111 +++++++++++++++++++-- source/tests/LoadCheck-Load4.vcf | 2 +- source/tests/xestiaab_contactload.h | 38 ++++++- 3 files changed, 140 insertions(+), 11 deletions(-) diff --git a/source/contacteditor/ContactDataObject.cpp b/source/contacteditor/ContactDataObject.cpp index 28c29e7..266a5e0 100644 --- a/source/contacteditor/ContactDataObject.cpp +++ b/source/contacteditor/ContactDataObject.cpp @@ -177,15 +177,11 @@ ContactLoadStatus ContactDataObject::LoadFile(wxString Filename){ PropertySeg2 = ContactLine.Mid((QuoteBreakPoint + 1)); if (Property == wxT("KIND") && KindProcessed == FALSE){ - - // See frmContactEditor-LoadGroup.cpp - + ProcessKind(PropertySeg2); } else if (Property == wxT("MEMBER")){ - // See frmContactEditor-LoadGroup.cpp - ProcessMember(PropertySeg1, PropertySeg2, &GroupCount); GroupCount++; @@ -240,8 +236,6 @@ void ContactDataObject::ProcessMember(wxString PropertySeg1, wxString PropertySe intPrevValue = 7; - // Look for type before continuing. - wxString PropertyName; wxString PropertyValue; wxString PropertyData; @@ -263,8 +257,6 @@ void ContactDataObject::ProcessMember(wxString PropertySeg1, wxString PropertySe intPrevValue = intiter->second; CaptureString(&PropertyValue, FALSE); - - //ContactProcess::ContactProcessCaptureStrings(&PropertyValue); if (PropertyName == wxT("ALTID")){ @@ -331,8 +323,109 @@ void ContactDataObject::ProcessMember(wxString PropertySeg1, wxString PropertySe void ContactDataObject::ProcessFN(wxString PropertySeg1, wxString PropertySeg2, int *FNCount){ + std::map SplitPoints; + std::map SplitLength; + + int intPrevValue = 4; + int intPref = 0; + int intType = 0; + + SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue); + + intPrevValue = 3; + + 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("TYPE")){ + + if (!PropertyValue.IsEmpty() || PropertyValue == wxT("home") || + PropertyValue == wxT("work") ){ + + FullNamesListType.erase(*FNCount); + FullNamesListType.insert(std::make_pair(*FNCount, PropertyValue)); + + } + + } else if (PropertyName == wxT("LANGUAGE")){ + + FullNamesListLanguage.erase(*FNCount); + FullNamesListLanguage.insert(std::make_pair(*FNCount, PropertyValue)); + + } else if (PropertyName == wxT("ALTID")){ + + FullNamesListAltID.erase(*FNCount); + FullNamesListAltID.insert(std::make_pair(*FNCount, PropertyValue)); + + } else if (PropertyName == wxT("PID")){ + + FullNamesListPID.erase(*FNCount); + FullNamesListPID.insert(std::make_pair(*FNCount, PropertyValue)); + + } else if (PropertyName == wxT("PREF")){ + + int PriorityNumber = 0; + bool ValidNumber = TRUE; + + try{ + PriorityNumber = std::stoi(PropertyValue.ToStdString()); + } + + catch(std::invalid_argument &e){ + ValidNumber = FALSE; + } + + if (ValidNumber == TRUE){ + + FullNamesListPref.erase(*FNCount); + FullNamesListPref.insert(std::make_pair(*FNCount, PriorityNumber)); + + } + + } else if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){ + + if (FirstToken == TRUE){ + + PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue); + FirstToken = FALSE; + + } else { + + PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue); + + } + + } + + } + FullNamesList.insert(std::make_pair(*FNCount, PropertySeg2)); + if (!PropertyTokens.IsEmpty()){ + + FullNamesListTokens.insert(std::make_pair(*FNCount, PropertyTokens)); + + } + } void SplitValues(wxString *PropertyLine, diff --git a/source/tests/LoadCheck-Load4.vcf b/source/tests/LoadCheck-Load4.vcf index b092f51..a3b057b 100644 --- a/source/tests/LoadCheck-Load4.vcf +++ b/source/tests/LoadCheck-Load4.vcf @@ -3,5 +3,5 @@ VERSION:4.0 KIND:individual MEMBER;ALTID=35;PID=40;PREF=45;MEDIATYPE=text/plain;EXAMPLE=Meep:7a2af44d-64 31-4797-a55f-d86d56304fda -FN:Test Contact +FN;TYPE=work;LANGUAGE=kw;ALTID=500;PID=40;PREF=45;EXAMPLE=Baaa:Test Contact END:VCARD diff --git a/source/tests/xestiaab_contactload.h b/source/tests/xestiaab_contactload.h index c8eca05..b3e53f4 100644 --- a/source/tests/xestiaab_contactload.h +++ b/source/tests/xestiaab_contactload.h @@ -77,7 +77,7 @@ TEST(ContactLoad, ContactLoadTests){ ASSERT_NE(TestFile.GroupsListPref.end(), TestFileIntIter); ASSERT_EQ(45, TestFileIntIter->second); - // Check that MEDIATYPE parameter. + // Check the MEDIATYPE parameter. TestFileIter = TestFile.GroupsListMediaType.find(0); ASSERT_NE(TestFile.GroupsListMediaType.end(), TestFileIter); @@ -94,7 +94,43 @@ TEST(ContactLoad, ContactLoadTests){ TestFileIter = TestFile.FullNamesList.find(0); ASSERT_NE(TestFile.FullNamesList.end(), TestFileIter); ASSERT_EQ("Test Contact", TestFileIter->second); + + // Check the TYPE parameter. + + TestFileIter = TestFile.FullNamesListType.find(0); + ASSERT_NE(TestFile.FullNamesListType.end(), TestFileIter); + ASSERT_EQ("work", TestFileIter->second); + + // Check the LANGUAGE parameter. + + TestFileIter = TestFile.FullNamesListLanguage.find(0); + ASSERT_NE(TestFile.FullNamesListLanguage.end(), TestFileIter); + ASSERT_EQ("kw", TestFileIter->second); + + // Check the ALTID parameter. + + TestFileIter = TestFile.FullNamesListAltID.find(0); + ASSERT_NE(TestFile.FullNamesListAltID.end(), TestFileIter); + ASSERT_EQ("500", TestFileIter->second); + + // Check the PID parameter. + TestFileIter = TestFile.FullNamesListPID.find(0); + ASSERT_NE(TestFile.FullNamesListPID.end(), TestFileIter); + ASSERT_EQ("40", TestFileIter->second); + + // Check the PREF parameter. + + TestFileIntIter = TestFile.FullNamesListPref.find(0); + ASSERT_NE(TestFile.FullNamesListPref.end(), TestFileIntIter); + ASSERT_EQ(45, TestFileIntIter->second); + + // Check for the extra tokens parameter. + + TestFileIter = TestFile.FullNamesListTokens.find(0); + ASSERT_NE(TestFile.FullNamesListTokens.end(), TestFileIter); + ASSERT_EQ("EXAMPLE=Baaa", TestFileIter->second); + } // TODO: Add tests for the Contact Loading process. \ No newline at end of file -- 2.39.5