Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / webrtc / voice_engine / test / auto_test / standard / dtmf_test.cc
1 /*
2  *  Copyright (c) 2011 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
11 #include "webrtc/voice_engine/test/auto_test/fixtures/after_streaming_fixture.h"
12 #include "webrtc/voice_engine/voice_engine_defines.h"
13
14 class DtmfTest : public AfterStreamingFixture {
15  protected:
16   void RunSixteenDtmfEvents(bool out_of_band) {
17     TEST_LOG("Sending telephone events:\n");
18     EXPECT_EQ(0, voe_dtmf_->SetDtmfFeedbackStatus(false));
19
20     for (int i = 0; i < 16; i++) {
21       TEST_LOG("%d ", i);
22       TEST_LOG_FLUSH;
23       EXPECT_EQ(0, voe_dtmf_->SendTelephoneEvent(
24           channel_, i, out_of_band, 160, 10));
25       Sleep(500);
26     }
27     TEST_LOG("\n");
28   }
29 };
30
31 TEST_F(DtmfTest, DtmfFeedbackIsEnabledByDefaultButNotDirectFeedback) {
32   bool dtmf_feedback = false;
33   bool dtmf_direct_feedback = false;
34
35   EXPECT_EQ(0, voe_dtmf_->GetDtmfFeedbackStatus(dtmf_feedback,
36                                                 dtmf_direct_feedback));
37
38   EXPECT_TRUE(dtmf_feedback);
39   EXPECT_FALSE(dtmf_direct_feedback);
40 }
41
42 TEST_F(DtmfTest, ManualSuccessfullySendsInBandTelephoneEvents) {
43   RunSixteenDtmfEvents(false);
44 }
45
46 TEST_F(DtmfTest, ManualSuccessfullySendsOutOfBandTelephoneEvents) {
47   RunSixteenDtmfEvents(true);
48 }
49
50 TEST_F(DtmfTest, TestTwoNonDtmfEvents) {
51   EXPECT_EQ(0, voe_dtmf_->SendTelephoneEvent(channel_, 32, true));
52   EXPECT_EQ(0, voe_dtmf_->SendTelephoneEvent(channel_, 110, true));
53 }
54
55 TEST_F(DtmfTest, ManualCanDisableDtmfPlayoutExceptOnIphone) {
56   TEST_LOG("Disabling DTMF playout (no tone should be heard) \n");
57   EXPECT_EQ(0, voe_dtmf_->SetDtmfPlayoutStatus(channel_, false));
58   EXPECT_EQ(0, voe_dtmf_->SendTelephoneEvent(channel_, 0, true));
59   Sleep(500);
60
61   TEST_LOG("Enabling DTMF playout (tone should be heard) \n");
62   EXPECT_EQ(0, voe_dtmf_->SetDtmfPlayoutStatus(channel_, true));
63   EXPECT_EQ(0, voe_dtmf_->SendTelephoneEvent(channel_, 0, true));
64   Sleep(500);
65 }
66
67 // This test modifies the DTMF payload type from the default 106 to 88
68 // and then runs through 16 DTMF out.of-band events.
69 TEST_F(DtmfTest, ManualCanChangeDtmfPayloadType) {
70   webrtc::CodecInst codec_instance;
71
72   TEST_LOG("Changing DTMF payload type.\n");
73
74   // Start by modifying the receiving side.
75   for (int i = 0; i < voe_codec_->NumOfCodecs(); i++) {
76     EXPECT_EQ(0, voe_codec_->GetCodec(i, codec_instance));
77     if (!_stricmp("telephone-event", codec_instance.plname)) {
78       codec_instance.pltype = 88;  // Use 88 instead of default 106.
79       EXPECT_EQ(0, voe_base_->StopSend(channel_));
80       EXPECT_EQ(0, voe_base_->StopPlayout(channel_));
81       EXPECT_EQ(0, voe_base_->StopReceive(channel_));
82       EXPECT_EQ(0, voe_codec_->SetRecPayloadType(channel_, codec_instance));
83       EXPECT_EQ(0, voe_base_->StartReceive(channel_));
84       EXPECT_EQ(0, voe_base_->StartPlayout(channel_));
85       EXPECT_EQ(0, voe_base_->StartSend(channel_));
86       break;
87     }
88   }
89
90   Sleep(500);
91
92   // Next, we must modify the sending side as well.
93   EXPECT_EQ(0, voe_dtmf_->SetSendTelephoneEventPayloadType(
94       channel_, codec_instance.pltype));
95
96   RunSixteenDtmfEvents(true);
97
98   EXPECT_EQ(0, voe_dtmf_->SetDtmfFeedbackStatus(true, false));
99 }