tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

rrtr_unittest.cc (1587B)


      1 /*
      2 *  Copyright (c) 2015 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 "modules/rtp_rtcp/source/rtcp_packet/rrtr.h"
     12 
     13 #include <cstddef>
     14 #include <cstdint>
     15 #include <cstring>
     16 
     17 #include "system_wrappers/include/ntp_time.h"
     18 #include "test/gtest.h"
     19 
     20 using webrtc::rtcp::Rrtr;
     21 
     22 namespace webrtc {
     23 namespace {
     24 
     25 constexpr uint32_t kNtpSec = 0x12345678;
     26 constexpr uint32_t kNtpFrac = 0x23456789;
     27 constexpr uint8_t kBlock[] = {0x04, 0x00, 0x00, 0x02, 0x12, 0x34,
     28                              0x56, 0x78, 0x23, 0x45, 0x67, 0x89};
     29 constexpr size_t kBlockSizeBytes = sizeof(kBlock);
     30 static_assert(
     31    kBlockSizeBytes == Rrtr::kLength,
     32    "Size of manually created Rrtr block should match class constant");
     33 
     34 TEST(RtcpPacketRrtrTest, Create) {
     35  uint8_t buffer[Rrtr::kLength];
     36  Rrtr rrtr;
     37  rrtr.SetNtp(NtpTime(kNtpSec, kNtpFrac));
     38 
     39  rrtr.Create(buffer);
     40  EXPECT_EQ(0, memcmp(buffer, kBlock, kBlockSizeBytes));
     41 }
     42 
     43 TEST(RtcpPacketRrtrTest, Parse) {
     44  Rrtr read_rrtr;
     45  read_rrtr.Parse(kBlock);
     46 
     47  // Run checks on const object to ensure all accessors have const modifier.
     48  const Rrtr& parsed = read_rrtr;
     49 
     50  EXPECT_EQ(kNtpSec, parsed.ntp().seconds());
     51  EXPECT_EQ(kNtpFrac, parsed.ntp().fractions());
     52 }
     53 
     54 }  // namespace
     55 }  // namespace webrtc