Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added the output file open check unit test and code.
[xestiaab/.git] / source / convert.cpp
index d8578d7..2da7e45 100644 (file)
@@ -26,7 +26,7 @@ ConvertResult ConvertContact(wxString InputFormat, wxString OutputFormat,
                wxT("vCard4") 
        };
 
-       bool ValidImport = false;
+       bool ValidInput = false;
        bool ValidOutput = false;
 
        // Check that the input format is valid.
@@ -34,26 +34,74 @@ ConvertResult ConvertContact(wxString InputFormat, wxString OutputFormat,
        for (long l = 0; l < ValidFormats.size(); l++){
        
                if (InputFormat == ValidFormats[l]){
-                       ValidImport = true;
+                       ValidInput = true;
                        break;
                }
        
        }
        
-       if (ValidImport == false){
+       if (ValidInput == false){
        
-               return CONVERTRESULT_INVALIDIMPORTFORMAT;
+               return CONVERTRESULT_INVALIDINPUTFORMAT;
        
        }
 
+       // Check that the output format is valid.
+
+       for (long l = 0; l < ValidFormats.size(); l++){
+       
+               if (OutputFormat == ValidFormats[l]){
+                       ValidOutput = true;
+                       break;
+               }
+       
+       }
+       
+       if (ValidOutput == false){
+       
+               return CONVERTRESULT_INVALIDOUTPUTFORMAT;
+       
+       }
+
+       // Check that the input and output formats
+       // are not the same.
+
        if (InputFormat == OutputFormat){
        
                return CONVERTRESULT_FORMATSSAME;
        
        }
        
-       // Check that the output format is valid.
-
+       // Check that the input file given exists.
+       
+       if (!wxFileExists(InputFilename)){
+               
+               return CONVERTRESULT_INPUTFILEMISSING;
+               
+       }
+       
+       wxFile InputFile;
+       
+       if (!InputFile.Open(InputFilename, wxFile::read, wxS_DEFAULT)){
+               
+               int InputFileErrNo = InputFile.GetLastError();
+               
+               return CONVERTRESULT_INPUTFILEERROR;
+               
+       }
+       
+       // Check that the output file can be opened.
+       
+       wxFile OutputFile;
+       
+       if (!OutputFilename.IsEmpty()){
+       
+               if (!OutputFile.Open(OutputFilename, wxFile::write, wxS_DEFAULT)){
+                       return CONVERTRESULT_OUTPUTFILEERROR;
+               }
+       
+       }
+       
        return CONVERTRESULT_OK;
        
 }
\ 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