• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ ASSERT_THROWS函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中ASSERT_THROWS函数的典型用法代码示例。如果您正苦于以下问题:C++ ASSERT_THROWS函数的具体用法?C++ ASSERT_THROWS怎么用?C++ ASSERT_THROWS使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了ASSERT_THROWS函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: TEST

TEST(MatchExpressionParserGeoNear, ParseInvalidNearSphere) {
    {
        BSONObj query = fromjson("{loc: {$maxDistance: 100, $nearSphere: [0,0]}}");
        StatusWithMatchExpression result =
            MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions());
        ASSERT_FALSE(result.isOK());
    }
    {
        BSONObj query = fromjson("{loc: {$minDistance: 100, $nearSphere: [0,0]}}");
        StatusWithMatchExpression result =
            MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions());
        ASSERT_FALSE(result.isOK());
    }
    {
        BSONObj query = fromjson("{loc: {$nearSphere: [0,0], $maxDistance: {}}}");
        ASSERT_THROWS(MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions()),
                      UserException);
    }
    {
        BSONObj query = fromjson("{loc: {$nearSphere: [0,0], $minDistance: {}}}");
        ASSERT_THROWS(MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions()),
                      UserException);
    }
    {
        BSONObj query = fromjson("{loc: {$nearSphere: [0,0], $eq: 1}}");
        ASSERT_THROWS(MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions()),
                      UserException);
    }
}
开发者ID:AnkyrinRepeat,项目名称:mongo,代码行数:29,代码来源:expression_parser_geo_test.cpp


示例2: database_testTransactionsSanity

void database_testTransactionsSanity()
{
	TempDB db;
	db.beginTransaction();
	ASSERT_THROWS(db.beginTransaction(),dbexception);
	ASSERT_THROWS(db.endTransaction(),dbexception);
}
开发者ID:Hoglet,项目名称:TimeIT,代码行数:7,代码来源:test_db.cpp


示例3: TEST_F

TEST_F(DocumentSourceFacetTest, ShouldRejectNonArrayFacets) {
    auto ctx = getExpCtx();
    auto spec = BSON("$facet" << BSON("a" << 1));
    ASSERT_THROWS(DocumentSourceFacet::createFromBson(spec.firstElement(), ctx), UserException);

    spec = BSON("$facet" << BSON("a" << BSON_ARRAY(BSON("$skip" << 4)) << "b" << 2));
    ASSERT_THROWS(DocumentSourceFacet::createFromBson(spec.firstElement(), ctx), UserException);
}
开发者ID:ksuarz,项目名称:mongo,代码行数:8,代码来源:document_source_facet_test.cpp


示例4: Remove_NegativeIndex_BadIndexEception

void Remove_NegativeIndex_BadIndexEception(){
	Fixed_LinkedList<char> fll(2);
	ASSERT_THROWS(fll.Remove(-1), LinkedListException);

	fll.Append('A');
	ASSERT_THROWS(fll.Remove(-1), LinkedListException);

	fll.Append('B');
	ASSERT_THROWS(fll.Remove(-1), LinkedListException);
}
开发者ID:Akiira,项目名称:DataStructures2,代码行数:10,代码来源:TestSuite_FixedLinkedList.cpp


示例5: test_b_UtilizacaoParque

