添加ringbuffer的测试
parent
97bdec1f62
commit
ae51fee51d
|
@ -112,7 +112,7 @@ int RingBuffer<T>::Add(T *data,uint64_t len){
|
|||
return -1;
|
||||
}
|
||||
if(m_len == m_size)
|
||||
return 0;
|
||||
return 0;
|
||||
T *tail = nullptr;
|
||||
if((m_head + m_len) > m_data_end){
|
||||
tail = m_head + m_len - m_size;
|
||||
|
@ -140,7 +140,6 @@ int RingBuffer<T>::Add(T *data,uint64_t len){
|
|||
return i;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
|
||||
*/
|
||||
|
@ -159,6 +158,7 @@ int RingBuffer<T>::TakeBack(T *data,uint64_t len){
|
|||
}
|
||||
|
||||
int i = 0;
|
||||
|
||||
for(i = 0;i < len;i++) {
|
||||
data[len - 1 - i] = (*tail) ;
|
||||
if((tail == m_head)) {
|
||||
|
@ -167,8 +167,7 @@ int RingBuffer<T>::TakeBack(T *data,uint64_t len){
|
|||
}
|
||||
if(tail > m_data) {
|
||||
tail--;
|
||||
}
|
||||
if(tail == m_data) {
|
||||
}else if(tail == m_data) {
|
||||
tail = m_data_end;
|
||||
}
|
||||
// next is head stop
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include "loger.h"
|
||||
#include "debug.h"
|
||||
#include "pattern/ringbuffer.hpp"
|
||||
#include <math.h>
|
||||
|
||||
#pragma pack(4)
|
||||
typedef struct test1{
|
||||
|
@ -46,7 +48,52 @@ BYTE_ORDER HostByteOrder(){
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
RingBuffer<int> pTest(200);
|
||||
int tmp[200];
|
||||
int tmp2[200];
|
||||
|
||||
int main(){
|
||||
int randlen;
|
||||
for (int w = 0; w < 200; w++) {
|
||||
tmp2[w] = w;
|
||||
}
|
||||
|
||||
for(int i = 0;i < 100;i++){
|
||||
std::cout << "\r\n";
|
||||
std::cout << "round " << i << std::endl;
|
||||
randlen = rand() % 100;
|
||||
std::cout <<"randlen" << randlen << "\r\n";
|
||||
int z = 0;
|
||||
|
||||
for (z = 0; z < randlen; z++) {
|
||||
pTest.Add(&tmp2[z], 1);
|
||||
}
|
||||
|
||||
std::cout << "check\r\n";
|
||||
for (z = 0; z < randlen; z++) {
|
||||
printf("%02d ", pTest.At(z));
|
||||
|
||||
//std::cout << pTest.At(z) << " ";
|
||||
if ((z != 0) && (z % 10 == 0)) {
|
||||
std::cout << "\r\n";
|
||||
}
|
||||
}
|
||||
std::cout << "\r\n";
|
||||
|
||||
std::cout << "take" << pTest.TakeBack(tmp, randlen) << "\r\n" << std::endl;
|
||||
std::cout << "\r\n";
|
||||
|
||||
for (int z = 0; z < randlen; z++) {
|
||||
printf("%02d ", tmp[z]);
|
||||
// std::cout << tmp[z]<< " ";
|
||||
if ((z != 0)&&(z % 10 == 0)){
|
||||
std::cout<<"\r\n";
|
||||
}
|
||||
}
|
||||
std::cout << "\r\n";
|
||||
}
|
||||
|
||||
std::cout<<"byteorder "<<HostByteOrder()<<std::endl;
|
||||
std::cout<< LimitFloat(1.123,2)<<std::endl;
|
||||
std::cout<<LimitFloat(1.123,3) << std::endl;
|
||||
|
|
Loading…
Reference in New Issue