delivered_packet_table_tests.cpp 3.81 KB
Newer Older
Andreas Schmidt's avatar
Andreas Schmidt committed
1 2
#include "common.h"

3
#include <cmath>
4
#include <prrt/proto/types/packet.h>
5 6 7 8 9 10 11

extern "C" {
    #include "prrt/proto/stores/deliveredPacketTable.h"
}

class DeliveredPacketTableTest : public ::testing::Test {
protected:
12
    void SetUp() override {
13 14
        deliveredPacketTable = PrrtDeliveredPacketTable_create();
    }
15 16 17
    void TearDown() override {
        PrrtDeliveredPacketTable_destroy(deliveredPacketTable);
    }
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
    PrrtDeliveredPacketTable* deliveredPacketTable;
};

TEST_F(DeliveredPacketTableTest, CreateDestroy) {
    ASSERT_EQ(deliveredPacketTable->start, 1);
}

TEST_F(DeliveredPacketTableTest, SimpleTestAndSet) {
    for (int i = 1; i < 10; ++i) {
        ASSERT_TRUE(PrrtDeliveredPacketTable_test_set_is_number_relevant(deliveredPacketTable, i));
        ASSERT_FALSE(PrrtDeliveredPacketTable_test_set_is_number_relevant(deliveredPacketTable, i));
    }
}

TEST_F(DeliveredPacketTableTest, SimpleMoveStart) {
    ASSERT_EQ(deliveredPacketTable->start, 1);
    ASSERT_TRUE(PrrtDeliveredPacketTable_test_set_is_number_relevant(deliveredPacketTable, 1));
    ASSERT_EQ(deliveredPacketTable->start, 2);
    ASSERT_TRUE(PrrtDeliveredPacketTable_test_set_is_number_relevant(deliveredPacketTable, 5));
    ASSERT_EQ(deliveredPacketTable->start, 2);
    ASSERT_TRUE(PrrtDeliveredPacketTable_test_set_is_number_relevant(deliveredPacketTable, 4));
    ASSERT_EQ(deliveredPacketTable->start, 2);
    ASSERT_TRUE(PrrtDeliveredPacketTable_test_set_is_number_relevant(deliveredPacketTable, 3));
    ASSERT_EQ(deliveredPacketTable->start, 2);
    ASSERT_TRUE(PrrtDeliveredPacketTable_test_set_is_number_relevant(deliveredPacketTable, 2));
    ASSERT_EQ(deliveredPacketTable->start, 6);

    for (int i = 1; i < 6; ++i) {
        ASSERT_FALSE(PrrtDeliveredPacketTable_test_set_is_number_relevant(deliveredPacketTable, i));
    }
}

TEST_F(DeliveredPacketTableTest, ProperStop) {
    prrtSequenceNumber_t seqno = (prrtSequenceNumber_t) (pow(2, 15) + 2);

    ASSERT_FALSE(PrrtDeliveredPacketTable_test_set_is_number_relevant(deliveredPacketTable, seqno));
    for (int i = 1; i < seqno / 2; ++i) {
        ASSERT_TRUE(PrrtDeliveredPacketTable_test_set_is_number_relevant(deliveredPacketTable, i));
    }
    ASSERT_TRUE(PrrtDeliveredPacketTable_test_set_is_number_relevant(deliveredPacketTable, seqno));
    ASSERT_FALSE(PrrtDeliveredPacketTable_test_set_is_number_relevant(deliveredPacketTable, 5));
}


TEST_F(DeliveredPacketTableTest, Sequence) {
    ASSERT_EQ(deliveredPacketTable->start, 1);
    ASSERT_TRUE(PrrtDeliveredPacketTable_test_set_is_number_relevant(deliveredPacketTable, 4));
    ASSERT_EQ(deliveredPacketTable->start, 1);
    ASSERT_TRUE(PrrtDeliveredPacketTable_test_set_is_number_relevant(deliveredPacketTable, 7));
    ASSERT_EQ(deliveredPacketTable->start, 1);
    ASSERT_TRUE(PrrtDeliveredPacketTable_test_set_is_number_relevant(deliveredPacketTable, 1));
    ASSERT_EQ(deliveredPacketTable->start, 2);
    ASSERT_FALSE(PrrtDeliveredPacketTable_test_set_is_number_relevant(deliveredPacketTable, 4));
    ASSERT_EQ(deliveredPacketTable->start, 2);
    ASSERT_TRUE(PrrtDeliveredPacketTable_test_set_is_number_relevant(deliveredPacketTable, 8));
    ASSERT_EQ(deliveredPacketTable->start, 2);
}

TEST_F(DeliveredPacketTableTest, ResetToZero) {
    for (int i = 1; i < pow(2, 16) + 5; ++i) {
        ASSERT_TRUE(PrrtDeliveredPacketTable_test_set_is_number_relevant(deliveredPacketTable, i));
        ASSERT_FALSE(PrrtDeliveredPacketTable_test_set_is_number_relevant(deliveredPacketTable, i));
    }
}

TEST_F(DeliveredPacketTableTest, CheckBlock) {
    ASSERT_TRUE(PrrtDeliveredPacketTable_test_is_block_relevant(deliveredPacketTable, 1, 6));
    for (int i = 1; i < 7; ++i) {
        ASSERT_TRUE(PrrtDeliveredPacketTable_test_set_is_number_relevant(deliveredPacketTable, i));
    }
    ASSERT_FALSE(PrrtDeliveredPacketTable_test_is_block_relevant(deliveredPacketTable, 1, 6));
}