test.c
来自「环形缓冲库」· C语言 代码 · 共 88 行
C
88 行
#include "bitRingLib.h"
#include "stdLib.h"
#include "stdio.h"
static BIT_RNG_ID gTestBitRingId = NULL;
testInit( void )
{
if( gTestBitRingId == NULL )
{
gTestBitRingId = bitRingCreate( 1024 );
if( gTestBitRingId == NULL )
{
printf( "[ testInit ]:Create gTestBitRingId fail!" );
testDInit( );
return ( 0 );
}
}
return( 1 );
}
testDInit( void )
{
if( gTestBitRingId != NULL )
{
if( ( bitRingDelete( gTestBitRingId ) ) == ERROR )
{
printf( "[ testDInit ]: delete gTestBitRingId fails.\n" );
}
gTestBitRingId = NULL;
}
return( 1 );
}
put( int iPutNum )
{
int b;
unsigned char pucPutDataBuff[ 256 ];
int i;
for( i = 0; i < 128; i++ )
{
pucPutDataBuff[ i ] = i;
}
b= bitRingPut( gTestBitRingId, pucPutDataBuff, 256, iPutNum );
printf("put bit is %d\n",b );
printf( "The bitRing buff data :\n" );
for( i=0; i<128; i++ )
{
printf( "0x%2x ",gTestBitRingId->pcBuffStart[ i ] );
if( (i + 1) %10 == 0 )
printf( "\n" );
}
return( 1 );
}
get( int iGetNum )
{
unsigned char putGetDataBuff[ 256 ]={};
int i,c;
c= bitRingGet( gTestBitRingId, putGetDataBuff, 256, iGetNum );
printf("get bit is %d\n",c );
printf( "The get data is :\n" );
for( i=0; i<128; i++ )
{
printf( "0x%2x ",putGetDataBuff[ i ] );
if( (i + 1) %10 == 0 )
printf( "\n" );
}
return( 1 );
}
clear( void)
{
memset( gTestBitRingId->pcBuffStart, 0, 1024/8 );
bitRingFlush( gTestBitRingId );
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?