PrrtBlock_tests.cpp 2.16 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <gtest/gtest.h>

extern "C" {
    #include "src/prrt/block.h"
    #include "src/prrt/packet.h"
    #include "src/prrt/coding_params.h"
}

class PrrtBlockTest : public ::testing::Test {
protected:
    virtual void SetUp() {
        encBlock = NULL;
        decBlock = NULL;
14
        PrrtCodingParams *cpar = (PrrtCodingParams *) calloc(1, sizeof(PrrtCodingParams));
15
        PrrtCodingParams_init(cpar);
16
17
        PrrtBlock_alloc(&encBlock, cpar, 0);
        PrrtBlock_alloc(&decBlock, cpar, 0);
18
19
20
21
22
23
24
25
26
27
28
29
    }
    PrrtBlock *encBlock;
    PrrtBlock *decBlock;
};


TEST_F(PrrtBlockTest, Encode) {
    uint16_t base = 0;

    PrrtPacket packets[2];
    PrrtPacket redPackets[2];

30
    for (int i = 1; i < 3; i++) {
31
32
33
34
35
36
37
38
        char data[3];
        sprintf(data, "%d", i);
        PrrtPacket *ptr = &packets[i - 1];
        PrrtPacket_create_data_packet(ptr, 0, data, (uint32_t) strlen(data), i);
        PrrtBlock_insert_data_packet(encBlock, ptr);
    }

    // ENCODING
39
40
41
    ASSERT_TRUE(PrrtBlock_encode_ready(encBlock));
    int j = 0;
    PrrtBlock_encode(encBlock, &base);
42

43
44
45
46
47
48
49
50
51
    uint32_t pkt_count = (encBlock)->data_count;
    for (j = 0; j < pkt_count; j++) {
        PrrtPacket *data_pkt = PrrtBlock_get_first_data(encBlock);
        ASSERT_EQ(data_pkt->seqno, packets[j].seqno);
    }
    uint32_t red_count = (encBlock)->redundancy_count;
    for (j = 0; j < red_count; j++) {
        PrrtPacket *red_pkt = PrrtBlock_get_first_red_data(encBlock);
        redPackets[j] = *red_pkt;
52
53
    }

54
55
56
57
    printf("------------------------\n");



58
59
60
61
    // DECODING
    PrrtBlock_insert_data_packet(decBlock, &packets[0]);
    PrrtBlock_insert_redundancy_packet(decBlock, &redPackets[0]);

62
    ASSERT_TRUE(PrrtBlock_decode_ready(decBlock));
63

64
    PrrtBlock_decode(decBlock);
65

66
    for (int k = 0; k < 2; ++k) {
67
        PrrtPacket *ptr = PrrtBlock_get_first_data(decBlock);
68
69
70
        PrrtPacket_print(ptr);
        PrrtPacket_print(&packets[k]);

71
72
73
74
75
        const char *s1 = (const char*) (packets[k].payload + PRRT_PACKET_DATA_HEADER_SIZE);
        const char *s2 = (const char*) (ptr->payload + PRRT_PACKET_DATA_HEADER_SIZE);
        ASSERT_STREQ(s1, s2);

        PrrtPacket_print(ptr);
76

77
78
        // TODO: check for proper data
    }
79
}