예제 #1
0
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 ) );
}