void test_b_UtilizacaoParque() {
	ParqueEstacionamento p1(10,20);
	p1.novo_cliente("Joao Santos");
	p1.novo_cliente("Pedro Morais");
	p1.novo_cliente("Rui Silva");
	p1.novo_cliente("Susana Costa");
	p1.novo_cliente("Maria Tavares");
	p1.entrar("Maria Tavares");
	p1.entrar("Susana Costa");
	p1.sair("Susana Costa");
	p1.sair("Maria Tavares");
	p1.entrar("Maria Tavares");
	p1.sair("Maria Tavares");
	p1.entrar("Rui Silva");
	p1.sair("Rui Silva");
	p1.entrar("Susana Costa");
	p1.entrar("Rui Silva");
	p1.sair("Rui Silva");
	p1.entrar("Rui Silva");
	p1.entrar("Pedro Morais");
	ASSERT_EQUAL(3, p1.num_utilizacoes("Rui Silva"));
	ASSERT_EQUAL(1, p1.num_utilizacoes("Pedro Morais"));
	ASSERT_EQUAL(0, p1.num_utilizacoes("Joao Santos"));

	ASSERT_THROWS(p1.num_utilizacoes("Tiago Silva"), ClienteNaoExistente);
	try {
		p1.num_utilizacoes("Tiago Silva");
	}
	catch (ClienteNaoExistente &e) {
		cout << "Apanhou excepção. Cliente não existente: " << e.getNome() << endl;
		ASSERT_EQUAL("Tiago Silva", e.getNome());
	}
}
开发者ID:andrefreitas,项目名称:feup-aeda,代码行数:33,代码来源:Test.cpp


示例6: test_f_InfoClientes

void test_f_InfoClientes() {
    ParqueEstacionamento p1(10,20);
	p1.novo_cliente("Joao Santos");
	p1.novo_cliente("Pedro Morais");
	p1.novo_cliente("Rui Silva");
	p1.novo_cliente("Susana Costa");
	p1.novo_cliente("Maria Tavares");
	p1.entrar("Maria Tavares");
	p1.entrar("Susana Costa");
	p1.sair("Susana Costa");
	p1.entrar("Rui Silva");
	p1.entrar("Susana Costa");
	ASSERTM("Este teste nunca falha! VERIFICAR informação escrita no monitor", true);
	cout << p1;
	InfoCartao ic=p1.get_cliente_pos(2);
	ASSERT_EQUAL("Rui Silva", ic.nome);

	ASSERT_THROWS(p1.get_cliente_pos(6), PosicaoNaoExistente);
	try {
		p1.get_cliente_pos(6);
	}
	catch (PosicaoNaoExistente &e) {
		ASSERTM("Este teste nunca falha. Verifique no monitor a informação", true);
		cout << "Apanhou excepção. Posição não existente:" << e.getValor() << endl;
		ASSERT_EQUAL(6, e.getValor());
	}
}
开发者ID:andrefreitas,项目名称:feup-aeda,代码行数:27,代码来源:Test.cpp


示例7: test_const_buffer_back_throws_after_push_pop

void test_const_buffer_back_throws_after_push_pop() {
	BoundedBuffer<int, 5> buffer { };
	buffer.push(5);
	buffer.pop();
	auto const & constBuffer = buffer;
	ASSERT_THROWS(constBuffer.back(), std::logic_error);
}
开发者ID:paddor,项目名称:cpp-advanced-exercises,代码行数:7,代码来源:bounded_buffer_content_suite.cpp


示例8: run

        void run() {
            // _id_ is at 0, so nIndexes == 1
            halfAddIndex("a");
            halfAddIndex("b");
            halfAddIndex("c");
            halfAddIndex("d");
            int offset = IndexBuildsInProgress::get(_ns, "b_1");
            ASSERT_EQUALS(2, offset);

            IndexBuildsInProgress::remove(_ns, offset);
            nsdetails(_ns)->indexBuildsInProgress--;

            ASSERT_EQUALS(2, IndexBuildsInProgress::get(_ns, "c_1"));
            ASSERT_EQUALS(3, IndexBuildsInProgress::get(_ns, "d_1"));

            offset = IndexBuildsInProgress::get(_ns, "d_1");
            IndexBuildsInProgress::remove(_ns, offset);
            nsdetails(_ns)->indexBuildsInProgress--;

            ASSERT_EQUALS(2, IndexBuildsInProgress::get(_ns, "c_1"));
            ASSERT_THROWS(IndexBuildsInProgress::get(_ns, "d_1"), MsgAssertionException);

            offset = IndexBuildsInProgress::get(_ns, "a_1");
            IndexBuildsInProgress::remove(_ns, offset);
            nsdetails(_ns)->indexBuildsInProgress--;

            ASSERT_EQUALS(1, IndexBuildsInProgress::get(_ns, "c_1"));
        }
