本文整理汇总了C++中Content::body方法的典型用法代码示例。如果您正苦于以下问题:C++ Content::body方法的具体用法?C++ Content::body怎么用?C++ Content::body使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Content
的用法示例。
在下文中一共展示了Content::body方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testSetContent
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() );
}
示例2: testImplicitMultipartGeneration
void ContentTest::testImplicitMultipartGeneration()
{
Content *c1 = new Content();
c1->contentType()->from7BitString( "text/plain" );
c1->setBody( "textpart" );
Content *c2 = new Content();
c2->contentType()->from7BitString( "text/html" );
c2->setBody( "htmlpart" );
c1->addContent( c2 );
// c1 implicitly converted into a multipart/mixed node.
QVERIFY( c1->contentType( false ) );
QCOMPARE( c1->contentType()->mimeType(), QByteArray( "multipart/mixed" ) );
QVERIFY( c1->body().isEmpty() );
QCOMPARE( c1->contents().count(), 2 );
Content *c = c1->contents().at( 0 ); // Former c1.
QVERIFY( c->contentType( false ) );
QCOMPARE( c->contentType()->mimeType(), QByteArray( "text/plain" ) );
QCOMPARE( c->body(), QByteArray( "textpart" ) );
QCOMPARE( c1->contents().at( 1 ), c2 );
// Now remove c2. c1 should be converted back to a text/plain content.
c1->removeContent( c2, false );
QVERIFY( c1->contents().isEmpty() );
QVERIFY( c1->contentType( false ) );
QCOMPARE( c1->contentType()->mimeType(), QByteArray( "text/plain" ) );
QCOMPARE( c1->body(), QByteArray( "textpart" ) );
// c2 should not have been touched.
QVERIFY( c2->contents().isEmpty() );
QVERIFY( c2->contentType( false ) );
QCOMPARE( c2->contentType()->mimeType(), QByteArray( "text/html" ) );
QCOMPARE( c2->body(), QByteArray( "htmlpart" ) );
// Clean up.
delete c1;
delete c2;
}