blob: b703e84576cff493d49cbfe335a8afb4ac54f740 [file] [log] [blame]
Danil Chapovalov09860e02019-10-30 13:12:241/*
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 */
Rasmus Brandtfbf66dd2022-05-23 07:53:3210#include "video/unique_timestamp_counter.h"
Danil Chapovalov09860e02019-10-30 13:12:2411
12#include "test/gtest.h"
13
14namespace webrtc {
15namespace {
16
17TEST(UniqueTimestampCounterTest, InitiallyZero) {
18 UniqueTimestampCounter counter;
19 EXPECT_EQ(counter.GetUniqueSeen(), 0);
20}
21
22TEST(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
32TEST(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