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

Side by Side Diff: webrtc/media/engine/webrtcvoiceengine_unittest.cc

Issue 2697453004: WebRtcVoiceEngineTest: Changed a static_cast to a checked_cast. (Closed)
Patch Set: Rebased. Created 3 years, 10 months 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
« no previous file with comments | « no previous file | webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory_internal.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2008 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2008 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include <memory> 11 #include <memory>
12 12
13 #include "webrtc/api/audio_codecs/builtin_audio_decoder_factory.h" 13 #include "webrtc/api/audio_codecs/builtin_audio_decoder_factory.h"
14 #include "webrtc/base/arraysize.h" 14 #include "webrtc/base/arraysize.h"
15 #include "webrtc/base/byteorder.h" 15 #include "webrtc/base/byteorder.h"
16 #include "webrtc/base/gunit.h" 16 #include "webrtc/base/gunit.h"
17 #include "webrtc/base/safe_conversions.h"
17 #include "webrtc/call/call.h" 18 #include "webrtc/call/call.h"
18 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" 19 #include "webrtc/logging/rtc_event_log/rtc_event_log.h"
19 #include "webrtc/media/base/fakemediaengine.h" 20 #include "webrtc/media/base/fakemediaengine.h"
20 #include "webrtc/media/base/fakenetworkinterface.h" 21 #include "webrtc/media/base/fakenetworkinterface.h"
21 #include "webrtc/media/base/fakertp.h" 22 #include "webrtc/media/base/fakertp.h"
22 #include "webrtc/media/base/mediaconstants.h" 23 #include "webrtc/media/base/mediaconstants.h"
23 #include "webrtc/media/engine/fakewebrtccall.h" 24 #include "webrtc/media/engine/fakewebrtccall.h"
24 #include "webrtc/media/engine/fakewebrtcvoiceengine.h" 25 #include "webrtc/media/engine/fakewebrtcvoiceengine.h"
25 #include "webrtc/media/engine/webrtcvoiceengine.h" 26 #include "webrtc/media/engine/webrtcvoiceengine.h"
26 #include "webrtc/modules/audio_coding/codecs/mock/mock_audio_decoder_factory.h" 27 #include "webrtc/modules/audio_coding/codecs/mock/mock_audio_decoder_factory.h"
(...skipping 3690 matching lines...) Expand 10 before | Expand all | Expand 10 after
3717 3718
3718 // Ensure the general codecs are generated first and in order. 3719 // Ensure the general codecs are generated first and in order.
3719 for (size_t i = 0; i != specs.size(); ++i) { 3720 for (size_t i = 0; i != specs.size(); ++i) {
3720 EXPECT_EQ(specs[i].format.name, get_codec(i).name); 3721 EXPECT_EQ(specs[i].format.name, get_codec(i).name);
3721 EXPECT_EQ(specs[i].format.clockrate_hz, get_codec(i).clockrate); 3722 EXPECT_EQ(specs[i].format.clockrate_hz, get_codec(i).clockrate);
3722 EXPECT_EQ(specs[i].format.num_channels, get_codec(i).channels); 3723 EXPECT_EQ(specs[i].format.num_channels, get_codec(i).channels);
3723 EXPECT_EQ(specs[i].format.parameters, get_codec(i).params); 3724 EXPECT_EQ(specs[i].format.parameters, get_codec(i).params);
3724 } 3725 }
3725 3726
3726 // Find the index of a codec, or -1 if not found, so that we can easily check 3727 // Find the index of a codec, or -1 if not found, so that we can easily check
3727 // supplementary codecs are orderd after the general codecs. 3728 // supplementary codecs are ordered after the general codecs.
3728 auto find_codec = 3729 auto find_codec =
3729 [&codecs](const webrtc::SdpAudioFormat& format) -> int { 3730 [&codecs](const webrtc::SdpAudioFormat& format) -> int {
3730 for (size_t i = 0; i != codecs.size(); ++i) { 3731 for (size_t i = 0; i != codecs.size(); ++i) {
3731 const cricket::AudioCodec& codec = codecs[i]; 3732 const cricket::AudioCodec& codec = codecs[i];
3732 if (STR_CASE_CMP(codec.name.c_str(), format.name.c_str()) == 0 && 3733 if (STR_CASE_CMP(codec.name.c_str(), format.name.c_str()) == 0 &&
3733 codec.clockrate == format.clockrate_hz && 3734 codec.clockrate == format.clockrate_hz &&
3734 codec.channels == format.num_channels) { 3735 codec.channels == format.num_channels) {
3735 return static_cast<int>(i); 3736 return rtc::checked_cast<int>(i);
3736 } 3737 }
3737 } 3738 }
3738 return -1; 3739 return -1;
3739 }; 3740 };
3740 3741
3741 // Ensure all supplementary codecs are generated last. Their internal ordering 3742 // Ensure all supplementary codecs are generated last. Their internal ordering
3742 // is not important. 3743 // is not important.
3743 // Without this cast, the comparison turned unsigned and, thus, failed for -1. 3744 // Without this cast, the comparison turned unsigned and, thus, failed for -1.
3744 const int num_specs = static_cast<int>(specs.size()); 3745 const int num_specs = static_cast<int>(specs.size());
3745 EXPECT_GE(find_codec({"cn", 8000, 1}), num_specs); 3746 EXPECT_GE(find_codec({"cn", 8000, 1}), num_specs);
3746 EXPECT_GE(find_codec({"cn", 16000, 1}), num_specs); 3747 EXPECT_GE(find_codec({"cn", 16000, 1}), num_specs);
3747 EXPECT_EQ(find_codec({"cn", 32000, 1}), -1); 3748 EXPECT_EQ(find_codec({"cn", 32000, 1}), -1);
3748 EXPECT_GE(find_codec({"telephone-event", 8000, 1}), num_specs); 3749 EXPECT_GE(find_codec({"telephone-event", 8000, 1}), num_specs);
3749 EXPECT_GE(find_codec({"telephone-event", 16000, 1}), num_specs); 3750 EXPECT_GE(find_codec({"telephone-event", 16000, 1}), num_specs);
3750 EXPECT_GE(find_codec({"telephone-event", 32000, 1}), num_specs); 3751 EXPECT_GE(find_codec({"telephone-event", 32000, 1}), num_specs);
3751 EXPECT_GE(find_codec({"telephone-event", 48000, 1}), num_specs); 3752 EXPECT_GE(find_codec({"telephone-event", 48000, 1}), num_specs);
3752 } 3753 }
OLDNEW
« no previous file with comments | « no previous file | webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory_internal.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698