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); } }
void database_testTransactionsSanity() { TempDB db; db.beginTransaction(); ASSERT_THROWS(db.beginTransaction(),dbexception); ASSERT_THROWS(db.endTransaction(),dbexception); }
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); }
TEST_F(DocumentSourceFacetTest, ShouldRejectFacetsWithStagesThatMustBeTheFirstStage) { auto ctx = getExpCtx(); auto spec = BSON("$facet" << BSON("a" << BSON_ARRAY(BSON("$indexStats" << BSONObj())))); ASSERT_THROWS(DocumentSourceFacet::createFromBson(spec.firstElement(), ctx), UserException); spec = BSON("$facet" << BSON( "a" << BSON_ARRAY(BSON("$limit" << 1) << BSON("$indexStats" << BSONObj())))); ASSERT_THROWS(DocumentSourceFacet::createFromBson(spec.firstElement(), ctx), UserException); }
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); }
TEST_F(DocumentSourceFacetTest, ShouldRejectFacetsWithInvalidNames) { auto ctx = getExpCtx(); auto spec = BSON("$facet" << BSON("" << BSON_ARRAY(BSON("$skip" << 4)))); ASSERT_THROWS(DocumentSourceFacet::createFromBson(spec.firstElement(), ctx), UserException); spec = BSON("$facet" << BSON("a.b" << BSON_ARRAY(BSON("$skip" << 4)))); ASSERT_THROWS(DocumentSourceFacet::createFromBson(spec.firstElement(), ctx), UserException); spec = BSON("$facet" << BSON("$a" << BSON_ARRAY(BSON("$skip" << 4)))); ASSERT_THROWS(DocumentSourceFacet::createFromBson(spec.firstElement(), ctx), UserException); }
TEST_F(DocumentSourceFacetTest, ShouldRejectFacetsContainingAFacetStage) { auto ctx = getExpCtx(); auto spec = fromjson("{$facet: {a: [{$facet: {a: [{$skip: 2}]}}]}}"); ASSERT_THROWS(DocumentSourceFacet::createFromBson(spec.firstElement(), ctx), UserException); spec = fromjson("{$facet: {a: [{$skip: 2}, {$facet: {a: [{$skip: 2}]}}]}}"); ASSERT_THROWS(DocumentSourceFacet::createFromBson(spec.firstElement(), ctx), UserException); spec = fromjson("{$facet: {a: [{$skip: 2}], b: [{$facet: {a: [{$skip: 2}]}}]}}"); ASSERT_THROWS(DocumentSourceFacet::createFromBson(spec.firstElement(), ctx), UserException); }
TEST(MatchExpressionParserGeoNear, ParseInvalidNear) { { BSONObj query = fromjson("{loc: {$maxDistance: 100, $near: [0,0]}}"); StatusWithMatchExpression result = MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions()); ASSERT_FALSE(result.isOK()); } { BSONObj query = fromjson("{loc: {$minDistance: 100, $near: [0,0]}}"); StatusWithMatchExpression result = MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions()); ASSERT_FALSE(result.isOK()); } { BSONObj query = fromjson("{loc: {$near: [0,0], $maxDistance: {}}}"); ASSERT_THROWS(MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions()), UserException); } { BSONObj query = fromjson("{loc: {$near: [0,0], $minDistance: {}}}"); ASSERT_THROWS(MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions()), UserException); } { BSONObj query = fromjson("{loc: {$near: [0,0], $eq: 40}}"); ASSERT_THROWS(MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions()), UserException); } { BSONObj query = fromjson("{loc: {$eq: 40, $near: [0,0]}}"); StatusWithMatchExpression result = MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions()); ASSERT_FALSE(result.isOK()); } { BSONObj query = fromjson( "{loc: {$near: [0,0], $geoWithin: {$geometry: {type: \"Polygon\", coordinates: []}}}}"); ASSERT_THROWS(MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions()), UserException); } { BSONObj query = fromjson("{loc: {$near: {$foo: 1}}}"); StatusWithMatchExpression result = MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions()); ASSERT_FALSE(result.isOK()); } { BSONObj query = fromjson("{loc: {$minDistance: 10}}"); StatusWithMatchExpression result = MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions()); ASSERT_FALSE(result.isOK()); } }
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()); } }
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()); } }
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); }
TEST_F(DocumentSourceFacetTest, ShouldRejectFacetsContainingAnOutStage) { auto ctx = getExpCtx(); auto spec = BSON("$facet" << BSON("a" << BSON_ARRAY(BSON("$out" << "out_collection")))); ASSERT_THROWS(DocumentSourceFacet::createFromBson(spec.firstElement(), ctx), UserException); spec = BSON("$facet" << BSON("a" << BSON_ARRAY(BSON("$skip" << 1) << BSON("$out" << "out_collection")))); ASSERT_THROWS(DocumentSourceFacet::createFromBson(spec.firstElement(), ctx), UserException); spec = BSON("$facet" << BSON("a" << BSON_ARRAY(BSON("$out" << "out_collection") << BSON("$skip" << 1)))); ASSERT_THROWS(DocumentSourceFacet::createFromBson(spec.firstElement(), ctx), UserException); }
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")); }
void run() { // Recreate the collection as capped, without an _id index. _client.dropCollection( _ns ); BSONObj info; ASSERT( _client.runCommand( "unittests", BSON( "create" << "indexupdate" << "capped" << true << "size" << ( 10 * 1024 ) << "autoIndexId" << false ), info ) ); // Insert some documents. int32_t nDocs = 1000; for( int32_t i = 0; i < nDocs; ++i ) { _client.insert( _ns, BSON( "_id" << i ) ); } // Initialize curop. cc().curop()->reset(); // Request an interrupt. killCurrentOp.killAll(); BSONObj indexInfo = BSON( "key" << BSON( "_id" << 1 ) << "ns" << _ns << "name" << "_id" ); // The call is interrupted because mayInterrupt == true. ASSERT_THROWS( theDataFileMgr.insertWithObjMod( "unittests.system.indexes", indexInfo, true ), UserException ); // The new index is not listed in system.indexes because the index build failed. ASSERT_EQUALS( 0U, _client.count( "unittests.system.indexes", BSON( "ns" << _ns ) ) ); }
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 ); }
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); }
void Prepend_Full_FullException() { Fixed_LinkedList<char> fll(2); fll.Prepend('C'); fll.Prepend('B'); ASSERT_THROWS(fll.Prepend('A'), LinkedListException); }
void calcReadsThrowsExceptionForInvalidInput() { //Arrange std::istringstream in {"1 + +"}; //Act & Assert ASSERT_THROWS(calc(in), std::exception); }
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() ); } }
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); }
// $near must be the only field in the expression object. TEST(MatchExpressionParserGeoNear, ParseNearExtraField) { BSONObj query = fromjson( "{loc:{$near:{$maxDistance:100, " "$geometry:{type:\"Point\", coordinates:[0,0]}}, foo: 1}}"); ASSERT_THROWS(MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions()), UserException); }
TEST_F(ServiceStateMachineFixture, TestThrowHandling) { _sep->setUassertInHandler(); ASSERT_EQ(ServiceStateMachine::State::Ended, runPingTest()); ASSERT_THROWS(checkPingOk(), MsgAssertionException); ASSERT_TRUE(_tl->ranSource()); ASSERT_FALSE(_tl->ranSink()); }
TEST_F(ServiceStateMachineFixture, TestSourceError) { _tl->setNextFailure(MockTL::Source); ASSERT_EQ(ServiceStateMachine::State::Ended, runPingTest()); ASSERT_THROWS(checkPingOk(), MsgAssertionException); ASSERT_TRUE(_tl->ranSource()); ASSERT_FALSE(_tl->ranSink()); }
TEST_F(KeysManagerShardedTest, GetKeyForValidationTimesOutIfRefresherIsNotRunning) { operationContext()->setDeadlineAfterNowBy(Microseconds(250 * 1000), ErrorCodes::ExceededTimeLimit); ASSERT_THROWS( keyManager()->getKeyForValidation(operationContext(), 1, LogicalTime(Timestamp(100, 0))), DBException); }
virtual void run(){ OperationContextImpl txn; DBDirectClient client(&txn); BSONObj result; BSONObj cmdObj = BSON( "count" << "" ); ASSERT_THROWS( client.runCommand( "", cmdObj, result ), UserException ); }
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)); }
void ParameterError_01() { int x = -1; int y = 0; int height = 1; int width = 1; ASSERT_THROWS(new Rect(x,y,height,width),InputException); }
TEST_F(KeysManagerShardedTest, GetKeyForValidationTimesOutIfRefresherIsNotRunning) { operationContext()->setDeadlineAfterNowBy(Microseconds(250 * 1000)); ASSERT_THROWS(keyManager() ->getKeyForValidation(operationContext(), 1, LogicalTime(Timestamp(100, 0))) .status_with_transitional_ignore(), DBException); }
void database_testSQLErrorManagement() { const char* dbname="/tmp/dbtest.db"; createVersion4db(dbname); CSQL db(dbname); std::string faultyStatement="select * from tmies"; ASSERT_THROWS(db.exe(faultyStatement),dbexception); }
void TriangleTest_Error_05(){ int ax = 1; int ay = 2; int bx = 3; int by = 4; int cx = -5; int cy = 6; ASSERT_THROWS(new Triangle(ax,ay,bx,by,cx,cy,""),InputException); }