Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added source, header and unit tests for TZ vCard property in the ContactDataObject.
authorSteve Brokenshire <sbrokenshire@xestia.co.uk>
Sun, 13 Dec 2015 18:07:53 +0000 (18:07 +0000)
committerSteve Brokenshire <sbrokenshire@xestia.co.uk>
Sun, 13 Dec 2015 18:07:53 +0000 (18:07 +0000)
source/contacteditor/ContactDataObject.cpp
source/contacteditor/ContactDataObject.h
source/tests/LoadCheck-Load4.vcf
source/tests/xestiaab_contactload.h

index 5275553..2a7f6a4 100644 (file)
@@ -83,6 +83,7 @@ ContactLoadStatus ContactDataObject::LoadFile(wxString Filename){
        int GroupCount = 0;
        int FNCount = 0;
        int NicknameCount = 0;
+       int TimeZoneCount = 0;
        wxString ContactLine;
        wxString PropertyLine;
        wxString PropertySeg1;
@@ -220,6 +221,11 @@ ContactLoadStatus ContactDataObject::LoadFile(wxString Filename){
                        ProcessAnniversary(PropertySeg1, PropertySeg2);
                        AnniversaryProcessed = TRUE;
                
+               } else if (Property == wxT("TZ")){
+               
+                       ProcessTimeZone(PropertySeg1, PropertySeg2, &TimeZoneCount);
+                       TimeZoneCount++;
+               
                }
                
        }
