LibGoblin_BinInfo_GetBinInfo(
int i_bid )
{
- if(( gi_now_binary_info <= i_bid ) && ( 0 > i_bid ))
+ if(( gi_max_binary_info <= i_bid ) || ( 0 > i_bid ))
{ return NULL; }
return BINFO(i_bid);
p_binfo_now = NULL;
i_id_now = -1;
- if( gi_now_binary_info == gi_max_binary_info ) {
+ if( gi_now_binary_info < gi_max_binary_info ) {
for( i_cnt = 0; i_cnt < gi_max_binary_info; i_cnt++ ) {
if( -1 == BINFO(i_cnt)->i_id ) {
p_binfo_now = BINFO(i_cnt);
i_id_now = i_cnt;
+ gi_now_binary_info++;
break;
}
}
+ }
+ else if( gi_now_binary_info == gi_alloc_binary_info ) {
- if( NULL == p_binfo_now ) {
- p_binfo_base = realloc( gp_binary_info,
+ p_binfo_base = realloc( gp_binary_info,
sizeof( LibGoblin_BinaryInfo ) *
- (gi_max_binary_info + LIBGOBLIN_BINFO_UNITS) );
- if( NULL == p_binfo_base ) {
- return NULL;
- }
+ (gi_alloc_binary_info + LIBGOBLIN_BINFO_UNITS) );
+ if( NULL == p_binfo_base ) {
+ return NULL;
+ }
- for( i_cnt = gi_max_binary_info;
- i_cnt < (gi_max_binary_info + LIBGOBLIN_BINFO_UNITS); i_cnt++ ) {
- LibGoblin_BinInfo_ClearBinInfo( p_binfo_base + i_cnt );
- }
+ for( i_cnt = gi_alloc_binary_info;
+ i_cnt < (gi_alloc_binary_info + LIBGOBLIN_BINFO_UNITS); i_cnt++ ) {
+ LibGoblin_BinInfo_ClearBinInfo( p_binfo_base + i_cnt );
+ }
- gp_binary_info = p_binfo_base;
- gi_max_binary_info += LIBGOBLIN_BINFO_UNITS;
+ gp_binary_info = p_binfo_base;
+ gi_alloc_binary_info += LIBGOBLIN_BINFO_UNITS;
- p_binfo_now = BINFO(gi_now_binary_info);
- i_id_now = gi_now_binary_info++;
- }
+ p_binfo_now = BINFO(gi_now_binary_info);
+ i_id_now = gi_now_binary_info++;
+
+ if( i_id_now == gi_max_binary_info ) { gi_max_binary_info++; }
}
else {
p_binfo_now = BINFO(gi_now_binary_info);
i_id_now = gi_now_binary_info++;
+
+ if( i_id_now == gi_max_binary_info ) { gi_max_binary_info++; }
}
+ assert( NULL != p_binfo_now );
+
LibGoblin_BinInfo_ClearBinInfo( p_binfo_now );
p_binfo_now->i_id = i_id_now;
p_binfo_now->b_phase = LIBGOBLIN_BINFO_PHASE_ALLOCED;
LibGoblin_BinInfo_FreeBinInfo(
LibGoblin_BinaryInfo *p_binfo )
{
+ int i_binfoid;
if( NULL == p_binfo ) { return 0x01; }
p_binfo->p_format = NULL;
}
+ i_binfoid = p_binfo->i_id;
LibGoblin_BinInfo_ClearBinInfo( p_binfo );
+
+ if( gi_max_binary_info == (i_binfoid + 1) ) { gi_max_binary_info--; }
+ gi_now_binary_info--;
+ if( 0 == gi_now_binary_info ) { gi_max_binary_info = 0; }
return 0x00;
}
LibGoblin_BinInfo_ClearBinInfo( p_binfo );
}
- gi_max_binary_info = LIBGOBLIN_BINFO_UNITS;
- gi_now_binary_info = 0;
+ gi_alloc_binary_info = LIBGOBLIN_BINFO_UNITS;
+ gi_max_binary_info = 0;
+ gi_now_binary_info = 0;
return 0x00;
}
free( gp_binary_info );
gp_binary_info = NULL;
- gi_max_binary_info = 0;
- gi_now_binary_info = 0;
+ gi_alloc_binary_info = 0;
+ gi_max_binary_info = 0;
+ gi_now_binary_info = 0;
return 0x00;
}
CU_ASSERT( 0x00 == i_result );
i_bid = LibGoblin_AllocBinInfo();
- CU_ASSERT( 0x00 <= i_result );
+ CU_ASSERT( 0x00 == i_bid );
i_result = LibGoblin_FreeBinInfo( i_bid );
CU_ASSERT( 0x00 == i_result );
}
+/*--------------------------------------------------------------------*/
+void Test_LibGoblin_BinInfo_AllocFree_test00_002( void )
+{
+ int i_cnt;
+ int i_bid;
+ int i_result;
+
+ i_result = LibGoblin_BinInfo_Init();
+ CU_ASSERT( 0x00 == i_result );
+
+ for( i_cnt = 0; i_cnt < 33; i_cnt++ ) {
+ i_bid = LibGoblin_AllocBinInfo();
+ CU_ASSERT( i_cnt == i_bid );
+ }
+
+ for( i_cnt = 0; i_cnt < 8; i_cnt++ ) {
+ i_result = LibGoblin_FreeBinInfo( i_cnt );
+ CU_ASSERT( 0x00 == i_result );
+ }
+
+ for( i_cnt = 0; i_cnt < 8; i_cnt++ ) {
+ i_bid = LibGoblin_AllocBinInfo();
+ CU_ASSERT( i_cnt == i_bid );
+ }
+
+ for( i_cnt = 0; i_cnt < 33; i_cnt++ ) {
+ i_result = LibGoblin_FreeBinInfo( i_cnt );
+ CU_ASSERT( 0x00 == i_result );
+ }
+
+ i_result = LibGoblin_FreeBinInfo( i_cnt );
+ CU_ASSERT( 0x00 != i_result );
+
+ i_result = LibGoblin_FreeBinInfo( 0 );
+ CU_ASSERT( 0x00 != i_result );
+
+ i_result = LibGoblin_BinInfo_Term();
+ CU_ASSERT( 0x00 == i_result );
+
+ return;
+}
+
+
/* LibGoblin_BinInfo_Init() & Term() **********************************/
/*--------------------------------------------------------------------*/
void Test_LibGoblin_BinInfo_InitTerm_test00_001( void )
Test_LibGoblin_BinInfo_InitTerm_test00_001 );
CU_add_test( pt_goblin, "LibGoblin_BinInfo_AllocFree_test00_001",
Test_LibGoblin_BinInfo_AllocFree_test00_001 );
+ CU_add_test( pt_goblin, "LibGoblin_BinInfo_AllocFree_test00_002",
+ Test_LibGoblin_BinInfo_AllocFree_test00_002 );
return 0x00;