From bfeaecc9ef791d6a2c58cafa71f332eecb606b20 Mon Sep 17 00:00:00 2001 From: Steve Brokenshire Date: Fri, 27 Oct 2017 07:26:00 +0100 Subject: [PATCH] ContactSave Unit Tests: Cleanup and formatting to Given/When/Then --- source/tests/xestiaab_contactsave.h | 128 +++++++++++++++++++--------- 1 file changed, 89 insertions(+), 39 deletions(-) diff --git a/source/tests/xestiaab_contactsave.h b/source/tests/xestiaab_contactsave.h index 446571a..c2de21f 100644 --- a/source/tests/xestiaab_contactsave.h +++ b/source/tests/xestiaab_contactsave.h @@ -20,12 +20,9 @@ #include "../contacteditor/cdo/ContactDataObject.h" -TEST(ContactSave, ContactSaveTests){ - - ContactDataObject TestFile1; - ContactDataObject TestFile2; - ContactDataObject TestFile3; - +TEST(ContactSave, GivenAContactDataObjectWhenSaveStringIsCalledThenContactDataSavesToAString) +{ + wxString SaveData; wxString SaveDataCompare = "BEGIN:VCARD\n" "VERSION:4.0\n" @@ -35,31 +32,37 @@ TEST(ContactSave, ContactSaveTests){ "TITLE:Knight of the Tests\n" "TITLE:The Tester of Cornwall\n" "END:VCARD"; + + // Given + + ContactDataObject testFile; - ASSERT_EQ(CONTACTLOAD_OK, TestFile1.LoadFile("LoadCheck-Load1.vcf")); + ContactLoadStatus testFileLoadStatus = CONTACTLOAD_UNITTESTFAIL; + testFileLoadStatus = testFile1.LoadFile("LoadCheck-Load1.vcf"); - ASSERT_EQ(CONTACTSAVE_OK, TestFile1.SaveString(&SaveData)); + ASSERT_EQ(CONTACTLOAD_OK, testFileLoadStatus); + + // When - ASSERT_EQ(SaveDataCompare, SaveData); + ContactSaveStatus testFileSaveStatus = CONTACTSAVE_UNITTESTFAIL; + testFileSaveStatus = testFile.SaveString(&SaveData); - ASSERT_EQ(CONTACTLOAD_OK, TestFile2.LoadFile("LoadCheck-Load2.vcf")); + // Then - SaveData.clear(); - SaveDataCompare = "BEGIN:VCARD\n" - "VERSION:4.0\n" - "PRODID:-//Xestia//Address Book Unit Testing//KW\n" - "REV:20160703T091000Z\n" - "FN:Test vCard\n" - "TITLE:The Third Title\n" - "TITLE:Knight of the Tests\n" - "TITLE:The Tester of Cornwall\n" - "END:VCARD"; - - ASSERT_EQ(CONTACTSAVE_OK, TestFile2.SaveString(&SaveData)); + ASSERT_EQ(CONTACTSAVE_OK, testFileSaveStatus); ASSERT_EQ(SaveDataCompare, SaveData); - SaveData.clear(); - SaveDataCompare = "BEGIN:VCARD\n" +} + +TEST(ContactSave, GivenContactDataObjectWithLotsOfInformationWhenSaveStringIsCalledThenContactStringMatches) +{ + + ContactDataObject testFile; + + wxString saveData; + wxString saveDataCompare; + + saveDataCompare = "BEGIN:VCARD\n" "VERSION:4.0\n" "PRODID:-//Xestia//Address Book Unit Testing//KW\n" "UID:903588-9082374-989120310-AAFECDBCDF\n" @@ -710,27 +713,74 @@ TEST(ContactSave, ContactSaveTests){ "X-FOODS;STATUS=FAVOURITE;TYPE=CHEESEANDONION:Cornish Pasties\n" "END:VCARD"; - ASSERT_EQ(CONTACTLOAD_OK, TestFile3.LoadFile("LoadCheck-Load4.vcf")); - ASSERT_EQ(CONTACTSAVE_OK, TestFile3.SaveString(&SaveData)); + ASSERT_EQ(CONTACTLOAD_OK, testFile.LoadFile("LoadCheck-Load4.vcf")); + ASSERT_EQ(CONTACTSAVE_OK, testFile.SaveString(&saveData)); - ASSERT_EQ(SaveDataCompare, SaveData); + ASSERT_EQ(saveDataCompare, saveData); } -TEST(ContactSave, ContactSaveFileTests){ +TEST(ContactSave, GivenSeveralContactFilesWhenLoadFileAndSaveFileIsCalledThenContactDataIsLoadedAndSaved) +{ - ContactDataObject TestFile1; - ContactDataObject TestFile2; - ContactDataObject TestFile3; + // Given - ASSERT_EQ(CONTACTLOAD_OK, TestFile1.LoadFile("LoadCheck-Load1.vcf")); - ASSERT_EQ(CONTACTSAVE_OK, TestFile1.SaveFile("SaveCheck-Save1.vcf")); - ASSERT_EQ(CONTACTSAVE_FILEERROR, TestFile1.SaveFile("/invalidfile")); + ContactDataObject testFile1; + ContactDataObject testFile2; + ContactDataObject testFile3; - ASSERT_EQ(CONTACTLOAD_OK, TestFile2.LoadFile("LoadCheck-Load2.vcf")); - ASSERT_EQ(CONTACTSAVE_OK, TestFile2.SaveFile("SaveCheck-Save2.vcf")); + ContactLoadStatus testFile1SaveStatus = CONTACTSAVE_UNITTESTFAIL; + ContactSaveStatus testFile1LoadStatus = CONTACTLOAD_UNITTESTFAIL; + + ContactLoadStatus testFile2SaveStatus = CONTACTSAVE_UNITTESTFAIL; + ContactSaveStatus testFile2LoadStatus = CONTACTLOAD_UNITTESTFAIL; + + ContactLoadStatus testFile3SaveStatus = CONTACTSAVE_UNITTESTFAIL; + ContactSaveStatus testFile3LoadStatus = CONTACTLOAD_UNITTESTFAIL; + + // When + + testFile1LoadStatus = testFile1.LoadFile("LoadCheck-Load1.vcf"); + testFile1SaveStatus = testFile1.SaveFile("SaveCheck-Save1.vcf"); + + testFile2LoadStatus = testFile2.LoadFile("LoadCheck-Load2.vcf"); + testFile2SaveStatus = testFile2.SaveFile("SaveCheck-Save2.vcf"); + + testFile3LoadStatus = testFile3.LoadFile("LoadCheck-Load4.vcf"); + testFile3SaveStatus = testFile3.SaveFile("SaveCheck-Save4.vcf"); + + // Then + + ASSERT_EQ(CONTACTLOAD_OK, testFile1LoadStatus); + ASSERT_EQ(CONTACTSAVE_OK, testFile1SaveStatus); + + ASSERT_EQ(CONTACTLOAD_OK, testFile1LoadStatus); + ASSERT_EQ(CONTACTSAVE_OK, testFile1SaveStatus); + + ASSERT_EQ(CONTACTLOAD_OK, testFile3.LoadFile("LoadCheck-Load4.vcf")); + ASSERT_EQ(CONTACTSAVE_OK, testFile3.SaveFile("SaveCheck-Save4.vcf")); + +} + +TEST(ContactSave, GivenContactDataObjectWhenFileIsSavedToInvalidLocationThenErrorResultIsReturned) +{ - ASSERT_EQ(CONTACTLOAD_OK, TestFile3.LoadFile("LoadCheck-Load4.vcf")); - ASSERT_EQ(CONTACTSAVE_OK, TestFile3.SaveFile("SaveCheck-Save4.vcf")); + // Given + + ContactDataObject testFile; + ContactLoadStatus testFileLoadStatus = CONTACTLOAD_UNITTESTFAIL; + ContactSaveStatus testFileSaveStatus = CONTACTSAVE_UNITTESTFAIL; + + testFileLoadStatus = testFile1.LoadFile("LoadCheck-Load1.vcf"); + + ASSERT_EQ(CONTACTLOAD_OK, testFileLoadStatus); -} \ No newline at end of file + // When + + testFileSaveStatus = testFile.SaveFile("/invalidfile"); + + // Then + + ASSERT_EQ(CONTACTSAVE_FILEERROR, testFileSaveStatus); + +} -- 2.39.5