From: Steve Brokenshire Date: Sun, 20 Dec 2015 18:33:31 +0000 (+0000) Subject: Added source code, headers and unit testing for the ROLE vCard Property for ContactDa... X-Git-Tag: release-0.09~224 X-Git-Url: http://Server1/repobrowser/?a=commitdiff_plain;h=a23e50effb7909d2217c6364b31f258bb9c55ff2;p=xestiaab%2F.git Added source code, headers and unit testing for the ROLE vCard Property for ContactDataObject. --- diff --git a/source/contacteditor/ContactDataObject.cpp b/source/contacteditor/ContactDataObject.cpp index a8c6e7d..d40087c 100644 --- a/source/contacteditor/ContactDataObject.cpp +++ b/source/contacteditor/ContactDataObject.cpp @@ -93,6 +93,7 @@ ContactLoadStatus ContactDataObject::LoadFile(wxString Filename){ int RelatedCount = 0; int URLCount = 0; int TitleCount = 0; + int RoleCount = 0; wxString ContactLine; wxString PropertyLine; wxString PropertySeg1; @@ -290,6 +291,13 @@ ContactLoadStatus ContactDataObject::LoadFile(wxString Filename){ ProcessTitle(PropertySeg1, PropertySeg2, &TitleCount); TitleCount++; + } else if (Property == wxT("ROLE")) { + + // See frmContactEditor-LoadTitle.cpp + + ProcessRole(PropertySeg1, PropertySeg2, &RoleCount); + RoleCount++; + } } @@ -3173,6 +3181,180 @@ void ContactDataObject::ProcessTitle(wxString PropertySeg1, wxString PropertySeg } +void ContactDataObject::ProcessRole(wxString PropertySeg1, wxString PropertySeg2, int *RoleCount){ + + std::map SplitPoints; + std::map SplitLength; + std::map::iterator SLiter; + wxString PropertyData; + wxString PropertyName; + wxString PropertyValue; + wxString PropertyTokens; + bool FirstToken = TRUE; + int intPrevValue = 6; + int intPref = 0; + int intType = 0; + long ListCtrlIndex; + + SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue); + + intPrevValue = 5; + + PropertyType PropType = PROPERTY_NONE; + + // Look for type before continuing. + + CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType); + + // Setup the pointers. + + std::map *RoleList = NULL; + std::map *RoleListAltID = NULL; + std::map *RoleListPID = NULL; + std::map *RoleListType = NULL; + std::map *RoleListTokens = NULL; + std::map *RoleListLanguage = NULL; + std::map *RoleListPref = NULL; + + // Setup blank lines for later on. + + switch(PropType){ + case PROPERTY_NONE: + RoleList = &GeneralRoleList; + RoleListType = &GeneralRoleListType; + RoleListAltID = &GeneralRoleListAltID; + RoleListPID = &GeneralRoleListPID; + RoleListTokens = &GeneralRoleListTokens; + RoleListLanguage = &GeneralRoleListLanguage; + RoleListPref = &GeneralRoleListPref; + break; + case PROPERTY_HOME: + RoleList = &HomeRoleList; + RoleListType = &HomeRoleListType; + RoleListAltID = &HomeRoleListAltID; + RoleListPID = &HomeRoleListPID; + RoleListTokens = &HomeRoleListTokens; + RoleListLanguage = &HomeRoleListLanguage; + RoleListPref = &HomeRoleListPref; + break; + case PROPERTY_WORK: + RoleList = &BusinessRoleList; + RoleListType = &BusinessRoleListType; + RoleListAltID = &BusinessRoleListAltID; + RoleListPID = &BusinessRoleListPID; + RoleListTokens = &BusinessRoleListTokens; + RoleListLanguage = &BusinessRoleListLanguage; + RoleListPref = &BusinessRoleListPref; + break; + } + + intPrevValue = 5; + + 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 == wxT("ALTID")){ + + RoleListAltID->erase(*RoleCount); + RoleListAltID->insert(std::make_pair(*RoleCount, PropertyValue)); + + } else if (PropertyName == wxT("PID")){ + + RoleListPID->erase(*RoleCount); + RoleListPID->insert(std::make_pair(*RoleCount, 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){ + + RoleListPref->erase(*RoleCount); + RoleListPref->insert(std::make_pair(*RoleCount, PriorityNumber)); + + } + + } else if (PropertyName == wxT("LANGUAGE")){ + + RoleListLanguage->erase(*RoleCount); + RoleListLanguage->insert(std::make_pair(*RoleCount, PropertyValue)); + + } else { + + // Something else we don't know about so append + // to the tokens variable. + + 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); + + } + + } + + } + + } + + // Add the data to the General/Home/Work address variables. + + CaptureString(&PropertySeg2, FALSE); + + RoleList->insert(std::make_pair(*RoleCount, PropertySeg2)); + + if (!PropertyTokens.IsEmpty()){ + + RoleListTokens->insert(std::make_pair(*RoleCount, PropertyTokens)); + + } + +} + void SplitValues(wxString *PropertyLine, std::map *SplitPoints, std::map *SplitLength, diff --git a/source/contacteditor/ContactDataObject.h b/source/contacteditor/ContactDataObject.h index 6ee0279..9c421a4 100644 --- a/source/contacteditor/ContactDataObject.h +++ b/source/contacteditor/ContactDataObject.h @@ -72,6 +72,7 @@ class ContactDataObject{ void ProcessRelated(wxString PropertySeg1, wxString PropertySeg2, int *RelatedCount); void ProcessURL(wxString PropertySeg1, wxString PropertySeg2, int *URLCount); void ProcessTitle(wxString PropertySeg1, wxString PropertySeg2, int *TitleCount); + void ProcessRole(wxString PropertySeg1, wxString PropertySeg2, int *RoleCount); public: diff --git a/source/tests/LoadCheck-Load4.vcf b/source/tests/LoadCheck-Load4.vcf index 34df7cf..673c074 100644 --- a/source/tests/LoadCheck-Load4.vcf +++ b/source/tests/LoadCheck-Load4.vcf @@ -65,4 +65,9 @@ TITLE;TYPE=home;ALTID=30;PID=31;LANGUAGE=grass/dry;PREF=32;EEP=DARK:Lord of Darkness TITLE;TYPE=work;ALTID=40;PID=41;LANGUAGE=moths/eew;PREF=42;EEP=BOTH:Master o f the Light & Darkness +ROLE;ALTID=50;PID=51;PREF=52;LANGUAGE=en;ASTERISK=None:Ordinary Person +ROLE;TYPE=home;ALTID=60;PID=61;PREF=62;LANGUAGE=en-GB;SOMEWHERE=There:Ordina + ry Lazy Person +ROLE;TYPE=work;ALTID=70;PID=71;PREF=72;LANGUAGE=en-AU;HERE=Nope:Company Owne + r END:VCARD diff --git a/source/tests/xestiaab_contactload.h b/source/tests/xestiaab_contactload.h index 0f3f88a..ece3063 100644 --- a/source/tests/xestiaab_contactload.h +++ b/source/tests/xestiaab_contactload.h @@ -1589,7 +1589,7 @@ TEST(ContactLoad, TitleTests){ std::map::iterator TestFileIter; std::map::iterator TestFileIntIter; - // Start with the general URL. + // Start with the general title. TestFileIter = TestFile.GeneralTitleList.find(0); ASSERT_NE(TestFile.GeneralTitleList.end(), TestFileIter); @@ -1625,7 +1625,7 @@ TEST(ContactLoad, TitleTests){ ASSERT_NE(TestFile.GeneralTitleListTokens.end(), TestFileIter); ASSERT_EQ("EEP=LIGHT", TestFileIter->second); - // Start with the home URL. + // Start with the home title. TestFileIter = TestFile.HomeTitleList.find(1); ASSERT_NE(TestFile.HomeTitleList.end(), TestFileIter); @@ -1661,7 +1661,7 @@ TEST(ContactLoad, TitleTests){ ASSERT_NE(TestFile.HomeTitleListTokens.end(), TestFileIter); ASSERT_EQ("EEP=DARK", TestFileIter->second); - // Start with the business URL. + // Start with the business title. TestFileIter = TestFile.BusinessTitleList.find(2); ASSERT_NE(TestFile.BusinessTitleList.end(), TestFileIter); @@ -1699,4 +1699,125 @@ TEST(ContactLoad, TitleTests){ } +TEST(ContactLoad, RoleTests){ + + 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 role. + + TestFileIter = TestFile.GeneralRoleList.find(0); + ASSERT_NE(TestFile.GeneralRoleList.end(), TestFileIter); + ASSERT_EQ("Ordinary Person", TestFileIter->second); + + // Check the ALTID section. + + TestFileIter = TestFile.GeneralRoleListAltID.find(0); + ASSERT_NE(TestFile.GeneralRoleListAltID.end(), TestFileIter); + ASSERT_EQ("50", TestFileIter->second); + + // Check the PID section. + + TestFileIter = TestFile.GeneralRoleListPID.find(0); + ASSERT_NE(TestFile.GeneralRoleListPID.end(), TestFileIter); + ASSERT_EQ("51", TestFileIter->second); + + // Check the LANGUAGE section. + + TestFileIter = TestFile.GeneralRoleListLanguage.find(0); + ASSERT_NE(TestFile.GeneralRoleListLanguage.end(), TestFileIter); + ASSERT_EQ("en", TestFileIter->second); + + // Check the PREF section. + + TestFileIntIter = TestFile.GeneralRoleListPref.find(0); + ASSERT_NE(TestFile.GeneralRoleListPref.end(), TestFileIntIter); + ASSERT_EQ(52, TestFileIntIter->second); + + // Check the extra tokens. + + TestFileIter = TestFile.GeneralRoleListTokens.find(0); + ASSERT_NE(TestFile.GeneralRoleListTokens.end(), TestFileIter); + ASSERT_EQ("ASTERISK=None", TestFileIter->second); + + // Start with the home role. + + TestFileIter = TestFile.HomeRoleList.find(1); + ASSERT_NE(TestFile.HomeRoleList.end(), TestFileIter); + ASSERT_EQ("Ordinary Lazy Person", TestFileIter->second); + + // Check the ALTID section. + + TestFileIter = TestFile.HomeRoleListAltID.find(1); + ASSERT_NE(TestFile.HomeRoleListAltID.end(), TestFileIter); + ASSERT_EQ("60", TestFileIter->second); + + // Check the PID section. + + TestFileIter = TestFile.HomeRoleListPID.find(1); + ASSERT_NE(TestFile.HomeRoleListPID.end(), TestFileIter); + ASSERT_EQ("61", TestFileIter->second); + + // Check the LANGUAGE section. + + TestFileIter = TestFile.HomeRoleListLanguage.find(1); + ASSERT_NE(TestFile.HomeRoleListLanguage.end(), TestFileIter); + ASSERT_EQ("en-GB", TestFileIter->second); + + // Check the PREF section. + + TestFileIntIter = TestFile.HomeRoleListPref.find(1); + ASSERT_NE(TestFile.HomeRoleListPref.end(), TestFileIntIter); + ASSERT_EQ(62, TestFileIntIter->second); + + // Check the extra tokens. + + TestFileIter = TestFile.HomeRoleListTokens.find(1); + ASSERT_NE(TestFile.HomeRoleListTokens.end(), TestFileIter); + ASSERT_EQ("SOMEWHERE=There", TestFileIter->second); + + // Start with the business role. + + TestFileIter = TestFile.BusinessRoleList.find(2); + ASSERT_NE(TestFile.BusinessRoleList.end(), TestFileIter); + ASSERT_EQ("Company Owner", TestFileIter->second); + + // Check the ALTID section. + + TestFileIter = TestFile.BusinessRoleListAltID.find(2); + ASSERT_NE(TestFile.BusinessRoleListAltID.end(), TestFileIter); + ASSERT_EQ("70", TestFileIter->second); + + // Check the PID section. + + TestFileIter = TestFile.BusinessRoleListPID.find(2); + ASSERT_NE(TestFile.BusinessRoleListPID.end(), TestFileIter); + ASSERT_EQ("71", TestFileIter->second); + + // Check the LANGUAGE section. + + TestFileIter = TestFile.BusinessRoleListLanguage.find(2); + ASSERT_NE(TestFile.BusinessRoleListLanguage.end(), TestFileIter); + ASSERT_EQ("en-AU", TestFileIter->second); + + // Check the PREF section. + + TestFileIntIter = TestFile.BusinessRoleListPref.find(2); + ASSERT_NE(TestFile.BusinessRoleListPref.end(), TestFileIntIter); + ASSERT_EQ(72, TestFileIntIter->second); + + // Check the extra tokens. + + TestFileIter = TestFile.BusinessRoleListTokens.find(2); + ASSERT_NE(TestFile.BusinessRoleListTokens.end(), TestFileIter); + ASSERT_EQ("HERE=Nope", TestFileIter->second); + +} + // TODO: Add tests for the Contact Loading process. \ No newline at end of file