本文整理汇总了C++中ASSERT_THROWS函数的典型用法代码示例。如果您正苦于以下问题:C++ ASSERT_THROWS函数的具体用法?C++ ASSERT_THROWS怎么用?C++ ASSERT_THROWS使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ASSERT_THROWS函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
}
示例2: database_testTransactionsSanity
void database_testTransactionsSanity()
{
TempDB db;
db.beginTransaction();
ASSERT_THROWS(db.beginTransaction(),dbexception);
ASSERT_THROWS(db.endTransaction(),dbexception);
}
示例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);
}
示例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);
}
示例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());
}
}
示例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());
}
}
示例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);
}
示例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"));
}
示例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 );
}
示例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);
}
示例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);
}
示例12: calcReadsThrowsExceptionForInvalidInput
void calcReadsThrowsExceptionForInvalidInput() {
//Arrange
std::istringstream in {"1 + +"};
//Act & Assert
ASSERT_THROWS(calc(in), std::exception);
}
示例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() );
}
}
示例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);
}
示例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());
}