From: Steve Brokenshire Date: Thu, 24 Dec 2015 23:55:13 +0000 (+0000) Subject: Added source code, headers and unit testing for the LOGO vCard Property for ContactDa... X-Git-Tag: release-0.09~217 X-Git-Url: http://Server1/repobrowser/?p=xestiaab%2F.git;a=commitdiff_plain;h=072925fb1ad8123b6739fdfdaaf490bc8611f381 Added source code, headers and unit testing for the LOGO vCard Property for ContactDataObject. --- diff --git a/source/contacteditor/ContactDataObject.cpp b/source/contacteditor/ContactDataObject.cpp index 1bc8b77..b7978f8 100644 --- a/source/contacteditor/ContactDataObject.cpp +++ b/source/contacteditor/ContactDataObject.cpp @@ -98,6 +98,7 @@ ContactLoadStatus ContactDataObject::LoadFile(wxString Filename){ int NoteCount = 0; int CategoryCount = 0; int PhotoCount = 0; + int LogoCount = 0; wxString ContactLine; wxString PropertyLine; wxString PropertySeg1; @@ -330,6 +331,13 @@ ContactLoadStatus ContactDataObject::LoadFile(wxString Filename){ ProcessPhoto(PropertySeg1, PropertySeg2, &PhotoCount); PhotoCount++; + } else if (Property == wxT("LOGO")) { + + // See frmContactEditor-LoadPhoto.cpp + + ProcessLogo(PropertySeg1, PropertySeg2, &LogoCount); + LogoCount++; + } } @@ -4060,7 +4068,6 @@ void ContactDataObject::ProcessPhoto(wxString PropertySeg1, wxString PropertySeg int intPrevValue = 7; int intPref = 0; int intType = 0; - long ListCtrlIndex; SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue); @@ -4262,6 +4269,223 @@ void ContactDataObject::ProcessPhoto(wxString PropertySeg1, wxString PropertySeg } +void ContactDataObject::ProcessLogo(wxString PropertySeg1, wxString PropertySeg2, int *LogoCount){ + + 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 = 6; + int intPref = 0; + int intType = 0; + + SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue); + + intPrevValue = 5; + + PropertyType PropType = PROPERTY_NONE; + + // Look for type before continuing. + + CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType); + + intPrevValue = 5; + + 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")){ + + LogosListAltID.erase(*LogoCount); + LogosListAltID.insert(std::make_pair(*LogoCount, PropertyValue)); + + } else if (PropertyName == wxT("PID")){ + + LogosListPID.erase(*LogoCount); + LogosListPID.insert(std::make_pair(*LogoCount, 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){ + + LogosListPref.erase(*LogoCount); + LogosListPref.insert(std::make_pair(*LogoCount, PriorityNumber)); + + } + + } else if (PropertyName == wxT("MEDIATYPE")){ + + LogosListMediatype.erase(*LogoCount); + LogosListMediatype.insert(std::make_pair(*LogoCount, 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); + + for (int i = 0; i <= intPropertyLen; i++){ + + intSplitSize++; + + if (PropertySeg2.Mid(i, 1) == wxT(";")){ + + intSplitsFound++; + SplitPoints.insert(std::make_pair(intSplitsFound, (i + 1))); + + if (intSplitsFound == 6){ + + SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1))); + break; + + } else { + + SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1))); + + } + + intSplitSize = 0; + + } + + } + + wxString wxSPhotoURI; + wxString wxSPhotoMIME; + wxString wxSPhotoEncoding; + wxString wxSPhotoData; + std::string base64enc; + + if (intSplitsFound == 0){ + + } else { + + std::map::iterator striter; + + striter = SplitLength.find(1); + + wxStringTokenizer wSTDataType(PropertySeg2.Mid(0, striter->second), wxT(":")); + + while (wSTDataType.HasMoreTokens() == TRUE){ + + wxSPhotoURI = wSTDataType.GetNextToken(); + wxSPhotoMIME = wSTDataType.GetNextToken(); + break; + + } + + wxStringTokenizer wSTDataInfo(PropertySeg2.Mid((striter->second + 1)), wxT(",")); + + while (wSTDataInfo.HasMoreTokens() == TRUE){ + + wxSPhotoEncoding = wSTDataInfo.GetNextToken(); + wxSPhotoData = wSTDataInfo.GetNextToken(); + base64enc = wxSPhotoData.mb_str(); + break; + + } + + } + + // Add the data to the General/Home/Work address variables. + + LogosList.insert(std::make_pair(*LogoCount, base64enc)); + LogosListPictureType.insert(std::make_pair(*LogoCount, wxSPhotoMIME)); + LogosListPicEncType.insert(std::make_pair(*LogoCount, wxSPhotoEncoding)); + + switch(PropType){ + case PROPERTY_NONE: + break; + case PROPERTY_HOME: + LogosListType.insert(std::make_pair(*LogoCount, "home")); + break; + case PROPERTY_WORK: + LogosListType.insert(std::make_pair(*LogoCount, "work")); + break; + } + + if (!PropertyTokens.IsEmpty()){ + + LogosListTokens.insert(std::make_pair(*LogoCount, PropertyTokens)); + + } + +} + void SplitValues(wxString *PropertyLine, std::map *SplitPoints, std::map *SplitLength, diff --git a/source/contacteditor/ContactDataObject.h b/source/contacteditor/ContactDataObject.h index 48c7182..116a3b6 100644 --- a/source/contacteditor/ContactDataObject.h +++ b/source/contacteditor/ContactDataObject.h @@ -77,6 +77,7 @@ class ContactDataObject{ void ProcessNote(wxString PropertySeg1, wxString PropertySeg2, int *NoteCount); void ProcessCategory(wxString PropertySeg1, wxString PropertySeg2, int *CategoryCount); void ProcessPhoto(wxString PropertySeg1, wxString PropertySeg2, int *PhotoCount); + void ProcessLogo(wxString PropertySeg1, wxString PropertySeg2, int *LogoCount); public: diff --git a/source/tests/LoadCheck-Load4.vcf b/source/tests/LoadCheck-Load4.vcf index 71a7b69..77954f3 100644 --- a/source/tests/LoadCheck-Load4.vcf +++ b/source/tests/LoadCheck-Load4.vcf @@ -96,4 +96,13 @@ PHOTO;ALTID=20;PID=21;MEDIATYPE=image/png;PREF=22;BEEP=BOOP:data:image/png;b PHOTO;ALTID=90;PID=91;MEDIATYPE=image/png;PREF=92;PHOTO=YUP:data:image/png;b ase64,iVBORw0KGgoAAAANSUhEUgAAABEAAAAKCAIAAADdHiL1AAAAIElEQVQoz2MUm53EgApep sxF4XfaoylgYiAdjOoZ3HoAeuQD2WdxRzcAAAAASUVORK5CYII= +LOGO;ALTID=70;PID=71;MEDIATYPE=image/png;PREF=72;MEEP=MOO:data:image/png;bas + e64,iVBORw0KGgoAAAANSUhEUgAAABEAAAAKCAIAAADdHiL1AAAAJUlEQVQoz2NkwAb+//8PYTA + yMmLKMjGQDuilhxHudBrbM8zCDQCxHQkPeaUvawAAAABJRU5ErkJggg== +LOGO;ALTID=20;PID=21;MEDIATYPE=image/png;PREF=22;BEEP=BOOP:data:image/png;ba + se64,iVBORw0KGgoAAAANSUhEUgAAABEAAAAKCAIAAADdHiL1AAAAHklEQVQoz2NkYPjPgAr+ow + kwMqIpYGIgHYzqGdx6AAKNAxMN5P6+AAAAAElFTkSuQmCC +LOGO;ALTID=90;PID=91;MEDIATYPE=image/png;PREF=92;LOGO=YUP:data:image/png;bas + e64,iVBORw0KGgoAAAANSUhEUgAAABEAAAAKCAIAAADdHiL1AAAAIElEQVQoz2MUm53EgApepsx + F4XfaoylgYiAdjOoZ3HoAeuQD2WdxRzcAAAAASUVORK5CYII= END:VCARD diff --git a/source/tests/xestiaab_contactload.h b/source/tests/xestiaab_contactload.h index dea51d3..66e548e 100644 --- a/source/tests/xestiaab_contactload.h +++ b/source/tests/xestiaab_contactload.h @@ -2465,4 +2465,165 @@ TEST(ContactLoad, PhotoTests){ } +TEST(ContactLoad, LogoTests){ + + ContactDataObject TestFile; + + // Check that the vCard 4.0 file loads OK. + + ASSERT_EQ(CONTACTLOAD_OK, TestFile.LoadFile("LoadCheck-Load4.vcf")); + + std::map::iterator TestStrIter; + std::map::iterator TestFileIter; + std::map::iterator TestFileIntIter; + + // Start with the first photo. + + TestStrIter = TestFile.LogosList.find(0); + ASSERT_NE(TestFile.LogosList.end(), TestStrIter); + ASSERT_EQ("iVBORw0KGgoAAAANSUhEUgAAABEAAAAKCAIAAADdHiL1AAAAJUlEQVQoz2NkwAb+//8PYTAyMmLKMjGQDuilhxHudBrbM8zCDQCxHQkPeaUvawAAAABJRU5ErkJggg==", + TestStrIter->second); + + // Check that it has the correct encoding. + + TestFileIter = TestFile.LogosListPicEncType.find(0); + ASSERT_NE(TestFile.LogosListPicEncType.end(), TestFileIter); + ASSERT_EQ("base64", TestFileIter->second); + + // Check that it has the correct image type. + + TestFileIter = TestFile.LogosListPictureType.find(0); + ASSERT_NE(TestFile.LogosListPictureType.end(), TestFileIter); + ASSERT_EQ("image/png", TestFileIter->second); + + // Check the ALTID section. + + TestFileIter = TestFile.LogosListAltID.find(0); + ASSERT_NE(TestFile.LogosListAltID.end(), TestFileIter); + ASSERT_EQ("70", TestFileIter->second); + + // Check the PID section. + + TestFileIter = TestFile.LogosListPID.find(0); + ASSERT_NE(TestFile.LogosListPID.end(), TestFileIter); + ASSERT_EQ("71", TestFileIter->second); + + // Check the MEDIATYPE section. + + TestFileIter = TestFile.LogosListMediatype.find(0); + ASSERT_NE(TestFile.LogosListMediatype.end(), TestFileIter); + ASSERT_EQ("image/png", TestFileIter->second); + + // Check the PREF section. + + TestFileIntIter = TestFile.LogosListPref.find(0); + ASSERT_NE(TestFile.LogosListPref.end(), TestFileIntIter); + ASSERT_EQ(72, TestFileIntIter->second); + + // Check the extra tokens. + + TestFileIter = TestFile.LogosListTokens.find(0); + ASSERT_NE(TestFile.LogosListTokens.end(), TestFileIter); + ASSERT_EQ("MEEP=MOO", TestFileIter->second); + + // Start with the second photo. + + TestStrIter = TestFile.LogosList.find(1); + ASSERT_NE(TestFile.LogosList.end(), TestStrIter); + ASSERT_EQ("iVBORw0KGgoAAAANSUhEUgAAABEAAAAKCAIAAADdHiL1AAAAHklEQVQoz2NkYPjPgAr+owkwMqIpYGIgHYzqGdx6AAKNAxMN5P6+AAAAAElFTkSuQmCC", + TestStrIter->second); + + // Check that it has the correct encoding. + + TestFileIter = TestFile.LogosListPicEncType.find(1); + ASSERT_NE(TestFile.LogosListPicEncType.end(), TestFileIter); + ASSERT_EQ("base64", TestFileIter->second); + + // Check that it has the correct image type. + + TestFileIter = TestFile.LogosListPictureType.find(1); + ASSERT_NE(TestFile.LogosListPictureType.end(), TestFileIter); + ASSERT_EQ("image/png", TestFileIter->second); + + // Check the ALTID section. + + TestFileIter = TestFile.LogosListAltID.find(1); + ASSERT_NE(TestFile.LogosListAltID.end(), TestFileIter); + ASSERT_EQ("20", TestFileIter->second); + + // Check the PID section. + + TestFileIter = TestFile.LogosListPID.find(1); + ASSERT_NE(TestFile.LogosListPID.end(), TestFileIter); + ASSERT_EQ("21", TestFileIter->second); + + // Check the MEDIATYPE section. + + TestFileIter = TestFile.LogosListMediatype.find(1); + ASSERT_NE(TestFile.LogosListMediatype.end(), TestFileIter); + ASSERT_EQ("image/png", TestFileIter->second); + + // Check the PREF section. + + TestFileIntIter = TestFile.LogosListPref.find(1); + ASSERT_NE(TestFile.LogosListPref.end(), TestFileIntIter); + ASSERT_EQ(22, TestFileIntIter->second); + + // Check the extra tokens. + + TestFileIter = TestFile.LogosListTokens.find(1); + ASSERT_NE(TestFile.LogosListTokens.end(), TestFileIter); + ASSERT_EQ("BEEP=BOOP", TestFileIter->second); + + // Start with the second photo. + + TestStrIter = TestFile.LogosList.find(2); + ASSERT_NE(TestFile.LogosList.end(), TestStrIter); + ASSERT_EQ("iVBORw0KGgoAAAANSUhEUgAAABEAAAAKCAIAAADdHiL1AAAAIElEQVQoz2MUm53EgApepsxF4XfaoylgYiAdjOoZ3HoAeuQD2WdxRzcAAAAASUVORK5CYII=", + TestStrIter->second); + + // Check that it has the correct encoding. + + TestFileIter = TestFile.LogosListPicEncType.find(2); + ASSERT_NE(TestFile.LogosListPicEncType.end(), TestFileIter); + ASSERT_EQ("base64", TestFileIter->second); + + // Check that it has the correct image type. + + TestFileIter = TestFile.LogosListPictureType.find(2); + ASSERT_NE(TestFile.LogosListPictureType.end(), TestFileIter); + ASSERT_EQ("image/png", TestFileIter->second); + + // Check the ALTID section. + + TestFileIter = TestFile.LogosListAltID.find(2); + ASSERT_NE(TestFile.LogosListAltID.end(), TestFileIter); + ASSERT_EQ("90", TestFileIter->second); + + // Check the PID section. + + TestFileIter = TestFile.LogosListPID.find(2); + ASSERT_NE(TestFile.LogosListPID.end(), TestFileIter); + ASSERT_EQ("91", TestFileIter->second); + + // Check the MEDIATYPE section. + + TestFileIter = TestFile.LogosListMediatype.find(2); + ASSERT_NE(TestFile.LogosListMediatype.end(), TestFileIter); + ASSERT_EQ("image/png", TestFileIter->second); + + // Check the PREF section. + + TestFileIntIter = TestFile.LogosListPref.find(2); + ASSERT_NE(TestFile.LogosListPref.end(), TestFileIntIter); + ASSERT_EQ(92, TestFileIntIter->second); + + // Check the extra tokens. + + TestFileIter = TestFile.LogosListTokens.find(2); + ASSERT_NE(TestFile.LogosListTokens.end(), TestFileIter); + ASSERT_EQ("LOGO=YUP", TestFileIter->second); + +} + // TODO: Add tests for the Contact Loading process. \ No newline at end of file