receptionTable_tests.cpp 1.41 KB
Newer Older
Andreas Schmidt's avatar
Andreas Schmidt committed
1
#include "common.h"
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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54

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

class ReceptionTableTest : public ::testing::Test {
protected:
    virtual void SetUp()
    {
        lg = PrrtReceptionTable_create();
    }

    virtual void TearDown()
    {
        PrrtReceptionTable_destroy(lg);
    }

    PrrtReceptionTable *lg;
};

TEST_F(ReceptionTableTest, CreateDestroy)
{
    PrrtReceptionTable *lg = PrrtReceptionTable_create();
    void *n = NULL;
    ASSERT_NE(n, lg);
    ASSERT_NE(n, lg->bitmap);
    PrrtReceptionTable_destroy(lg);
}

TEST_F(ReceptionTableTest, CalculateStatistics)
{

    PrrtReceptionTable_mark_received(lg, 0);
    PrrtReceptionTable_mark_received(lg, 1);
    PrrtReceptionTable_mark_received(lg, 2);
    PrrtReceptionTable_mark_received(lg, 3);
    PrrtReceptionTable_mark_received(lg, 4);
    PrrtReceptionTable_mark_received(lg, 5);
    PrrtReceptionTable_mark_received(lg, 6);
    PrrtReceptionTable_mark_received(lg, 9);

    PrrtLossStatistics stats = PrrtReceptionTable_calculate_statistics(lg);

    printf("PC: %d, EC: %d, GC: %d, GL: %d, BC: %d, BL: %d\n", stats.packetCount, stats.erasureCount, stats.gapCount,
           stats.gapLength, stats.burstCount, stats.burstLength);

    ASSERT_EQ(10, stats.packetCount);
    ASSERT_EQ(2, stats.erasureCount);
    ASSERT_EQ(1, stats.gapCount);
    ASSERT_EQ(2, stats.gapLength);
    ASSERT_EQ(8, stats.burstLength);
    ASSERT_EQ(2, stats.burstCount);
}