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

kabc

  • 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  QDir mOutput4_0Dir;
41 
42  QStringList mInputFiles;
43 
44  private Q_SLOTS:
45  void initTestCase();
46  void testVCardRoundtrip_data();
47  void testVCardRoundtrip();
48 };
49 
50 // check the validity of our test data set
51 void RoundtripTest::initTestCase()
52 {
53  mOutFilePattern = QLatin1String( "%1.ref" );
54 
55  // check that all resource prefixes exist
56 
57  mInputDir = QDir( QLatin1String( ":/input" ) );
58  QVERIFY( mInputDir.exists() );
59  QVERIFY( mInputDir.cd( QLatin1String( "tests" ) ) );
60 
61  mOutput2_1Dir = QDir( QLatin1String( ":/output2.1" ) );
62  QVERIFY( mOutput2_1Dir.exists() );
63  QVERIFY( mOutput2_1Dir.cd( QLatin1String( "tests" ) ) );
64 
65  mOutput3_0Dir = QDir( QLatin1String( ":/output3.0" ) );
66  QVERIFY( mOutput3_0Dir.exists() );
67  QVERIFY( mOutput3_0Dir.cd( QLatin1String( "tests" ) ) );
68 
69  mOutput4_0Dir = QDir( QLatin1String( ":/output4.0" ) );
70  QVERIFY( mOutput4_0Dir.exists() );
71  QVERIFY( mOutput4_0Dir.cd( QLatin1String( "tests" ) ) );
72 
73  // check that there are input files
74 
75  mInputFiles = mInputDir.entryList();
76  QVERIFY( !mInputFiles.isEmpty() );
77 }
78 
79 void RoundtripTest::testVCardRoundtrip_data()
80 {
81  QTest::addColumn<QString>( "inputFile" );
82  QTest::addColumn<QString>( "output2_1File" );
83  QTest::addColumn<QString>( "output3_0File" );
84  QTest::addColumn<QString>( "output4_0File" );
85 
86  Q_FOREACH ( const QString &inputFile, mInputFiles ) {
87  const QString outFile = mOutFilePattern.arg( inputFile );
88 
89  QTest::newRow( QFile::encodeName( inputFile ) )
90  << inputFile
91  << ( mOutput2_1Dir.exists( outFile ) ? outFile : QString() )
92  << ( mOutput3_0Dir.exists( outFile ) ? outFile : QString() )
93  << ( mOutput4_0Dir.exists( outFile ) ? outFile : QString() );
94  }
95 }
96 
97 void RoundtripTest::testVCardRoundtrip()
98 {
99  QFETCH( QString, inputFile );
100  QFETCH( QString, output2_1File );
101  QFETCH( QString, output3_0File );
102  QFETCH( QString, output4_0File );
103 
104  QVERIFY2( !output2_1File.isEmpty()
105  || !output3_0File.isEmpty()
106  || !output4_0File.isEmpty(),
107  "No reference output file for either format version" );
108 
109  QFile input( QFileInfo( mInputDir, inputFile ).absoluteFilePath() );
110  QVERIFY( input.open( QIODevice::ReadOnly ) );
111 
112  const QByteArray inputData = input.readAll();
113  QVERIFY( !inputData.isEmpty() );
114 
115  VCardConverter converter;
116  const Addressee::List list = converter.parseVCards( inputData );
117  QVERIFY( !list.isEmpty() );
118 
119  if ( !output2_1File.isEmpty() ) {
120  const QByteArray outputData = converter.createVCards( list, VCardConverter::v2_1 );
121 
122  QFile outputFile( QFileInfo( mOutput2_1Dir, output2_1File ).absoluteFilePath() );
123  QVERIFY( outputFile.open( QIODevice::ReadOnly ) );
124 
125  const QByteArray outputRefData = outputFile.readAll();
126  QCOMPARE( outputData.size(), outputRefData.size() );
127 
128  const QList<QByteArray> outputLines = outputData.split( '\n' );
129  const QList<QByteArray> outputRefLines = outputRefData.split( '\n' );
130  QCOMPARE( outputLines.count(), outputRefLines.count() );
131 
132  for ( int i = 0; i < outputLines.count(); ++i ) {
133  const QByteArray actual = outputLines[ i ];
134  const QByteArray expect = outputRefLines[ i ];
135 
136  if ( actual != expect ) {
137  qCritical() << "Mismatch in v2.1 output line" << ( i + 1 );
138  QCOMPARE( actual.count(), expect.count() );
139 
140  qCritical() << "\nActual:" << actual << "\nExpect:" << expect;
141  QCOMPARE( actual, expect );
142  }
143  }
144  }
145 
146  if ( !output3_0File.isEmpty() ) {
147  const QByteArray outputData = converter.createVCards( list, VCardConverter::v3_0 );
148 
149  QFile outputFile( QFileInfo( mOutput3_0Dir, output3_0File ).absoluteFilePath() );
150  QVERIFY( outputFile.open( QIODevice::ReadOnly ) );
151 
152  const QByteArray outputRefData = outputFile.readAll();
153 // QCOMPARE( outputData.size(), outputRefData.size() );
154 
155  const QList<QByteArray> outputLines = outputData.split( '\n' );
156  const QList<QByteArray> outputRefLines = outputRefData.split( '\n' );
157  QCOMPARE( outputLines.count(), outputRefLines.count() );
158 
159  for ( int i = 0; i < outputLines.count(); ++i ) {
160  const QByteArray actual = outputLines[ i ];
161  const QByteArray expect = outputRefLines[ i ];
162 
163  if ( actual != expect ) {
164  qCritical() << "Mismatch in v3.0 output line" << ( i + 1 );
165 
166  qCritical() << "\nActual:" << actual << "\nExpect:" << expect;
167  QCOMPARE( actual.count(), expect.count() );
168  QCOMPARE( actual, expect );
169  }
170  }
171  }
172 }
173 
174 QTEST_KDEMAIN( RoundtripTest, NoGUI )
175 
176 #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
KABC
Definition: address.h:29
This file is part of the KDE documentation.
Documentation copyright © 1996-2015 The KDE developers.
Generated on Tue Nov 24 2015 17:37:00 by doxygen 1.8.8 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-4.14.3 API Reference

Skip menu "kdepimlibs-4.14.3 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
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