Added type size test and error to ipool::allocate

This commit is contained in:
John Wellbelove 2017-08-25 14:27:20 +01:00
parent ce7db33844
commit 259dbfa741
2 changed files with 29 additions and 1 deletions

View File

@ -90,7 +90,20 @@ namespace etl
public:
pool_object_not_in_pool(string_type file_name, numeric_type line_number)
: pool_exception(ETL_ERROR_TEXT("pool:notinpool", ETL_FILE"B"), file_name, line_number)
: pool_exception(ETL_ERROR_TEXT("pool:not in pool", ETL_FILE"B"), file_name, line_number)
{}
};
//***************************************************************************
/// The exception thrown when an the type requested is larger than the element size.
///\ingroup pool
//***************************************************************************
class pool_element_size : public pool_exception
{
public:
pool_element_size(string_type file_name, numeric_type line_number)
: pool_exception(ETL_ERROR_TEXT("pool:element size", ETL_FILE"C"), file_name, line_number)
{}
};
@ -112,6 +125,11 @@ namespace etl
template <typename T>
T* allocate()
{
if (sizeof(T) > ITEM_SIZE)
{
ETL_ASSERT(false, ETL_ERROR(etl::pool_element_size));
}
return reinterpret_cast<T*>(allocate_item());
}

View File

@ -264,6 +264,16 @@ namespace
CHECK_EQUAL(4U, pool.available());
}
//*************************************************************************
TEST(test_type_error)
{
etl::pool<uint32_t, 4> pool;
etl::ipool& ip = pool;
CHECK_THROW(ip.allocate<double>(), etl::pool_element_size);
}
};
}