开发者ID:violentesc,项目名称:mongo,代码行数:28,代码来源:indexupdatetests.cpp


示例9: database_testDatacell

void database_testDatacell()
{
	std::string data("Text");
	DBAbstraction::DataCell dc1(data.c_str());
	DBAbstraction::DataCell dc2("");

	dc2=dc1;
	ASSERT_EQUAL(data,dc2.getString());
	ASSERT_THROWS(dc2.getInt(), dbexception );
	ASSERT_THROWS(dc2.getBool(), dbexception );

	DBAbstraction::DataCell dci(1);
	ASSERT_EQUAL(1,dci.getInt());
	ASSERT_THROWS(dci.getString(), dbexception );

}
开发者ID:Hoglet,项目名称:TimeIT,代码行数:16,代码来源:test_db.cpp


示例10: run

        void run() {
            Lock::GlobalWrite lk;

            OpTime o1,o2;

            {
                mongo::mutex::scoped_lock lk2(OpTime::m);
                o1 = OpTime::now(lk2);
                o2 = OpTime::now(lk2);
            }

            BSONObjBuilder b;
            b.appendTimestamp("ts", o2.asLL());
            BSONObj obj = b.obj();

            MockInitialSync mock;

            // all three should succeed
            mock.applyOp(obj, o1);

            mock.failOnStep = MockInitialSync::FAIL_FIRST_APPLY;
            mock.applyOp(obj, o1);

            mock.retry = false;
            mock.applyOp(obj, o1);

            // force failure
            MockInitialSync mock2;
            mock2.failOnStep = MockInitialSync::FAIL_BOTH_APPLY;

            ASSERT_THROWS(mock2.applyOp(obj, o2), UserException);
        }
开发者ID:Desartstudio,项目名称:mongo-nonx86,代码行数:32,代码来源:replsettests.cpp


示例11: Prepend_Full_FullException

void Prepend_Full_FullException() {
    Fixed_LinkedList<char> fll(2);
    fll.Prepend('C');
    fll.Prepend('B');

    ASSERT_THROWS(fll.Prepend('A'), LinkedListException);
}
开发者ID:Akiira,项目名称:DataStructures2,代码行数:7,代码来源:TestSuite_FixedLinkedList.cpp


示例12: calcReadsThrowsExceptionForInvalidInput

void calcReadsThrowsExceptionForInvalidInput() {
	//Arrange
	std::istringstream in {"1 + +"};

	//Act & Assert
	ASSERT_THROWS(calc(in), std::exception);
}
开发者ID:lukasmartinelli,项目名称:retrocalc,代码行数:7,代码来源:Test.cpp


示例13: run

 void run() {
     IndexDetails& id = addIndexWithInfo();
     // Create a btree builder.
     BtreeBuilder<V1> builder( false, id );
     // Add some keys to the builder, in order.  We need enough keys to build an internal
     // node in order to check for an interrupt.
     int32_t nKeys = 1000;
     for( int32_t i = 0; i < nKeys; ++i ) {
         BSONObj key = BSON( "a" << i );
         builder.addKey( key, /* dummy location */ DiskLoc() );
     }
     // The root of the index has not yet been set.
     ASSERT( id.head.isNull() );
     // Register a request to kill the current operation.
     cc().curop()->kill();
     if ( _mayInterrupt ) {
         // Call commit on the builder, which will be aborted due to the kill request.
         ASSERT_THROWS( builder.commit( _mayInterrupt ), UserException );
         // The root of the index is not set because commit() did not complete.
         ASSERT( id.head.isNull() );
     }
     else {
         // Call commit on the builder, which will not be aborted because mayInterrupt is
         // false.
         builder.commit( _mayInterrupt );
         // The root of the index is set because commit() completed.
         ASSERT( !id.head.isNull() );
     }
 }
