tor-browser

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

clockdrift_detector_unittest.cc (1913B)


      1 /*
      2 *  Copyright (c) 2018 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/audio_processing/aec3/clockdrift_detector.h"
     12 
     13 #include "test/gtest.h"
     14 
     15 namespace webrtc {
     16 TEST(ClockdriftDetector, ClockdriftDetector) {
     17  ClockdriftDetector c;
     18  // No clockdrift at start.
     19  EXPECT_TRUE(c.ClockdriftLevel() == ClockdriftDetector::Level::kNone);
     20 
     21  // Monotonically increasing delay.
     22  for (int i = 0; i < 100; i++)
     23    c.Update(1000);
     24  EXPECT_TRUE(c.ClockdriftLevel() == ClockdriftDetector::Level::kNone);
     25  for (int i = 0; i < 100; i++)
     26    c.Update(1001);
     27  EXPECT_TRUE(c.ClockdriftLevel() == ClockdriftDetector::Level::kNone);
     28  for (int i = 0; i < 100; i++)
     29    c.Update(1002);
     30  // Probable clockdrift.
     31  EXPECT_TRUE(c.ClockdriftLevel() == ClockdriftDetector::Level::kProbable);
     32  for (int i = 0; i < 100; i++)
     33    c.Update(1003);
     34  // Verified clockdrift.
     35  EXPECT_TRUE(c.ClockdriftLevel() == ClockdriftDetector::Level::kVerified);
     36 
     37  // Stable delay.
     38  for (int i = 0; i < 10000; i++)
     39    c.Update(1003);
     40  // No clockdrift.
     41  EXPECT_TRUE(c.ClockdriftLevel() == ClockdriftDetector::Level::kNone);
     42 
     43  // Decreasing delay.
     44  for (int i = 0; i < 100; i++)
     45    c.Update(1001);
     46  for (int i = 0; i < 100; i++)
     47    c.Update(999);
     48  // Probable clockdrift.
     49  EXPECT_TRUE(c.ClockdriftLevel() == ClockdriftDetector::Level::kProbable);
     50  for (int i = 0; i < 100; i++)
     51    c.Update(1000);
     52  for (int i = 0; i < 100; i++)
     53    c.Update(998);
     54  // Verified clockdrift.
     55  EXPECT_TRUE(c.ClockdriftLevel() == ClockdriftDetector::Level::kVerified);
     56 }
     57 }  // namespace webrtc