Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added source code, headers and unit testing for the GEO vCard property for ContactDat...
authorSteve Brokenshire <sbrokenshire@xestia.co.uk>
Sun, 20 Dec 2015 03:28:30 +0000 (03:28 +0000)
committerSteve Brokenshire <sbrokenshire@xestia.co.uk>
Sun, 20 Dec 2015 03:28:30 +0000 (03:28 +0000)
source/contacteditor/ContactDataObject.cpp
source/contacteditor/ContactDataObject.h
source/tests/LoadCheck-Load4.vcf
source/tests/xestiaab_contactload.h

index 3de45b7..f7a7e91 100644 (file)
@@ -89,6 +89,7 @@ ContactLoadStatus ContactDataObject::LoadFile(wxString Filename){
        int IMCount = 0;
        int TelephoneCount = 0;
        int LanguageCount = 0;
+       int GeographicCount = 0;
        wxString ContactLine;
        wxString PropertyLine;
        wxString PropertySeg1;
@@ -258,6 +259,13 @@ ContactLoadStatus ContactDataObject::LoadFile(wxString Filename){
                        ProcessLanguage(PropertySeg1, PropertySeg2, &LanguageCount);
                        LanguageCount++;
                
+               } else if (Property == wxT("GEO")){
+               
+                       // See frmContactEditor-LoadGeo.cpp
+                       
+                       ProcessGeographic(PropertySeg1, PropertySeg2, &GeographicCount);        
+                       GeographicCount++;
+               
                }
                
        }
@@ -2402,6 +2410,156 @@ void ContactDataObject::ProcessLanguage(wxString PropertySeg1, wxString Property
 
 }
 
