void ContentTest::testHeaderAppendPrepend() { Content *c = new Content; QByteArray d1( "Resent-From: [email protected]" ); QByteArray d2( "Resent-From: [email protected]" ); Headers::Generic *h1 = new Headers::Generic( "Resent-From", 0, "*****@*****.**" ); Headers::Generic *h2 = new Headers::Generic( "Resent-From", 0, "*****@*****.**" ); c->appendHeader( h1 ); c->appendHeader( h2 ); c->assemble(); QByteArray head = d1 + '\n' + d2 + '\n'; QCOMPARE( c->head(), head ); QByteArray d3( "Resent-From: [email protected]" ); Headers::Generic *h3 = new Headers::Generic( "Resent-From", 0, "*****@*****.**" ); c->prependHeader( h3 ); c->assemble(); head.prepend( d3 + '\n' ); QCOMPARE( c->head(), head ); }
void ContentTest::testHeaderAddRemove() { // Add a Content-Description header to a content. Content *c = new Content; QVERIFY( !c->contentDescription( false ) ); c->contentDescription()->from7BitString( "description" ); // The content must now have the header. QVERIFY( c->contentDescription( false ) ); QCOMPARE( c->contentDescription()->as7BitString( false ), QByteArray( "description" ) ); // The content's head must also have the header. Save the head. c->assemble(); QByteArray head = c->head(); // Clear the content. It must now forget the cached header. c->clear(); QVERIFY( c->head().isEmpty() ); QVERIFY( !c->contentDescription( false ) ); // Put the head back. It must now remember the header. c->setHead( head ); QVERIFY( !c->contentDescription( false ) ); c->parse(); QVERIFY( c->contentDescription( false ) ); c->contentDescription()->from7BitString( "description" ); // Now remove the header explicitly. bool ret = c->removeHeader( "Content-Description" ); QVERIFY( ret ); // The content must have forgotten the header now. QVERIFY( !c->contentDescription( false ) ); // And after assembly the header should stay gone. c->assemble(); QVERIFY( c->head().isEmpty() ); QVERIFY( !c->contentDescription( false ) ); }
void ContentTest::testSetContent() { Content *c = new Content(); QVERIFY( !c->hasContent() ); // head and body present c->setContent( "head1\nhead2\n\nbody1\n\nbody2\n" ); QVERIFY( c->hasContent() ); QCOMPARE( c->head(), QByteArray( "head1\nhead2\n" ) ); QCOMPARE( c->body(), QByteArray( "body1\n\nbody2\n" ) ); QList<QByteArray> list; list << "head1" << "head2" << "" << "body1" << "" << "body2"; c->setContent( list ); QVERIFY( c->hasContent() ); QCOMPARE( c->head(), QByteArray( "head1\nhead2\n" ) ); QCOMPARE( c->body(), QByteArray( "body1\n\nbody2\n" ) ); // ### the final \n is questionable // empty content c->setContent( QByteArray() ); QVERIFY( !c->hasContent() ); QVERIFY( c->head().isEmpty() ); QVERIFY( c->body().isEmpty() ); // empty head c->setContent( "\nbody1\n\nbody2\n" ); QVERIFY( c->hasContent() ); QVERIFY( c->head().isEmpty() ); QCOMPARE( c->body(), QByteArray( "body1\n\nbody2\n" ) ); list.clear(); list << "" << "body1" << "" << "body2"; c->setContent( list ); QVERIFY( c->hasContent() ); QVERIFY( c->head().isEmpty() ); QCOMPARE( c->body(), QByteArray( "body1\n\nbody2\n" ) ); // empty body c->setContent( "head1\nhead2\n\n" ); QVERIFY( c->hasContent() ); QCOMPARE( c->head(), QByteArray( "head1\nhead2\n" ) ); QVERIFY( c->body().isEmpty() ); list.clear(); list << "head1" << "head2" << ""; c->setContent( list ); QVERIFY( c->hasContent() ); QCOMPARE( c->head(), QByteArray( "head1\nhead2\n" ) ); QVERIFY( c->body().isEmpty() ); }