Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added code and unit tests for writing the processed data to file or console.
authorSteve Brokenshire <sbrokenshire@xestia.co.uk>
Sun, 6 Dec 2015 09:54:31 +0000 (09:54 +0000)
committerSteve Brokenshire <sbrokenshire@xestia.co.uk>
Sun, 6 Dec 2015 09:54:31 +0000 (09:54 +0000)
source/convert.cpp
source/tests/xestiaab_convert.h

index ae0e4db..0cfaa9f 100644 (file)
@@ -18,6 +18,7 @@
 
 #include "convert.h"
 #include "vcard/vcard.h"
+#include "vcard/vcard34conv.h"
 
 ConvertResult ConvertContact(wxString InputFormat, wxString OutputFormat, 
        wxString InputFilename, wxString OutputFilename){
@@ -118,6 +119,9 @@ ConvertResult ConvertContact(wxString InputFormat, wxString OutputFormat,
        
        // Check that the file has the correct file format.
        
+       vCard vCard4Format;
+       wxString FinalData;
+       
        if (InputFormat == "vCard4"){
        
                // Read from the file.
@@ -125,13 +129,16 @@ ConvertResult ConvertContact(wxString InputFormat, wxString OutputFormat,
                wxString InputFileData;
                InputFile.ReadAll(&InputFileData, wxConvAuto());
        
-               vCard InputvCard;
+               vCard vCard4Format;
                
-               InputvCard.LoadString(InputFileData);
+               vCard4Format.LoadString(InputFileData);
                
-               if (InputvCard.Get("VERSION") != "4.0"){
+               if (vCard4Format.Get("VERSION") != "4.0"){
                        return CONVERTRESULT_INPUTFILEINVALIDFORMAT;
                }
+               
+               // No conversion needs to be as the card is already
+               // in the vCard 4.0 format.
        
        } else if (InputFormat == "vCard3"){
        
@@ -150,6 +157,42 @@ ConvertResult ConvertContact(wxString InputFormat, wxString OutputFormat,
        
        }
        
+       // Convert the vCard into the required format and
+       // get the string value.
+       
+       if (OutputFormat == "vCard4"){
+       
+               // Do nothing as the vCard is already in the vCard 4.0
+               // format.
+       
+       } else if (OutputFormat == "vCard3"){
+       
+               // Convert the vCard to vCard 3.0.
+               
+               vCard34Conv vCard34ConvObj;
+               
+               vCard vCard3Format;
+               
+               vCard34ConvObj.ConvertToV3(InputFilename, &FinalData);
+       
+       }
+       
+       // Check if we are outputting to console or to file.
+       
+       if (OutputPipe == false){
+       
+               // We are outputting to a file.
+               
+               OutputFile.Write(FinalData, wxConvUTF8);
+       
+       } else {
+       
+               // Write out the data to the console.
+       
+               std::cout << FinalData << std::endl;
+       
+       }
+       
        return CONVERTRESULT_OK;
        
 }
\ No newline at end of file
index 4077998..29e753c 100644 (file)
@@ -87,5 +87,17 @@ TEST(ConvertCmdLine, ConvertTests){
                wxT("vCard4"), 
                wxT("LoadCheck-Load1.vcf"), 
                wxT("Temp-LoadCheck-Load1.vcf")));
+               
+       // Check that that outputting to console (piping) works.
+       
+       ASSERT_EQ(CONVERTRESULT_OK, ConvertContact(wxT("vCard4"), 
+               wxT("vCard3"), 
+               wxT("LoadCheck-Load1.vcf"), 
+               wxT("")));
+
+       ASSERT_EQ(CONVERTRESULT_OK, ConvertContact(wxT("vCard3"), 
+               wxT("vCard4"), 
+               wxT("LoadCheck-Load1-v3.vcf"), 
+               wxT("")));
 
 }
\ 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