bool PropertyFind = TRUE;
bool KindProcessed = FALSE;
bool NameProcessed = FALSE;
+ bool GenderProcessed = FALSE;
+ bool BirthdayProcessed = FALSE;
+ bool AnniversaryProcessed = FALSE;
int ContactLineLen = 0;
int QuoteBreakPoint = 0;
int GroupCount = 0;
ProcessNickname(PropertySeg1, PropertySeg2, &NicknameCount);
NicknameCount++;
+ } else if (Property == wxT("GENDER") && GenderProcessed == FALSE){
+
+ ProcessGender(PropertySeg1, PropertySeg2);
+ GenderProcessed = TRUE;
+
+ } else if (Property == wxT("BDAY") && BirthdayProcessed == FALSE){
+
+ ProcessBirthday(PropertySeg1, PropertySeg2);
+ BirthdayProcessed = TRUE;
+
+ } else if (Property == wxT("ANNIVERSARY") && AnniversaryProcessed == FALSE){
+
+ ProcessAnniversary(PropertySeg1, PropertySeg2);
+ AnniversaryProcessed = TRUE;
+
}
}
}
+void ContactDataObject::ProcessGender(wxString PropertySeg1, wxString PropertySeg2){
+
+ 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 = 8;
+
+ SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
+
+ intPrevValue = 7;
+
+ 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);
+
+ }
+
+ if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
+
+ if (FirstToken == TRUE){
+
+ PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
+ FirstToken = FALSE;
+
+ } else {
+
+ PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
+
+ }
+
+ }
+
+ }
+
+ wxStringTokenizer GenderData (PropertySeg2, wxT(";"));
+
+ wxString GenderComponent;
+
+ if (GenderData.CountTokens() >= 2){
+
+ Gender = GenderData.GetNextToken();
+ GenderDetails = GenderData.GetString();
+
+ CaptureString(&GenderDetails, FALSE);
+
+ } else {
+
+ Gender = GenderData.GetNextToken();
+
+ }
+
+ if (!PropertyTokens.IsEmpty()){
+
+ GenderTokens = PropertyTokens;
+
+ }
+
+}
+
+void ContactDataObject::ProcessBirthday(wxString PropertySeg1, wxString PropertySeg2){
+
+ // Process date. Preserve the remainder in the string.
+
+ 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 BirthdayText = FALSE;
+ int intPrevValue = 6;
+
+ SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
+
+ intPrevValue = 5;
+
+ // Look for type before continuing.
+
+ 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;
+
+ if (PropertyName == wxT("VALUE") && PropertyValue == wxT("text") && BirthdayText == FALSE){
+
+ CaptureString(&PropertySeg2, FALSE);
+ Birthday = PropertySeg2;
+ BirthdayText = TRUE;
+
+ }
+
+ }
+
+ // Setup blank lines for later on.
+
+ intPrevValue = 5;
+ 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;
+
+ // Process properties.
+
+ CaptureString(&PropertyValue, FALSE);
+
+ if (PropertyValue.Mid((PropertyValue.Len() - 1), 1) == wxT("\"")){
+
+ PropertyValue.Trim();
+ PropertyValue.RemoveLast();
+
+ }
+
+ if (PropertyValue.Mid(0, 1) == wxT("\"")){
+
+ PropertyValue.Remove(0, 1);
+
+ }
+
+ if (PropertyName == wxT("ALTID")){
+
+ BirthdayAltID = PropertyValue;
+
+ } else if (PropertyName == wxT("CALSCALE")){
+
+ BirthdayCalScale = PropertyValue;
+
+ } else if (PropertyName != wxT("VALUE")) {
+
+ // Something else we don't know about so append
+ // to the tokens variable.
+
+ if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
+
+ if (FirstToken == TRUE){
+
+ PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
+ FirstToken = FALSE;
+
+ } else {
+
+ PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
+
+ }
+
+ }
+
+ }
+
+ }
+
+ // Add the data to the variables and form.
+
+ if (BirthdayText == FALSE){
+
+ Birthday = PropertySeg2;
+
+ }
+
+ if (!PropertyTokens.IsEmpty()){
+
+ BirthdayTokens = PropertyTokens;
+
+ }
+
+}
+
+void ContactDataObject::ProcessAnniversary(wxString PropertySeg1, wxString PropertySeg2){
+
+ // Process date. Preserve the remainder in the string.
+
+ 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 AnniversaryText = FALSE;
+ int intPrevValue = 6;
+
+ SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
+
+ intPrevValue = 5;
+
+ // Look for type before continuing.
+
+ 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;
+
+ if (PropertyName == wxT("VALUE") && PropertyValue == wxT("text") && AnniversaryText == FALSE){
+
+ CaptureString(&PropertySeg2, FALSE);
+ Anniversary = PropertySeg2;
+ AnniversaryText = TRUE;
+
+ }
+
+ }
+
+ // Setup blank lines for later on.
+
+ intPrevValue = 5;
+ 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;
+
+ // Process properties.
+
+ CaptureString(&PropertyValue, FALSE);
+
+ if (PropertyValue.Mid((PropertyValue.Len() - 1), 1) == wxT("\"")){
+
+ PropertyValue.Trim();
+ PropertyValue.RemoveLast();
+
+ }
+
+ if (PropertyValue.Mid(0, 1) == wxT("\"")){
+
+ PropertyValue.Remove(0, 1);
+
+ }
+
+ if (PropertyName == wxT("ALTID")){
+
+ AnniversaryAltID = PropertyValue;
+
+ } else if (PropertyName == wxT("CALSCALE")){
+
+ AnniversaryCalScale = PropertyValue;
+
+ } else if (PropertyName != wxT("VALUE")) {
+
+ // Something else we don't know about so append
+ // to the tokens variable.
+
+ if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
+
+ if (FirstToken == TRUE){
+
+ PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
+ FirstToken = FALSE;
+
+ } else {
+
+ PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
+
+ }
+
+ }
+
+ }
+
+ }
+
+ // Add the data to the variables and form.
+
+ if (AnniversaryText == FALSE){
+
+ Anniversary = PropertySeg2;
+
+ }
+
+ if (!PropertyTokens.IsEmpty()){
+
+ AnniversaryTokens = PropertyTokens;
+
+ }
+
+}
+
void SplitValues(wxString *PropertyLine,
std::map<int,int> *SplitPoints,
std::map<int,int> *SplitLength,
// Check the extra tokens parameter.
ASSERT_EQ("TEST=Yes", TestFile.NameTokens);
-
+
+}
+
+TEST(ContactLoad, NicknameTests){
+
+ 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 nickname has been read (NICKNAME). General.
TestFileIter = TestFile.GeneralNicknamesList.find(0);
}
+TEST(ContactLoad, GenderTests){
+
+ // Check that the gender has been read.
+
+ 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;
+
+ ASSERT_NE("", TestFile.Gender);
+ ASSERT_EQ("F", TestFile.Gender);
+ ASSERT_EQ("Example Text", TestFile.GenderDetails);
+ ASSERT_EQ("BEEP=Boop", TestFile.GenderTokens);
+
+}
+
+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.
+
+ ASSERT_EQ(CONTACTLOAD_OK, TestFile.LoadFile("LoadCheck-Load4.vcf"));
+
+ std::map<int,wxString>::iterator TestFileIter;
+ std::map<int,int>::iterator TestFileIntIter;
+
+ ASSERT_NE("", TestFile.Birthday);
+ ASSERT_EQ("20040101", TestFile.Birthday);
+
+ // Check the ALTID parameter.
+
+ ASSERT_EQ("35", TestFile.BirthdayAltID);
+
+ // Check the CALSCALE parameter.
+
+ ASSERT_EQ("georgian", TestFile.BirthdayCalScale);
+
+ // Check the extra tokens parameter.
+
+ ASSERT_EQ("HAPPY=Days", TestFile.BirthdayTokens);
+
+ // Check the VALUE parameter. (Note have to use a different file
+ // due to the *1 rule in RFC6350.
+
+ ContactDataObject TestFileValue;
+ ASSERT_EQ(CONTACTLOAD_OK, TestFile.LoadFile("LoadCheck-Load4-BDayValue.vcf"));
+
+ ASSERT_EQ("Circa 2000s", TestFile.Birthday);
+
+}
+
+TEST(ContactLoad, AnniversaryTests){
+
+ // 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.
+
+ ASSERT_EQ(CONTACTLOAD_OK, TestFile.LoadFile("LoadCheck-Load4.vcf"));
+
+ std::map<int,wxString>::iterator TestFileIter;
+ std::map<int,int>::iterator TestFileIntIter;
+
+ ASSERT_NE("", TestFile.Anniversary);
+ ASSERT_EQ("20200516", TestFile.Anniversary);
+
+ // Check the ALTID parameter.
+
+ ASSERT_EQ("70", TestFile.AnniversaryAltID);
+
+ // Check the CALSCALE parameter.
+
+ ASSERT_EQ("georgian", TestFile.AnniversaryCalScale);
+
+ // Check the extra tokens parameter.
+
+ ASSERT_EQ("WONDERFUL=Day", TestFile.AnniversaryTokens);
+
+ // Check the VALUE parameter. (Note have to use a different file
+ // due to the *1 rule in RFC6350.
+
+ ContactDataObject TestFileValue;
+ ASSERT_EQ(CONTACTLOAD_OK, TestFile.LoadFile("LoadCheck-Load4-BDayValue.vcf"));
+
+ ASSERT_EQ("Circa 2020s", TestFile.Anniversary);
+
+}
+
// TODO: Add tests for the Contact Loading process.
\ No newline at end of file