Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: media/base/audio_timestamp_helper_unittest.cc

Issue 1534273002: Switch to standard integer types in media/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/base/audio_timestamp_helper.h" 5 #include "media/base/audio_timestamp_helper.h"
6 #include "media/base/timestamp_constants.h" 6 #include "media/base/timestamp_constants.h"
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 8
9 namespace media { 9 namespace media {
10 10
11 static const int kDefaultSampleRate = 44100; 11 static const int kDefaultSampleRate = 44100;
12 12
13 class AudioTimestampHelperTest : public ::testing::Test { 13 class AudioTimestampHelperTest : public ::testing::Test {
14 public: 14 public:
15 AudioTimestampHelperTest() : helper_(kDefaultSampleRate) { 15 AudioTimestampHelperTest() : helper_(kDefaultSampleRate) {
16 helper_.SetBaseTimestamp(base::TimeDelta()); 16 helper_.SetBaseTimestamp(base::TimeDelta());
17 } 17 }
18 18
19 // Adds frames to the helper and returns the current timestamp in 19 // Adds frames to the helper and returns the current timestamp in
20 // microseconds. 20 // microseconds.
21 int64 AddFrames(int frames) { 21 int64_t AddFrames(int frames) {
22 helper_.AddFrames(frames); 22 helper_.AddFrames(frames);
23 return helper_.GetTimestamp().InMicroseconds(); 23 return helper_.GetTimestamp().InMicroseconds();
24 } 24 }
25 25
26 int64 FramesToTarget(int target_in_microseconds) { 26 int64_t FramesToTarget(int target_in_microseconds) {
27 return helper_.GetFramesToTarget( 27 return helper_.GetFramesToTarget(
28 base::TimeDelta::FromMicroseconds(target_in_microseconds)); 28 base::TimeDelta::FromMicroseconds(target_in_microseconds));
29 } 29 }
30 30
31 void TestGetFramesToTargetRange(int frame_count, int start, int end) { 31 void TestGetFramesToTargetRange(int frame_count, int start, int end) {
32 for (int i = start; i <= end; ++i) { 32 for (int i = start; i <= end; ++i) {
33 EXPECT_EQ(frame_count, FramesToTarget(i)) << " Failure for timestamp " 33 EXPECT_EQ(frame_count, FramesToTarget(i)) << " Failure for timestamp "
34 << i << " us."; 34 << i << " us.";
35 } 35 }
36 } 36 }
(...skipping 29 matching lines...) Expand all
66 helper_.AddFrames(5); 66 helper_.AddFrames(5);
67 EXPECT_EQ(113, helper_.GetTimestamp().InMicroseconds()); 67 EXPECT_EQ(113, helper_.GetTimestamp().InMicroseconds());
68 EXPECT_TRUE(timestamp_1 == helper_.GetTimestamp()); 68 EXPECT_TRUE(timestamp_1 == helper_.GetTimestamp());
69 } 69 }
70 70
71 71
72 TEST_F(AudioTimestampHelperTest, GetDuration) { 72 TEST_F(AudioTimestampHelperTest, GetDuration) {
73 helper_.SetBaseTimestamp(base::TimeDelta::FromMicroseconds(100)); 73 helper_.SetBaseTimestamp(base::TimeDelta::FromMicroseconds(100));
74 74
75 int frame_count = 5; 75 int frame_count = 5;
76 int64 expected_durations[] = { 113, 113, 114, 113, 113, 114 }; 76 int64_t expected_durations[] = {113, 113, 114, 113, 113, 114};
77 for (size_t i = 0; i < arraysize(expected_durations); ++i) { 77 for (size_t i = 0; i < arraysize(expected_durations); ++i) {
78 base::TimeDelta duration = helper_.GetFrameDuration(frame_count); 78 base::TimeDelta duration = helper_.GetFrameDuration(frame_count);
79 EXPECT_EQ(expected_durations[i], duration.InMicroseconds()); 79 EXPECT_EQ(expected_durations[i], duration.InMicroseconds());
80 80
81 base::TimeDelta timestamp_1 = helper_.GetTimestamp() + duration; 81 base::TimeDelta timestamp_1 = helper_.GetTimestamp() + duration;
82 helper_.AddFrames(frame_count); 82 helper_.AddFrames(frame_count);
83 base::TimeDelta timestamp_2 = helper_.GetTimestamp(); 83 base::TimeDelta timestamp_2 = helper_.GetTimestamp();
84 EXPECT_TRUE(timestamp_1 == timestamp_2); 84 EXPECT_TRUE(timestamp_1 == timestamp_2);
85 } 85 }
86 } 86 }
(...skipping 26 matching lines...) Expand all
113 // tested above to verify that the code is rounding properly. 113 // tested above to verify that the code is rounding properly.
114 TestGetFramesToTargetRange(0, 103, 124); 114 TestGetFramesToTargetRange(0, 103, 124);
115 TestGetFramesToTargetRange(-1, 80, 102); 115 TestGetFramesToTargetRange(-1, 80, 102);
116 TestGetFramesToTargetRange(-2, 57, 79); 116 TestGetFramesToTargetRange(-2, 57, 79);
117 TestGetFramesToTargetRange(-3, 35, 56); 117 TestGetFramesToTargetRange(-3, 35, 56);
118 TestGetFramesToTargetRange(-4, 12, 34); 118 TestGetFramesToTargetRange(-4, 12, 34);
119 TestGetFramesToTargetRange(-5, 0, 11); 119 TestGetFramesToTargetRange(-5, 0, 11);
120 } 120 }
121 121
122 } // namespace media 122 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698