21 #include "addressee.h"
22 #include "vcardconverter.h"
24 #include <qtest_kde.h>
30 class RoundtripTest :
public QObject
46 void testVCardRoundtrip_data();
47 void testVCardRoundtrip();
51 void RoundtripTest::initTestCase()
58 QVERIFY( mInputDir.exists() );
62 QVERIFY( mOutput2_1Dir.exists() );
66 QVERIFY( mOutput3_0Dir.exists() );
70 QVERIFY( mOutput4_0Dir.exists() );
75 mInputFiles = mInputDir.entryList();
76 QVERIFY( !mInputFiles.isEmpty() );
79 void RoundtripTest::testVCardRoundtrip_data()
81 QTest::addColumn<QString>(
"inputFile" );
82 QTest::addColumn<QString>(
"output2_1File" );
83 QTest::addColumn<QString>(
"output3_0File" );
84 QTest::addColumn<QString>(
"output4_0File" );
88 Q_FOREACH (
const QString &inputFile, mInputFiles) {
89 const QString outFile = outFilePattern.
arg(inputFile);
90 const QString outFileV2_1 = outFile21Pattern.
arg(inputFile);
91 const QString outFileV4 = outFile4Pattern.
arg(inputFile);
94 << (mOutput2_1Dir.exists(outFileV2_1) ? outFileV2_1 :
QString())
95 << (mOutput3_0Dir.exists(outFile) ? outFile :
QString())
96 << (mOutput4_0Dir.exists(outFileV4) ? outFileV4 :
QString());
100 void RoundtripTest::testVCardRoundtrip()
103 QFETCH(
QString, output2_1File );
104 QFETCH(
QString, output3_0File );
105 QFETCH(
QString, output4_0File );
107 QVERIFY2( !output2_1File.isEmpty()
108 || !output3_0File.isEmpty()
109 || !output4_0File.isEmpty(),
110 "No reference output file for either format version" );
112 QFile input(
QFileInfo( mInputDir, inputFile ).absoluteFilePath() );
113 QVERIFY( input.open( QIODevice::ReadOnly ) );
116 QVERIFY( !inputData.isEmpty() );
122 if ( !output2_1File.isEmpty() ) {
123 const QByteArray outputData = converter.createVCards( list, VCardConverter::v2_1 );
125 QFile outputFile(
QFileInfo( mOutput2_1Dir, output2_1File ).absoluteFilePath() );
126 QVERIFY( outputFile.open( QIODevice::ReadOnly ) );
128 const QByteArray outputRefData = outputFile.readAll();
129 QCOMPARE( outputData.
size(), outputRefData.size() );
133 QCOMPARE( outputLines.count(), outputRefLines.
count() );
135 for (
int i = 0; i < outputLines.count(); ++i ) {
137 const QByteArray expect = outputRefLines[ i ];
139 if ( actual != expect ) {
140 qCritical() <<
"Mismatch in v2.1 output line" << ( i + 1 );
143 qCritical() <<
"\nActual:" << actual <<
"\nExpect:" << expect;
144 QCOMPARE( actual, expect );
149 if ( !output3_0File.isEmpty() ) {
150 const QByteArray outputData = converter.createVCards( list, VCardConverter::v3_0 );
151 QFile outputFile(
QFileInfo( mOutput3_0Dir, output3_0File ).absoluteFilePath() );
152 QVERIFY( outputFile.open( QIODevice::ReadOnly ) );
154 const QByteArray outputRefData = outputFile.readAll();
159 QCOMPARE( outputLines.
count(), outputRefLines.
count() );
161 for (
int i = 0; i < outputLines.
count(); ++i ) {
163 const QByteArray expect = outputRefLines[ i ];
165 if ( actual != expect ) {
166 qCritical() <<
"Mismatch in v3.0 output line" << ( i + 1 );
168 qCritical() <<
"\nActual:" << actual <<
"\nExpect:" << expect;
169 QCOMPARE( actual.
count(), expect.count() );
170 QCOMPARE( actual, expect );
175 if (!output4_0File.isEmpty()) {
176 const QByteArray outputData = converter.createVCards(list, VCardConverter::v4_0);
178 QFile outputFile(
QFileInfo(mOutput4_0Dir, output4_0File).absoluteFilePath());
179 QVERIFY(outputFile.open(QIODevice::ReadOnly));
181 const QByteArray outputRefData = outputFile.readAll();
188 for (
int i = 0; i < outputLines.
count(); ++i) {
192 if (actual != expect) {
193 qCritical() <<
"Mismatch in v4.0 output line" << (i + 1);
195 qCritical() <<
"\nActual:" << actual <<
"\nExpect:" << expect;
196 QCOMPARE(actual.
count(), expect.count());
197 QCOMPARE(actual, expect);
204 QTEST_KDEMAIN( RoundtripTest, NoGUI )
206 #include "testroundtrip.moc"
QList< QByteArray > split(char sep) const
a QValueList of Addressee, with sorting functionality
Class to converting contact objects into vCard format and vice versa.
int count(const T &value) const
QTestData & newRow(const char *dataTag)
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
QByteArray encodeName(const QString &fileName)