From: Steve Brokenshire Date: Sun, 27 Dec 2015 02:35:34 +0000 (+0000) Subject: Added source code, headers and unit tests for the SOURCE vCard property for ContactDa... X-Git-Tag: release-0.09~210 X-Git-Url: http://Server1/repobrowser/?a=commitdiff_plain;h=8a44cb6af4ffe0aae2d27208d9471e0d6b158c8b;p=xestiaab%2F.git Added source code, headers and unit tests for the SOURCE vCard property for ContactDataObject. --- diff --git a/source/contacteditor/ContactDataObject.cpp b/source/contacteditor/ContactDataObject.cpp index bb85052..4dad1f9 100644 --- a/source/contacteditor/ContactDataObject.cpp +++ b/source/contacteditor/ContactDataObject.cpp @@ -81,6 +81,7 @@ ContactLoadStatus ContactDataObject::LoadFile(wxString Filename){ bool UIDProcessed = FALSE; int ContactLineLen = 0; int QuoteBreakPoint = 0; + int SourceCount = 0; int GroupCount = 0; int FNCount = 0; int NicknameCount = 0; @@ -214,6 +215,11 @@ ContactLoadStatus ContactDataObject::LoadFile(wxString Filename){ UIDToken = PropertySeg2; UIDProcessed = TRUE; + } else if (Property == wxT("SOURCE")){ + + ProcessSource(PropertySeg1, PropertySeg2, &SourceCount); + SourceCount++; + } else if (Property == wxT("MEMBER")){ ProcessMember(PropertySeg1, PropertySeg2, &GroupCount); @@ -435,6 +441,158 @@ void ContactDataObject::ProcessKind(wxString KindType){ } +void ContactDataObject::ProcessSource(wxString PropertySeg1, wxString PropertySeg2, int *SourceCount){ + + size_t intPropertyLen = PropertySeg1.Len(); + std::map SplitPoints; + std::map SplitLength; + std::map::iterator SLiter; + wxString PropertyData; + wxString PropertyName; + wxString PropertyValue; + wxString PropertyTokens; + bool FirstToken = TRUE; + int intSplitsFound = 0; + int intSplitSize = 0; + int intPrevValue = 8; + int intPref = 0; + int intType = 0; + + SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue); + + intPrevValue = 7; + + PropertyType PropType = PROPERTY_NONE; + + // Look for type before continuing. + + CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType); + + intPrevValue = 7; + + for (std::map::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")){ + + SourceListAltID.erase(*SourceCount); + SourceListAltID.insert(std::make_pair(*SourceCount, PropertyValue)); + + } else if (PropertyName == wxT("PID")){ + + SourceListPID.erase(*SourceCount); + SourceListPID.insert(std::make_pair(*SourceCount, 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){ + + SourceListPref.erase(*SourceCount); + SourceListPref.insert(std::make_pair(*SourceCount, PriorityNumber)); + + } + + } else if (PropertyName == wxT("MEDIATYPE")){ + + SourceListMediatype.erase(*SourceCount); + SourceListMediatype.insert(std::make_pair(*SourceCount, 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); + + } + + } + + } + + } + + intPropertyLen = PropertySeg2.Len(); + SplitPoints.clear(); + SplitLength.clear(); + intSplitsFound = 0; + intSplitSize = 0; + intPrevValue = 0; + + CaptureString(&PropertySeg2, FALSE); + + // Add the data to the General/Home/Work address variables. + + switch(PropType){ + case PROPERTY_NONE: + break; + case PROPERTY_HOME: + SourceListType.insert(std::make_pair(*SourceCount, "home")); + break; + case PROPERTY_WORK: + SourceListType.insert(std::make_pair(*SourceCount, "work")); + break; + } + + SourceList.insert(std::make_pair(*SourceCount, PropertySeg2)); + + if (!PropertyTokens.IsEmpty()){ + + SourceListTokens.insert(std::make_pair(*SourceCount, PropertyTokens)); + + } + +} + void ContactDataObject::ProcessMember(wxString PropertySeg1, wxString PropertySeg2, int *GroupCount){ std::map SplitPoints; diff --git a/source/contacteditor/ContactDataObject.h b/source/contacteditor/ContactDataObject.h index 4e834d5..1186e21 100644 --- a/source/contacteditor/ContactDataObject.h +++ b/source/contacteditor/ContactDataObject.h @@ -55,6 +55,7 @@ class ContactDataObject{ private: void ProcessKind(wxString KindData); + void ProcessSource(wxString PropertySeg1, wxString PropertySeg2, int *SourceCount); void ProcessMember(wxString PropertySeg1, wxString PropertySeg2, int *GroupCount); void ProcessFN(wxString PropertySeg1, wxString PropertySeg2, int *FNCount); void ProcessN(wxString PropertySeg1, wxString PropertySeg2); @@ -116,6 +117,14 @@ class ContactDataObject{ wxString GenderTokens; wxString UIDToken; + + std::map SourceList; + std::map SourceListAltID; + std::map SourceListPID; + std::map SourceListType; + std::map SourceListTokens; + std::map SourceListMediatype; + std::map SourceListPref; /* We don't use these at the moment but we want to keep them for compatability reasons */ diff --git a/source/tests/LoadCheck-Load4.vcf b/source/tests/LoadCheck-Load4.vcf index 704deee..575f55c 100644 --- a/source/tests/LoadCheck-Load4.vcf +++ b/source/tests/LoadCheck-Load4.vcf @@ -2,6 +2,12 @@ BEGIN:VCARD VERSION:4.0 UID:903588-9082374-989120310-AAFECDBCDF KIND:individual +SOURCE;ALTID=74;PID=71;PREF=72;MEDIATYPE=text/plain;STATUS=FEED:http://examp + le.com/source/sourcea.vcf +SOURCE;TYPE=home;ALTID=84;PID=81;MEDIATYPE=text/plainpaper;STATUS=ONLINE;PRE + F=82:http://example.com/source/sourceb.vcf +SOURCE;TYPE=work;ALTID=94;PID=91;MEDIATYPE=text/sandpaper;PREF=92;STATUS=OFF + LINE:http://example.com/source/sourcec.vcf MEMBER;ALTID=35;PID=40;PREF=45;MEDIATYPE=text/plain;EXAMPLE=Meep:7a2af44d-64 31-4797-a55f-d86d56304fda FN;TYPE=work;LANGUAGE=kw;ALTID=500;PID=40;PREF=45;EXAMPLE=Baaa:Test Contact diff --git a/source/tests/xestiaab_contactload.h b/source/tests/xestiaab_contactload.h index da35e06..e2217a1 100644 --- a/source/tests/xestiaab_contactload.h +++ b/source/tests/xestiaab_contactload.h @@ -169,6 +169,144 @@ TEST(ContactLoad, UIDTest){ } +TEST(ContactLoad, SourceTests){ + + ContactDataObject TestFile; + + // Check that the vCard 4.0 file loads OK. + + ASSERT_EQ(CONTACTLOAD_OK, TestFile.LoadFile("LoadCheck-Load4.vcf")); + + std::map::iterator TestFileIter; + std::map::iterator TestFileIntIter; + + // Start with a general source address. + + TestFileIter = TestFile.SourceList.find(0); + ASSERT_NE(TestFile.SourceList.end(), TestFileIter); + ASSERT_EQ("http://example.com/source/sourcea.vcf", TestFileIter->second); + + // Check the TYPE section. + + TestFileIter = TestFile.SourceListType.find(0); + ASSERT_EQ(TestFile.SourceListType.end(), TestFileIter); + + // Check the ALTID section. + + TestFileIter = TestFile.SourceListAltID.find(0); + ASSERT_NE(TestFile.SourceListAltID.end(), TestFileIter); + ASSERT_EQ("74", TestFileIter->second); + + // Check the PID section. + + TestFileIter = TestFile.SourceListPID.find(0); + ASSERT_NE(TestFile.SourceListPID.end(), TestFileIter); + ASSERT_EQ("71", TestFileIter->second); + + // Check the MEDIATYPE section. + + TestFileIter = TestFile.SourceListMediatype.find(0); + ASSERT_NE(TestFile.SourceListMediatype.end(), TestFileIter); + ASSERT_EQ("text/plain", TestFileIter->second); + + // Check the PREF section. + + TestFileIntIter = TestFile.SourceListPref.find(0); + ASSERT_NE(TestFile.SourceListPref.end(), TestFileIntIter); + ASSERT_EQ(72, TestFileIntIter->second); + + // Check the extra tokens. + + TestFileIter = TestFile.SourceListTokens.find(0); + ASSERT_NE(TestFile.SourceListTokens.end(), TestFileIter); + ASSERT_EQ("STATUS=FEED", TestFileIter->second); + + // Start with the home source address. + + TestFileIter = TestFile.SourceList.find(1); + ASSERT_NE(TestFile.SourceList.end(), TestFileIter); + ASSERT_EQ("http://example.com/source/sourceb.vcf", TestFileIter->second); + + // Check the TYPE section. + + TestFileIter = TestFile.SourceListType.find(1); + ASSERT_NE(TestFile.SourceListType.end(), TestFileIter); + ASSERT_EQ("home", TestFileIter->second); + + // Check the ALTID section. + + TestFileIter = TestFile.SourceListAltID.find(1); + ASSERT_NE(TestFile.SourceListAltID.end(), TestFileIter); + ASSERT_EQ("84", TestFileIter->second); + + // Check the PID section. + + TestFileIter = TestFile.SourceListPID.find(1); + ASSERT_NE(TestFile.SourceListPID.end(), TestFileIter); + ASSERT_EQ("81", TestFileIter->second); + + // Check the MEDIATYPE section. + + TestFileIter = TestFile.SourceListMediatype.find(1); + ASSERT_NE(TestFile.SourceListMediatype.end(), TestFileIter); + ASSERT_EQ("text/plainpaper", TestFileIter->second); + + // Check the PREF section. + + TestFileIntIter = TestFile.SourceListPref.find(1); + ASSERT_NE(TestFile.SourceListPref.end(), TestFileIntIter); + ASSERT_EQ(82, TestFileIntIter->second); + + // Check the extra tokens. + + TestFileIter = TestFile.SourceListTokens.find(1); + ASSERT_NE(TestFile.SourceListTokens.end(), TestFileIter); + ASSERT_EQ("STATUS=ONLINE", TestFileIter->second); + + // Start with the home source address. + + TestFileIter = TestFile.SourceList.find(2); + ASSERT_NE(TestFile.SourceList.end(), TestFileIter); + ASSERT_EQ("http://example.com/source/sourcec.vcf", TestFileIter->second); + + // Check the TYPE section. + + TestFileIter = TestFile.SourceListType.find(2); + ASSERT_NE(TestFile.SourceListType.end(), TestFileIter); + ASSERT_EQ("work", TestFileIter->second); + + // Check the ALTID section. + + TestFileIter = TestFile.SourceListAltID.find(2); + ASSERT_NE(TestFile.SourceListAltID.end(), TestFileIter); + ASSERT_EQ("94", TestFileIter->second); + + // Check the PID section. + + TestFileIter = TestFile.SourceListPID.find(2); + ASSERT_NE(TestFile.SourceListPID.end(), TestFileIter); + ASSERT_EQ("91", TestFileIter->second); + + // Check the MEDIATYPE section. + + TestFileIter = TestFile.SourceListMediatype.find(2); + ASSERT_NE(TestFile.SourceListMediatype.end(), TestFileIter); + ASSERT_EQ("text/sandpaper", TestFileIter->second); + + // Check the PREF section. + + TestFileIntIter = TestFile.SourceListPref.find(2); + ASSERT_NE(TestFile.SourceListPref.end(), TestFileIntIter); + ASSERT_EQ(92, TestFileIntIter->second); + + // Check the extra tokens. + + TestFileIter = TestFile.SourceListTokens.find(2); + ASSERT_NE(TestFile.SourceListTokens.end(), TestFileIter); + ASSERT_EQ("STATUS=OFFLINE", TestFileIter->second); + +} + TEST(ContactLoad, NicknameTests){ ContactDataObject TestFile;