Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added code and unit tests for the SaveFile function in ContactDataObject
authorSteve Brokenshire <sbrokenshire@xestia.co.uk>
Sun, 3 Jul 2016 14:28:32 +0000 (15:28 +0100)
committerSteve Brokenshire <sbrokenshire@xestia.co.uk>
Sun, 3 Jul 2016 14:28:32 +0000 (15:28 +0100)
source/contacteditor/cdo/ContactDataObject-Save.cpp
source/contacteditor/cdo/ContactDataObject.h
source/tests/xestiaab_contactsave.h

index d14240b..daf6159 100644 (file)
 #include "ContactDataObject.h"
 #include "../../version.h"
 
+ContactSaveStatus ContactDataObject::SaveFile(wxString SaveFilename){
+       
+       // Get the data using SaveString.
+       
+       wxString SaveData = "";
+       SaveString(&SaveData);
+       
+       // Open a file and try to write into it.
+       
+       wxFile ContactFile;
+       
+       if (!ContactFile.Open(SaveFilename, wxFile::write, wxS_DEFAULT)){
+       
+               return CONTACTSAVE_FILEERROR;
+       
+       }
+       
+       if (ContactFile.Write(SaveData, wxConvUTF8) == false){
+               
+               return CONTACTSAVE_WRITEERROR;
+               
+       }
+       
+       ContactFile.Close();
+       
+       return CONTACTSAVE_OK;
+       
+}
+
 ContactSaveStatus ContactDataObject::SaveString(wxString *SaveData){
        
        ContactSaveStatus SaveDataStatus = CONTACTSAVE_UNITTESTFAIL;
index 5942425..c8c42b0 100644 (file)
@@ -40,7 +40,9 @@ enum ContactLoadStatus{
 
 enum ContactSaveStatus{
        CONTACTSAVE_UNITTESTFAIL = -1,
-       CONTACTSAVE_OK, 
+       CONTACTSAVE_OK,
+       CONTACTSAVE_FILEERROR,
+       CONTACTSAVE_WRITEERROR
 };
 
 enum ContactKindType{
index 26b38e6..d0c2cfe 100644 (file)
@@ -713,4 +713,22 @@ TEST(ContactSave, ContactSaveTests){
        
        ASSERT_EQ(SaveDataCompare, SaveData);
 
+}
+
+TEST(ContactSave, ContactSaveFileTests){
+       
+       ContactDataObject TestFile1;
+       ContactDataObject TestFile2;
+       ContactDataObject TestFile3;
+       
+       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"));
+       
+       ASSERT_EQ(CONTACTLOAD_OK, TestFile2.LoadFile("LoadCheck-Load2.vcf"));
+       ASSERT_EQ(CONTACTSAVE_OK, TestFile2.SaveFile("SaveCheck-Save2.vcf"));
+
+       ASSERT_EQ(CONTACTLOAD_OK, TestFile3.LoadFile("LoadCheck-Load4.vcf"));
+       ASSERT_EQ(CONTACTSAVE_OK, TestFile3.SaveFile("SaveCheck-Save4.vcf"));
+       
 }
\ No newline at end of file
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