From: Steve Brokenshire Date: Sun, 20 Dec 2015 02:37:05 +0000 (+0000) Subject: Added source code, headers and unit testing code for the LANG vCard property for... X-Git-Tag: release-0.09~228 X-Git-Url: http://Server1/repobrowser/?a=commitdiff_plain;h=12e81906f4a76d4773a0305e0722aed881148db7;p=xestiaab%2F.git Added source code, headers and unit testing code for the LANG vCard property for ContactDataObject. --- diff --git a/source/contacteditor/ContactDataObject.cpp b/source/contacteditor/ContactDataObject.cpp index 28c12b3..3de45b7 100644 --- a/source/contacteditor/ContactDataObject.cpp +++ b/source/contacteditor/ContactDataObject.cpp @@ -88,6 +88,7 @@ ContactLoadStatus ContactDataObject::LoadFile(wxString Filename){ int EmailCount = 0; int IMCount = 0; int TelephoneCount = 0; + int LanguageCount = 0; wxString ContactLine; wxString PropertyLine; wxString PropertySeg1; @@ -250,6 +251,13 @@ ContactLoadStatus ContactDataObject::LoadFile(wxString Filename){ ProcessTelephone(PropertySeg1, PropertySeg2, &TelephoneCount); TelephoneCount++; + } else if (Property == wxT("LANG")){ + + // See frmContactEditor-LoadLanguage.cpp + + ProcessLanguage(PropertySeg1, PropertySeg2, &LanguageCount); + LanguageCount++; + } } @@ -1938,7 +1946,7 @@ void ContactDataObject::ProcessIM(wxString PropertySeg1, wxString PropertySeg2, IMListTokens->insert(std::make_pair(*IMCount, PropertyTokens)); - } + } } @@ -2253,6 +2261,147 @@ void ContactDataObject::ProcessTelephone(wxString PropertySeg1, wxString Propert } +void ContactDataObject::ProcessLanguage(wxString PropertySeg1, wxString PropertySeg2, int *LanguageCount){ + + std::map SplitPoints; + std::map SplitLength; + + int intPrevValue = 6; + int intPref = 0; + + SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue); + + intPrevValue = 5; + + PropertyType PropType = PROPERTY_NONE; + + // Look for type before continuing. + + CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType); + + std::map *LanguageList = NULL; + std::map *LanguageListType = NULL; + std::map *LanguageListAltID = NULL; + std::map *LanguageListPID = NULL; + std::map *LanguageListTokens = NULL; + std::map *LanguageListPref = NULL; + + switch(PropType){ + case PROPERTY_NONE: + LanguageList = &GeneralLanguageList; + LanguageListType = &GeneralLanguageListType; + LanguageListAltID = &GeneralLanguageListAltID; + LanguageListPID = &GeneralLanguageListPID; + LanguageListTokens = &GeneralLanguageListTokens; + LanguageListPref = &GeneralLanguageListPref; + break; + case PROPERTY_HOME: + LanguageList = &HomeLanguageList; + LanguageListType = &HomeLanguageListType; + LanguageListAltID = &HomeLanguageListAltID; + LanguageListPID = &HomeLanguageListPID; + LanguageListTokens = &HomeLanguageListTokens; + LanguageListPref = &HomeLanguageListPref; + break; + case PROPERTY_WORK: + LanguageList = &BusinessLanguageList; + LanguageListType = &BusinessLanguageListType; + LanguageListAltID = &BusinessLanguageListAltID; + LanguageListPID = &BusinessLanguageListPID; + LanguageListTokens = &BusinessLanguageListTokens; + LanguageListPref = &BusinessLanguageListPref; + break; + } + + intPrevValue = 5; + + 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")){ + + LanguageListAltID->erase(*LanguageCount); + LanguageListAltID->insert(std::make_pair(*LanguageCount, PropertyValue)); + + } else if (PropertyName == wxT("PID")){ + + LanguageListPID->erase(*LanguageCount); + LanguageListPID->insert(std::make_pair(*LanguageCount, 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){ + + LanguageListPref->erase(*LanguageCount); + LanguageListPref->insert(std::make_pair(*LanguageCount, 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); + + } + + } + + } + + } + + LanguageList->insert(std::make_pair(*LanguageCount, PropertySeg2)); + + // Add the name token data. + + if (!PropertyTokens.IsEmpty()){ + + LanguageListTokens->insert(std::make_pair(*LanguageCount, PropertyTokens)); + + } + +} + void SplitValues(wxString *PropertyLine, std::map *SplitPoints, std::map *SplitLength, diff --git a/source/contacteditor/ContactDataObject.h b/source/contacteditor/ContactDataObject.h index f8e79bb..4503a0c 100644 --- a/source/contacteditor/ContactDataObject.h +++ b/source/contacteditor/ContactDataObject.h @@ -580,6 +580,7 @@ class ContactDataObject{ void ProcessEmail(wxString PropertySeg1, wxString PropertySeg2, int *EmailCount); void ProcessIM(wxString PropertySeg1, wxString PropertySeg2, int *IMCount); void ProcessTelephone(wxString PropertySeg1, wxString PropertySeg2, int *TelephoneCount); + void ProcessLanguage(wxString PropertySeg1, wxString PropertySeg2, int *LanguageCount); }; diff --git a/source/tests/LoadCheck-Load4.vcf b/source/tests/LoadCheck-Load4.vcf index e4d91ac..3172cb8 100644 --- a/source/tests/LoadCheck-Load4.vcf +++ b/source/tests/LoadCheck-Load4.vcf @@ -44,4 +44,7 @@ IMPP;TYPE=work;ALTID=98;PID=99;PREF=50;MEDIATYPE=text/superplain;BUSINESS=Mo TEL;ALTID=10;PID=20;PREF=40;WONDERFUL=Colour;TYPE="fax,cell":tel:00000000 TEL;TYPE="home,fax";ALTID=10;PID=20;PREF=40;BUSINESS=Money:tel:00001111 TEL;TYPE="work,voice";ALTID=25;PID=50;PREF=75;BEEP=Boop:tel:22221111 +LANG;ALTID=20;PID=40;PREF=80;GELFORN=Great:kw +LANG;TYPE=home;ALTID=22;PID=45;PREF=90;LANGUAGE=yes:en +LANG;TYPE=work;ALTID=10;PID=15;PREF=20;FFENSTRI=ie:cy END:VCARD diff --git a/source/tests/xestiaab_contactload.h b/source/tests/xestiaab_contactload.h index 09e4c4a..39fe16f 100644 --- a/source/tests/xestiaab_contactload.h +++ b/source/tests/xestiaab_contactload.h @@ -1112,7 +1112,106 @@ TEST(ContactLoad, TelephoneTests){ } -TEST(ContactLoad, TelephoneTests){ +TEST(ContactLoad, LanguageTests){ + + 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 language. + + TestFileIter = TestFile.GeneralLanguageList.find(0); + ASSERT_NE(TestFile.GeneralLanguageList.end(), TestFileIter); + ASSERT_EQ("kw", TestFileIter->second); + + // Check the ALTID section. + + TestFileIter = TestFile.GeneralLanguageListAltID.find(0); + ASSERT_NE(TestFile.GeneralLanguageListAltID.end(), TestFileIter); + ASSERT_EQ("20", TestFileIter->second); + + // Check the PID section. + + TestFileIter = TestFile.GeneralLanguageListPID.find(0); + ASSERT_NE(TestFile.GeneralLanguageListPID.end(), TestFileIter); + ASSERT_EQ("40", TestFileIter->second); + + // Check the PREF section. + + TestFileIntIter = TestFile.GeneralLanguageListPref.find(0); + ASSERT_NE(TestFile.GeneralLanguageListPref.end(), TestFileIntIter); + ASSERT_EQ(80, TestFileIntIter->second); + + // Check the extra tokens. + + TestFileIter = TestFile.GeneralLanguageListTokens.find(0); + ASSERT_NE(TestFile.GeneralLanguageListTokens.end(), TestFileIter); + ASSERT_EQ("GELFORN=Great", TestFileIter->second); + + // Start with the home language. + + TestFileIter = TestFile.HomeLanguageList.find(1); + ASSERT_NE(TestFile.HomeLanguageList.end(), TestFileIter); + ASSERT_EQ("en", TestFileIter->second); + + // Check the ALTID section. + + TestFileIter = TestFile.HomeLanguageListAltID.find(1); + ASSERT_NE(TestFile.HomeLanguageListAltID.end(), TestFileIter); + ASSERT_EQ("22", TestFileIter->second); + + // Check the PID section. + + TestFileIter = TestFile.HomeLanguageListPID.find(1); + ASSERT_NE(TestFile.HomeLanguageListPID.end(), TestFileIter); + ASSERT_EQ("45", TestFileIter->second); + + // Check the PREF section. + + TestFileIntIter = TestFile.HomeLanguageListPref.find(1); + ASSERT_NE(TestFile.HomeLanguageListPref.end(), TestFileIntIter); + ASSERT_EQ(90, TestFileIntIter->second); + + // Check the extra tokens. + + TestFileIter = TestFile.HomeLanguageListTokens.find(1); + ASSERT_NE(TestFile.HomeLanguageListTokens.end(), TestFileIter); + ASSERT_EQ("LANGUAGE=yes", TestFileIter->second); + + // Start with the business language. + + TestFileIter = TestFile.BusinessLanguageList.find(2); + ASSERT_NE(TestFile.BusinessLanguageList.end(), TestFileIter); + ASSERT_EQ("cy", TestFileIter->second); + + // Check the ALTID section. + + TestFileIter = TestFile.BusinessLanguageListAltID.find(2); + ASSERT_NE(TestFile.BusinessLanguageListAltID.end(), TestFileIter); + ASSERT_EQ("10", TestFileIter->second); + + // Check the PID section. + + TestFileIter = TestFile.BusinessLanguageListPID.find(2); + ASSERT_NE(TestFile.BusinessLanguageListPID.end(), TestFileIter); + ASSERT_EQ("15", TestFileIter->second); + + // Check the PREF section. + + TestFileIntIter = TestFile.BusinessLanguageListPref.find(2); + ASSERT_NE(TestFile.BusinessLanguageListPref.end(), TestFileIntIter); + ASSERT_EQ(20, TestFileIntIter->second); + + // Check the extra tokens. + + TestFileIter = TestFile.BusinessLanguageListTokens.find(2); + ASSERT_NE(TestFile.BusinessLanguageListTokens.end(), TestFileIter); + ASSERT_EQ("FFENSTRI=ie", TestFileIter->second); }