您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ EXPECT_THROW函数代码示例

51自学网 2021-06-01 20:36:17
  C++
这篇教程C++ EXPECT_THROW函数代码示例写得很实用,希望能帮到您。

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

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

示例1: TEST

TEST( MethodBuilderTests, theTest ){	co::RefPtr<co::ITypeBuilder> typeBuilder = TestHelper::createBuilder( co::TK_INTERFACE, "MethodBuilderbuilderTest.NewInterface" );	co::IType* stringType = TestHelper::type( "string" );	co::RefPtr<co::ITypeBuilder> exbuilder = TestHelper::createBuilder( co::TK_EXCEPTION, "MethodBuilderbuilderTest.NewException" );	co::IException* testException = co::cast<co::IException>( exbuilder->createType() );	co::RefPtr<co::IMethodBuilder> mb = typeBuilder->defineMethod( "testMethod" );	EXPECT_THROW( mb->defineException( NULL ), co::IllegalArgumentException );	EXPECT_THROW( mb->defineReturnType( NULL ), co::IllegalArgumentException );	EXPECT_THROW( mb->defineParameter( "ok", NULL, true, true ) , co::IllegalArgumentException );	EXPECT_THROW( mb->defineParameter( "ok", stringType, false, false ) , co::IllegalArgumentException );	mb->defineParameter( "p1", stringType, false, true );	mb->defineParameter( "p2", stringType, true, true );	mb->defineParameter( "p3", stringType, true, false );	mb->defineException( testException );	mb->defineReturnType( stringType );	EXPECT_THROW( mb->defineParameter( "p1", stringType, true, false ) , co::IllegalNameException ); // clash	EXPECT_NO_THROW( mb->createMethod() );	co::IInterface* itf = co::cast<co::IInterface>( typeBuilder->createType() );	ASSERT_TRUE( itf != NULL );	co::IMethod* mInfo = co::cast<co::IMethod>( itf->getMember( "testMethod" ) );	ASSERT_TRUE( mInfo != NULL );	ASSERT_EQ( 3, mInfo->getParameters().getSize() );	co::Range<co::IParameter* const> params = mInfo->getParameters();	co::IParameter* p = params.getFirst();	ASSERT_EQ( "p1", p->getName() );	ASSERT_EQ( stringType, p->getType() );	ASSERT_FALSE( p->getIsIn() );	ASSERT_TRUE( p->getIsOut() );	params.popFirst();	p = params.getFirst();	ASSERT_EQ( "p2", p->getName() );	ASSERT_EQ( stringType, p->getType() );	ASSERT_TRUE( p->getIsIn() );	ASSERT_TRUE( p->getIsOut() );	params.popFirst();	p = params.getFirst();	ASSERT_EQ( "p3", p->getName() );	ASSERT_EQ( stringType, p->getType() );	ASSERT_TRUE( p->getIsIn() );	ASSERT_FALSE( p->getIsOut() );	ASSERT_EQ( stringType, mInfo->getReturnType() );	ASSERT_EQ( testException , mInfo->getExceptions().getFirst() );	EXPECT_NO_THROW( co::getSystem()->getTypes()->getTransaction()->commit() );	EXPECT_THROW( mb->createMethod(), co::NotSupportedException );}
开发者ID:coral-framework,项目名称:coral-old,代码行数:65,


示例2: TEST_F

 TEST_F(TaskTest, GetTaskWithInvalidIdThrows) {     auto invalid_id = ews::item_id();     EXPECT_THROW(service().get_task(invalid_id), ews::exchange_error); }
开发者ID:PhilippRo,项目名称:ews-cpp,代码行数:5,


示例3: TEST_F

TEST_F(lagi_util, UtilRenameExNotFound) {	EXPECT_THROW(util::Rename("./data/nonexistent", ""), FileNotFoundError);}
开发者ID:Azpidatziak,项目名称:Aegisub,代码行数:3,


示例4: TEST

TEST(TrackerTest, MadeUpURL){	// Made up tracker	URL madeUp("udp://barneysTracker.com:1234");	EXPECT_THROW(new Tracker(&madeUp), InvalidTracker);}
开发者ID:barnabycolby,项目名称:Magneto,代码行数:6,


示例5: TEST_F

TEST_F(TestVariant, MinLimitUnknown){    EXPECT_THROW(vmf::Variant::minLimit<vmf::vmf_integer>(vmf::Variant::type_unknown), vmf::IncorrectParamException);}
开发者ID:SSE4,项目名称:vmf-1,代码行数:4,


示例6: TEST

TEST(bash_ast, parse_illegal_script){  EXPECT_THROW(bash_ast ast(get_src_dir() + std::string("/scripts/illegal_script.sh")), libbash::parse_exception);}
开发者ID:Aparicio99,项目名称:libbash,代码行数:4,


示例7: TEST_F

TEST_F(PlatformImpTest, negative_msr_write_bad_value){    // The write mask specified in the constructor is 0 from bits 63:60 and 1 from bits 59:0.    EXPECT_THROW(m_platform->msr_write(geopm::GEOPM_DOMAIN_CPU, 0, "MSR_TEST_0", 0xF000000000000000),        geopm::Exception);}
开发者ID:cmcantalupo,项目名称:geopm,代码行数:6,


示例8: TEST_F

TEST_F(connected_test, delete_exchange_notexist) {  EXPECT_THROW(channel->DeleteExchange("exchange_notexist"), ChannelException);}
开发者ID:alanxz,项目名称:SimpleAmqpClient,代码行数:3,


示例9: TEST

TEST(Column, basis) {    // Create a new database    SQLite::Database db(":memory:", SQLite::OPEN_READWRITE|SQLite::OPEN_CREATE);    EXPECT_EQ(SQLite::OK, db.getErrorCode());    EXPECT_EQ(SQLite::OK, db.getExtendedErrorCode());    // Create a new table    EXPECT_EQ(0, db.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, msg TEXT, int INTEGER, double REAL, binary BLOB, empty TEXT)"));    EXPECT_TRUE(db.tableExists("test"));    EXPECT_TRUE(db.tableExists(std::string("test")));    EXPECT_EQ(0, db.getLastInsertRowid());    // Create a first row (autoid: 1) with all kind of data and a null value    SQLite::Statement   insert(db, "INSERT INTO test VALUES (NULL, /"first/", -123, 0.123, ?, NULL)");    // Bind the blob value to the first parameter of the SQL query    const char  buffer[] = {'b', 'l', '/0', 'b'}; // "bl/0b" : 4 char, with a null byte inside    const int   size = sizeof(buffer); // size = 4    const void* blob = &buffer;    insert.bind(1, blob, size);    // Execute the one-step query to insert the row    EXPECT_EQ(1, insert.exec());    EXPECT_EQ(1, db.getLastInsertRowid());    EXPECT_EQ(1, db.getTotalChanges());    EXPECT_THROW(insert.exec(), SQLite::Exception); // exec() shall throw as it needs to be reseted    // Compile a SQL query    SQLite::Statement   query(db, "SELECT * FROM test");    EXPECT_STREQ("SELECT * FROM test", query.getQuery().c_str());    EXPECT_EQ(6, query.getColumnCount ());    query.executeStep();    EXPECT_TRUE (query.hasRow());    EXPECT_FALSE(query.isDone());    // validates every variant of cast operators, and conversions of types    {        const sqlite3_int64 id1     = query.getColumn(0); // operator int64_t()        const int64_t       id2     = query.getColumn(0); // operator int64_t()        const long long     id3     = query.getColumn(0); // operator int64_t()        const long          id4     = query.getColumn(0); // operator int64_t() or long() depending on compiler/architecture        const unsigned int  uint1   = query.getColumn(0); // operator uint32_t()        const uint32_t      uint2   = query.getColumn(0); // operator uint32_t()        const char*         ptxt    = query.getColumn(1); // operator const char*()        const std::string   msg     = query.getColumn(1); // operator std::string() (or const char* with MSVC)        const int           integer = query.getColumn(2); // operator int()        const double        real    = query.getColumn(3); // operator double()        const void*         pblob   = query.getColumn(4); // operator void*()        const std::string   sblob   = query.getColumn(4); // operator std::string() (or const char* with MSVC)        const void*         pempty  = query.getColumn(5); // operator void*()        EXPECT_EQ(1,            id1);        EXPECT_EQ(1,            id2);        EXPECT_EQ(1,            id3);        EXPECT_EQ(1,            id4);        EXPECT_EQ(1U,           uint1);        EXPECT_EQ(1U,           uint2);        EXPECT_STREQ("first",   ptxt);        EXPECT_EQ("first",      msg);        EXPECT_EQ(-123,         integer);        EXPECT_EQ(0.123,        real);        EXPECT_EQ(0,            memcmp("bl/0b", pblob, size));        EXPECT_EQ((size_t)size, sblob.size());        EXPECT_EQ(0,            memcmp("bl/0b", &sblob[0], size));        EXPECT_EQ(NULL,         pempty);    }    // validates every variant of explicit getters    {        int64_t             id      = query.getColumn(0).getInt64();        const unsigned int  uint1   = query.getColumn(0).getUInt();        const uint32_t      uint2   = query.getColumn(0).getUInt();        const char*         ptxt    = query.getColumn(1).getText();        const std::string   msg1    = query.getColumn(1).getText();        const std::string   msg2    = query.getColumn(1).getString();        const int           integer = query.getColumn(2).getInt();        const double        real    = query.getColumn(3).getDouble();        const void*         pblob   = query.getColumn(4).getBlob();        const std::string   sblob   = query.getColumn(4).getString();        EXPECT_EQ(1,            id);        EXPECT_EQ(1U,           uint1);        EXPECT_EQ(1U,           uint2);        EXPECT_STREQ("first",   ptxt);        EXPECT_EQ("first",      msg1);        EXPECT_EQ("first",      msg2);        EXPECT_EQ(-123,         integer);        EXPECT_EQ(0.123,        real);        EXPECT_EQ(0,            memcmp("bl/0b", pblob, 4));        EXPECT_EQ(0,            memcmp("bl/0b", &sblob[0], 4));    }    // Validate getBytes(), getType(), isInteger(), isNull()...    EXPECT_EQ(SQLite::INTEGER,  query.getColumn(0).getType());    EXPECT_EQ(true,             query.getColumn(0).isInteger());    EXPECT_EQ(false,            query.getColumn(0).isFloat());    EXPECT_EQ(false,            query.getColumn(0).isText());    EXPECT_EQ(false,            query.getColumn(0).isBlob());    EXPECT_EQ(false,            query.getColumn(0).isNull());    EXPECT_STREQ("1",           query.getColumn(0).getText());  // convert to string    EXPECT_EQ(1,                query.getColumn(0).getBytes()); // size of the string "1" without the null terminator    EXPECT_EQ(SQLite::TEXT,     query.getColumn(1).getType());    EXPECT_EQ(false,            query.getColumn(1).isInteger());//.........这里部分代码省略.........
开发者ID:wio-pm,项目名称:wio-sqlitecpp,代码行数:101,


示例10: TEST

TEST(CacheTest, MissingValue) {    cache::lru_cache<int, int> cache_lru(1);    EXPECT_THROW(cache_lru.get(7), std::range_error);}
开发者ID:davidalbertonogueira,项目名称:cpp-lru-cache,代码行数:4,


示例11: TEST_F

TEST_F(IfTest, Value){	EXPECT_THROW(testRule->value(*startState), runtime_error);}
开发者ID:Svalburg,项目名称:TypeSystemImplementation,代码行数:4,


示例12: TEST

TEST(CoreTests, VolumeOutOfBounds) {    Volume<char> * image = new Volume<char>(10,10, 10);    // Getters    EXPECT_THROW(image->get(-1), OutOfBoundsException);    EXPECT_THROW(image->get(10*10*10), OutOfBoundsException);    EXPECT_THROW(image->get(-4, 4, 2), OutOfBoundsException);    EXPECT_THROW(image->get(-1,-10, 0), OutOfBoundsException);    EXPECT_THROW(image->get(10, 0, 0), OutOfBoundsException);    EXPECT_THROW(image->get(2, 1, -1), OutOfBoundsException);    EXPECT_THROW(image->get(int3(-1, 4, 0)), OutOfBoundsException);    EXPECT_THROW(image->get(int3(0, 200, 2)), OutOfBoundsException);    EXPECT_THROW(image->get(Region(11, 11, 1)), OutOfBoundsException);    // Setters    EXPECT_THROW(image->set(-1,1), OutOfBoundsException);    EXPECT_THROW(image->set(10*10*10,1), OutOfBoundsException);    EXPECT_THROW(image->set(-4, 4, 2,1), OutOfBoundsException);    EXPECT_THROW(image->set(-1,-10, 0,1), OutOfBoundsException);    EXPECT_THROW(image->set(10, 0, 0,1), OutOfBoundsException);    EXPECT_THROW(image->set(2, 1, -1,1), OutOfBoundsException);    EXPECT_THROW(image->set(int3(-1, 4, 0),1), OutOfBoundsException);    EXPECT_THROW(image->set(int3(0, 200, 2),1), OutOfBoundsException);    EXPECT_THROW(image->set(Region(11, 11, 1),1), OutOfBoundsException);}
开发者ID:smistad,项目名称:SIPL,代码行数:25,


示例13: TEST

TEST(ElIDStream, Read){    std::stringstream buffer;    tawara::ids::ReadResult r;    // 1xxxxxxx    buffer.put(0x80);    r = tawara::ids::read(buffer);    EXPECT_EQ(r.first, 0x80);    EXPECT_EQ(r.second, 1);    buffer.put(0x81);    r = tawara::ids::read(buffer);    EXPECT_EQ(r.first, 0x81);    EXPECT_EQ(r.second, 1);    buffer.put(0x97);    r = tawara::ids::read(buffer);    EXPECT_EQ(r.first, 0x97);    EXPECT_EQ(r.second, 1);    buffer.put(0xC0);    r = tawara::ids::read(buffer);    EXPECT_EQ(r.first, 0xC0);    EXPECT_EQ(r.second, 1);    buffer.put(0xFE);    r = tawara::ids::read(buffer);    EXPECT_EQ(r.first, 0xFE);    EXPECT_EQ(r.second, 1);    buffer.put(0xFF);    EXPECT_THROW(tawara::ids::read(buffer), tawara::InvalidEBMLID);    // 01xxxxxx xxxxxxxx    buffer.put(0x40); buffer.put(0x00);;    r = tawara::ids::read(buffer);    EXPECT_EQ(r.first, 0x4000);    EXPECT_EQ(r.second, 2);    buffer.put(0x40); buffer.put(0x01);;    r = tawara::ids::read(buffer);    EXPECT_EQ(r.first, 0x4001);    EXPECT_EQ(r.second, 2);    buffer.put(0x4B); buffer.put(0x35);;    r = tawara::ids::read(buffer);    EXPECT_EQ(r.first, 0x4B35);    EXPECT_EQ(r.second, 2);    buffer.put(0x7F); buffer.put(0xFE);;    r = tawara::ids::read(buffer);    EXPECT_EQ(r.first, 0x7FFE);    EXPECT_EQ(r.second, 2);    buffer.put(0x7F); buffer.put(0xFF);;    EXPECT_THROW(tawara::ids::read(buffer), tawara::InvalidEBMLID);    /* Uncomment this if EBML IDs expand to 64 bits.    // 00000001 xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx    buffer.put(0x01);    for (int ii(0); ii < 7; ii++)    {        buffer.put(0x00);    }    r = tawara::ids::read(buffer);    EXPECT_EQ(r.first, 0x0100000000000000);    EXPECT_EQ(r.second, 8);    buffer.put(0x01);    for (int ii(0); ii < 6; ii++)    {        buffer.put(0x00);    }    buffer.put(0x01);    r = tawara::ids::read(buffer);    EXPECT_EQ(r.first, 0x0100000000000001);    EXPECT_EQ(r.second, 8);    buffer.put(0x01);    for (int ii(0); ii < 6; ii++)    {        buffer.put(0xFF);    }    buffer.put(0xFE);    r = tawara::ids::read(buffer);    EXPECT_EQ(r.first, 0x01FFFFFFFFFFFFFE);    EXPECT_EQ(r.second, 8);    buffer.put(0x01);    for (int ii(0); ii < 7; ii++)    {        buffer.put(0xFF);    }    EXPECT_THROW(tawara::ids::read(buffer), tawara::InvalidEBMLID);    */    // EBML tag    buffer.put(0x1A); buffer.put(0x45); buffer.put(0xDF); buffer.put(0xA3);    r = tawara::ids::read(buffer);    EXPECT_EQ(r.first, 0x1A45DFA3);    EXPECT_EQ(r.second, 4);}
开发者ID:gbiggs,项目名称:tawara,代码行数:87,


示例14: TEST

TEST(dynamic_num_filter, unknown_function) {  std::map<std::string, std::string> params;  EXPECT_THROW(      dynamic_num_filter f(LIBNUM_FILTER_SAMPLE, "unknown_function", params),      converter_exception);}
开发者ID:jubatus,项目名称:jubatus_core,代码行数:6,


示例15: TEST_F

TEST_F(PeriodicActionPoolTest, no_threads){    EXPECT_THROW(PeriodicActionPool::create("TestPool",                                            0),                 std::exception);}
开发者ID:bigclouds,项目名称:volumedriver,代码行数:6,


示例16: TEST_F

TEST_F(CudaAdapterTest, HandleCudaStatus) {  handleCudaStatus(cudaSuccess, "test");  EXPECT_THROW(handleCudaStatus(cudaErrorMissingConfiguration, "test"), CudaException);  EXPECT_THROW(handleCudaStatus(cudaErrorNoDevice, "test"), CudaException);  EXPECT_THROW(handleCudaStatus(cudaErrorIncompatibleDriverContext, "test"), CudaException);}
开发者ID:Berjiz,项目名称:CuEira,代码行数:6,


示例17: TEST_F

TEST_F(SSLContextTest, TestLoadCertKey) {  std::string certData, keyData, anotherKeyData;  const char* certPath = "folly/io/async/test/certs/tests-cert.pem";  const char* keyPath = "folly/io/async/test/certs/tests-key.pem";  const char* anotherKeyPath = "folly/io/async/test/certs/client_key.pem";  folly::readFile(certPath, certData);  folly::readFile(keyPath, keyData);  folly::readFile(anotherKeyPath, anotherKeyData);  {    SCOPED_TRACE("Valid cert/key pair from buffer");    SSLContext tmpCtx;    tmpCtx.loadCertificateFromBufferPEM(certData);    tmpCtx.loadPrivateKeyFromBufferPEM(keyData);    EXPECT_TRUE(tmpCtx.isCertKeyPairValid());  }  {    SCOPED_TRACE("Valid cert/key pair from files");    SSLContext tmpCtx;    tmpCtx.loadCertificate(certPath);    tmpCtx.loadPrivateKey(keyPath);    EXPECT_TRUE(tmpCtx.isCertKeyPairValid());  }  {    SCOPED_TRACE("Invalid cert/key pair from file. Load cert first");    SSLContext tmpCtx;    tmpCtx.loadCertificate(certPath);    EXPECT_THROW(tmpCtx.loadPrivateKey(anotherKeyPath), std::runtime_error);  }  {    SCOPED_TRACE("Invalid cert/key pair from file. Load key first");    SSLContext tmpCtx;    tmpCtx.loadPrivateKey(anotherKeyPath);    tmpCtx.loadCertificate(certPath);    EXPECT_FALSE(tmpCtx.isCertKeyPairValid());  }  {    SCOPED_TRACE("Invalid key/cert pair from buf. Load cert first");    SSLContext tmpCtx;    tmpCtx.loadCertificateFromBufferPEM(certData);    EXPECT_THROW(        tmpCtx.loadPrivateKeyFromBufferPEM(anotherKeyData), std::runtime_error);  }  {    SCOPED_TRACE("Invalid key/cert pair from buf. Load key first");    SSLContext tmpCtx;    tmpCtx.loadPrivateKeyFromBufferPEM(anotherKeyData);    tmpCtx.loadCertificateFromBufferPEM(certData);    EXPECT_FALSE(tmpCtx.isCertKeyPairValid());  }  {    SCOPED_TRACE(        "loadCertKeyPairFromBufferPEM() must throw when cert/key mismatch");    SSLContext tmpCtx;    EXPECT_THROW(        tmpCtx.loadCertKeyPairFromBufferPEM(certData, anotherKeyData),        std::runtime_error);  }  {    SCOPED_TRACE(        "loadCertKeyPairFromBufferPEM() must succeed when cert/key match");    SSLContext tmpCtx;    tmpCtx.loadCertKeyPairFromBufferPEM(certData, keyData);  }  {    SCOPED_TRACE(        "loadCertKeyPairFromFiles() must throw when cert/key mismatch");    SSLContext tmpCtx;    EXPECT_THROW(        tmpCtx.loadCertKeyPairFromFiles(certPath, anotherKeyPath),        std::runtime_error);  }  {    SCOPED_TRACE("loadCertKeyPairFromFiles() must succeed when cert/key match");    SSLContext tmpCtx;    tmpCtx.loadCertKeyPairFromFiles(certPath, keyPath);  }}
开发者ID:johnyxc,项目名称:folly,代码行数:87,


示例18: TEST

TEST(lagi_format, bad_cast) {    EXPECT_THROW(agi::format("%d", "hello"), std::bad_cast);    EXPECT_THROW(agi::format("%.*s", "hello", "str"), std::bad_cast);}
开发者ID:chenjide,项目名称:Aegisub,代码行数:4,


示例19: TEST

TEST(BuildersFactory, Unknown) {    EXPECT_THROW(cpp_redis::builders::create_builder('a'), cpp_redis::redis_error);}
开发者ID:AlgoSkyNet,项目名称:cpp_redis,代码行数:3,


示例20: TEST_F

TEST_F(OperatorsTableScanStringTest, ScanLikeNonStringColumn) {  auto scan = create_table_scan(_gt, ColumnID{0}, PredicateCondition::Like, "%test");  EXPECT_THROW(scan->execute(), std::exception);}
开发者ID:hyrise,项目名称:hyrise,代码行数:4,



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


C++ EXPECT_TRUE函数代码示例
C++ EXPECT_STREQ函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。