-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpptest.cpp
More file actions
37 lines (33 loc) · 839 Bytes
/
Copy pathcpptest.cpp
File metadata and controls
37 lines (33 loc) · 839 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
* Show that libringbb.so can also be used in C++.
* */
#include "ring_byte_buf.h"
#include <cstring>
#include <iostream>
using namespace std;
#define HOPE_EQ(a,b) \
do{\
if((a) != (b))\
cerr<<"HOPE_EQ FAILED "<< __FILE__<<":"<< __LINE__<<endl;\
}while(0)
int main(){
// the same with test_1() in test_ringbb.c
ringbb rb;
rbb_init(&rb, 10);
HOPE_EQ(rb.capacity, 64);
HOPE_EQ(rb.size, 0);
const char *m1 = "0123456789";
rbb_push_back(&rb, m1, 10);
HOPE_EQ(rb.capacity, 64);
HOPE_EQ(rb.size, 10);
char p1[16] = {};
size_t r = rbb_pop_front(&rb, p1, 16);
HOPE_EQ(r, 10);
HOPE_EQ(memcmp(m1,p1,10), 0);
r = rbb_pop_front(&rb, p1, 16);
HOPE_EQ(r, 0);
r = rbb_pop_front(&rb, p1, 0);
HOPE_EQ(r, 0);
rbb_free(&rb);
cout << "Done!\n";
}