diff options
author | Benny Prijono <bennylp@teluu.com> | 2007-02-16 21:44:36 +0000 |
---|---|---|
committer | Benny Prijono <bennylp@teluu.com> | 2007-02-16 21:44:36 +0000 |
commit | ab9c3ac5334c2e0666a43da968fa175aaea7f281 (patch) | |
tree | 34af7d19c89b67332d728576f552f5be0ea1c90c /pjlib/src/pjlib-test | |
parent | b6e52a72449807da582fd96f098b5a729d6f97d3 (diff) |
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
Diffstat (limited to 'pjlib/src/pjlib-test')
-rw-r--r-- | pjlib/src/pjlib-test/pool.c | 55 |
1 files changed, 55 insertions, 0 deletions
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 <pj/pool.h> +#include <pj/pool_buf.h> #include <pj/rand.h> #include <pj/log.h> +#include <pj/except.h> #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; } |