+void ContactDataObject::ProcessGeographic(wxString PropertySeg1, wxString PropertySeg2, int *GeographicCount){
+
+       std::map<int, int> SplitPoints;
+       std::map<int, int> SplitLength;
+
+       int intPrevValue = 5;
+       int intPref = 0;                        
+       
+       SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
+       
+       intPrevValue = 4;
+       
+       PropertyType PropType = PROPERTY_NONE;
+               
+       // Look for type before continuing.
+       
+       CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType);
+       
+       std::map<int, wxString> *GeopositionList = NULL;
+       std::map<int, wxString> *GeopositionListType = NULL;
+       std::map<int, wxString> *GeopositionListAltID = NULL;
+       std::map<int, wxString> *GeopositionListPID = NULL;
+       std::map<int, wxString> *GeopositionListTokens = NULL;
+       std::map<int, wxString> *GeopositionListMediatype = NULL;
+       std::map<int, int> *GeopositionListPref = NULL;
+
+       switch(PropType){
+               case PROPERTY_NONE:
+                       GeopositionList = &GeneralGeographyList;
+                       GeopositionListType = &GeneralGeographyListType;
+                       GeopositionListAltID = &GeneralGeographyListAltID;
+                       GeopositionListPID = &GeneralGeographyListPID;
+                       GeopositionListTokens = &GeneralGeographyListTokens;
+                       GeopositionListMediatype = &GeneralGeographyListMediatype;
+                       GeopositionListPref = &GeneralGeographyListPref;        
+                       break;
+               case PROPERTY_HOME:
+                       GeopositionList = &HomeGeographyList;
+                       GeopositionListType = &HomeGeographyListType;
+                       GeopositionListAltID = &HomeGeographyListAltID;
+                       GeopositionListPID = &HomeGeographyListPID;
+                       GeopositionListTokens = &HomeGeographyListTokens;
+                       GeopositionListMediatype = &HomeGeographyListMediatype;
+                       GeopositionListPref = &HomeGeographyListPref;   
+                       break;
+               case PROPERTY_WORK:
+                       GeopositionList = &BusinessGeographyList;
+                       GeopositionListType = &BusinessGeographyListType;
+                       GeopositionListAltID = &BusinessGeographyListAltID;
+                       GeopositionListPID = &BusinessGeographyListPID;
+                       GeopositionListTokens = &BusinessGeographyListTokens;
+                       GeopositionListMediatype = &BusinessGeographyListMediatype;     
+                       GeopositionListPref = &BusinessGeographyListPref;
+                       break;
+       }
+       
+       intPrevValue = 4;
+       
+       std::map<int,int>::iterator SLiter;
+       wxString PropertyData;
+       wxString PropertyName;
+       wxString PropertyValue;
+       wxString PropertyTokens;
+       bool FirstToken = TRUE;
+       
+       for (std::map<int, int>::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")){
+
+                       GeopositionListAltID->erase(*GeographicCount);
+                       GeopositionListAltID->insert(std::make_pair(*GeographicCount, PropertyValue));
+               
+               } else if (PropertyName == wxT("PID")){
+
+                       GeopositionListPID->erase(*GeographicCount);
+                       GeopositionListPID->insert(std::make_pair(*GeographicCount, PropertyValue));
+               
+               } else if (PropertyName == wxT("MEDIATYPE")){
+
+                       GeopositionListMediatype->erase(*GeographicCount);
+                       GeopositionListMediatype->insert(std::make_pair(*GeographicCount, 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){
+
+                               GeopositionListPref->erase(*GeographicCount);
+                               GeopositionListPref->insert(std::make_pair(*GeographicCount, 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);
+                               
+                               }
+                       
+                       }
+               
+               }
+       
+       }
+               
+       GeopositionList->insert(std::make_pair(*GeographicCount, PropertySeg2));
+       
+       // Add the name token data.
+       
+       if (!PropertyTokens.IsEmpty()){
+       
+               GeopositionListTokens->insert(std::make_pair(*GeographicCount, PropertyTokens));
+       
+       }
+
+}
+
 void SplitValues(wxString *PropertyLine, 
        std::map<int,int> *SplitPoints, 
        std::map<int,int> *SplitLength, 
index 4503a0c..fad1f00 100644 (file)
@@ -581,6 +581,7 @@ class ContactDataObject{
        void ProcessIM(wxString PropertySeg1, wxString PropertySeg2, int *IMCount);
        void ProcessTelephone(wxString PropertySeg1, wxString PropertySeg2, int *TelephoneCount);
        void ProcessLanguage(wxString PropertySeg1, wxString PropertySeg2, int *LanguageCount);
+       void ProcessGeographic(wxString PropertySeg1, wxString PropertySeg2, int *GeographicCount);
 
 };
 
index 3172cb8..207287e 100644 (file)
@@ -47,4 +47,9 @@ 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
+GEO;ALTID=13;MEDIATYPE=text/plain;PID=26;PREF=39;POS=Yep:geo:3.5,3.5
+GEO;TYPE=home;ALTID=140;MEDIATYPE=text/ratherplain;PID=70;PREF=1;POS=Nope:ge
+ o:7.0,7.0
+GEO;TYPE=work;ALTID=75;PID=32;TYPE=text/greenplain;PREF=4;POS=Money;MEDIATYP
+ E=text/greenplain:geo:14.0,14.0
 END:VCARD
index 39fe16f..f4be7fb 100644 (file)
@@ -1215,4 +1215,125 @@ TEST(ContactLoad, LanguageTests){
 
 }
 
+TEST(ContactLoad, GeographicTests){
+
+       ContactDataObject TestFile;
+
+       // Check that the vCard 4.0 file loads OK.
+
+       ASSERT_EQ(CONTACTLOAD_OK, TestFile.LoadFile("LoadCheck-Load4.vcf"));
+
+       std::map<int,wxString>::iterator TestFileIter;
+       std::map<int,int>::iterator TestFileIntIter;
+       
+       // Start with the general Geoposition.
+       
+       TestFileIter = TestFile.GeneralGeographyList.find(0);
+       ASSERT_NE(TestFile.GeneralGeographyList.end(), TestFileIter);
+       ASSERT_EQ("geo:3.5,3.5", TestFileIter->second);
+       
+       // Check the ALTID section.
+       
+       TestFileIter = TestFile.GeneralGeographyListAltID.find(0);
+       ASSERT_NE(TestFile.GeneralGeographyListAltID.end(), TestFileIter);
+       ASSERT_EQ("13", TestFileIter->second);
+       
+       // Check the PID section.
+       
+       TestFileIter = TestFile.GeneralGeographyListPID.find(0);
+       ASSERT_NE(TestFile.GeneralGeographyListPID.end(), TestFileIter);
+       ASSERT_EQ("26", TestFileIter->second);
+       
+       // Check the MEDIATYPE section.
+       
+       TestFileIter = TestFile.GeneralGeographyListMediatype.find(0);
+       ASSERT_NE(TestFile.GeneralGeographyListMediatype.end(), TestFileIter);
+       ASSERT_EQ("text/plain", TestFileIter->second);
+       
+       // Check the PREF section.
+       
+       TestFileIntIter = TestFile.GeneralGeographyListPref.find(0);
+       ASSERT_NE(TestFile.GeneralGeographyListPref.end(), TestFileIntIter);
+       ASSERT_EQ(39, TestFileIntIter->second);
+       
+       // Check the extra tokens.
+       
+       TestFileIter = TestFile.GeneralGeographyListTokens.find(0);
+       ASSERT_NE(TestFile.GeneralGeographyListTokens.end(), TestFileIter);
+       ASSERT_EQ("POS=Yep", TestFileIter->second);
+
+       // Start with the home Geoposition.
+       
+       TestFileIter = TestFile.HomeGeographyList.find(1);
+       ASSERT_NE(TestFile.HomeGeographyList.end(), TestFileIter);
+       ASSERT_EQ("geo:7.0,7.0", TestFileIter->second);
+       
+       // Check the ALTID section.
+       
+       TestFileIter = TestFile.HomeGeographyListAltID.find(1);
+       ASSERT_NE(TestFile.HomeGeographyListAltID.end(), TestFileIter);
+       ASSERT_EQ("140", TestFileIter->second);
+       
+       // Check the PID section.
+       
+       TestFileIter = TestFile.HomeGeographyListPID.find(1);
+       ASSERT_NE(TestFile.HomeGeographyListPID.end(), TestFileIter);
+       ASSERT_EQ("70", TestFileIter->second);
+       
+       // Check the MEDIATYPE section.
+       
+       TestFileIter = TestFile.HomeGeographyListMediatype.find(1);
+       ASSERT_NE(TestFile.HomeGeographyListMediatype.end(), TestFileIter);
+       ASSERT_EQ("text/ratherplain", TestFileIter->second);
+       
+       // Check the PREF section.
+       
+       TestFileIntIter = TestFile.HomeGeographyListPref.find(1);
+       ASSERT_NE(TestFile.HomeGeographyListPref.end(), TestFileIntIter);
+       ASSERT_EQ(1, TestFileIntIter->second);
+       
+       // Check the extra tokens.
+       
+       TestFileIter = TestFile.HomeGeographyListTokens.find(1);
+       ASSERT_NE(TestFile.HomeGeographyListTokens.end(), TestFileIter);
+       ASSERT_EQ("POS=Nope", TestFileIter->second);
+
+       // Start with the business Geoposition.
+       
+       TestFileIter = TestFile.BusinessGeographyList.find(2);
+       ASSERT_NE(TestFile.BusinessGeographyList.end(), TestFileIter);
+       ASSERT_EQ("geo:14.0,14.0", TestFileIter->second);
+       
+       // Check the ALTID section.
+       
+       TestFileIter = TestFile.BusinessGeographyListAltID.find(2);
+       ASSERT_NE(TestFile.BusinessGeographyListAltID.end(), TestFileIter);
+       ASSERT_EQ("75", TestFileIter->second);
+       
+       // Check the PID section.
+       
+       TestFileIter = TestFile.BusinessGeographyListPID.find(2);
+       ASSERT_NE(TestFile.BusinessGeographyListPID.end(), TestFileIter);
+       ASSERT_EQ("32", TestFileIter->second);
+       
+       // Check the MEDIATYPE section.
+       
+       TestFileIter = TestFile.BusinessGeographyListMediatype.find(2);
+       ASSERT_NE(TestFile.BusinessGeographyListMediatype.end(), TestFileIter);
+       ASSERT_EQ("text/greenplain", TestFileIter->second);
+       
+       // Check the PREF section.
+       
+       TestFileIntIter = TestFile.BusinessGeographyListPref.find(2);
+       ASSERT_NE(TestFile.BusinessGeographyListPref.end(), TestFileIntIter);
+       ASSERT_EQ(4, TestFileIntIter->second);
+       
+       // Check the extra tokens.
+       
+       TestFileIter = TestFile.BusinessGeographyListTokens.find(2);
+       ASSERT_NE(TestFile.BusinessGeographyListTokens.end(), TestFileIter);
+       ASSERT_EQ("POS=Money", TestFileIter->second);
+
+}
+
 // TODO: Add tests for the Contact Loading process.
\ No newline at end of file
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy