From ab9c3ac5334c2e0666a43da968fa175aaea7f281 Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Fri, 16 Feb 2007 21:44:36 +0000 Subject: Fixed ticket #105: unnecessary assert in fixed buffer based pool (pool_buf) on no memory condition git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@953 74dad513-b988-da41-8d7b-12977e46ad98 --- pjlib/src/pjlib-test/pool.c | 55 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'pjlib/src/pjlib-test/pool.c') diff --git a/pjlib/src/pjlib-test/pool.c b/pjlib/src/pjlib-test/pool.c index d48a3589..978faea4 100644 --- a/pjlib/src/pjlib-test/pool.c +++ b/pjlib/src/pjlib-test/pool.c @@ -17,8 +17,10 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include +#include #include #include +#include #include "test.h" /** @@ -139,6 +141,54 @@ on_error: return status; } +/* Test the buffer based pool */ +static int pool_buf_test(void) +{ + enum { STATIC_BUF_SIZE = 40 }; + /* 16 is the internal struct in pool_buf */ + static char buf[ STATIC_BUF_SIZE + sizeof(pj_pool_t) + + sizeof(pj_pool_block) + 16]; + pj_pool_t *pool; + void *p; + PJ_USE_EXCEPTION; + + PJ_LOG(3,("test", "...pool_buf test")); + + pool = pj_pool_create_on_buf("no name", buf, sizeof(buf)); + if (!pool) + return -70; + + /* Drain the pool */ + PJ_TRY { + if ((p=pj_pool_alloc(pool, STATIC_BUF_SIZE/2)) == NULL) + return -75; + + if ((p=pj_pool_alloc(pool, STATIC_BUF_SIZE/2)) == NULL) + return -76; + } + PJ_CATCH_ANY { + return -77; + } + PJ_END; + + /* On the next alloc, exception should be thrown */ + PJ_TRY { + p = pj_pool_alloc(pool, STATIC_BUF_SIZE); + if (p != NULL) { + /* This is unexpected, the alloc should fail */ + return -78; + } + } + PJ_CATCH_ANY { + /* This is the expected result */ + } + PJ_END; + + /* Done */ + return 0; +} + + int pool_test(void) { enum { LOOP = 2 }; @@ -160,6 +210,11 @@ int pool_test(void) if (rc != -40) return rc; } + rc = pool_buf_test(); + if (rc != 0) + return rc; + + return 0; } -- cgit v1.2.3