X-Git-Url: http://Server1/repobrowser/?p=xestiaab%2F.git;a=blobdiff_plain;f=source%2Ftests%2Fxestiaab_contactload.h;h=cb625bbe7dae3d3d24b1d49f9120d31c52be7a54;hp=e2217a12a7cd686ed1a82823ef7a113055b96ed7;hb=03eae8e47936b7a7a1c395d971df33d47bcf9ae7;hpb=8a44cb6af4ffe0aae2d27208d9471e0d6b158c8b diff --git a/source/tests/xestiaab_contactload.h b/source/tests/xestiaab_contactload.h index e2217a1..cb625bb 100644 --- a/source/tests/xestiaab_contactload.h +++ b/source/tests/xestiaab_contactload.h @@ -1,6 +1,6 @@ // xestiaab_contactload.h - Xestia Address Book Contact Load Unit Tests. // -// (c) 2012-2015 Xestia Software Development. +// (c) 2012-2017 Xestia Software Development. // // This file is part of Xestia Address Book. // @@ -17,28 +17,104 @@ // with Xestia Address Book. If not, see #include -#include "../contacteditor/ContactDataObject.h" +#include "../contacteditor/cdo/ContactDataObject.h" -TEST(ContactLoad, ContactLoadTests){ +TEST(ContactLoad, GivenContactDataObjectWhenLoadFileIsCalledWithMissingFileThenReturnFileMissingError) +{ - ContactDataObject TestFile; + // Given - // Check that the file given is not missing. + ContactDataObject testFile; - ASSERT_EQ(CONTACTLOAD_FILEMISSING, TestFile.LoadFile("MissingFile.vcf")); + // When + + ContactLoadStatus testFileLoadStatus = CONTACTLOAD_UNITTESTFAIL; + testFile.LoadFile("MissingFile.vcf"); - // Check that the file given does not have an error when attempting to - // open it. + // Then + + ASSERT_EQ(CONTACTLOAD_FILEMISSING, testFileLoadStatus); + +} + +TEST(ContactLoad, GivenContactDataObjectWhenLoadFileIsCalledWithInvalidPermissionsSetThenReturnInvalidPermissionsError) +{ + + // Given + + ContactDataObject testFile; + + // When + + ContactLoadStatus testFileLoadStatus = CONTACTLOAD_UNITTESTFAIL; + testFileLoadStatus = testFile.LoadFile("InvalidPermissions.vcf"); + + // Then + + ASSERT_EQ(CONTACTLOAD_FILEERROR, testFileLoadStatus); + +} + +TEST(ContactLoad, GivenContactDataObjectWhenLoadFileIsCalledWithInvalidFormatThenReturnInvalidFormatError) +{ + + // Given + + ContactDataObject testFile; + + // When + + ContactLoadStatus testFileLoadStatus = CONTACTLOAD_UNITTESTFAIL; + testFileLoadStatus = testFile.LoadFile("LoadCheck-Load1-v3.vcf"); + + // Then + + ASSERT_EQ(CONTACTLOAD_FILEINVALIDFORMAT, testFileLoadStatus); + +} + +TEST(ContactLoad, GivenContactDataObjectWhenLoadFileIsCalledWithNonMeetingBaseSpecificationThenReturnFileBaseSpecificationError) +{ + + // Given + + ContactDataObject testFile; + + // When - ASSERT_EQ(CONTACTLOAD_FILEERROR, TestFile.LoadFile("InvalidPermissions.vcf")); + ContactLoadStatus testFileLoadStatus = CONTACTLOAD_UNITTESTFAIL; + testFileLoadStatus = testFile.LoadFile("LoadCheck-Load3.vcf"); + + // Then + + ASSERT_EQ(CONTACTLOAD_FILEBASESPECFAIL, testFileLoadStatus); + +} + +TEST(ContactLoad, GivenContactDataObjectWhenLoadFileIsCalledThenContactLoadedOK) +{ + + // Given + + ContactDataObject testFile; - // Check that the file is a valid vCard 4.0 file. + // When + + ContactLoadStatus testFileLoadStatus = CONTACTLOAD_UNITTESTFAIL; + testFileLoadStatus = testFile.LoadFile("LoadCheck-Load4.vcf"); - ASSERT_EQ(CONTACTLOAD_FILEINVALIDFORMAT, TestFile.LoadFile("LoadCheck-Load1-v3.vcf")); + // Then - // Check that the vCard 4.0 file meets the base specification. + ASSERT_EQ(CONTACTLOAD_OK, testFileLoadStatus); + +} + +TEST(ContactLoad, ContactLoadTests){ + + ContactDataObject TestFile; - ASSERT_EQ(CONTACTLOAD_FILEBASESPECFAIL, TestFile.LoadFile("LoadCheck-Load3.vcf")); + // Check that the file given does not have an error when attempting to + // open it. // Check that the vCard 4.0 file loads OK. @@ -169,6 +245,55 @@ TEST(ContactLoad, UIDTest){ } +TEST(ContactLoad, ClientPIDMapTests){ + + ContactDataObject TestFile; + + ASSERT_EQ(CONTACTLOAD_OK, TestFile.LoadFile("LoadCheck-Load4.vcf")); + + std::map::iterator TestFileIter; + + // Test the first Client PID Map. + + TestFileIter = TestFile.ClientPIDList.find(0); + ASSERT_NE(TestFile.ClientPIDList.end(), TestFileIter); + ASSERT_EQ("1;urn;uuid:aaaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", TestFileIter->second); + + TestFileIter = TestFile.ClientPIDListTokens.find(0); + ASSERT_EQ(TestFile.ClientPIDListTokens.end(), TestFileIter); + + // Test the second Client PID Map. + + TestFileIter = TestFile.ClientPIDList.find(1); + ASSERT_NE(TestFile.ClientPIDList.end(), TestFileIter); + ASSERT_EQ("2;urn;uuid:ccccccccc-cccc-cccc-cccc-cccccccccccc", TestFileIter->second); + + TestFileIter = TestFile.ClientPIDListTokens.find(1); + ASSERT_EQ(TestFile.ClientPIDListTokens.end(), TestFileIter); + + // Test the third Client PID Map. + + TestFileIter = TestFile.ClientPIDListTokens.find(2); + ASSERT_NE(TestFile.ClientPIDListTokens.end(), TestFileIter); + ASSERT_EQ("MEEP=MOO;WOOP=WOO", TestFileIter->second); + + TestFileIter = TestFile.ClientPIDList.find(2); + ASSERT_NE(TestFile.ClientPIDList.end(), TestFileIter); + ASSERT_EQ("3;urn;uuid:bbbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb", TestFileIter->second); + +} + +TEST(ContactLoad, RevisionTests){ + + ContactDataObject TestFile; + + ASSERT_EQ(CONTACTLOAD_OK, TestFile.LoadFile("LoadCheck-Load4.vcf")); + + ASSERT_EQ("20151227T033000Z", TestFile.Revision); + ASSERT_EQ("TEST=YES;DATA=NO;MORE=MAYBE", TestFile.RevisionTokens); + +} + TEST(ContactLoad, SourceTests){ ContactDataObject TestFile; @@ -307,6 +432,38 @@ TEST(ContactLoad, SourceTests){ } +TEST(ContactLoad, XMLTest){ + + 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 the first XML property. + + // Start with a general source address. + + TestFileIter = TestFile.XMLList.find(0); + ASSERT_NE(TestFile.XMLList.end(), TestFileIter); + ASSERT_EQ("Example Page 1", TestFileIter->second); + + TestFileIter = TestFile.XMLList.find(1); + ASSERT_NE(TestFile.XMLList.end(), TestFileIter); + ASSERT_EQ("Example Page 2", TestFileIter->second); + + TestFileIter = TestFile.XMLList.find(2); + ASSERT_NE(TestFile.XMLList.end(), TestFileIter); + ASSERT_EQ("Example Page 3", TestFileIter->second); + +} + TEST(ContactLoad, NicknameTests){ ContactDataObject TestFile; @@ -716,7 +873,7 @@ TEST(ContactLoad, AddressTests){ TestFileIter = TestFile.GeneralAddressListGeo.find(0); ASSERT_NE(TestFile.GeneralAddressListGeo.end(), TestFileIter); - ASSERT_EQ("\"geo:1.0, 1.0\"", TestFileIter->second); + ASSERT_EQ("geo:1.0, 1.0", TestFileIter->second); // Check the TZ section. @@ -802,7 +959,7 @@ TEST(ContactLoad, AddressTests){ TestFileIter = TestFile.HomeAddressListGeo.find(1); ASSERT_NE(TestFile.HomeAddressListGeo.end(), TestFileIter); - ASSERT_EQ("\"geo:4.0, 4.0\"", TestFileIter->second); + ASSERT_EQ("geo:4.0, 4.0", TestFileIter->second); // Check the TZ section. @@ -888,7 +1045,7 @@ TEST(ContactLoad, AddressTests){ TestFileIter = TestFile.BusinessAddressListGeo.find(2); ASSERT_NE(TestFile.BusinessAddressListGeo.end(), TestFileIter); - ASSERT_EQ("\"geo:7.0, 7.0\"", TestFileIter->second); + ASSERT_EQ("geo:7.0, 7.0", TestFileIter->second); // Check the TZ section. @@ -1156,13 +1313,19 @@ TEST(ContactLoad, TelephoneTests){ TestFileIter = TestFile.GeneralTelephoneList.find(0); ASSERT_NE(TestFile.GeneralTelephoneList.end(), TestFileIter); - ASSERT_EQ("tel:00000000", TestFileIter->second); + ASSERT_EQ("00000000", TestFileIter->second); + + // Check the data type section. + + TestFileIter = TestFile.GeneralTelephoneListDataType.find(0); + ASSERT_NE(TestFile.GeneralTelephoneListDataType.end(), TestFileIter); + ASSERT_EQ("tel", TestFileIter->second); // Check the type section. TestFileIter = TestFile.GeneralTelephoneListTypeInfo.find(0); ASSERT_NE(TestFile.GeneralTelephoneListTypeInfo.end(), TestFileIter); - ASSERT_EQ("fax,mobile", TestFileIter->second); + ASSERT_EQ("fax,cell", TestFileIter->second.ToStdString()); // Check the ALTID section. @@ -1192,7 +1355,13 @@ TEST(ContactLoad, TelephoneTests){ TestFileIter = TestFile.HomeTelephoneList.find(1); ASSERT_NE(TestFile.HomeTelephoneList.end(), TestFileIter); - ASSERT_EQ("tel:00001111", TestFileIter->second); + ASSERT_EQ("00001111", TestFileIter->second); + + // Check the data type section. + + TestFileIter = TestFile.HomeTelephoneListDataType.find(1); + ASSERT_NE(TestFile.HomeTelephoneListDataType.end(), TestFileIter); + ASSERT_EQ("tel", TestFileIter->second); // Check the type section. @@ -1228,7 +1397,13 @@ TEST(ContactLoad, TelephoneTests){ TestFileIter = TestFile.BusinessTelephoneList.find(2); ASSERT_NE(TestFile.BusinessTelephoneList.end(), TestFileIter); - ASSERT_EQ("tel:22221111", TestFileIter->second); + ASSERT_EQ("22221111", TestFileIter->second); + + // Check the data type section. + + TestFileIter = TestFile.BusinessTelephoneListDataType.find(2); + ASSERT_NE(TestFile.BusinessTelephoneListDataType.end(), TestFileIter); + ASSERT_EQ("tel", TestFileIter->second); // Check the type section. @@ -1380,7 +1555,7 @@ TEST(ContactLoad, GeographicTests){ TestFileIter = TestFile.GeneralGeographyList.find(0); ASSERT_NE(TestFile.GeneralGeographyList.end(), TestFileIter); - ASSERT_EQ("geo:3.5,3.5", TestFileIter->second); + ASSERT_EQ("3.5,3.5", TestFileIter->second); // Check the ALTID section. @@ -1416,7 +1591,7 @@ TEST(ContactLoad, GeographicTests){ TestFileIter = TestFile.HomeGeographyList.find(1); ASSERT_NE(TestFile.HomeGeographyList.end(), TestFileIter); - ASSERT_EQ("geo:7.0,7.0", TestFileIter->second); + ASSERT_EQ("7.0,7.0", TestFileIter->second); // Check the ALTID section. @@ -1452,7 +1627,7 @@ TEST(ContactLoad, GeographicTests){ TestFileIter = TestFile.BusinessGeographyList.find(2); ASSERT_NE(TestFile.BusinessGeographyList.end(), TestFileIter); - ASSERT_EQ("geo:14.0,14.0", TestFileIter->second); + ASSERT_EQ("14.0,14.0", TestFileIter->second); // Check the ALTID section. @@ -2497,6 +2672,11 @@ TEST(ContactLoad, PhotoTests){ ASSERT_NE(TestFile.PicturesListPID.end(), TestFileIter); ASSERT_EQ("71", TestFileIter->second); + // Check the TYPE section. + + TestFileIter = TestFile.PicturesListType.find(0); + ASSERT_EQ(TestFile.PicturesListType.end(), TestFileIter); + // Check the MEDIATYPE section. TestFileIter = TestFile.PicturesListMediatype.find(0); @@ -2546,6 +2726,12 @@ TEST(ContactLoad, PhotoTests){ ASSERT_NE(TestFile.PicturesListPID.end(), TestFileIter); ASSERT_EQ("21", TestFileIter->second); + // Check the TYPE section. + + TestFileIter = TestFile.PicturesListType.find(1); + ASSERT_NE(TestFile.PicturesListType.end(), TestFileIter); + ASSERT_EQ("home", TestFileIter->second); + // Check the MEDIATYPE section. TestFileIter = TestFile.PicturesListMediatype.find(1); @@ -2595,6 +2781,12 @@ TEST(ContactLoad, PhotoTests){ ASSERT_NE(TestFile.PicturesListPID.end(), TestFileIter); ASSERT_EQ("91", TestFileIter->second); + // Check the TYPE section. + + TestFileIter = TestFile.PicturesListType.find(2); + ASSERT_NE(TestFile.PicturesListType.end(), TestFileIter); + ASSERT_EQ("work", TestFileIter->second); + // Check the MEDIATYPE section. TestFileIter = TestFile.PicturesListMediatype.find(2); @@ -2658,6 +2850,8 @@ TEST(ContactLoad, LogoTests){ ASSERT_NE(TestFile.LogosListPID.end(), TestFileIter); ASSERT_EQ("71", TestFileIter->second); + // Check the TYPE section. + // Check the MEDIATYPE section. TestFileIter = TestFile.LogosListMediatype.find(0); @@ -2706,6 +2900,12 @@ TEST(ContactLoad, LogoTests){ TestFileIter = TestFile.LogosListPID.find(1); ASSERT_NE(TestFile.LogosListPID.end(), TestFileIter); ASSERT_EQ("21", TestFileIter->second); + + // Check the TYPE section. + + TestFileIter = TestFile.LogosListType.find(1); + ASSERT_NE(TestFile.LogosListType.end(), TestFileIter); + ASSERT_EQ("home", TestFileIter->second); // Check the MEDIATYPE section. @@ -2756,6 +2956,12 @@ TEST(ContactLoad, LogoTests){ ASSERT_NE(TestFile.LogosListPID.end(), TestFileIter); ASSERT_EQ("91", TestFileIter->second); + // Check the TYPE section. + + TestFileIter = TestFile.LogosListType.find(2); + ASSERT_NE(TestFile.LogosListType.end(), TestFileIter); + ASSERT_EQ("work", TestFileIter->second); + // Check the MEDIATYPE section. TestFileIter = TestFile.LogosListMediatype.find(2); @@ -4186,6 +4392,4 @@ TEST(ContactLoad, XTokenTest){ ASSERT_NE(TestFile.XTokenListTokens.end(), TestFileIter); ASSERT_EQ("FOODS;STATUS=FAVOURITE;TYPE=CHEESEANDONION", TestFileIter->second.ToStdString()); -} - -// TODO: Add tests for the Contact Loading process. \ No newline at end of file +} \ No newline at end of file