Commit f10b2e3e authored by Kai Vogelgesang's avatar Kai Vogelgesang Committed by Andreas Schmidt

Fix memory leaks in tests

parent c9cb20be
Pipeline #3129 passed with stages
in 1 minute and 49 seconds
......@@ -86,9 +86,29 @@ TEST_F(PrrtBlockTest, VDMCode)
ASSERT_EQ(4, decFec[3][0]);
ASSERT_EQ(9, decFec[3][1]);
ASSERT_EQ(5, decFec[3][2]);
// free allocated memory
for (i = 0; i < k; ++i) {
free(decFec[i]);
}
free(idx_p);
free(decFec);
for (j = 0; j < r; ++j) {
free(encFec[j]);
}
free(encFec);
free(src[3]);
free(src[2]);
free(src[1]);
free(src[0]);
free(src);
}
PrrtCoder_destroy(coder);
PrrtCodingConfiguration_destroy(params);
}
TEST_F(PrrtBlockTest, EncodeDecode)
......@@ -142,7 +162,7 @@ TEST_F(PrrtBlockTest, EncodeDecode)
PrrtBlock_insert_redundancy_packet(decBlock, redPackets[0]);
PrrtBlock_insert_redundancy_packet(decBlock, redPackets[1]);
PrrtBlock_insert_redundancy_packet(decBlock, redPackets[2]);
PrrtBlock_insert_data_packet(decBlock, packets[3]);
PrrtBlock_insert_data_packet(decBlock, PrrtPacket_copy(packets[3]));
ASSERT_TRUE(PrrtBlock_decode_ready(decBlock));
......@@ -160,12 +180,22 @@ TEST_F(PrrtBlockTest, EncodeDecode)
ASSERT_STREQ(s1, s2);
ASSERT_EQ(refLength, ptrLength);
PrrtPacket_destroy(ptr);
}
PrrtBlock_destroy(encBlock);
PrrtBlock_destroy(decBlock);
PrrtCoder_destroy(coder);
PrrtCodingConfiguration_destroy(cpar);
for (auto packet: packets) {
PrrtPacket_destroy(packet);
}
for (auto packet: refPackets) {
PrrtPacket_destroy(packet);
}
}
TEST_F(PrrtBlockTest, NoCodingConfigured)
......@@ -182,9 +212,9 @@ TEST_F(PrrtBlockTest, NoCodingConfigured)
for(uint32_t i = 0; i < 1; i++) {
char data[3];
sprintf(data, "%d", i);
packets[i] = PrrtPacket_create_data_packet(0, data, (prrtPacketLength_t) strlen(data), i + 1, 0);
packets[i] = PrrtPacket_create_data_packet(0, data, (prrtPacketLength_t) strlen(data) + 1, i + 1, 0);
packets[i]->index = (uint8_t) i;
refPackets[i] = PrrtPacket_create_data_packet(0, data, (prrtPacketLength_t) strlen(data), i + 1, 0);
refPackets[i] = PrrtPacket_create_data_packet(0, data, (prrtPacketLength_t) strlen(data) + 1, i + 1, 0);
ASSERT_TRUE(PrrtBlock_insert_data_packet(encBlock, packets[i]));
}
......@@ -201,6 +231,11 @@ TEST_F(PrrtBlockTest, NoCodingConfigured)
uint32_t red_count = List_count(encBlock->redundancyPackets);
ASSERT_EQ(red_count, 0);
for (int i = 0; i < 1; ++i) {
PrrtPacket_destroy(packets[i]);
PrrtPacket_destroy(refPackets[i]);
}
PrrtBlock_destroy(encBlock);
PrrtCoder_destroy(coder);
PrrtCodingConfiguration_destroy(cpar);
......
......@@ -6,13 +6,20 @@ extern "C" {
class BPlusTreeTest : public ::testing::Test {
protected:
virtual void SetUp() {
void SetUp() override {
root = NULL;
void* p = malloc(sizeof(int));
root = BPTree_insert(root, 1, p);
}
virtual void TearDown() {
void TearDown() override {
List *list = List_create();
BPTree_get_range(root, list, std::numeric_limits<BPTreeKey_t>::min(), std::numeric_limits<BPTreeKey_t>::max());
while (List_count(list) > 0) {
void *p = List_shift(list);
free(p);
}
List_destroy(list);
root = BPTree_destroy(root);
}
......@@ -21,7 +28,10 @@ protected:
};
TEST_F(BPlusTreeTest, InsertDelete) {
void* p = malloc(sizeof(int));
void* p = malloc(sizeof(int)),
*p2 = malloc(sizeof(int)),
*p3 = malloc(sizeof(int));
ASSERT_EQ(BPTree_height(root), 0);
ASSERT_EQ(BPTree_size(root), 1);
......@@ -29,15 +39,17 @@ TEST_F(BPlusTreeTest, InsertDelete) {
ASSERT_EQ(BPTree_height(root), 0);
ASSERT_EQ(BPTree_size(root), 2);
root = BPTree_insert(root, 3, p);
root = BPTree_insert(root, 3, p2);
ASSERT_EQ(BPTree_height(root), 0);
ASSERT_EQ(BPTree_size(root), 3);
root = BPTree_insert(root, 4, p);
root = BPTree_insert(root, 4, p3);
ASSERT_EQ(BPTree_height(root), 1);
ASSERT_EQ(BPTree_size(root), 4);
free(BPTree_get(root, 3));
root = BPTree_delete(root, 3);
ASSERT_EQ(BPTree_height(root), 0);
ASSERT_EQ(BPTree_size(root), 3);
}
......@@ -45,11 +57,13 @@ TEST_F(BPlusTreeTest, InsertDelete) {
TEST_F(BPlusTreeTest, InsertAndFind) {
void* p = malloc(sizeof(int));
void* p2 = malloc(sizeof(int));
void* p3 = malloc(sizeof(int));
root = BPTree_insert(root, 2, p);
root = BPTree_insert(root, 3, p2);
root = BPTree_insert(root, 4, p);
root = BPTree_insert(root, 4, p3);
ASSERT_EQ(BPTree_get(root, 3), p2);
ASSERT_NE(BPTree_get(root, 3), p3);
ASSERT_NE(BPTree_get(root, 3), p);
ASSERT_EQ(BPTree_size(root), 4);
}
......@@ -57,7 +71,10 @@ TEST_F(BPlusTreeTest, InsertAndFind) {
TEST_F(BPlusTreeTest, FindRange) {
int n = 10;
void* p[10];
free(BPTree_get(root, 1));
root = BPTree_delete(root, 1);
for (int i = 0; i < n; i++) {
void *pVoid = malloc(sizeof(int));
p[i] = pVoid;
......@@ -75,4 +92,6 @@ TEST_F(BPlusTreeTest, FindRange) {
list = List_create();
BPTree_get_range(root, list, 1, 3);
ASSERT_EQ(List_count(list), 3);
List_destroy(list);
}
......@@ -9,15 +9,17 @@ extern "C" {
class DeliveredPacketTableTest : public ::testing::Test {
protected:
virtual void SetUp() {
void SetUp() override {
deliveredPacketTable = PrrtDeliveredPacketTable_create();
}
void TearDown() override {
PrrtDeliveredPacketTable_destroy(deliveredPacketTable);
}
PrrtDeliveredPacketTable* deliveredPacketTable;
};
TEST_F(DeliveredPacketTableTest, CreateDestroy) {
ASSERT_EQ(deliveredPacketTable->start, 1);
free(deliveredPacketTable);
}
TEST_F(DeliveredPacketTableTest, SimpleTestAndSet) {
......
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