Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added code and unit tests to check that input file has the correct format for vCard3...
authorSteve Brokenshire <sbrokenshire@xestia.co.uk>
Sun, 6 Dec 2015 01:24:17 +0000 (01:24 +0000)
committerSteve Brokenshire <sbrokenshire@xestia.co.uk>
Sun, 6 Dec 2015 01:24:17 +0000 (01:24 +0000)
source/convert.cpp
source/convert.h
source/tests/xestiaab_convert.h

index 2da7e45..ae0e4db 100644 (file)
@@ -17,6 +17,7 @@
 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
 
 #include "convert.h"
+#include "vcard/vcard.h"
 
 ConvertResult ConvertContact(wxString InputFormat, wxString OutputFormat, 
        wxString InputFilename, wxString OutputFilename){
@@ -72,6 +73,14 @@ ConvertResult ConvertContact(wxString InputFormat, wxString OutputFormat,
        
        }
        
+       // Check that the input filename is not empty.
+       
+       if (InputFilename.empty()){
+       
+               return CONVERTRESULT_INPUTFILEEMPTY;
+       
+       }
+       
        // Check that the input file given exists.
        
        if (!wxFileExists(InputFilename)){
@@ -92,6 +101,7 @@ ConvertResult ConvertContact(wxString InputFormat, wxString OutputFormat,
        
        // Check that the output file can be opened.
        
+       bool OutputPipe = false;
        wxFile OutputFile;
        
        if (!OutputFilename.IsEmpty()){
@@ -100,6 +110,44 @@ ConvertResult ConvertContact(wxString InputFormat, wxString OutputFormat,
                        return CONVERTRESULT_OUTPUTFILEERROR;
                }
        
+       } else {
+       
+               OutputPipe = true;
+       
+       }
+       
+       // Check that the file has the correct file format.
+       
+       if (InputFormat == "vCard4"){
+       
+               // Read from the file.
+               
+               wxString InputFileData;
+               InputFile.ReadAll(&InputFileData, wxConvAuto());
+       
+               vCard InputvCard;
+               
+               InputvCard.LoadString(InputFileData);
+               
+               if (InputvCard.Get("VERSION") != "4.0"){
+                       return CONVERTRESULT_INPUTFILEINVALIDFORMAT;
+               }
+       
+       } else if (InputFormat == "vCard3"){
+       
+               // Read from the file.
+               
+               wxString InputFileData;
+               InputFile.ReadAll(&InputFileData, wxConvAuto());
+       
+               vCard InputvCard;
+               
+               InputvCard.LoadString(InputFileData);
+               
+               if (InputvCard.Get("VERSION") != "3.0"){
+                       return CONVERTRESULT_INPUTFILEINVALIDFORMAT;
+               }
+       
        }
        
        return CONVERTRESULT_OK;
index 7f71162..a1e4b40 100644 (file)
@@ -31,6 +31,8 @@ enum ConvertResult {
        CONVERTRESULT_INVALIDINPUTFORMAT,
        CONVERTRESULT_INVALIDOUTPUTFORMAT,
        CONVERTRESULT_INPUTFILEMISSING,
+       CONVERTRESULT_INPUTFILEEMPTY,
+       CONVERTRESULT_INPUTFILEINVALIDFORMAT,
        CONVERTRESULT_INPUTFILEERROR,
        CONVERTRESULT_OUTPUTFILEERROR
 };
index 7108715..4077998 100644 (file)
@@ -29,7 +29,7 @@ TEST(ConvertCmdLine, ConvertTests){
                wxT("Temp-LoadCheck-Load1-v3Conv.vcf")));
        ASSERT_EQ(CONVERTRESULT_OK, ConvertContact(wxT("vCard3"), 
                wxT("vCard4"), 
-               wxT("LoadCheck-Load1.vcf"), 
+               wxT("LoadCheck-Load1-v3.vcf"), 
                wxT("Temp-LoadCheck-Load1-v4Conv.vcf")));
                
        // Test that a matching input and output formats return
@@ -46,12 +46,12 @@ TEST(ConvertCmdLine, ConvertTests){
                wxT("vCard3"), 
                wxT("LoadCheck-Load1.vcf"), 
                wxT("Temp-LoadCheck-Load1-v3Conv.vcf")));
-               
-       // Test that an invalid output format return an error.
+
+       // Test that an empty input filename was given.
        
-       ASSERT_EQ(CONVERTRESULT_INVALIDOUTPUTFORMAT, ConvertContact(wxT("vCard3"), 
-               wxT("vCardNope"), 
-               wxT("LoadCheck-Load1.vcf"), 
+       ASSERT_EQ(CONVERTRESULT_INPUTFILEEMPTY, ConvertContact(wxT("vCard3"), 
+               wxT("vCard4"), 
+               wxT(""), 
                wxT("Temp-LoadCheck-Load1-v3Conv.vcf")));
 
        // Check that the input file given exists.
@@ -73,6 +73,19 @@ TEST(ConvertCmdLine, ConvertTests){
        ASSERT_EQ(CONVERTRESULT_OUTPUTFILEERROR, ConvertContact(wxT("vCard3"), 
                wxT("vCard4"), 
                wxT("LoadCheck-Load1.vcf"), 
-               wxT("InvalidPermissions.vcf")));        
+               wxT("InvalidPermissions.vcf")));
+               
+       // Check that the input file has the correct format.
+       // Tests for: vCard 4.0, vCard 3.0.
+       
+       ASSERT_EQ(CONVERTRESULT_INPUTFILEINVALIDFORMAT, ConvertContact(wxT("vCard4"), 
+               wxT("vCard3"), 
+               wxT("LoadCheck-Load1-v3.vcf"), 
+               wxT("Temp-LoadCheck-Load1.vcf")));
+
+       ASSERT_EQ(CONVERTRESULT_INPUTFILEINVALIDFORMAT, ConvertContact(wxT("vCard3"), 
+               wxT("vCard4"), 
+               wxT("LoadCheck-Load1.vcf"), 
+               wxT("Temp-LoadCheck-Load1.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