int RelatedCount = 0;
int URLCount = 0;
int TitleCount = 0;
+ int RoleCount = 0;
wxString ContactLine;
wxString PropertyLine;
wxString PropertySeg1;
ProcessTitle(PropertySeg1, PropertySeg2, &TitleCount);
TitleCount++;
+ } else if (Property == wxT("ROLE")) {
+
+ // See frmContactEditor-LoadTitle.cpp
+
+ ProcessRole(PropertySeg1, PropertySeg2, &RoleCount);
+ RoleCount++;
+
}
}
}
+void ContactDataObject::ProcessRole(wxString PropertySeg1, wxString PropertySeg2, int *RoleCount){
+
+ std::map<int, int> SplitPoints;
+ std::map<int, int> SplitLength;
+ std::map<int, int>::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<int, wxString> *RoleList = NULL;
+ std::map<int, wxString> *RoleListAltID = NULL;
+ std::map<int, wxString> *RoleListPID = NULL;
+ std::map<int, wxString> *RoleListType = NULL;
+ std::map<int, wxString> *RoleListTokens = NULL;
+ std::map<int, wxString> *RoleListLanguage = NULL;
+ std::map<int, int> *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<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;
+
+ // 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<int,int> *SplitPoints,
std::map<int,int> *SplitLength,
std::map<int,wxString>::iterator TestFileIter;
std::map<int,int>::iterator TestFileIntIter;
- // Start with the general URL.
+ // Start with the general title.
TestFileIter = TestFile.GeneralTitleList.find(0);
ASSERT_NE(TestFile.GeneralTitleList.end(), TestFileIter);
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);
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);
}
+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<int,wxString>::iterator TestFileIter;
+ std::map<int,int>::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