blob: 2fb4a8678591f4fc8b05b535a10ce0332b05fe23 [file] [log] [blame]
Victor Boivie7d3c49a2021-03-25 12:11:031/*
2 * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include "net/dcsctp/packet/bounded_byte_reader.h"
12
13#include "api/array_view.h"
14#include "rtc_base/buffer.h"
15#include "rtc_base/checks.h"
16#include "rtc_base/gunit.h"
17#include "test/gmock.h"
18
19namespace dcsctp {
20namespace {
21using ::testing::ElementsAre;
22
23TEST(BoundedByteReaderTest, CanLoadData) {
24 uint8_t data[14] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4};
25
26 BoundedByteReader<8> reader(data);
27 EXPECT_EQ(reader.variable_data_size(), 6U);
28 EXPECT_EQ(reader.Load32<0>(), 0x01020304U);
29 EXPECT_EQ(reader.Load32<4>(), 0x05060708U);
30 EXPECT_EQ(reader.Load16<4>(), 0x0506U);
31 EXPECT_EQ(reader.Load8<4>(), 0x05U);
32 EXPECT_EQ(reader.Load8<5>(), 0x06U);
33
34 BoundedByteReader<6> sub = reader.sub_reader<6>(0);
35 EXPECT_EQ(sub.Load16<0>(), 0x0900U);
36 EXPECT_EQ(sub.Load32<0>(), 0x09000102U);
37 EXPECT_EQ(sub.Load16<4>(), 0x0304U);
38
39 EXPECT_THAT(reader.variable_data(), ElementsAre(9, 0, 1, 2, 3, 4));
40}
41
42} // namespace
43} // namespace dcsctp