From: Steve Brokenshire Date: Sun, 6 Dec 2015 00:17:54 +0000 (+0000) Subject: Added the output file open check unit test and code. X-Git-Tag: release-0.09~262 X-Git-Url: http://Server1/repobrowser/?a=commitdiff_plain;h=0e3dcfcd57de79eac7dfce743447d81b5379e358;p=xestiaab%2F.git Added the output file open check unit test and code. --- diff --git a/source/convert.cpp b/source/convert.cpp index 69926de..2da7e45 100644 --- a/source/convert.cpp +++ b/source/convert.cpp @@ -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 diff --git a/source/convert.h b/source/convert.h index af99f8c..7f71162 100644 --- a/source/convert.h +++ b/source/convert.h @@ -32,6 +32,7 @@ enum ConvertResult { CONVERTRESULT_INVALIDOUTPUTFORMAT, CONVERTRESULT_INPUTFILEMISSING, CONVERTRESULT_INPUTFILEERROR, + CONVERTRESULT_OUTPUTFILEERROR }; ConvertResult ConvertContact(wxString InputFormat, wxString ExportFormat, diff --git a/source/tests/xestiaab_convert.h b/source/tests/xestiaab_convert.h index 7f3d3a7..7108715 100644 --- a/source/tests/xestiaab_convert.h +++ b/source/tests/xestiaab_convert.h @@ -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