@@ -990,11 +996,11 @@ void ContactDataObject::ProcessAnniversary(wxString PropertySeg1, wxString Prope
        wxString PropertyValue;
        wxString PropertyTokens;
        bool AnniversaryText = FALSE;
-       int intPrevValue = 6;
+       int intPrevValue = 13;
 
        SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
 
-       intPrevValue = 5;
+       intPrevValue = 12;
 
        // Look for type before continuing.
 
@@ -1023,7 +1029,7 @@ void ContactDataObject::ProcessAnniversary(wxString PropertySeg1, wxString Prope
 
        // Setup blank lines for later on.
        
-       intPrevValue = 5;
+       intPrevValue = 12;
        bool FirstToken = TRUE;
 
        for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
@@ -1104,6 +1110,158 @@ void ContactDataObject::ProcessAnniversary(wxString PropertySeg1, wxString Prope
 
 }
 
+void ContactDataObject::ProcessTimeZone(wxString PropertySeg1, wxString PropertySeg2, int *TimeZoneCount){
+
+       std::map<int, int> SplitPoints;
+       std::map<int, int> SplitLength;
+
+       int intPrevValue = 4;
+       int intPref = 0;                        
+       
+       SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
+       
+       intPrevValue = 3;
+       
+       PropertyType PropType;
+       
+       // Look for type before continuing.
+       
+       CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType);
+       
+       intPrevValue = 3;
+       
+       std::map<int, wxString> *TZList = NULL;
+       std::map<int, wxString> *TZListType = NULL;
+       std::map<int, wxString> *TZListMediatype = NULL;
+       std::map<int, wxString> *TZListAltID = NULL;
+       std::map<int, wxString> *TZListPID = NULL;
+       std::map<int, wxString> *TZListTokens = NULL;           
+       std::map<int, int> *TZListPref = NULL;
+       
+       switch(PropType){
+               case PROPERTY_NONE:
+                       TZList = &GeneralTZList;
+                       TZListType = &GeneralTZListType;
+                       TZListMediatype = &GeneralTZListMediatype;
+                       TZListAltID = &GeneralTZListAltID;
+                       TZListPID = &GeneralTZListPID;
+                       TZListTokens = &GeneralTZListTokens;
+                       TZListPref = &GeneralTZListPref;
+                       break;
+               case PROPERTY_HOME:
+                       TZList = &HomeTZList;
+                       TZListType = &HomeTZListType;
+                       TZListMediatype = &HomeTZListMediatype;
+                       TZListAltID = &HomeTZListAltID;
+                       TZListPID = &HomeTZListPID;
+                       TZListTokens = &HomeTZListTokens;
+                       TZListPref = &HomeTZListPref;
+                       break;
+               case PROPERTY_WORK:
+                       TZList = &BusinessTZList;
+                       TZListType = &BusinessTZListType;
+                       TZListMediatype = &BusinessTZListMediatype;
+                       TZListAltID = &BusinessTZListAltID;
+                       TZListPID = &BusinessTZListPID;
+                       TZListTokens = &BusinessTZListTokens;
+                       TZListPref = &BusinessTZListPref;
+                       break;
+       }
+       
+       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);
+
+               if (PropertyName == wxT("ALTID")){
+
+                       TZListAltID->erase(*TimeZoneCount);
+                       TZListAltID->insert(std::make_pair(*TimeZoneCount, PropertyValue));
+               
+               } else if (PropertyName == wxT("PID")){
+
+                       TZListPID->erase(*TimeZoneCount);
+                       TZListPID->insert(std::make_pair(*TimeZoneCount, 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){
+
+                               TZListPref->erase(*TimeZoneCount);
+                               TZListPref->insert(std::make_pair(*TimeZoneCount, PriorityNumber));
+
+                       }
+               
+               } else if (PropertyName == wxT("MEDIATYPE")){
+
+                       TZListMediatype->erase(*TimeZoneCount);
+                       TZListMediatype->insert(std::make_pair(*TimeZoneCount, 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);
+                       
+                               }
+               
+                       }
+               
+               }
+               
+       }
+       
+       TZList->insert(std::make_pair(*TimeZoneCount, PropertySeg2));
+       
+       // Add the name token data.
+       
+       if (!PropertyTokens.IsEmpty()){
+       
+               TZListTokens->insert(std::make_pair(*TimeZoneCount, PropertyTokens));
+       
+       }
+
+
+}
+
 void SplitValues(wxString *PropertyLine, 
        std::map<int,int> *SplitPoints, 
        std::map<int,int> *SplitLength, 
index 3a2ca7f..abf22dd 100644 (file)
@@ -572,6 +572,7 @@ class ContactDataObject{
        void ProcessGender(wxString PropertySeg1, wxString PropertySeg2);
        void ProcessBirthday(wxString PropertySeg1, wxString PropertySeg2);
        void ProcessAnniversary(wxString PropertySeg1, wxString PropertySeg2);
+       void ProcessTimeZone(wxString PropertySeg1, wxString PropertySeg2, int *TimeZoneCount);
 
 };
 
index 32ef415..1a6a8b9 100644 (file)
@@ -14,4 +14,10 @@ NICKNAME;TYPE=work;ALTID=99;PID=10;PREF=1;LANGUAGE=en-GB;YAY=Maybe;Boop=Boin
 GENDER;BEEP=Boop:F;Example Text
 BDAY;ALTID=35;CALSCALE=georgian;HAPPY=Days:20040101
 ANNIVERSARY;ALTID=70;CALSCALE=georgian;WONDERFUL=Day:20200516
+TZ;ALTID=35;PID=60;PREF=20;MEDIATYPE=text/plain;WHATS=This;A=Potato:Europe/T
+ ruro
+TZ;TYPE=home;ALTID=15;PID=20;PREF=40;MEDIATYPE=text/plain;MAYBE=not:Europe/P
+ enzance
+TZ;TYPE=work;PID=70;ALTID=45;PREF=80;MEDIATYPE=text/plain;MAYBE=yes:Europe/S
+ t Austell
 END:VCARD
index 10d10b0..d934194 100644 (file)
@@ -302,8 +302,6 @@ TEST(ContactLoad, BirthdayTests){
 
        // Check that the birthday has been read.
 
-       // Check that the gender has been read.
-
        ContactDataObject TestFile;
 
        // Check that the vCard 4.0 file loads OK.
@@ -340,9 +338,7 @@ TEST(ContactLoad, BirthdayTests){
 
 TEST(ContactLoad, AnniversaryTests){
 
-       // Check that the birthday has been read.
-
-       // Check that the gender has been read.
+       // Check that the anniversary has been read.
 
        ContactDataObject TestFile;
 
@@ -378,4 +374,125 @@ TEST(ContactLoad, AnniversaryTests){
 
 }
 
+TEST(ContactLoad, TimeZoneTests){
+
+       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;
+
+       // Check that the timezone has been read (TZ). General.
+       
+       TestFileIter = TestFile.GeneralTZList.find(0);
+       ASSERT_NE(TestFile.GeneralTZList.end(), TestFileIter);  
+       ASSERT_EQ("Europe/Truro", TestFileIter->second);
+
+       // Check the ALTID parameter.
+       
+       TestFileIter = TestFile.GeneralTZListAltID.find(0);
+       ASSERT_NE(TestFile.GeneralTZListAltID.end(), TestFileIter);
+       ASSERT_EQ("35", TestFileIter->second);
+       
+       // Check the PID parameter.
+       
+       TestFileIter = TestFile.GeneralTZListPID.find(0);
+       ASSERT_NE(TestFile.GeneralTZListPID.end(), TestFileIter);
+       ASSERT_EQ("60", TestFileIter->second);
+       
+       // Check the PREF parameter.
+
+       TestFileIntIter = TestFile.GeneralTZListPref.find(0);
+       ASSERT_NE(TestFile.GeneralTZListPref.end(), TestFileIntIter);
+       ASSERT_EQ(20, TestFileIntIter->second);
+
+       // Check the LANGUAGE parameter.
+
+       TestFileIter = TestFile.GeneralTZListMediatype.find(0);
+       ASSERT_NE(TestFile.GeneralTZListMediatype.end(), TestFileIter);
+       ASSERT_EQ("text/plain", TestFileIter->second);
+       
+       // Check the extra tokens parameter.
+       
+       TestFileIter = TestFile.GeneralTZListTokens.find(0);
+       ASSERT_NE(TestFile.GeneralTZListTokens.end(), TestFileIter);
+       ASSERT_EQ("WHATS=This;A=Potato", TestFileIter->second);
+       
+       // Check that the timezone has been read (TZ). Home.
+       
+       TestFileIter = TestFile.HomeTZList.find(1);
+       ASSERT_NE(TestFile.HomeTZList.end(), TestFileIter);     
+       ASSERT_EQ("Europe/Penzance", TestFileIter->second);
+
+       // Check the ALTID parameter.
+       
+       TestFileIter = TestFile.HomeTZListAltID.find(1);
+       ASSERT_NE(TestFile.HomeTZListAltID.end(), TestFileIter);
+       ASSERT_EQ("15", TestFileIter->second);
+       
+       // Check the PID parameter.
+       
+       TestFileIter = TestFile.HomeTZListPID.find(1);
+       ASSERT_NE(TestFile.HomeTZListPID.end(), TestFileIter);
+       ASSERT_EQ("20", TestFileIter->second);
+       
+       // Check the PREF parameter.
+
+       TestFileIntIter = TestFile.HomeTZListPref.find(1);
+       ASSERT_NE(TestFile.HomeTZListPref.end(), TestFileIntIter);
+       ASSERT_EQ(40, TestFileIntIter->second);
+
+       // Check the LANGUAGE parameter.
+
+       TestFileIter = TestFile.HomeTZListMediatype.find(1);
+       ASSERT_NE(TestFile.HomeTZListMediatype.end(), TestFileIter);
+       ASSERT_EQ("text/plain", TestFileIter->second);
+       
+       // Check the extra tokens parameter.
+       
+       TestFileIter = TestFile.HomeTZListTokens.find(1);
+       ASSERT_NE(TestFile.HomeTZListTokens.end(), TestFileIter);
+       ASSERT_EQ("MAYBE=not", TestFileIter->second);
+       
+       // Check that the timezone has been read (TZ). Business.
+       
+       TestFileIter = TestFile.BusinessTZList.find(2);
+       ASSERT_NE(TestFile.BusinessTZList.end(), TestFileIter);
+       ASSERT_EQ("Europe/St Austell", TestFileIter->second);
+
+       // Check the ALTID parameter.
+       
+       TestFileIter = TestFile.BusinessTZListAltID.find(2);
+       ASSERT_NE(TestFile.BusinessTZListAltID.end(), TestFileIter);
+       ASSERT_EQ("45", TestFileIter->second);
+       
+       // Check the PID parameter.
+       
+       TestFileIter = TestFile.BusinessTZListPID.find(2);
+       ASSERT_NE(TestFile.BusinessTZListPID.end(), TestFileIter);
+       ASSERT_EQ("70", TestFileIter->second);
+       
+       // Check the PREF parameter.
+
+       TestFileIntIter = TestFile.BusinessTZListPref.find(2);
+       ASSERT_NE(TestFile.BusinessTZListPref.end(), TestFileIntIter);
+       ASSERT_EQ(80, TestFileIntIter->second);
+
+       // Check the LANGUAGE parameter.
+
+       TestFileIter = TestFile.BusinessTZListMediatype.find(2);
+       ASSERT_NE(TestFile.BusinessTZListMediatype.end(), TestFileIter);
+       ASSERT_EQ("text/plain", TestFileIter->second);
+       
+       // Check the extra tokens parameter.
+       
+       TestFileIter = TestFile.BusinessTZListTokens.find(2);
+       ASSERT_NE(TestFile.BusinessTZListTokens.end(), TestFileIter);
+       ASSERT_EQ("MAYBE=yes", 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