From 0177e3dca8765fcab7ca524f3ba0f243a972fdfb Mon Sep 17 00:00:00 2001 From: Steve Brokenshire Date: Sun, 6 Dec 2015 09:54:31 +0000 Subject: [PATCH] Added code and unit tests for writing the processed data to file or console. --- source/convert.cpp | 49 +++++++++++++++++++++++++++++++-- source/tests/xestiaab_convert.h | 12 ++++++++ 2 files changed, 58 insertions(+), 3 deletions(-) diff --git a/source/convert.cpp b/source/convert.cpp index ae0e4db..0cfaa9f 100644 --- a/source/convert.cpp +++ b/source/convert.cpp @@ -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 diff --git a/source/tests/xestiaab_convert.h b/source/tests/xestiaab_convert.h index 4077998..29e753c 100644 --- a/source/tests/xestiaab_convert.h +++ b/source/tests/xestiaab_convert.h @@ -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 -- 2.39.2