本文整理汇总了C++中EXPECT_THROW函数的典型用法代码示例。如果您正苦于以下问题:C++ EXPECT_THROW函数的具体用法?C++ EXPECT_THROW怎么用?C++ EXPECT_THROW使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了EXPECT_THROW函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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 );
}
示例2: TEST_F
TEST_F(TaskTest, GetTaskWithInvalidIdThrows)
{
auto invalid_id = ews::item_id();
EXPECT_THROW(service().get_task(invalid_id), ews::exchange_error);
}
示例3: TEST_F
TEST_F(lagi_util, UtilRenameExNotFound) {
EXPECT_THROW(util::Rename("./data/nonexistent", ""), FileNotFoundError);
}
示例4: TEST
TEST(TrackerTest, MadeUpURL)
{
// Made up tracker
URL madeUp("udp://barneysTracker.com:1234");
EXPECT_THROW(new Tracker(&madeUp), InvalidTracker);
}
示例5: TEST_F
TEST_F(TestVariant, MinLimitUnknown)
{
EXPECT_THROW(vmf::Variant::minLimit<vmf::vmf_integer>(vmf::Variant::type_unknown), vmf::IncorrectParamException);
}
示例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);
}
示例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);
}
示例8: TEST_F
TEST_F(connected_test, delete_exchange_notexist) {
EXPECT_THROW(channel->DeleteExchange("exchange_notexist"), ChannelException);
}
示例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());
//.........这里部分代码省略.........
示例10: TEST
TEST(CacheTest, MissingValue) {
cache::lru_cache<int, int> cache_lru(1);
EXPECT_THROW(cache_lru.get(7), std::range_error);
}
示例11: TEST_F
TEST_F(IfTest, Value)
{
EXPECT_THROW(testRule->value(*startState), runtime_error);
}
示例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);
}
示例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);
}
示例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);
}
示例15: TEST_F
TEST_F(PeriodicActionPoolTest, no_threads)
{
EXPECT_THROW(PeriodicActionPool::create("TestPool",
0),
std::exception);
}