当前位置: 首页>>代码示例>>C++>>正文


C++ Content::body方法代码示例

本文整理汇总了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() );
}
开发者ID:pvuorela,项目名称:kcalcore,代码行数:50,代码来源:contenttest.cpp

示例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;
}
开发者ID:pvuorela,项目名称:kcalcore,代码行数:42,代码来源:contenttest.cpp


注:本文中的Content::body方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。