redo packet build/parse
now with evbuffer
This commit is contained in:
+50
-2
@@ -9,10 +9,11 @@
|
||||
#include <epicsUnitTest.h>
|
||||
|
||||
#include <pvxs/unittest.h>
|
||||
#include <pvxs/log.h>
|
||||
#include <evhelper.h>
|
||||
|
||||
namespace {
|
||||
using namespace pvxsimpl;
|
||||
namespace {
|
||||
|
||||
struct my_special_error : public std::runtime_error
|
||||
{
|
||||
@@ -63,11 +64,58 @@ void test_call()
|
||||
|
||||
}
|
||||
|
||||
void test_fill_evbuf()
|
||||
{
|
||||
testDiag("%s", __func__);
|
||||
|
||||
evbuf buf(evbuffer_new());
|
||||
|
||||
{
|
||||
EvOutBuf M(true, buf.get());
|
||||
testEq(M.size(), 0u);
|
||||
|
||||
for(uint32_t i : range(1024)) {
|
||||
to_wire(M, i);
|
||||
}
|
||||
testDiag("Extra %u", unsigned(M.size()));
|
||||
testOk1(!!M.good());
|
||||
|
||||
// ~EvOutBuf flushes to backing buf
|
||||
}
|
||||
|
||||
testEq(evbuffer_get_length(buf.get()), 4*1024u);
|
||||
|
||||
{
|
||||
EvInBuf M(true, buf.get());
|
||||
testEq(M.size(), 0u);
|
||||
|
||||
bool match = true;
|
||||
for(uint32_t expect : range(1024)) {
|
||||
uint32_t actual=0;
|
||||
from_wire(M, actual);
|
||||
if(actual!=expect) {
|
||||
testDiag("%08x == %08x", unsigned(expect), unsigned(actual));
|
||||
match = false;
|
||||
break; // only show first failure
|
||||
}
|
||||
}
|
||||
testOk1(!!match);
|
||||
testOk1(!!M.good());
|
||||
testEq(M.size(), 0u);
|
||||
testOk1(!M.refill(42)); // should be completely empty
|
||||
}
|
||||
|
||||
testEq(evbuffer_get_length(buf.get()), 0u);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
MAIN(testev)
|
||||
{
|
||||
testPlan(5);
|
||||
testPlan(14);
|
||||
test_call();
|
||||
test_fill_evbuf();
|
||||
libevent_global_shutdown();
|
||||
cleanup_for_valgrind();
|
||||
return testDone();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user