Ignore:
Timestamp:
Feb 16, 2007 9:44:36 PM (17 years ago)
Author:
bennylp
Message:

Fixed ticket #105: unnecessary assert in fixed buffer based pool (pool_buf) on no memory condition

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib/src/pjlib-test/pool.c

    r65 r953  
    1818 */ 
    1919#include <pj/pool.h> 
     20#include <pj/pool_buf.h> 
    2021#include <pj/rand.h> 
    2122#include <pj/log.h> 
     23#include <pj/except.h> 
    2224#include "test.h" 
    2325 
     
    140142} 
    141143 
     144/* Test the buffer based pool */ 
     145static int pool_buf_test(void) 
     146{ 
     147    enum { STATIC_BUF_SIZE = 40 }; 
     148    /* 16 is the internal struct in pool_buf */ 
     149    static char buf[ STATIC_BUF_SIZE + sizeof(pj_pool_t) +  
     150                     sizeof(pj_pool_block) + 16]; 
     151    pj_pool_t *pool; 
     152    void *p; 
     153    PJ_USE_EXCEPTION; 
     154 
     155    PJ_LOG(3,("test", "...pool_buf test")); 
     156 
     157    pool = pj_pool_create_on_buf("no name", buf, sizeof(buf)); 
     158    if (!pool) 
     159        return -70; 
     160 
     161    /* Drain the pool */ 
     162    PJ_TRY { 
     163        if ((p=pj_pool_alloc(pool, STATIC_BUF_SIZE/2)) == NULL) 
     164            return -75; 
     165 
     166        if ((p=pj_pool_alloc(pool, STATIC_BUF_SIZE/2)) == NULL) 
     167            return -76; 
     168    } 
     169    PJ_CATCH_ANY { 
     170        return -77; 
     171    } 
     172    PJ_END; 
     173 
     174    /* On the next alloc, exception should be thrown */ 
     175    PJ_TRY { 
     176        p = pj_pool_alloc(pool, STATIC_BUF_SIZE); 
     177        if (p != NULL) { 
     178            /* This is unexpected, the alloc should fail */ 
     179            return -78; 
     180        } 
     181    } 
     182    PJ_CATCH_ANY { 
     183        /* This is the expected result */ 
     184    } 
     185    PJ_END; 
     186 
     187    /* Done */ 
     188    return 0; 
     189} 
     190 
     191 
    142192int pool_test(void) 
    143193{ 
     
    161211    } 
    162212 
     213    rc = pool_buf_test(); 
     214    if (rc != 0) 
     215        return rc; 
     216 
     217 
    163218    return 0; 
    164219} 
Note: See TracChangeset for help on using the changeset viewer.