Commit a8c09c80 authored by jcastro's avatar jcastro

Add unit test to reproduce UB in Queue::Entry destructor

See #379
parent 4600c150
......@@ -27,3 +27,4 @@ pistache_test(payload_test)
pistache_test(streaming_test)
pistache_test(rest_server_test)
pistache_test(string_view_test)
pistache_test(mailbox_test)
#include "gtest/gtest.h"
#include <pistache/mailbox.h>
struct Data {
static int num_instances;
static constexpr int fingerprint = 0xdeadbeef;
Data() : val(Data::fingerprint) {
num_instances++;
}
~Data() {
EXPECT_EQ(val, Data::fingerprint);
EXPECT_GE(0, --num_instances );
}
int val;
};
int Data::num_instances = 0;
constexpr int Data::fingerprint;
TEST(queue_test, destructor_test) {
Pistache::Queue<Data> queue;
EXPECT_TRUE(queue.empty());
for( int i = 0; i < 5; i++ ) {
auto* e = queue.allocEntry(Data());
queue.push(e);
}
// Should call Data::~Data 5 times and not 6 (placeholder entry)
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment