File: nalReader_unittest.cpp

package info (click to toggle)
libyami 1.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 4,152 kB
  • sloc: cpp: 44,247; ansic: 1,255; makefile: 728; lisp: 479; sh: 21; python: 19
file content (116 lines) | stat: -rw-r--r-- 2,542 bytes parent folder | download | duplicates (2)
1
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
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
 * Copyright 2016 Intel Corporation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
3B *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

// primary header
#include "nalReader.h"

// library headers
#include "common/unittest.h"

namespace YamiParser {

class NalReaderTest
    : public ::testing::Test {
};

#define NALREADER_TEST(name) \
    TEST_F(NalReaderTest, name)

NALREADER_TEST(ReadBeyondBoundary)
{
    uint8_t data = 0x55;
    uint32_t u;
    int32_t s;
    NalReader reader(&data, 1);
    EXPECT_EQ(0u, reader.read(1));
    EXPECT_EQ(1u, reader.read(1));
    EXPECT_TRUE(reader.readUe(u));
    EXPECT_EQ(1u, u);
    EXPECT_TRUE(reader.readSe(s));
    EXPECT_EQ(0, s);

    EXPECT_FALSE(reader.end());
    EXPECT_FALSE(reader.read(u, 8));
    EXPECT_TRUE(reader.end());
    EXPECT_FALSE(reader.readUe(u));
    EXPECT_EQ(0u, reader.readUe());
    EXPECT_FALSE(reader.readSe(s));
    EXPECT_EQ(0, reader.readSe());
}

void checkBitreadEmpty(NalReader& reader)
{
    EXPECT_TRUE(reader.end());
    EXPECT_EQ(0u, reader.getPos());
    EXPECT_EQ(0u,
        reader.getRemainingBitsCount());

    uint32_t u;
    int32_t s;
    EXPECT_FALSE(reader.readUe(u));
    EXPECT_FALSE(reader.readSe(s));

    EXPECT_TRUE(reader.end());
}

NALREADER_TEST(NullInit)
{
    uint8_t data = 0;
    NalReader r1(&data, 0);
    checkBitreadEmpty(r1);

    NalReader r2(NULL, 0);
    checkBitreadEmpty(r2);

    EXPECT_DEATH(NalReader r3(NULL, 1), "");
}

NALREADER_TEST(GetPosForEPB)
{
    //0x0, 0x0, 0x3, is emulation prevention byte
    const uint8_t data[] = {
        0x0, 0x0, 0x3, 0x0,
        0x0, 0x0, 0x0, 0x0,
        0x1
    };
    NalReader r(data, sizeof(data));
    EXPECT_EQ(0u, r.getPos());

    r.skip(1);
    EXPECT_EQ(1u, r.getPos());

    r.skip(7);
    EXPECT_EQ(8u, r.getPos());

    r.skip(8);
    //we are reach the epb
    EXPECT_EQ(16u, r.getPos());

    r.skip(8);
    EXPECT_EQ(24u, r.getPos());

    r.skip(32);

    uint8_t b;
    EXPECT_TRUE(r.readT(b));
    EXPECT_EQ(1u, b);
}

} // namespace YamiParser