Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added unit tests for the ALTID, PID & PREF properties for the MEMBER vCard property.
authorSteve Brokenshire <sbrokenshire@xestia.co.uk>
Thu, 10 Dec 2015 00:00:42 +0000 (00:00 +0000)
committerSteve Brokenshire <sbrokenshire@xestia.co.uk>
Thu, 10 Dec 2015 00:00:42 +0000 (00:00 +0000)
source/contacteditor/ContactDataObject.cpp
source/contacteditor/ContactDataObject.h
source/tests/LoadCheck-Load4.vcf [new file with mode: 0644]
source/tests/xestiaab_contactload.h

index 49a5f2c..8fb6a39 100644 (file)
@@ -73,8 +73,10 @@ ContactLoadStatus ContactDataObject::LoadFile(wxString Filename){
        bool ExtraLineSeek = TRUE;
        bool QuoteMode = FALSE;
        bool PropertyFind = TRUE;
+       bool KindProcessed = FALSE;
        int ContactLineLen = 0;
        int QuoteBreakPoint = 0;
+       int GroupCount = 0;
        wxString ContactLine;
        wxString PropertyLine;
        wxString PropertySeg1;
@@ -173,10 +175,192 @@ ContactLoadStatus ContactDataObject::LoadFile(wxString Filename){
                PropertySeg1 = ContactLine.Mid(0, QuoteBreakPoint);
                PropertySeg2 = ContactLine.Mid((QuoteBreakPoint + 1));
                
+                if (Property == wxT("KIND") && KindProcessed == FALSE){
+               
+                       // See frmContactEditor-LoadGroup.cpp
+               
+                       ProcessKind(PropertySeg2);
+               
+               } else if (Property == wxT("MEMBER")){
+
+                       // See frmContactEditor-LoadGroup.cpp
+
+                       ProcessMember(PropertySeg1, PropertySeg2, &GroupCount);
+                       GroupCount++;   
+               
+               }
                
-        
        }
        
        return CONTACTLOAD_OK;
 
+}
+
+void ContactDataObject::ProcessKind(wxString KindType){
+
+       if (KindType == wxT("individual")){
+                       
+               ContactKind = CONTACTKIND_INDIVIDUAL;
+                       
+       } else if (KindType == wxT("group")){
+                       
+               ContactKind = CONTACTKIND_GROUP;
+                       
+       } else if (KindType == wxT("org")){
+                       
+               ContactKind = CONTACTKIND_ORGANISATION;
+                       
+       } else if (KindType == wxT("location")){
+                       
+               ContactKind = CONTACTKIND_LOCATION;
+                       
+       } else {
+                       
+               ContactKind = CONTACTKIND_NONE;                 
+       }
+
+}
+
+void ContactDataObject::ProcessMember(wxString PropertySeg1, wxString PropertySeg2, int *GroupCount){
+
+       std::map<int, int> SplitPoints;
+       std::map<int, int> SplitLength;
+
+       int intPrevValue = 8;
+       int intPref = 0;                        
+       int intType = 0;
+       
+       SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
+
+       intPrevValue = 7;
+       
+       // Look for type before continuing.
+       
+       wxString PropertyName;
+       wxString PropertyValue;
+       wxString PropertyData;
+       wxString PropertyTokens;
+       std::map<int,int>::iterator SLiter;
+       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);
+               
+               //ContactProcess::ContactProcessCaptureStrings(&PropertyValue);
+       
+               if (PropertyName == wxT("ALTID")){
+
+                       GroupsListAltID.erase(*GroupCount);
+                       GroupsListAltID.insert(std::make_pair(*GroupCount, PropertyValue));
+               
+               } else if (PropertyName == wxT("PID")){
+
+                       GroupsListPID.erase(*GroupCount);
+                       GroupsListPID.insert(std::make_pair(*GroupCount, 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){
+
+                               GroupsListPref.erase(*GroupCount);
+                               GroupsListPref.insert(std::make_pair(*GroupCount, PriorityNumber));
+               
+                       }
+               
+               } else if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
+                       
+                       if (FirstToken == TRUE){
+                               
+                               PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
+                               FirstToken = FALSE;
+                               
+                       } else {
+                       
+                               PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
+                               
+                       }
+                       
+               }
+               
+       }
+
+       //SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
+
+       GroupsList.insert(std::make_pair(*GroupCount, PropertySeg2));
+
+
+}
+
+void SplitValues(wxString *PropertyLine, 
+       std::map<int,int> *SplitPoints, 
+       std::map<int,int> *SplitLength, 
+       int intSize){
+       
+       size_t intPropertyLen = PropertyLine->Len();
+       int intSplitsFound = 0;
+       int intSplitSize = 0;
+       int intSplitSeek = 0;
+       
+       for (int i = intSize; i <= intPropertyLen; i++){
+
+               intSplitSize++;
+       
+               if (PropertyLine->Mid(i, 1) == wxT(";") &&
+                   PropertyLine->Mid((i - 1), 1) != wxT("\\")){
+          
+                   if (intSplitsFound == 0){
+           
+                       SplitLength->insert(std::make_pair(intSplitsFound, (intSplitSize)));
+         
+                   } else {
+          
+                       SplitLength->insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
+           
+                   }
+           
+                   SplitPoints->insert(std::make_pair(intSplitsFound, (i + 1)));
+           
+                   intSplitsFound++;
+                   intSplitSeek = i;
+                   intSplitSize = 0;
+           
+               }
+
+       }
+
+       if (intSplitsFound == 0){
+
+               SplitPoints->insert(std::make_pair(intSplitsFound, (8 + 1)));
+               SplitLength->insert(std::make_pair(intSplitsFound, intSplitSize));
+
+       } else {
+
+               SplitPoints->insert(std::make_pair(intSplitsFound, (intSplitSeek + 1)));
+               SplitLength->insert(std::make_pair(intSplitsFound, intSplitSize));
+
+       }
+
 }
