// 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){
}
+ // Check that the input filename is not empty.
+
+ if (InputFilename.empty()){
+
+ return CONVERTRESULT_INPUTFILEEMPTY;
+
+ }
+
// Check that the input file given exists.
if (!wxFileExists(InputFilename)){
// Check that the output file can be opened.
+ bool OutputPipe = false;
wxFile OutputFile;
if (!OutputFilename.IsEmpty()){
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;
CONVERTRESULT_INVALIDINPUTFORMAT,
CONVERTRESULT_INVALIDOUTPUTFORMAT,
CONVERTRESULT_INPUTFILEMISSING,
+ CONVERTRESULT_INPUTFILEEMPTY,
+ CONVERTRESULT_INPUTFILEINVALIDFORMAT,
CONVERTRESULT_INPUTFILEERROR,
CONVERTRESULT_OUTPUTFILEERROR
};
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
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.
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