1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
media / base / audio_glitch_info_unittest.cc [blame]
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "media/base/audio_glitch_info.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/time/time.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace media {
class AudioGlitchInfoTester {
public:
static AudioGlitchInfo SingleBoundedSystemGlitch(
const base::TimeDelta duration,
const AudioGlitchInfo::Direction direction) {
return AudioGlitchInfo::SingleBoundedSystemGlitch(duration, direction);
}
};
TEST(AudioGlitchInfo, EqualityOperator) {
AudioGlitchInfo info1{.duration = base::Seconds(1), .count = 123};
AudioGlitchInfo info2{.duration = base::Seconds(3), .count = 369};
AudioGlitchInfo info3 = info1;
EXPECT_EQ(info1.duration, base::Seconds(1));
EXPECT_EQ(info1.count, 123u);
EXPECT_EQ(info2.duration, base::Seconds(3));
EXPECT_EQ(info2.count, 369u);
EXPECT_FALSE(info1 == info2);
EXPECT_TRUE(info1 == info3);
}
TEST(AudioGlitchInfo, AudioGlitchInfoAccumulator) {
AudioGlitchInfo::Accumulator accumulator;
EXPECT_EQ(accumulator.GetAndReset(), AudioGlitchInfo());
accumulator.Add(AudioGlitchInfo{.duration = base::Seconds(1), .count = 123});
accumulator.Add(AudioGlitchInfo{.duration = base::Seconds(2), .count = 246});
auto accumulated_glitches = accumulator.GetAndReset();
EXPECT_EQ(accumulated_glitches.duration, base::Seconds(3));
EXPECT_EQ(accumulated_glitches.count, 369u);
EXPECT_EQ(accumulator.GetAndReset(), AudioGlitchInfo());
}
TEST(AudioGlitchInfo, ToString) {
AudioGlitchInfo info{.duration = base::Milliseconds(123), .count = 456};
EXPECT_EQ(info.ToString(), "duration (ms): 123, count: 456");
}
TEST(AudioGlitchInfo, SingleBoundedSystemGlitch) {
base::HistogramTester histogram_tester_;
{
AudioGlitchInfo result{.duration = base::Seconds(1), .count = 1};
EXPECT_EQ(AudioGlitchInfoTester::SingleBoundedSystemGlitch(
base::Seconds(1.5), AudioGlitchInfo::Direction::kRender),
result);
histogram_tester_.ExpectTimeBucketCount(
"Media.Audio.Render.SystemGlitchDuration", base::Seconds(1.5), 1);
}
{
AudioGlitchInfo result{.duration = base::Seconds(0.5), .count = 1};
EXPECT_EQ(AudioGlitchInfoTester::SingleBoundedSystemGlitch(
base::Seconds(0.5), AudioGlitchInfo::Direction::kCapture),
result);
histogram_tester_.ExpectTimeBucketCount(
"Media.Audio.Capture.SystemGlitchDuration", base::Seconds(0.5), 1);
}
}
} // namespace media