\ No newline at end of file
index 050bd53..0792954 100644 (file)
@@ -25,6 +25,7 @@
 #include <wx/tokenzr.h>
 
 #include "../vcard/vcard.h"
+#include "../common/textprocessing.h"
 
 enum ContactLoadStatus{
        CONTACTLOAD_UNITTESTFAIL = -1,
@@ -35,10 +36,20 @@ enum ContactLoadStatus{
        CONTACTLOAD_FILEBASESPECFAIL
 };
 
+enum ContactKindType{
+       CONTACTKIND_NONE,
+       CONTACTKIND_INDIVIDUAL,
+       CONTACTKIND_GROUP,
+       CONTACTKIND_ORGANISATION,
+       CONTACTKIND_LOCATION
+};
+
 class ContactDataObject{
 
        public:
 
+       ContactKindType ContactKind = CONTACTKIND_NONE;
+
        /* Items on General Tab */
 
        wxString NameTitle;
@@ -546,7 +557,14 @@ class ContactDataObject{
        // Subroutines.
        
        ContactLoadStatus LoadFile(wxString Filename);
+       void ProcessKind(wxString KindData);
+       void ProcessMember(wxString PropertySeg1, wxString PropertySeg2, int *GroupCount);
 
 };
 
+void SplitValues(wxString *PropertyLine, 
+       std::map<int,int> *SplitPoints, 
+       std::map<int,int> *SplitLength, 
+       int intSize);
+
 #endif
\ No newline at end of file
diff --git a/source/tests/LoadCheck-Load4.vcf b/source/tests/LoadCheck-Load4.vcf
new file mode 100644 (file)
index 0000000..8785a45
--- /dev/null
@@ -0,0 +1,6 @@
+BEGIN:VCARD
+VERSION:4.0
+KIND:individual
+MEMBER;ALTID=35;PID=40;PREF=45:7a2af44d-6431-4797-a55f-d86d56304fda
+FN:Test
+END:VCARD
index 1820bbf..f40eeb9 100644 (file)
@@ -21,7 +21,6 @@
 
 TEST(ContactLoad, ContactLoadTests){
 
-
        ContactDataObject TestFile;
 
        // Check that the file given is not missing.
@@ -44,6 +43,39 @@ TEST(ContactLoad, ContactLoadTests){
        // Check that the vCard 4.0 file loads OK.
 
        ASSERT_EQ(CONTACTLOAD_OK, TestFile.LoadFile("LoadCheck-Load4.vcf"));
+       
+       // Check that the kind status has been set. (KIND).
+       
+       ASSERT_NE(CONTACTKIND_NONE, TestFile.ContactKind);
+       ASSERT_EQ(CONTACTKIND_INDIVIDUAL, TestFile.ContactKind);
+       
+       // Check that the groups have been read (MEMBER).
+       
+       std::map<int,wxString>::iterator TestFileIter;
+       std::map<int,int>::iterator TestFileIntIter;
+       
+       TestFileIter = TestFile.GroupsList.find(0);
+       
+       ASSERT_NE(TestFile.GroupsList.end(), TestFileIter);
+       ASSERT_EQ("7a2af44d-6431-4797-a55f-d86d56304fda", TestFileIter->second);
+
+       // Check the ALTID parameter.
+
+       TestFileIter = TestFile.GroupsListAltID.find(0);
+       ASSERT_NE(TestFile.GroupsListAltID.end(), TestFileIter);
+       ASSERT_EQ("35", TestFileIter->second);
+
+       // Check the PID parameter.
+       
+       TestFileIter = TestFile.GroupsListPID.find(0);
+       ASSERT_NE(TestFile.GroupsListPID.end(), TestFileIter);
+       ASSERT_EQ("40", TestFileIter->second);
+       
+       // Check the PREF parameter.
+       
+       TestFileIntIter = TestFile.GroupsListPref.find(0);
+       ASSERT_NE(TestFile.GroupsListPref.end(), TestFileIntIter);
+       ASSERT_EQ(45, TestFileIntIter->second);
 
 }
 
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