/[resiprocate]/main/resip/stack/test/testDtmfPayload.cxx
ViewVC logotype

Contents of /main/resip/stack/test/testDtmfPayload.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 11043 - (show annotations) (download)
Wed Mar 19 12:43:41 2014 UTC (5 years, 8 months ago) by Dpocock
File size: 3920 byte(s)
resip/stack: DTMF: access button as an RFC 4733 event code
1 #include "rutil/Logger.hxx"
2 #include "rutil/DataStream.hxx"
3 #include "resip/stack/DtmfPayloadContents.hxx"
4 #include "resip/stack/HeaderFieldValue.hxx"
5 #include "rutil/ParseBuffer.hxx"
6
7 #include <iostream>
8 #include "TestSupport.hxx"
9 #include "tassert.h"
10
11 using namespace resip;
12 using namespace std;
13
14 #define RESIPROCATE_SUBSYSTEM Subsystem::TEST
15
16 int
17 main(int argc, char* argv[])
18 {
19 Log::Level l = Log::Stack;
20
21 if (argc > 1)
22 {
23 switch(*argv[1])
24 {
25 case 'd': l = Log::Debug;
26 break;
27 case 'i': l = Log::Info;
28 break;
29 case 's': l = Log::Stack;
30 break;
31 case 'c': l = Log::Crit;
32 break;
33 }
34
35 }
36
37 Log::initialize(Log::Cout, l, argv[0]);
38 CritLog(<<"Test Driver Starting");
39
40 {
41 Data txt("Signal=5\r\n"
42 "Duration=100\r\n");
43 HeaderFieldValue hfv(txt.data(), txt.size());
44 Mime type("application", "dtmf-relay");
45 DtmfPayloadContents payload(hfv, type);
46
47 assert(payload.dtmfPayload().getButton() == '5');
48 assert(payload.dtmfPayload().getEventCode() == 5);
49 assert(payload.dtmfPayload().getDuration() == 100);
50 }
51
52 {
53 Data txt("Signal=A\r\n"
54 "Duration=150\r\n");
55 HeaderFieldValue hfv(txt.data(), txt.size());
56 Mime type("application", "dtmf-relay");
57 DtmfPayloadContents payload(hfv, type);
58
59 assert(payload.dtmfPayload().getButton() == 'A');
60 assert(payload.dtmfPayload().getEventCode() == 12);
61 assert(payload.dtmfPayload().getDuration() == 150);
62 }
63
64 {
65 Data txt("Signal=a\r\n"
66 "Duration=100\r\n");
67 HeaderFieldValue hfv(txt.data(), txt.size());
68 Mime type("application", "dtmf-relay");
69 try
70 {
71 DtmfPayloadContents payload(hfv, type);
72 char button = payload.dtmfPayload().getButton();
73 ErrLog(<<"Failed to detect a bad DTMF signal");
74 assert(0);
75 }
76 catch (ParseException& ex)
77 {
78 // expected exception because of lowercase 'a'
79 InfoLog(<<"detected the bad DTMF signal correctly");
80 }
81 }
82
83 return 0;
84 }
85
86 /* ====================================================================
87 *
88 * Copyright 2014 Daniel Pocock http://danielpocock.com All rights reserved.
89 *
90 * Redistribution and use in source and binary forms, with or without
91 * modification, are permitted provided that the following conditions
92 * are met:
93 *
94 * 1. Redistributions of source code must retain the above copyright
95 * notice, this list of conditions and the following disclaimer.
96 *
97 * 2. Redistributions in binary form must reproduce the above copyright
98 * notice, this list of conditions and the following disclaimer in
99 * the documentation and/or other materials provided with the
100 * distribution.
101 *
102 * 3. Neither the name of the author(s) nor the names of any contributors
103 * may be used to endorse or promote products derived from this software
104 * without specific prior written permission.
105 *
106 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) AND CONTRIBUTORS "AS IS" AND
107 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
108 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
109 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTORS BE LIABLE
110 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
111 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
112 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
113 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
114 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
115 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
116 * SUCH DAMAGE.
117 *
118 * ====================================================================
119 *
120 *
121 */
122

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27