• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepimlibs API Reference
  • KDE Home
  • Contact Us
 

kabc

  • sources
  • kde-4.12
  • kdepimlibs
  • kabc
  • vcardparser
testroundtrip.cpp
1 /*
2  This file is part of libkabc.
3  Copyright (c) 2012 Kevin Krammer <krammer@kde.org>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 #include "addressee.h"
22 #include "vcardconverter.h"
23 
24 #include <qtest_kde.h>
25 
26 #include <QObject>
27 
28 using namespace KABC;
29 
30 class RoundtripTest : public QObject
31 {
32  Q_OBJECT
33 
34  private:
35  QString mOutFilePattern;
36 
37  QDir mInputDir;
38  QDir mOutput2_1Dir;
39  QDir mOutput3_0Dir;
40 
41  QStringList mInputFiles;
42 
43  private Q_SLOTS:
44  void initTestCase();
45  void testVCardRoundtrip_data();
46  void testVCardRoundtrip();
47 };
48 
49 // check the validity of our test data set
50 void RoundtripTest::initTestCase()
51 {
52  mOutFilePattern = QLatin1String( "%1.ref" );
53 
54  // check that all resource prefixes exist
55 
56  mInputDir = QDir( QLatin1String( ":/input" ) );
57  QVERIFY( mInputDir.exists() );
58  QVERIFY( mInputDir.cd( QLatin1String( "tests" ) ) );
59 
60  mOutput2_1Dir = QDir( QLatin1String( ":/output2.1" ) );
61  QVERIFY( mOutput2_1Dir.exists() );
62  QVERIFY( mOutput2_1Dir.cd( QLatin1String( "tests" ) ) );
63 
64  mOutput3_0Dir = QDir( QLatin1String( ":/output3.0" ) );
65  QVERIFY( mOutput3_0Dir.exists() );
66  QVERIFY( mOutput3_0Dir.cd( QLatin1String( "tests" ) ) );
67 
68  // check that there are input files
69 
70  mInputFiles = mInputDir.entryList();
71  QVERIFY( !mInputFiles.isEmpty() );
72 }
73 
74 void RoundtripTest::testVCardRoundtrip_data()
75 {
76  QTest::addColumn<QString>( "inputFile" );
77  QTest::addColumn<QString>( "output2_1File" );
78  QTest::addColumn<QString>( "output3_0File" );
79 
80  Q_FOREACH ( const QString &inputFile, mInputFiles ) {
81  const QString outFile = mOutFilePattern.arg( inputFile );
82 
83  QTest::newRow( QFile::encodeName( inputFile ) )
84  << inputFile
85  << ( mOutput2_1Dir.exists( outFile ) ? outFile : QString() )
86  << ( mOutput3_0Dir.exists( outFile ) ? outFile : QString() );
87  }
88 }
89 
90 void RoundtripTest::testVCardRoundtrip()
91 {
92  QFETCH( QString, inputFile );
93  QFETCH( QString, output2_1File );
94  QFETCH( QString, output3_0File );
95 
96  QVERIFY2( !output2_1File.isEmpty() || !output3_0File.isEmpty(),
97  "No reference output file for either format version" );
98 
99  QFile input( QFileInfo( mInputDir, inputFile ).absoluteFilePath() );
100  QVERIFY( input.open( QIODevice::ReadOnly ) );
101 
102  const QByteArray inputData = input.readAll();
103  QVERIFY( !inputData.isEmpty() );
104 
105  VCardConverter converter;
106  const Addressee::List list = converter.parseVCards( inputData );
107  QVERIFY( !list.isEmpty() );
108 
109  if ( !output2_1File.isEmpty() ) {
110  const QByteArray outputData = converter.createVCards( list, VCardConverter::v2_1 );
111 
112  QFile outputFile( QFileInfo( mOutput2_1Dir, output2_1File ).absoluteFilePath() );
113  QVERIFY( outputFile.open( QIODevice::ReadOnly ) );
114 
115  const QByteArray outputRefData = outputFile.readAll();
116  QCOMPARE( outputData.size(), outputRefData.size() );
117 
118  const QList<QByteArray> outputLines = outputData.split( '\n' );
119  const QList<QByteArray> outputRefLines = outputRefData.split( '\n' );
120  QCOMPARE( outputLines.count(), outputRefLines.count() );
121 
122  for ( int i = 0; i < outputLines.count(); ++i ) {
123  const QByteArray actual = outputLines[ i ];
124  const QByteArray expect = outputRefLines[ i ];
125 
126  if ( actual != expect ) {
127  qCritical() << "Mismatch in v2.1 output line" << ( i + 1 );
128  QCOMPARE( actual.count(), expect.count() );
129 
130  qCritical() << "\nActual:" << actual << "\nExpect:" << expect;
131  QCOMPARE( actual, expect );
132  }
133  }
134  }
135 
136  if ( !output3_0File.isEmpty() ) {
137  const QByteArray outputData = converter.createVCards( list, VCardConverter::v3_0 );
138 
139  QFile outputFile( QFileInfo( mOutput3_0Dir, output3_0File ).absoluteFilePath() );
140  QVERIFY( outputFile.open( QIODevice::ReadOnly ) );
141 
142  const QByteArray outputRefData = outputFile.readAll();
143 // QCOMPARE( outputData.size(), outputRefData.size() );
144 
145  const QList<QByteArray> outputLines = outputData.split( '\n' );
146  const QList<QByteArray> outputRefLines = outputRefData.split( '\n' );
147  QCOMPARE( outputLines.count(), outputRefLines.count() );
148 
149  for ( int i = 0; i < outputLines.count(); ++i ) {
150  const QByteArray actual = outputLines[ i ];
151  const QByteArray expect = outputRefLines[ i ];
152 
153  if ( actual != expect ) {
154  qCritical() << "Mismatch in v3.0 output line" << ( i + 1 );
155 
156  qCritical() << "\nActual:" << actual << "\nExpect:" << expect;
157  QCOMPARE( actual.count(), expect.count() );
158  QCOMPARE( actual, expect );
159  }
160  }
161  }
162 }
163 
164 QTEST_KDEMAIN( RoundtripTest, NoGUI )
165 
166 #include "testroundtrip.moc"
KABC::AddresseeList
a QValueList of Addressee, with sorting functionality
Definition: addresseelist.h:288
KABC::VCardConverter
Class to converting contact objects into vCard format and vice versa.
Definition: vcardconverter.h:53
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:01:05 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kabc

Skip menu "kabc"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal