File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -153,6 +153,23 @@ std::set<char *> TrackAlloc<UserAllocator>::allocated_blocks;
153153
154154typedef TrackAlloc<boost::default_user_allocator_new_delete> track_alloc;
155155
156+ // This is a simple UserAllocator to allow coverage-testing of the codepath
157+ // where memory allocation fails.
158+ struct always_fails_allocation_alloc
159+ {
160+ typedef std::size_t size_type;
161+ typedef std::ptrdiff_t difference_type;
162+
163+ static char * malloc (const size_type /* bytes*/ )
164+ {
165+ return 0 ;
166+ }
167+
168+ static void free (char * const /* block*/ )
169+ {
170+ }
171+ };
172+
156173void test ()
157174{
158175 {
@@ -229,6 +246,16 @@ void test()
229246 }
230247 }
231248#endif
249+
250+ {
251+ // Test the case where memory allocation intentionally fails
252+ boost::object_pool<tester, always_fails_allocation_alloc> pool;
253+ BOOST_TEST ( pool.construct () == 0 );
254+ BOOST_TEST ( pool.construct (1 ,2 ) == 0 );
255+ #if defined(BOOST_HAS_VARIADIC_TMPL) && defined(BOOST_HAS_RVALUE_REFS)
256+ BOOST_TEST ( pool.construct (1 ,2 ,3 ,4 ) == 0 );
257+ #endif
258+ }
232259}
233260
234261void test_alloc ()
You can’t perform that action at this time.
0 commit comments