#include "convert.h"
#include "vcard/vcard.h"
+#include "vcard/vcard34conv.h"
ConvertResult ConvertContact(wxString InputFormat, wxString OutputFormat,
wxString InputFilename, wxString OutputFilename){
// Check that the file has the correct file format.
+ vCard vCard4Format;
+ wxString FinalData;
+
if (InputFormat == "vCard4"){
// Read from the file.
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"){
}
+ // 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
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