From: Steve Brokenshire Date: Sat, 19 Dec 2015 21:33:38 +0000 (+0000) Subject: Added source code, header and unit testing for the EMAIL vCard property for the Conta... X-Git-Tag: release-0.09~231 X-Git-Url: http://Server1/repobrowser/?a=commitdiff_plain;h=64e5af606c4f78b992c820414044a6ad8fef29f2;p=xestiaab%2F.git Added source code, header and unit testing for the EMAIL vCard property for the ContactDataObject. --- diff --git a/source/contacteditor/ContactDataObject.cpp b/source/contacteditor/ContactDataObject.cpp index eeb95b0..b49e0bb 100644 --- a/source/contacteditor/ContactDataObject.cpp +++ b/source/contacteditor/ContactDataObject.cpp @@ -85,6 +85,7 @@ ContactLoadStatus ContactDataObject::LoadFile(wxString Filename){ int NicknameCount = 0; int TimeZoneCount = 0; int AddressCount = 0; + int EmailCount = 0; wxString ContactLine; wxString PropertyLine; wxString PropertySeg1; @@ -232,6 +233,13 @@ ContactLoadStatus ContactDataObject::LoadFile(wxString Filename){ ProcessAddress(PropertySeg1, PropertySeg2, &AddressCount); AddressCount++; + } else if (Property == wxT("EMAIL")){ + + // See frmContactEditor-LoadEmail.cpp + + ProcessEmail(PropertySeg1, PropertySeg2, &EmailCount); + EmailCount++; + } } @@ -1632,6 +1640,148 @@ void ContactDataObject::ProcessAddress(wxString PropertySeg1, wxString PropertyS } +void ContactDataObject::ProcessEmail(wxString PropertySeg1, wxString PropertySeg2, int *EmailCount){ + + std::map SplitPoints; + std::map SplitLength; + + int intPrevValue = 7; + int intPref = 0; + + SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue); + + intPrevValue = 6; + + PropertyType PropType; + + // Look for type before continuing. + + CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType); + + std::map *EmailList = NULL; + std::map *EmailListType = NULL; + std::map *EmailListAltID = NULL; + std::map *EmailListPID = NULL; + std::map *EmailListTokens = NULL; + std::map *EmailListPref = NULL; + + switch(PropType){ + case PROPERTY_NONE: + EmailList = &GeneralEmailList; + EmailListType = &GeneralEmailListType; + EmailListAltID = &GeneralEmailListAltID; + EmailListPID = &GeneralEmailListPID; + EmailListTokens = &GeneralEmailListTokens; + EmailListPref = &GeneralEmailListPref; + break; + case PROPERTY_HOME: + EmailList = &HomeEmailList; + EmailListType = &HomeEmailListType; + EmailListAltID = &HomeEmailListAltID; + EmailListPID = &HomeEmailListPID; + EmailListTokens = &HomeEmailListTokens; + EmailListPref = &HomeEmailListPref; + break; + case PROPERTY_WORK: + EmailList = &BusinessEmailList; + EmailListType = &BusinessEmailListType; + EmailListAltID = &BusinessEmailListAltID; + EmailListPID = &BusinessEmailListPID; + EmailListTokens = &BusinessEmailListTokens; + EmailListPref = &BusinessEmailListPref; + break; + } + + intPrevValue = 6; + + std::map::iterator SLiter; + wxString PropertyData; + wxString PropertyName; + wxString PropertyValue; + wxString PropertyTokens; + 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); + + // Process properties. + + if (PropertyName == wxT("ALTID")){ + + EmailListAltID->erase(*EmailCount); + EmailListAltID->insert(std::make_pair(*EmailCount, PropertyValue)); + + } else if (PropertyName == wxT("PID")){ + + EmailListPID->erase(*EmailCount); + EmailListPID->insert(std::make_pair(*EmailCount, 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){ + + EmailListPref->erase(*EmailCount); + EmailListPref->insert(std::make_pair(*EmailCount, PriorityNumber)); + + } + + } else { + + if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){ + + if (FirstToken == TRUE){ + + PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue); + FirstToken = FALSE; + + } else { + + PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue); + + } + + } + + } + + } + + EmailList->insert(std::make_pair(*EmailCount, PropertySeg2)); + + // Add the name token data. + + if (!PropertyTokens.IsEmpty()){ + + EmailListTokens->insert(std::make_pair(*EmailCount, PropertyTokens)); + + } + + +} + void SplitValues(wxString *PropertyLine, std::map *SplitPoints, std::map *SplitLength, diff --git a/source/contacteditor/ContactDataObject.h b/source/contacteditor/ContactDataObject.h index f91ea61..6a9d90f 100644 --- a/source/contacteditor/ContactDataObject.h +++ b/source/contacteditor/ContactDataObject.h @@ -574,6 +574,7 @@ class ContactDataObject{ void ProcessAnniversary(wxString PropertySeg1, wxString PropertySeg2); void ProcessTimeZone(wxString PropertySeg1, wxString PropertySeg2, int *TimeZoneCount); void ProcessAddress(wxString PropertySeg1, wxString PropertySeg2, int *AddressCount); + void ProcessEmail(wxString PropertySeg1, wxString PropertySeg2, int *EmailCount); }; diff --git a/source/tests/LoadCheck-Load4.vcf b/source/tests/LoadCheck-Load4.vcf index c54c535..8a1fb57 100644 --- a/source/tests/LoadCheck-Load4.vcf +++ b/source/tests/LoadCheck-Load4.vcf @@ -32,4 +32,7 @@ ADR;TYPE=work;LABEL="7 Flyby Drive\nElaine\nCornwall\nPL84 9YE\nCornwall\nUn ited Kingdom";LANGUAGE=en-GB;ALTID=45;PREF=10;PID=28;GEO="geo:7.0, 7.0";TZ= Europe/Newquay;MEDIATYPE=text/plain;JAM=Red:;;7 Flyby Drive;Elaine;Cornwall ;PL84 9YE;United Kingdom +EMAIL;ALTID=10;PID=20;PREF=40;WONDERFUL=Colour:moo@example.com +EMAIL;TYPE=home;ALTID=5;PID=10;PREF=20;PEACE=quiet:moo.home@example.com +EMAIL;TYPE=work;ALTID=1;PID=2;PREF=3;BUSINESS=Money:moo.business@example.com END:VCARD diff --git a/source/tests/xestiaab_contactload.h b/source/tests/xestiaab_contactload.h index 3b99f75..873911b 100644 --- a/source/tests/xestiaab_contactload.h +++ b/source/tests/xestiaab_contactload.h @@ -766,4 +766,109 @@ TEST(ContactLoad, AddressTests){ } + +TEST(ContactLoad, EmailTests){ + + 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 general email. + + TestFileIter = TestFile.GeneralEmailList.find(0); + ASSERT_NE(TestFile.GeneralEmailList.end(), TestFileIter); + ASSERT_EQ("moo@example.com", TestFileIter->second); + + // Check the ALTID section. + + TestFileIter = TestFile.GeneralEmailListAltID.find(0); + ASSERT_NE(TestFile.GeneralEmailListAltID.end(), TestFileIter); + ASSERT_EQ("10", TestFileIter->second); + + // Check the PID section. + + TestFileIter = TestFile.GeneralEmailListPID.find(0); + ASSERT_NE(TestFile.GeneralEmailListPID.end(), TestFileIter); + ASSERT_EQ("20", TestFileIter->second); + + // Check the PREF section. + + TestFileIntIter = TestFile.GeneralEmailListPref.find(0); + ASSERT_NE(TestFile.GeneralEmailListPref.end(), TestFileIntIter); + ASSERT_EQ(40, TestFileIntIter->second); + + // Check the extra tokens. + + TestFileIter = TestFile.GeneralEmailListTokens.find(0); + ASSERT_NE(TestFile.GeneralEmailListTokens.end(), TestFileIter); + ASSERT_EQ("WONDERFUL=Colour", TestFileIter->second); + + // Start with the home email. + + TestFileIter = TestFile.HomeEmailList.find(1); + ASSERT_NE(TestFile.HomeEmailList.end(), TestFileIter); + ASSERT_EQ("moo.home@example.com", TestFileIter->second); + + // Check the ALTID section. + + TestFileIter = TestFile.HomeEmailListAltID.find(1); + ASSERT_NE(TestFile.HomeEmailListAltID.end(), TestFileIter); + ASSERT_EQ("5", TestFileIter->second); + + // Check the PID section. + + TestFileIter = TestFile.HomeEmailListPID.find(1); + ASSERT_NE(TestFile.HomeEmailListPID.end(), TestFileIter); + ASSERT_EQ("10", TestFileIter->second); + + // Check the PREF section. + + TestFileIntIter = TestFile.HomeEmailListPref.find(1); + ASSERT_NE(TestFile.HomeEmailListPref.end(), TestFileIntIter); + ASSERT_EQ(20, TestFileIntIter->second); + + // Check the extra tokens. + + TestFileIter = TestFile.HomeEmailListTokens.find(1); + ASSERT_NE(TestFile.HomeEmailListTokens.end(), TestFileIter); + ASSERT_EQ("PEACE=quiet", TestFileIter->second); + + // Start with the business email. + + TestFileIter = TestFile.BusinessEmailList.find(2); + ASSERT_NE(TestFile.BusinessEmailList.end(), TestFileIter); + ASSERT_EQ("moo.business@example.com", TestFileIter->second); + + // Check the ALTID section. + + TestFileIter = TestFile.BusinessEmailListAltID.find(2); + ASSERT_NE(TestFile.BusinessEmailListAltID.end(), TestFileIter); + ASSERT_EQ("1", TestFileIter->second); + + // Check the PID section. + + TestFileIter = TestFile.BusinessEmailListPID.find(2); + ASSERT_NE(TestFile.BusinessEmailListPID.end(), TestFileIter); + ASSERT_EQ("2", TestFileIter->second); + + // Check the PREF section. + + TestFileIntIter = TestFile.BusinessEmailListPref.find(2); + ASSERT_NE(TestFile.BusinessEmailListPref.end(), TestFileIntIter); + ASSERT_EQ(3, TestFileIntIter->second); + + // Check the extra tokens. + + TestFileIter = TestFile.BusinessEmailListTokens.find(2); + ASSERT_NE(TestFile.BusinessEmailListTokens.end(), TestFileIter); + ASSERT_EQ("BUSINESS=Money", TestFileIter->second); + + +} + // TODO: Add tests for the Contact Loading process. \ No newline at end of file