~ubuntu-branches/ubuntu/quantal/kdepim/quantal

« back to all changes in this revision

Viewing changes to messagecomposer/tests/messagefactorytest.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2011-12-15 14:17:51 UTC
  • mto: This revision was merged to the branch mainline in revision 193.
  • Revision ID: package-import@ubuntu.com-20111215141751-bmhdpiwl23wd9w26
Tags: upstream-4.7.90
ImportĀ upstreamĀ versionĀ 4.7.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
#include <qtest_kde.h>
49
49
#include <QDateTime>
50
50
#include <KCharsets>
 
51
#include <QtCore/QDir>
 
52
#include "templateparser/globalsettings_base.h"
 
53
#include "templateparser/templateparser_export.h"
 
54
 
51
55
using namespace Message;
52
56
using namespace MessageComposer;
53
57
 
129
133
  
130
134
}
131
135
 
132
 
 
133
136
void MessageFactoryTest::testCreateReplyHtml()
134
137
{
135
138
  KMime::Message::Ptr msg = loadMessageFromFile( QLatin1String("html_utf8_encoded.mbox") );
148
151
  QString datetime = KGlobal::locale()->formatDate( date.date(), KLocale::LongDate );
149
152
  datetime += QLatin1String( " " ) + KGlobal::locale()->formatTime( date.time(), true );
150
153
  QString replyStr = QString::fromLatin1( "On " + datetime.toLatin1() + " you wrote:\n> encoded?\n" );
151
 
  QVERIFY( reply.msg->contentType()->mimeType() == "text/plain" );
 
154
  QVERIFY( reply.msg->contentType()->mimeType() == "multipart/alternative" );
152
155
  QVERIFY( reply.msg->subject()->asUnicodeString() == QLatin1String( "Re: reply to please" ) );
153
 
  QCOMPARE_OR_DIFF( reply.msg->body(), replyStr.toLatin1() );
 
156
  QCOMPARE_OR_DIFF( reply.msg->contents().at(0)->body(), replyStr.toLatin1() );
154
157
 
155
158
}
156
159
 
172
175
  QString datetime = KGlobal::locale()->formatDate( date.date(), KLocale::LongDate );
173
176
  datetime += QLatin1String( " " ) + KGlobal::locale()->formatTime( date.time(), true );
174
177
  QString replyStr = QString::fromLatin1( "On " + datetime.toLatin1() + " you wrote:\n> quote me please.\n" );
175
 
  QVERIFY( reply.msg->contentType()->mimeType() == "text/plain" );
 
178
  QVERIFY( reply.msg->contentType()->mimeType() == "multipart/alternative" );
176
179
  QVERIFY( reply.msg->subject()->asUnicodeString() == QLatin1String( "Re: asking for reply" ) );
177
 
  QCOMPARE_OR_DIFF( reply.msg->body(), replyStr.toLatin1() );
 
180
  QCOMPARE_OR_DIFF( reply.msg->contents().at(0)->body(), replyStr.toLatin1() );
178
181
 
179
182
}
180
183
 
202
205
  TestCSSHelper testCSSHelper;
203
206
  MessageCore::Test::TestObjectTreeSource testSource( &testWriter, &testCSSHelper );
204
207
  MessageViewer::NodeHelper* nh = new MessageViewer::NodeHelper;
205
 
  MessageViewer::ObjectTreeParser otp( &testSource, nh, 0, false, false, true, 0 );
 
208
  MessageViewer::ObjectTreeParser otp( &testSource, nh, 0, false, true, 0 );
206
209
  otp.parseObjectTree( reply.msg.get() );
207
210
  QVERIFY( otp.textualContent().contains( replyStr ) );*/
208
211
 
209
212
}
210
213
 
211
 
 
212
214
void MessageFactoryTest::testCreateForward()
213
215
{
214
216
  KMime::Message::Ptr msg = createPlainTestMessage();
257
259
  QCOMPARE_OR_DIFF( fw->encodedContent(), fwdMsg.toLatin1() );
258
260
}
259
261
 
260
 
 
261
262
void MessageFactoryTest::testCreateRedirect()
262
263
{
263
264
  KMime::Message::Ptr msg = createPlainTestMessage();
369
370
  QCOMPARE_OR_DIFF( rdir->encodedContent(), baseline.toLatin1() );
370
371
}
371
372
 
