int GroupCount = 0;
int FNCount = 0;
int NicknameCount = 0;
+ int TimeZoneCount = 0;
wxString ContactLine;
wxString PropertyLine;
wxString PropertySeg1;
ProcessAnniversary(PropertySeg1, PropertySeg2);
AnniversaryProcessed = TRUE;
+ } else if (Property == wxT("TZ")){
+
+ ProcessTimeZone(PropertySeg1, PropertySeg2, &TimeZoneCount);
+ TimeZoneCount++;
+
}
}
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.
// Setup blank lines for later on.
- intPrevValue = 5;
+ intPrevValue = 12;
bool FirstToken = TRUE;
for (std::map<int, int>::iterator intiter = SplitPoints.begin();
}
+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,
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);
};
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
// 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.
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;
}
+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