Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added the output file open check unit test and code.
authorSteve Brokenshire <sbrokenshire@xestia.co.uk>
Sun, 6 Dec 2015 00:17:54 +0000 (00:17 +0000)
committerSteve Brokenshire <sbrokenshire@xestia.co.uk>
Sun, 6 Dec 2015 00:17:54 +0000 (00:17 +0000)
source/convert.cpp
source/convert.h
source/tests/xestiaab_convert.h

index 69926de..2da7e45 100644 (file)
@@ -90,6 +90,18 @@ ConvertResult ConvertContact(wxString InputFormat, wxString OutputFormat,
                
        }
        
+       // 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
index af99f8c..7f71162 100644 (file)
@@ -32,6 +32,7 @@ enum ConvertResult {
        CONVERTRESULT_INVALIDOUTPUTFORMAT,
        CONVERTRESULT_INPUTFILEMISSING,
        CONVERTRESULT_INPUTFILEERROR,
+       CONVERTRESULT_OUTPUTFILEERROR
 };
 
 ConvertResult ConvertContact(wxString InputFormat, wxString ExportFormat, 
index 7f3d3a7..7108715 100644 (file)
@@ -26,11 +26,11 @@ TEST(ConvertCmdLine, ConvertTests){
        ASSERT_EQ(CONVERTRESULT_OK, ConvertContact(wxT("vCard4"), 
                wxT("vCard3"), 
                wxT("LoadCheck-Load1.vcf"), 
-               wxT("LoadCheck-Load1-v3Conv.vcf")));
+               wxT("Temp-LoadCheck-Load1-v3Conv.vcf")));
        ASSERT_EQ(CONVERTRESULT_OK, ConvertContact(wxT("vCard3"), 
                wxT("vCard4"), 
                wxT("LoadCheck-Load1.vcf"), 
-               wxT("LoadCheck-Load1-v3Conv.vcf")));
+               wxT("Temp-LoadCheck-Load1-v4Conv.vcf")));
                
        // Test that a matching input and output formats return
        // an error.
@@ -38,32 +38,41 @@ TEST(ConvertCmdLine, ConvertTests){
        ASSERT_EQ(CONVERTRESULT_FORMATSSAME, ConvertContact(wxT("vCard3"), 
                wxT("vCard3"), 
                wxT("LoadCheck-Load1.vcf"), 
-               wxT("LoadCheck-Load1-v3Conv.vcf")));
+               wxT("Temp-LoadCheck-Load1-v3Conv.vcf")));
                
        // Test that an invalid input format returns an error.
                
        ASSERT_EQ(CONVERTRESULT_INVALIDINPUTFORMAT, ConvertContact(wxT("vCardNope"), 
                wxT("vCard3"), 
                wxT("LoadCheck-Load1.vcf"), 
-               wxT("LoadCheck-Load1-v3Conv.vcf")));
+               wxT("Temp-LoadCheck-Load1-v3Conv.vcf")));
                
        // Test that an invalid output format return an error.
        
        ASSERT_EQ(CONVERTRESULT_INVALIDOUTPUTFORMAT, ConvertContact(wxT("vCard3"), 
                wxT("vCardNope"), 
                wxT("LoadCheck-Load1.vcf"), 
-               wxT("LoadCheck-Load1-v3Conv.vcf")));
+               wxT("Temp-LoadCheck-Load1-v3Conv.vcf")));
 
-       // Check that the file given exists.
+       // Check that the input file given exists.
        
        ASSERT_EQ(CONVERTRESULT_INPUTFILEMISSING, ConvertContact(wxT("vCard3"), 
                wxT("vCard4"), 
                wxT("InvalidFile.vcf"), 
                wxT("Temp-LoadCheck-Load1-v3Conv.vcf")));
 
+       // Check that input file can't be opened.
+
        ASSERT_EQ(CONVERTRESULT_INPUTFILEERROR, ConvertContact(wxT("vCard3"), 
                wxT("vCard4"), 
                wxT("InvalidPermissions.vcf"), 
                wxT("Temp-LoadCheck-Load1-v3Conv.vcf")));
+               
+       // Check that the output file can't be opened.
+       
+       ASSERT_EQ(CONVERTRESULT_OUTPUTFILEERROR, ConvertContact(wxT("vCard3"), 
+               wxT("vCard4"), 
+               wxT("LoadCheck-Load1.vcf"), 
+               wxT("InvalidPermissions.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