372
 
 
373
373
void MessageFactoryTest::testCreateMDN()
374
374
{
375
375
  KMime::Message::Ptr msg = createPlainTestMessage();
389
389
  TestCSSHelper testCSSHelper;
390
390
  TestObjectTreeSource testSource( &testWriter, &testCSSHelper );
391
391
  MessageViewer::NodeHelper* nh = new MessageViewer::NodeHelper;
392
 
  MessageViewer::ObjectTreeParser otp( &testSource, nh, 0, false, false, true, 0 );
 
392
  MessageViewer::ObjectTreeParser otp( &testSource, nh, 0, false, true, 0 );
393
393
  MessageViewer::ProcessResult pResult( nh ); */
394
394
 
395
395
//   kDebug() << MessageCore::NodeHelper::firstChild( mdn->mainBodyPart() )->encodedContent();
407
407
                    mdnContent.toLatin1() );
408
408
}
409
409
 
410
 
 
411
410
KMime::Message::Ptr MessageFactoryTest::createPlainTestMessage()
412
411
{
413
412
  Composer *composer = new Composer;
439
438
  msg->setContent( data );
440
439
  msg->parse();
441
440
  return msg;
442
 
 
 
441
}
 
442
 
 
443
void MessageFactoryTest::test_multipartAlternative_data()
 
444
{
 
445
  QTest::addColumn<QString>( "mailFileName" );
 
446
  QTest::addColumn<int>( "contentAt" );
 
447
  QTest::addColumn<QString>( "selection" );
 
448
  QTest::addColumn<QString>( "expected" );
 
449
 
 
450
  QDir dir( QLatin1String( MAIL_DATA_DIR ) );
 
451
  foreach ( const QString &file, dir.entryList( QStringList( QLatin1String("plain_message.mbox") ), QDir::Files | QDir::Readable | QDir::NoSymLinks  ) ) {
 
452
     QTest::newRow( file.toLatin1() ) << QString( dir.path() + QLatin1Char( '/' ) + file ) << 0 << "" <<
 
453
     "> This *is* the *message* text *from* Sudhendu Kumar<dontspamme@yoohoo.com>\n"
 
454
     "> \n"
 
455
     "> --\n"
 
456
     "> Thanks & Regards\n"
 
457
     "> Sudhendu Kumar";
 
458
     QTest::newRow( file.toLatin1() ) << QString( dir.path() + QLatin1Char( '/' ) + file ) << 1 << "" << "<html><head></head><body>"
 
459
     "<blockquote>This <i>is</i> the <b>message</b> text <u>from</u> Sudhendu Kumar&lt;dontspamme@yoohoo.com&gt;<br>"
 
460
     "<br>-- <br>Thanks &amp; Regards<br>Sudhendu Kumar<br></blockquote><br/></body></html>";
 
461
   }
 
462
}
 
463
 
 
464
void MessageFactoryTest::test_multipartAlternative()
 
465
{
 
466
  QFETCH( QString, mailFileName );
 
467
  QFETCH( int, contentAt );
 
468
  QFETCH( QString, selection );
 
469
  QFETCH( QString, expected );
 
470
 
 
471
  QFile mailFile( mailFileName );
 
472
  QVERIFY( mailFile.open( QIODevice::ReadOnly ) );
 
473
  const QByteArray mailData = KMime::CRLFtoLF( mailFile.readAll() );
 
474
  QVERIFY( !mailData.isEmpty() );
 
475
  KMime::Message::Ptr origMsg( new KMime::Message );
 
476
  origMsg->setContent( mailData );
 
477
  origMsg->parse();
 
478
 
 
479
  KPIMIdentities::IdentityManager* identMan = new KPIMIdentities::IdentityManager;
 
480
 
 
481
  MessageFactory factory( origMsg, 0 );
 
482
  factory.setIdentityManager( identMan );
 
483
  factory.setSelection( selection );
 
484
  factory.setQuote( true );
 
485
  factory.setReplyStrategy( ReplyAll );
 
486
  TemplateParser::GlobalSettings::self()->setTemplateReplyAll( QLatin1String( "%QUOTE" ) );
 
487
 
 
488
  QString str;
 
489
  str = TemplateParser::GlobalSettings::self()->templateReplyAll();
 
490
  factory.setTemplate( str );
 
491
 
 
492
  MessageFactory::MessageReply reply =  factory.createReply();
 
493
  QVERIFY( reply.replyAll = true );
 
494
  QVERIFY( reply.msg->contentType()->mimeType() == "multipart/alternative" );
 
495
  QVERIFY( reply.msg->subject()->asUnicodeString() == QLatin1String( "Re: Plain Message Test" ) );
 
496
  QCOMPARE( reply.msg->contents().at( contentAt )->encodedBody().data(), expected.toLatin1().data() );
443
497
}
444
498
 
445
499
#include "messagefactorytest.moc"