开发者ID:DylanTong,项目名称:mongo,代码行数:29,代码来源:btreebuildertests.cpp


示例14: run

        void run() {
            writelock lk("");

            OpTime o1 = OpTime::now();
            OpTime o2 = OpTime::now();

            BSONObjBuilder b;
            b.appendTimestamp("ts", o2.asLL());
            BSONObj obj = b.obj();

            MockInitialSync mock;

            // all three should succeed
            mock.applyOp(obj, o1);

            mock.failOnStep = MockInitialSync::FAIL_FIRST_APPLY;
            mock.applyOp(obj, o1);

            mock.retry = false;
            mock.applyOp(obj, o1);

            // force failure
            MockInitialSync mock2;
            mock2.failOnStep = MockInitialSync::FAIL_BOTH_APPLY;

            ASSERT_THROWS(mock2.applyOp(obj, o2), UserException);
        }
开发者ID:dibiasio,项目名称:mongo,代码行数:27,代码来源:replsettests.cpp


示例15: TEST_F

TEST_F(ServiceStateMachineFixture, TestThrowHandling) {
    _sep->setUassertInHandler();

    ASSERT_EQ(ServiceStateMachine::State::Ended, runPingTest());
    ASSERT_THROWS(checkPingOk(), MsgAssertionException);
    ASSERT_TRUE(_tl->ranSource());
    ASSERT_FALSE(_tl->ranSink());
}
开发者ID:wzqtony,项目名称:mongo,代码行数:8,代码来源:service_state_machine_test.cpp


示例16: TEST_F

TEST_F(KeysManagerShardedTest, GetKeyForValidationTimesOutIfRefresherIsNotRunning) {
    operationContext()->setDeadlineAfterNowBy(Microseconds(250 * 1000),
                                              ErrorCodes::ExceededTimeLimit);

    ASSERT_THROWS(
        keyManager()->getKeyForValidation(operationContext(), 1, LogicalTime(Timestamp(100, 0))),
        DBException);
}
开发者ID:ShaneHarvey,项目名称:mongo,代码行数:8,代码来源:keys_collection_manager_sharding_test.cpp


示例17: run

        virtual void run(){
            OperationContextImpl txn;
            DBDirectClient client(&txn);

            BSONObj result;
            BSONObj cmdObj = BSON( "count" << "" );
            ASSERT_THROWS( client.runCommand( "", cmdObj, result ), UserException );
        }
开发者ID:ANTco,项目名称:mongo,代码行数:8,代码来源:directclienttests.cpp


示例18: TEST

TEST(ParameterValidation, subscribeEmptyDataType)
{
  ros::NodeHandle nh;
  ros::SubscribeOptions ops;
  ops.init<test_roscpp::TestEmpty>("blah", 0, callback);
  ops.datatype.clear();
  ASSERT_THROWS(nh.subscribe(ops));
}
开发者ID:Aand1,项目名称:ROSCH,代码行数:8,代码来源:parameter_validation.cpp


示例19: ParameterError_01

	void ParameterError_01() {
		int x = -1;
		int y = 0;
		int height = 1;
		int width = 1;

		ASSERT_THROWS(new Rect(x,y,height,width),InputException);
	}
开发者ID:bonfa,项目名称:ACTR_Cpp_VisualModule,代码行数:8,代码来源:RectTest.cpp


示例20: TEST_F

TEST_F(KeysManagerShardedTest, GetKeyForValidationTimesOutIfRefresherIsNotRunning) {
    operationContext()->setDeadlineAfterNowBy(Microseconds(250 * 1000));

    ASSERT_THROWS(keyManager()
                      ->getKeyForValidation(operationContext(), 1, LogicalTime(Timestamp(100, 0)))
                      .status_with_transitional_ignore(),
                  DBException);
}
开发者ID:DINKIN,项目名称:mongo,代码行数:8,代码来源:keys_collection_manager_sharding_test.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ ASSERT_TRUE函数代码示例发布时间:2022-05-30
下一篇:
C++ ASSERT_STR_EQUAL函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap