From 134b7476fefe9440a5120b15e3d913afc9c48f04 Mon Sep 17 00:00:00 2001 From: Steve Brokenshire Date: Sat, 4 Nov 2017 19:28:25 +0000 Subject: [PATCH] ContactLoad Unit Tests: Partial split of tests to Given/When/Then format --- source/tests/xestiaab_contactload.h | 525 ++++++++++++++++++++++++---- 1 file changed, 448 insertions(+), 77 deletions(-) diff --git a/source/tests/xestiaab_contactload.h b/source/tests/xestiaab_contactload.h index 86564ed..9239d5e 100644 --- a/source/tests/xestiaab_contactload.h +++ b/source/tests/xestiaab_contactload.h @@ -29,7 +29,7 @@ TEST(ContactLoad, GivenContactDataObjectWhenLoadFileIsCalledWithMissingFileThenR // When ContactLoadStatus testFileLoadStatus = CONTACTLOAD_UNITTESTFAIL; - testFileLoadStatus = testFile.LoadFile("MissingFile.vcf"); + testFile.LoadFile("MissingFile.vcf"); // Then @@ -109,130 +109,501 @@ TEST(ContactLoad, GivenContactDataObjectWhenLoadFileIsCalledThenContactLoadedOK) } -TEST(ContactLoad, ContactLoadTests){ - - ContactDataObject TestFile; - - // Check that the file given does not have an error when attempting to - // open it. +TEST(ContactLoad, GivenLoadedContactDataObjectWhenContactKindIsCheckedThenContactKindIsIndividual) +{ - // Check that the vCard 4.0 file loads OK. + // Check that the kind status has been set. (KIND). - ASSERT_EQ(CONTACTLOAD_OK, TestFile.LoadFile("LoadCheck-Load4.vcf")); + // Given + + ContactDataObject testFile; + ContactLoadStatus testFileLoadStatus = testFile.LoadFile("LoadCheck-Load4.vcf"); + ASSERT_EQ(CONTACTLOAD_OK, testFileLoadStatus); + + // When + ContactKindType testFileContactKindStatus = TestFile.ContactKind; + + // Then // Check that the kind status has been set. (KIND). - ASSERT_NE(CONTACTKIND_NONE, TestFile.ContactKind); - ASSERT_EQ(CONTACTKIND_INDIVIDUAL, TestFile.ContactKind); + ASSERT_NE(CONTACTKIND_NONE, testFileContactKindStatus); + ASSERT_EQ(CONTACTKIND_INDIVIDUAL, testFileContactKindStatus); +} + +TEST(ContactLoad, GivenContactDataObjectWhenFindIsCalledOnGroupsListForFirstGroupThenOnlyFirstGroupIsReturned) +{ + // Check that the groups have been read (MEMBER). + + std::map::iterator testFileIter; + + // Given + + ContactDataObject testFile; + ContactLoadStatus testFileLoadStatus = testFile.LoadFile("LoadCheck-Load4.vcf"); + ASSERT_EQ(CONTACTLOAD_OK, testFileLoadStatus); - std::map::iterator TestFileIter; - std::map::iterator TestFileIntIter; + // When + + testFileIter = testFile.GroupsList.find(0); - TestFileIter = TestFile.GroupsList.find(0); + // Then - ASSERT_NE(TestFile.GroupsList.end(), TestFileIter); - ASSERT_EQ("7a2af44d-6431-4797-a55f-d86d56304fda", TestFileIter->second); + 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); +TEST(ContactLoad, GivenContactDataObjectWhenFindIsCalledOnGroupsListAltIDForFirstGroupThenOnlyFirstGroupAltIDIsReturned) +{ - // Check the PID parameter. + // Check the ALTID parameter for MEMBER. + + std::map::iterator testFileIter; + + // Given - TestFileIter = TestFile.GroupsListPID.find(0); - ASSERT_NE(TestFile.GroupsListPID.end(), TestFileIter); - ASSERT_EQ("40", TestFileIter->second); + ContactDataObject testFile; + ContactLoadStatus testFileLoadStatus = testFile.LoadFile("LoadCheck-Load4.vcf"); + ASSERT_EQ(CONTACTLOAD_OK, testFileLoadStatus); - // Check the PREF parameter. + // When + + testFileIter = testFile.GroupsListAltID.find(0); - TestFileIntIter = TestFile.GroupsListPref.find(0); - ASSERT_NE(TestFile.GroupsListPref.end(), TestFileIntIter); - ASSERT_EQ(45, TestFileIntIter->second); + // Then + + ASSERT_NE(testFile.GroupsListAltID.end(), testFileIter); + ASSERT_EQ("35", testFileIter->second); + +} + +TEST(ContactLoad, GivenContactDataObjectWhenFindIsCalledOnGroupsListPIDForFirstGroupThenOnlyFirstGroupPIDIsReturned) +{ + + // Check the PID parameter for MEMBER. + + std::map::iterator testFileIter; + std::map::iterator testFileIntIter; + + // Given - // Check the MEDIATYPE parameter. + ContactLoadStatus testFileLoadStatus = testFile.LoadFile("LoadCheck-Load4.vcf"); + ASSERT_EQ(CONTACTLOAD_OK, testFileLoadStatus); - TestFileIter = TestFile.GroupsListMediaType.find(0); - ASSERT_NE(TestFile.GroupsListMediaType.end(), TestFileIter); - ASSERT_EQ("text/plain", TestFileIter->second); + // When + + testFileIter = testFile.GroupsListPID.find(0); - // Check the extra tokens parameter. + // Then + + ASSERT_NE(testFile.GroupsListPID.end(), testFileIter); + ASSERT_EQ("40", testFileIter->second); + +} + +TEST(ContactLoad, GivenContactDataObjectWhenFindIsCalledOnGroupsListPreferenceForFirstGroupThenOnlyFirstGroupPreferenceIsReturned) +{ + + // Check the PREF parameter for MEMBER. + + std::map::iterator testFileIter; + std::map::iterator testFileIntIter; + ContactDataObject testFile; + + // Given + + ContactLoadStatus testFileLoadStatus = testFile.LoadFile("LoadCheck-Load4.vcf"); + ASSERT_EQ(CONTACTLOAD_OK, testFileLoadStatus); + + // When + + testFileIntIter = testFile.GroupsListPref.find(0); + + // Then + + ASSERT_NE(testFile.GroupsListPref.end(), testFileIntIter); + ASSERT_EQ(45, testFileIntIter->second); + +} + +TEST(ContactLoad, GivenContactDataObjectWhenFindIsCalledOnGroupsListMediatypeForFirstGroupThenOnlyFirstGroupMediatypeIsReturned) +{ + + // Check the MEDIATYPE parameter for MEMBER. + + std::map::iterator testFileIter; + std::map::iterator testFileIntIter; + ContactDataObject testFile; + + // Given + + ContactLoadStatus testFileLoadStatus = testFile.LoadFile("LoadCheck-Load4.vcf"); + ASSERT_EQ(CONTACTLOAD_OK, testFileLoadStatus); - TestFileIter = TestFile.GroupsListTokens.find(0); - ASSERT_NE(TestFile.GroupsListTokens.end(), TestFileIter); - ASSERT_EQ("EXAMPLE=Meep", TestFileIter->second); + // When + + testFileIter = testFile.GroupsListMediaType.find(0); + // Then + + ASSERT_NE(testFile.GroupsListMediaType.end(), testFileIter); + ASSERT_EQ("text/plain", testFileIter->second); + +} + +TEST(ContactLoad, GivenContactDataObjectWhenFindIsCalledOnGroupsListExtraTokensForFirstGroupThenOnlyFirstGroupExtraTokensIsReturned) +{ + + // Check the extra tokens parameter for MEMBER. + + std::map::iterator testFileIter; + std::map::iterator testFileIntIter; + ContactDataObject testFile; + + // Given + + ContactLoadStatus testFileLoadStatus = testFile.LoadFile("LoadCheck-Load4.vcf"); + ASSERT_EQ(CONTACTLOAD_OK, testFileLoadStatus); + + // When + + TestFileIter = testFile.GroupsListTokens.find(0); + + // Then + + ASSERT_NE(testFile.GroupsListTokens.end(), testFileIter); + ASSERT_EQ("EXAMPLE=Meep", testFileIter->second); + +} + +TEST(ContactLoad, GivenContactDataObjectWhenFindIsCalledOnFullNameForFirstFullNameThenOnlyFirstFullNameIsReturned) +{ + // Check that the formatted name has been read (FN). + + std::map::iterator testFileIter; + std::map::iterator testFileIntIter; + ContactDataObject testFile; + + // Given + + ContactLoadStatus testFileLoadStatus = testFile.LoadFile("LoadCheck-Load4.vcf"); + ASSERT_EQ(CONTACTLOAD_OK, testFileLoadStatus); - TestFileIter = TestFile.FullNamesList.find(0); - ASSERT_NE(TestFile.FullNamesList.end(), TestFileIter); - ASSERT_EQ("Test Contact", TestFileIter->second); + // When - // Check the TYPE parameter. + testFileIter = testFile.FullNamesList.find(0); - TestFileIter = TestFile.FullNamesListType.find(0); - ASSERT_NE(TestFile.FullNamesListType.end(), TestFileIter); - ASSERT_EQ("work", TestFileIter->second); + // Then + + ASSERT_NE(testFile.FullNamesList.end(), testFileIter); + ASSERT_EQ("Test Contact", testFileIter->second); + +} + +TEST(ContactLoad, GivenContactDataObjectWhenFindIsCalledOnFullNameTypeForFirstFullNameThenOnlyFirstFullNameTypeIsReturned) +{ + + // Check the TYPE parameter for FN. + + std::map::iterator testFileIter; + std::map::iterator testFileIntIter; + ContactDataObject testFile; + + // Given + + ContactLoadStatus testFileLoadStatus = testFile.LoadFile("LoadCheck-Load4.vcf"); + ASSERT_EQ(CONTACTLOAD_OK, testFileLoadStatus); + + // When + + testFileIter = testFile.FullNamesListType.find(0); + + // Then + + ASSERT_NE(testFile.FullNamesListType.end(), testFileIter); + ASSERT_EQ("work", testFileIter->second); + +} + +TEST(ContactLoad, GivenContactDataObjectWhenFindIsCalledOnFullNameLanguageForFirstFullNameThenOnlyFirstFullNameLanguageIsReturned) +{ + + // Check the LANGUAGE parameter for FN. + + std::map::iterator testFileIter; + std::map::iterator testFileIntIter; + ContactDataObject testFile; + + // Given + + ContactLoadStatus testFileLoadStatus = testFile.LoadFile("LoadCheck-Load4.vcf"); + ASSERT_EQ(CONTACTLOAD_OK, testFileLoadStatus); - // Check the LANGUAGE parameter. + // When + + testFileIter = testFile.FullNamesListLanguage.find(0); + + // Then + + ASSERT_NE(testFile.FullNamesListLanguage.end(), testFileIter); + ASSERT_EQ("kw", testFileIter->second); + +} + +TEST(ContactLoad, GivenContactDataObjectWhenFindIsCalledOnFullNameAltIDForFirstFullNameThenOnlyFirstFullNameAltIDIsReturned) +{ + + // Check the ALTID parameter for FN. + + std::map::iterator testFileIter; + std::map::iterator testFileIntIter; + ContactDataObject testFile; + + // Given + + ContactLoadStatus testFileLoadStatus = testFile.LoadFile("LoadCheck-Load4.vcf"); + ASSERT_EQ(CONTACTLOAD_OK, testFileLoadStatus); - TestFileIter = TestFile.FullNamesListLanguage.find(0); - ASSERT_NE(TestFile.FullNamesListLanguage.end(), TestFileIter); - ASSERT_EQ("kw", TestFileIter->second); + // When - // Check the ALTID parameter. + testFileIter = testFile.FullNamesListAltID.find(0); + + // Then - TestFileIter = TestFile.FullNamesListAltID.find(0); - ASSERT_NE(TestFile.FullNamesListAltID.end(), TestFileIter); - ASSERT_EQ("500", TestFileIter->second); + ASSERT_NE(testFile.FullNamesListAltID.end(), testFileIter); + ASSERT_EQ("500", testFileIter->second); - // Check the PID parameter. +} - TestFileIter = TestFile.FullNamesListPID.find(0); - ASSERT_NE(TestFile.FullNamesListPID.end(), TestFileIter); - ASSERT_EQ("40", TestFileIter->second); +TEST(ContactLoad, GivenContactDataObjectWhenFindIsCalledOnFullNamePIDForFirstFullNameThenOnlyFirstFullNamePIDIsReturned) +{ + + // Check the PID parameter for FN. + + std::map::iterator testFileIter; + std::map::iterator testFileIntIter; + ContactDataObject testFile; + + // Given + + ContactLoadStatus testFileLoadStatus = testFile.LoadFile("LoadCheck-Load4.vcf"); + ASSERT_EQ(CONTACTLOAD_OK, testFileLoadStatus); - // Check the PREF parameter. + // When + + testFileIter = testFile.FullNamesListPID.find(0); + + // Then + + ASSERT_NE(testFile.FullNamesListPID.end(), testFileIter); + ASSERT_EQ("40", testFileIter->second); + +} + +TEST(ContactLoad, GivenContactDataObjectWhenFindIsCalledOnFullNamePrefForFirstFullNameThenOnlyFirstFullNamePrefIsReturned) +{ + + // Check the PREF parameter for FN. + + std::map::iterator testFileIter; + std::map::iterator testFileIntIter; + ContactDataObject testFile; + + // Given + + ContactLoadStatus testFileLoadStatus = testFile.LoadFile("LoadCheck-Load4.vcf"); + ASSERT_EQ(CONTACTLOAD_OK, testFileLoadStatus); - TestFileIntIter = TestFile.FullNamesListPref.find(0); - ASSERT_NE(TestFile.FullNamesListPref.end(), TestFileIntIter); - ASSERT_EQ(45, TestFileIntIter->second); + // When + + testFileIntIter = testFile.FullNamesListPref.find(0); - // Check for the extra tokens parameter. + // Then + + ASSERT_NE(testFile.FullNamesListPref.end(), testFileIntIter); + ASSERT_EQ(45, testFileIntIter->second); + +} + +TEST(ContactLoad, GivenContactDataObjectWhenFindIsCalledOnFullNameExtraTokensForFirstFullNameThenOnlyFirstFullNameExtraTokensIsReturned) +{ + + // Check for the extra tokens parameter for FN. + + std::map::iterator testFileIter; + std::map::iterator testFileIntIter; + ContactDataObject testFile; + + // Given + + ContactLoadStatus testFileLoadStatus = testFile.LoadFile("LoadCheck-Load4.vcf"); + ASSERT_EQ(CONTACTLOAD_OK, testFileLoadStatus); - TestFileIter = TestFile.FullNamesListTokens.find(0); - ASSERT_NE(TestFile.FullNamesListTokens.end(), TestFileIter); - ASSERT_EQ("EXAMPLE=Baaa", TestFileIter->second); + // When - // Check that the name has been read (N). + testFileIter = testFile.FullNamesListTokens.find(0); - ASSERT_EQ("Contact", TestFile.NameSurname); - ASSERT_EQ("Test", TestFile.NameForename); - ASSERT_EQ("Example", TestFile.NameOtherNames); - ASSERT_EQ("Robot", TestFile.NameTitle); - ASSERT_EQ("LOONY", TestFile.NameSuffix); + // Then - // Check the ALTID parameter. + ASSERT_NE(testFile.FullNamesListTokens.end(), testFileIter); + ASSERT_EQ("EXAMPLE=Baaa", testFileIter->second); - ASSERT_EQ("3", TestFile.NameAltID); +} + +TEST(ContactLoad, GivenContactDataObjectWhenNameValuesAreRetrievedThenValuesForNameIsReturned) +{ + + // Check that the name has been read for N. + + std::map::iterator testFileIter; + std::map::iterator testFileIntIter; + ContactDataObject testFile; + + // Given + + ContactLoadStatus testFileLoadStatus = testFile.LoadFile("LoadCheck-Load4.vcf"); + ASSERT_EQ(CONTACTLOAD_OK, testFileLoadStatus); - // Check the LANGUAGE parameter. + // When - ASSERT_EQ("kw", TestFile.NameLanguage); + wxString nameSurname = testFile.NameSurname; + wxString nameForename = testFile.NameForename; + wxString nameOtherNames = testFile.NameOtherNames; + wxString nameTitle = testFile.NameTitle; + wxString nameSuffix = testFile.NameSuffix; - // Check the SORT-AS parameter. + // Then + + ASSERT_EQ("Contact", nameSurname); + ASSERT_EQ("Test", nameForename); + ASSERT_EQ("Example", nameOtherNames); + ASSERT_EQ("Robot", nameTitle); + ASSERT_EQ("LOONY", nameSuffix); + +} + +TEST(ContactLoad, GivenContactDataObjectWhenNameAltIDIsRetrievedThenValueforNameAltIDIsReturned) +{ + + // Check the ALTID parameter for N. + + std::map::iterator testFileIter; + std::map::iterator testFileIntIter; + ContactDataObject testFile; + + // Given + + ContactLoadStatus testFileLoadStatus = testFile.LoadFile("LoadCheck-Load4.vcf"); + ASSERT_EQ(CONTACTLOAD_OK, testFileLoadStatus); + + // When + + wxString nameAltID = TestFile.NameAltID; + + // Then + + ASSERT_EQ("3", nameAltID); + +} + +TEST(ContactLoad, GivenContactDataObjectWhenNameAltIDIsRetrievedThenValueforNameAltIDIsReturned) +{ + + // Check the LANGUAGE parameter for N. + + std::map::iterator testFileIter; + std::map::iterator testFileIntIter; + ContactDataObject testFile; + + // Given + + ContactLoadStatus testFileLoadStatus = testFile.LoadFile("LoadCheck-Load4.vcf"); + ASSERT_EQ(CONTACTLOAD_OK, testFileLoadStatus); + + // When + + wxString nameLanguage = TestFile.NameLanguage; + + // Then + + ASSERT_EQ("kw", nameLanguage); + +} + +TEST(ContactLoad, GivenContactDataObjectWhenNameDisplayAsIsRetrievedThenValueforNameDisplayAsIsReturned) +{ + + // Check the SORT-AS parameter for N. + + std::map::iterator testFileIter; + std::map::iterator testFileIntIter; + ContactDataObject testFile; + + // Given + + ContactLoadStatus testFileLoadStatus = testFile.LoadFile("LoadCheck-Load4.vcf"); + ASSERT_EQ(CONTACTLOAD_OK, testFileLoadStatus); + + // When + + wxString nameDisplayAs = TestFile.NameDisplayAs; + + // Then - ASSERT_EQ("Contact,Test", TestFile.NameDisplayAs); + ASSERT_EQ("Contact,Test", nameDisplayAs); - // Check the extra tokens parameter. +} + +TEST(ContactLoad, GivenContactDataObjectWhenNameExtraTokensIsRetrievedThenValueforNameExtraTokensIsReturned) +{ + + // Check the extra tokens parameter for N. + + std::map::iterator testFileIter; + std::map::iterator testFileIntIter; + ContactDataObject testFile; + + // Given + + ContactLoadStatus testFileLoadStatus = testFile.LoadFile("LoadCheck-Load4.vcf"); + ASSERT_EQ(CONTACTLOAD_OK, testFileLoadStatus); - ASSERT_EQ("TEST=Yes", TestFile.NameTokens); + // When + + wxString nameTokens = testFile.NameTokens; + + // Then + + ASSERT_EQ("TEST=Yes", nameTokens); } +/* TEMPLATE: PLEASE COPY BEFORE USING IT. */ + +TEST(ContactLoad, GivenWhenThen) +{ + + std::map::iterator testFileIter; + std::map::iterator testFileIntIter; + ContactDataObject testFile; + + // Given + + ContactLoadStatus testFileLoadStatus = testFile.LoadFile("LoadCheck-Load4.vcf"); + ASSERT_EQ(CONTACTLOAD_OK, testFileLoadStatus); + + // When + + // Then + +} + +/* END OF TEMPLATE: LOOK UP */ + TEST(ContactLoad, UIDTest){ ContactDataObject TestFile; -- 2.39.5