• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2019 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 #include "modules/video_coding/unique_timestamp_counter.h"
11 
12 #include "test/gtest.h"
13 
14 namespace webrtc {
15 namespace {
16 
TEST(UniqueTimestampCounterTest,InitiallyZero)17 TEST(UniqueTimestampCounterTest, InitiallyZero) {
18   UniqueTimestampCounter counter;
19   EXPECT_EQ(counter.GetUniqueSeen(), 0);
20 }
21 
TEST(UniqueTimestampCounterTest,CountsUniqueValues)22 TEST(UniqueTimestampCounterTest, CountsUniqueValues) {
23   UniqueTimestampCounter counter;
24   counter.Add(100);
25   counter.Add(100);
26   counter.Add(200);
27   counter.Add(150);
28   counter.Add(100);
29   EXPECT_EQ(counter.GetUniqueSeen(), 3);
30 }
31 
TEST(UniqueTimestampCounterTest,ForgetsOldValuesAfter1000NewValues)32 TEST(UniqueTimestampCounterTest, ForgetsOldValuesAfter1000NewValues) {
33   const int kNumValues = 1500;
34   const int kMaxHistory = 1000;
35   const uint32_t value = 0xFFFFFFF0;
36   UniqueTimestampCounter counter;
37   for (int i = 0; i < kNumValues; ++i) {
38     counter.Add(value + 10 * i);
39   }
40   ASSERT_EQ(counter.GetUniqueSeen(), kNumValues);
41   // Slightly old values not affect number of seen unique values.
42   for (int i = kNumValues - kMaxHistory; i < kNumValues; ++i) {
43     counter.Add(value + 10 * i);
44   }
45   EXPECT_EQ(counter.GetUniqueSeen(), kNumValues);
46   // Very old value will be treated as unique.
47   counter.Add(value);
48   EXPECT_EQ(counter.GetUniqueSeen(), kNumValues + 1);
49 }
50 
51 }  // namespace
52 }  // namespace webrtc
53