Source Code Cross Referenced for TestSipHeader2.java in  » 6.0-JDK-Modules » j2me » javax » microedition » sip » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » j2me » javax.microedition.sip 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         *   
0003:         *
0004:         * Copyright  1990-2007 Sun Microsystems, Inc. All Rights Reserved.
0005:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
0006:         * 
0007:         * This program is free software; you can redistribute it and/or
0008:         * modify it under the terms of the GNU General Public License version
0009:         * 2 only, as published by the Free Software Foundation.
0010:         * 
0011:         * This program is distributed in the hope that it will be useful, but
0012:         * WITHOUT ANY WARRANTY; without even the implied warranty of
0013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0014:         * General Public License version 2 for more details (a copy is
0015:         * included at /legal/license.txt).
0016:         * 
0017:         * You should have received a copy of the GNU General Public License
0018:         * version 2 along with this work; if not, write to the Free Software
0019:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
0020:         * 02110-1301 USA
0021:         * 
0022:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
0023:         * Clara, CA 95054 or visit www.sun.com if you need additional
0024:         * information or have any questions.
0025:         */
0026:
0027:        package javax.microedition.sip;
0028:
0029:        import com.sun.midp.i3test.TestCase;
0030:        import com.sun.midp.io.j2me.storage.RandomAccessStream;
0031:        import com.sun.midp.io.j2me.storage.File;
0032:
0033:        import javax.microedition.io.Connector;
0034:        import java.io.IOException;
0035:        import java.io.OutputStream;
0036:
0037:        /**
0038:         * Tests for the SipHeader class.
0039:         *
0040:         * We assume that for a header like
0041:         * <pre>
0042:         * Accept-Language: da, en-gb;q=0.8, en;q=0.7
0043:         * </pre>
0044:         * 3 name-headerValue pairs will be generated by the implementation.
0045:         */
0046:        class THeader {
0047:
0048:            /*
0049:             * structured internal representation
0050:             * Contact: "Mr. Watson" <sip:watson@worcester.bell-telephone.com>;
0051:             *             q=0.7;expires=3600
0052:             *  {{"Contact"},
0053:             *   {": "},
0054:             *   {"\"Mr. Watson\" <sip:watson@worcester.bell-telephone.com>"},
0055:             *   {";"},
0056:             *   {"q","=","0.7"},
0057:             *   {";"},
0058:             *   {"expires=3600",{"\r\n"}
0059:             * };
0060:             *  name       
0061:             *  delim  
0062:             *  value    
0063:             *  delim 
0064:             *  param           
0065:             *  delim  param
0066:             *
0067:             *  hline =  name  delim  value *( delim param )
0068:             *  param = pname pdelim pvalue
0069:             */
0070:            String[][] guts;
0071:
0072:            THeader(String[][] guts0) {
0073:                guts = acopy(guts0);
0074:            }
0075:
0076:            THeader(THeader p) {
0077:                guts = acopy(p.guts);
0078:            }
0079:
0080:            // auxiliary tools, generic stuff
0081:            public static String concata(String[] a) {
0082:                String res = "";
0083:                for (int i = 0; i < a.length; i++) {
0084:                    res = res + a[i];
0085:                }
0086:                return res;
0087:            }
0088:
0089:            public static String concata(String[][] a, int i0, int im) {
0090:                String res = "";
0091:                if (a.length < im) {
0092:                    im = a.length;
0093:                }
0094:                for (int i = i0; i < im; i++) {
0095:                    res = res + concata(a[i]);
0096:                }
0097:                return res;
0098:            }
0099:
0100:            public static String[] acopy(String[] g) {
0101:                String[] res = new String[g.length];
0102:                for (int i = 0; i < g.length; i++) {
0103:                    res[i] = new String(g[i]);
0104:                }
0105:                return res;
0106:            }
0107:
0108:            public static String[][] acopy(String[][] g) {
0109:                String[][] res = new String[g.length][];
0110:                for (int i = 0; i < g.length; i++) {
0111:                    res[i] = acopy(g[i]);
0112:                }
0113:                return res;
0114:            }
0115:
0116:            public static String[][] acopyWithoutDelimAndPrm(String[][] g,
0117:                    int no) {
0118:                String[][] res = new String[g.length - 2][];
0119:                if (0 <= no && no < g.length) {
0120:                    for (int i = 0, j = 0; i < g.length; i++) {
0121:                        if (i != no && i != no - 1) {
0122:                            res[j++] = acopy(g[i]);
0123:                        }
0124:                    }
0125:                    return res;
0126:                } else {
0127:                    return acopy(g);
0128:                }
0129:            }
0130:
0131:            public static String[][] acopyWithDelimAndPrm(String[][] g,
0132:                    String[] delim, String[] prm) {
0133:                String[][] res = new String[g.length + 2][];
0134:                int i, j;
0135:                for (i = 0, j = 0; i < g.length - 1; i++) {
0136:                    res[j++] = acopy(g[i]);
0137:                }
0138:                res[j++] = acopy(delim);
0139:                res[j++] = acopy(prm);
0140:                res[j++] = acopy(g[i++]);
0141:                return res;
0142:            }
0143:
0144:            // read access functions
0145:            // note: even positions for data, odd for delimiters
0146:            public String getName() {
0147:                return guts[0][0];
0148:            }
0149:
0150:            public String getValue() {
0151:                return guts[2][0];
0152:            }
0153:
0154:            public String getHeaderValue() {
0155:                return concata(guts, 2, guts.length - 1);
0156:            }
0157:
0158:            public String toString() {
0159:                return concata(guts, 0, guts.length);
0160:            }
0161:
0162:            public String getPrmNam(int i) {
0163:                /*
0164:                 * myout.println("index: " + i +" => " + ((i + 2) * 2
0165:                 *    +" guts.length: "+guts.length));
0166:                 */
0167:                if ((i + 2) * 2 >= guts.length)
0168:                    return null;
0169:                return guts[(i + 2) * 2][0];
0170:            }
0171:
0172:            public String getPrmVal(int i) {
0173:                return guts[(i + 2) * 2][2];
0174:            }
0175:
0176:            public String[] getPrmWhole(int i) {
0177:                return guts[(i + 2) * 2];
0178:            }
0179:
0180:            public String[] getParameterNames() {
0181:                String[] res = new String[guts.length / 2 - 2];
0182:                for (int i = 0; i < res.length; i++) {
0183:                    res[i] = getPrmNam(i);
0184:                }
0185:                return res;
0186:            }
0187:
0188:            public int findPrmNam(String name) {
0189:
0190:                for (int i = 0, imax = guts.length / 2 - 2; i < imax; i++) {
0191:                    if (name.equals(getPrmNam(i))) {
0192:                        return i;
0193:                    }
0194:                }
0195:                return -1;
0196:            }
0197:
0198:            // write access functions
0199:            // note: even positions for data, odd for delimiters
0200:            public void setName(String n) {
0201:                guts[0][0] = n;
0202:            }
0203:
0204:            public void setValue(String v) {
0205:                guts[2][0] = v;
0206:            }
0207:
0208:            public void setPrmNam(int i, String n) {
0209:                guts[(i + 2) * 2][0] = n;
0210:            }
0211:
0212:            public void setPrmVal(int i, String v) {
0213:                guts[(i + 2) * 2][2] = v;
0214:            }
0215:
0216:            public void setPrmWhole(int i, String[] p) {
0217:                guts[(i + 2) * 2] = p;
0218:            }
0219:
0220:            public void rmvPrm(int i) {
0221:                guts = acopyWithoutDelimAndPrm(guts, (i + 2) * 2);
0222:            }
0223:
0224:            public void appendPrmWhole(String[] prm) {
0225:                guts = acopyWithDelimAndPrm(guts, new String[] { TestSipHeader2
0226:                        .makeDelimiterFor(this ) }, prm);
0227:            }
0228:
0229:            public void setOrAddPrmWhole(String[] prm) {
0230:                int prmN = findPrmNam(prm[0]);
0231:                if (-1 != prmN) {
0232:                    // myout.println("setOrAddPrmWhole: set");
0233:                    setPrmWhole(prmN, prm);
0234:                } else {
0235:                    // myout.println("setOrAddPrmWhole: append");
0236:                    appendPrmWhole(prm);
0237:                }
0238:            }
0239:        }
0240:
0241:        class BlockedTestException extends Exception {
0242:            public BlockedTestException() {
0243:            };
0244:        }
0245:
0246:        class NothingToDoInTestException extends Exception {
0247:            public NothingToDoInTestException() {
0248:            };
0249:        }
0250:
0251:        abstract class TestSipHeader2_constants extends TestCase {
0252:            /** this one should never appear in the report */
0253:            public static final char NOTRUN = '-';
0254:            /** failure happened before the test was run */
0255:            public static final char BLOCKED = 'b';
0256:            /** test failed: wrong data */
0257:            public static final char FAILED = 'f';
0258:            /** test failed because it caused an exception */
0259:            public static final char EXCEPTION = 'X';
0260:            /** there has been nothing to do: not bad */
0261:            public static final char NOTHINGTODO = 'o';
0262:            /** success */
0263:            public static final char SUCCESS = 's';
0264:
0265:            final int nTests = 6;
0266:            final int nSubTests = 31; // not more that # of bits
0267:            final int exceptionAndNoSubTests = nSubTests - 1;
0268:        }
0269:
0270:        public class TestSipHeader2 extends TestSipHeader2_constants {
0271:            /** used as: testResult[firstHeaderN][secondHeaderN][testN] */
0272:            int testN;
0273:            /** used as: testResult[firstHeaderN][secondHeaderN][testN] */
0274:            int firstHeaderN;
0275:            /** used as: testResult[firstHeaderN][secondHeaderN][testN] */
0276:            int secondHeaderN;
0277:            /** used as: testResult[firstHeaderN][secondHeaderN][testN] */
0278:            char[][][] testResult;
0279:            /**
0280:             * a bit vertor. used as: 
0281:             *    failureReason[firstHeaderN][secondHeaderN][testN]
0282:             */
0283:            int[][][] failureReason;
0284:            /** array of test names */
0285:            String[] testName = new String[nTests];
0286:            /** array of subtest names (that is, read access test names) */
0287:            private String[] subTestName = new String[nSubTests];
0288:            /**
0289:             * contains data on which we perform tests.
0290:             */
0291:            String[][][] headerSample = new String[][][] {
0292:                    { { "Accept" }, { ": " }, { "application/sdp" }, { "\r\n" } },
0293:                    { { "Accept" }, { ": " }, { "application/sdp" }, { ";" },
0294:                            { "level", "=", "1" }, { "\r\n" } },
0295:                    { { "Accept" }, { ": " }, { "text/html" }, { "\r\n" } },
0296:                    { { "Accept-Encoding" }, { ": " }, { "gzip" }, { "\r\n" } },
0297:                    { { "Accept-Encoding" }, { ": " }, { "identity" },
0298:                            { "\r\n" } },
0299:                    { { "Accept-Language" }, { ": " }, { "da" }, { "\r\n" } },
0300:                    { { "Accept-Language" }, { ": " }, { "en-gb;q=0.8" },
0301:                            { "\r\n" } },
0302:                    { { "Accept-Language" }, { ": " }, { "en;q=0.7" },
0303:                            { "\r\n" } },
0304:                    { { "Alert-Info" }, { ": " },
0305:                            { "<http://www.example.com/sounds/moo.wav>" },
0306:                            { "\r\n" } },
0307:                    {
0308:                            { "Alert-Info" },
0309:                            { ": " },
0310:                            { "<http://www.freetones.org/vasya-pupkin/imperial.mp3>" },
0311:                            { "\r\n" } },
0312:                    { { "Allow" }, { ": " }, { "INVITE" }, { "\r\n" } },
0313:                    { { "Allow" }, { ": " }, { "ACK" }, { "\r\n" } },
0314:                    {
0315:                            { "Authentication-Info" },
0316:                            { ": " },
0317:                            { "nextnonce", "=",
0318:                                    "\"47364c23432d2e131a5fb210812c\"" },
0319:                            { "\r\n" } },
0320:                    { { "Authentication-Info" }, { ": " },
0321:                            { "rspauth", "=", "\"1234567890\"" }, { "\r\n" } },
0322:                    {
0323:                            { "Authorization" },
0324:                            { ": " },
0325:                            { "Digest" },
0326:                            { " " },
0327:                            { "username=\"Alice\"" },
0328:                            { ", " },
0329:                            { "realm", "=", "\"atlanta.com\"" },
0330:                            { ", \n       " },
0331:                            { "nonce", "=",
0332:                                    "\"84a4cc6f3082121f32b42a2187831a9e\"" },
0333:                            { ", \n       " },
0334:                            { "response", "=",
0335:                                    "\"7587245234b3434cc3412213e5f113a5432\"" },
0336:                            { "\r\n" } },
0337:                    { { "Call-ID" }, { ": " },
0338:                            { "a84b4c76e66710@pc33.atlanta.com" }, { "\r\n" } },
0339:                    {
0340:                            { "Call-ID" },
0341:                            { ": " },
0342:                            { "f81d4fae-7dec-11d0-a765-00a0c91e6bf6@foo.bar.com" },
0343:                            { "\r\n" } },
0344:                    { { "Call-Info" }, { ": " },
0345:                            { "<http://wwww.example.com/alice/photo.jpg>" },
0346:                            { " ;" }, { "purpose", "=", "icon" }, { "\r\n" } },
0347:                    { { "Call-Info" }, { ": " },
0348:                            { "<http://www1.example.com/alice/>" }, { " ;" },
0349:                            { "purpose", "=", "info" }, { "\r\n" } },
0350:                    {
0351:                            { "Contact" },
0352:                            { ": " },
0353:                            { "\"Mr. Watson\" <sip:watson@worcester.bell-telephone.com>" },
0354:                            { ";" }, { "q", "=", "0.7" }, { ";" },
0355:                            { "expires", "=", "3600" }, { "\r\n" } },
0356:                    { { "Contact" }, { ": " },
0357:                            { "<sip:watson@worcester.bell-telephone.com>" },
0358:                            { ";" }, { "q", "=", "0.7" }, { ";" },
0359:                            { "expires", "=", "3600" }, { "\r\n" } },
0360:                    { { "Contact" }, { ": " },
0361:                            { "<sip:alice@pc33.atlanta.com>" }, { "\r\n" } },
0362:                    {
0363:                            { "CONTACT" },
0364:                            { ": " },
0365:                            { "sip:user@host?Subject=foo&Call-Info=<http://www.foo.com>" },
0366:                            { "\r\n" } },
0367:                    { { "CONTACT" }, { ": " }, { "<sip:alice@atlanta.com>" },
0368:                            { ";" }, { "ExPiReS", "=", "3600" }, { "\r\n" } },
0369:                    { { "Content-Disposition" }, { ": " }, { "session" },
0370:                            { "\r\n" } },
0371:                    { { "Content-Disposition" }, { ": " }, { "icon" },
0372:                            { "\r\n" } },
0373:                    { { "Content-Disposition" }, { ": " }, { "session" },
0374:                            { ";" }, { "handling=optional" }, { "\r\n" } },
0375:                    { { "Content-Encoding" }, { ": " }, { "gzip" }, { "\r\n" } },
0376:                    { { "Content-Encoding" }, { ": " }, { "compress" },
0377:                            { "\r\n" } },
0378:                    { { "Content-Encoding" }, { ": " }, { "identity" },
0379:                            { "\r\n" } },
0380:                    { { "Content-Encoding" }, { ": " }, { "deflate" },
0381:                            { "\r\n" } },
0382:                    { { "Content-Language" }, { ": " }, { "fr" }, { "\r\n" } },
0383:                    { { "Content-Language" }, { ": " }, { "ru" }, { "\r\n" } },
0384:                    { { "Content-Length" }, { ": " }, { "142" }, { "\r\n" } },
0385:                    { { "Content-Length" }, { ": " }, { "0" }, { "\r\n" } },
0386:                    { { "Content-Type" }, { ": " }, { "application/sdp" },
0387:                            { "\r\n" } },
0388:                    { { "Content-Type" }, { ": " }, { "image/gif" }, { "\r\n" } },
0389:                    // ?? TODO: is space a delimiter?
0390:                    { { "CSeq" }, { ": " }, { "314159 INVITE" }, { "\r\n" } },
0391:                    { { "CSeq" }, { ": " }, { "63104 OPTIONS" }, { "\r\n" } },
0392:                    { { "Date" }, { ": " },
0393:                            { "Sat, 13 Nov 2010 23:29:00 GMT" }, { "\r\n" } },
0394:                    { { "Date" }, { ": " }, { "Thu, 9 Jun 2005 17:32:21 GMT" },
0395:                            { "\r\n" } },
0396:                    { { "Error-Info" }, { ": " },
0397:                            { "<sip:not-in-service-recording@atlanta.com>" },
0398:                            { "\r\n" } },
0399:                    { { "Error-Info" }, { ": " }, { "<sip:abc@def.gh>" },
0400:                            { "\r\n" } },
0401:                    { { "Expires" }, { ": " }, { "5" }, { "\r\n" } },
0402:                    { { "Expires" }, { ": " }, { "7200" }, { "\r\n" } },
0403:                    { { "From" }, { ": " }, { "Bob <sip:bob@biloxi.com>" },
0404:                            { ";" }, { "tag", "=", "a6c85cf" }, { "\r\n" } },
0405:                    { { "From" }, { ": " },
0406:                            { "Alice <sip:alice@atlanta.com>" }, { ";" },
0407:                            { "tag", "=", "1928301774" }, { "\r\n" } },
0408:                    { { "From" }, { ": " },
0409:                            { "sip:+12125551212@phone2net.com" }, { ";" },
0410:                            { "tag=887s" }, { "\r\n" } },
0411:                    { { "From" }, { ": " },
0412:                            { "Anonymous <sip:c8oqz84zk7z@privacy.org>" },
0413:                            { ";" }, { "tag", "=", "hyh8" }, { "\r\n" } },
0414:                    { { "In-Reply-To" }, { ": " },
0415:                            { "17320@shanghai.chinatel.cn" }, { "\r\n" } },
0416:                    { { "In-Reply-To" }, { ": " },
0417:                            { "70710@saturn.bell-tel.com" }, { "\r\n" } },
0418:                    { { "Max-Forwards" }, { ": " }, { "70" }, { "\r\n" } },
0419:                    { { "Max-Forwards" }, { ": " }, { "65" }, { "\r\n" } },
0420:                    { { "Min-Expires" }, { ": " }, { "60" }, { "\r\n" } },
0421:                    { { "Min-Expires" }, { ": " }, { "82" }, { "\r\n" } },
0422:                    { { "Organization" }, { ": " }, { " Boxes by Bob" },
0423:                            { "\r\n" } },
0424:                    { { "Organization" }, { ": " },
0425:                            { " gov.nist, whatever it could mean..." },
0426:                            { "\r\n" } },
0427:                    { { "Priority" }, { ": " }, { "emergency" }, { "\r\n" } },
0428:                    { { "Priority" }, { ": " }, { "non-urgent" }, { "\r\n" } },
0429:                    { { "Proxy-Authenticate" }, { ": " }, { "Digest" },
0430:                            { " " }, { "realm=\"atlanta.com\"" }, { ", " },
0431:                            { "domain=\"sip:ss1.carrier.com\"" }, { ", " },
0432:                            { "qop=\"auth\"" }, { ", " },
0433:                            { "nonce=\"e84f1cce41e6cbe5aea9c8e88d35a\"" },
0434:                            { ", " }, { "opaque=\"\"" }, { ", " },
0435:                            { "stale=FALSE" }, { ", " }, { "algorithm=MD5" },
0436:                            { "\r\n" } },
0437:                    //
0438:                    { { "Proxy-Authorization" }, { ": " }, { "Digest" },
0439:                            { " " }, { "username=\"Alice\"" }, { ", " },
0440:                            { "realm=\"otlonto.com\"" }, { ", " },
0441:                            { "nonce=\"c60f3082ee1212b402a21831ae\"" },
0442:                            { ", " },
0443:                            { "response=\"245f23415f11432b3434341c022\"" },
0444:                            { "\r\n" } },
0445:
0446:                    { { "Proxy-Require" }, { ": " }, { "foo" }, { "\r\n" } },
0447:                    { { "Proxy-Require" }, { ": " }, { "bar" }
0448:                    // , {"; "}, {"par", "=", "val"}
0449:                    },
0450:                    { { "Record-Route" }, { ": " },
0451:                            { "<sip:p4.domain.com;lr>" }, { "\r\n" } },
0452:                    { { "Record-Route" }, { ": " }, { "<sip:p3.middle.com>" },
0453:                            { "\r\n" } },
0454:                    { { "Reply-To" }, { ": " },
0455:                            { "Boob <sip:boob@beloxi.com>" }, { "\r\n" } },
0456:                    { { "Reply-To" }, { ": " },
0457:                            { "Todd <sip:todd@biloxi.com>" }, { "\r\n" } },
0458:                    { { "Require" }, { ": " }, { "100rel" }, { "\r\n" } },
0459:                    { { "Require" }, { ": " }, { "glitchware-purse" },
0460:                            { "\r\n" } },
0461:                    { { "Retry-After" }, { ": " }, { "18000" }, { ";" },
0462:                            { "duration", "=", "3600" }, { "\r\n" } },
0463:                    { { "Retry-After" }, { ": " }, { "120" },
0464:                            { " (I'm in a meeting)" }, { "\r\n" } },
0465:                    { { "Route" }, { ": " }, { "<sip:alice@atlanta.com>" },
0466:                            { "\r\n" } },
0467:                    { { "Route" }, { ": " },
0468:                            { "<sip:UserB@there.com;maddr=ss2.wcom.com>" },
0469:                            { "\r\n" } },
0470:                    { { "Server" }, { ": " }, { "HomeServer v2" }, { "\r\n" } },
0471:                    { { "Server" }, { ": " },
0472:                            { "GlitchWare Ink Server v.1.0" }, { "\r\n" } },
0473:                    //        {{"Route"}, {": "}, 
0474:                    //            {"<sip:alice@atlanta.com>"}, {", "}, 
0475:                    //            {"<sip:bob@biloxi.com>"}, {", \n             "}, 
0476:                    //            {"<sip:carol@chicago.com>"}, {"\r\n"}}, 
0477:                    {
0478:                            { "Subject" },
0479:                            { ": " },
0480:                            { "I know you're there, pick up the phone and talk to me!" },
0481:                            { "\r\n" } },
0482:                    { { "Subject" }, { ": " }, { "Weekend plans" }, { "\r\n" } },
0483:                    { { "Supported" }, { ": " }, { "100rel" }, { "\r\n" } },
0484:                    { { "Supported" }, { ": " }, { "ggg" }, { "\r\n" } },
0485:                    { { "Timestamp" }, { ": " }, { "54" }, { "\r\n" } },
0486:                    { { "Timestamp" }, { ": " }, { "102" }, { "\r\n" } },
0487:                    { { "To" }, { ": " }, { "Bob <sip:bob@biloxi.com>" },
0488:                            { "\r\n" } },
0489:                    { { "To" }, { ": " }, { "Todd <sip:todd@biloxi.com>" },
0490:                            { ";" }, { "tag", "=", "a6c85cf" }, { "\r\n" } },
0491:                    { { "Unsupported" }, { ": " }, { "100rel" }, { "\r\n" } },
0492:                    { { "Unsupported" }, { ": " }, { "mumble-dumble" },
0493:                            { "\r\n" } },
0494:                    { { "User-Agent" }, { ": " }, { "Softphone Beta1.5" },
0495:                            { "\r\n" } },
0496:                    { { "User-Agent" }, { ": " }, { "yes-kia car talk" },
0497:                            { "\r\n" } },
0498:                    { { "Via" }, { ": " }, { "SIP/2.0/UDP pc33.atlanta.com" },
0499:                            { ";" }, { "branch", "=", "z9hG4bKhjhs8ass877" },
0500:                            { "\r\n" } },
0501:                    { { "Via" }, { ": " },
0502:                            { "SIP/2.0/UDP bigbox3.site3.atlanta.com" },
0503:                            { "\n         ;" },
0504:                            { "branch", "=", "z9hG4bK77ef4c2312983.1" },
0505:                            { ";" }, { "received", "=", "192.0.2.2" },
0506:                            { "\r\n" } },
0507:                    { { "Warning" }, { ": " },
0508:                            { "370 devnull \"Choose a bigger pipe\"" },
0509:                            { "\r\n" } },
0510:                    {
0511:                            { "Warning" },
0512:                            { ": " },
0513:                            { "300 isi.edu \"Incompatible network protocol\"" },
0514:                            { "\r\n" } },
0515:                    { { "WWW-Authenticate" }, { ": " }, { "Digest" }, { " " },
0516:                            { "realm=\"atlanta.com\"" }, { ", " },
0517:                            { "domain=\"sip:boxesbybob.com\"" }, { ", " },
0518:                            { "qop=\"auth\"" }, { ", " },
0519:                            { "nonce=\"f84f1cec41e6cbe5aea9c8e88d359\"" },
0520:                            { ", " }, { "opaque=\"\"" }, { ", " },
0521:                            { "stale=FALSE" }, { ", " }, { "algorithm=MD5" },
0522:                            { "\r\n" } },
0523:                    // Extension headers
0524:                    { { "Asd" }, { ": " }, { "fghjkl" }, { "; " },
0525:                            { "qwe", "=", "rty" }, { "; " },
0526:                            { "zxc", "=", "vbn" }, { "\r\n" } },
0527:                    { { "Zxcv" }, { ": " }, { "bnm" }, { "\r\n" } },
0528:                    { { "Qwe" }, { ": " }, { "rty" }, { "; " },
0529:                            { "ui", "=", "op89" }, { "; " },
0530:                            { "zx", "=", "cvb" }, { "; " },
0531:                            { "nm", "=", "jhg-kl-09" }, { "\r\n" } },
0532:            // */
0533:            };
0534:
0535:            // auxiliary tools, specific stuff
0536:            public static String makeDelimiterFor(THeader h) {
0537:                String headerName = h.getName();
0538:                String res = "; ";
0539:                if (headerName == "WWW-Authenticate"
0540:                        || headerName == "Proxy-Authenticate"
0541:                        || headerName == "Proxy-Authorization"
0542:                        || headerName == "Authorization") {
0543:                    res = ", ";
0544:                    // TODO: IIRC the 1st delimiter is space while the 2nd one is comma
0545:                }
0546:                return res;
0547:            }
0548:
0549:            /**
0550:             * modify the string so that it looks good in the log (replace
0551:             * CR/LF by 'R' and 'N')
0552:             * @param s the string to be print-encoded
0553:             * @return the modified string
0554:             */
0555:            static String prtEncode(String s) {
0556:                return s.replace('\r', 'R').replace('\n', 'N');
0557:            }
0558:
0559:            /**
0560:             * extract the test name from the class name. The class name has
0561:             * the form ...blah..blah...Tester_XYZ, where XYZ is the test name.
0562:             * @param s class name
0563:             * @return test name
0564:             */
0565:            static String className2testName(String s) {
0566:                return s.substring(s.lastIndexOf('_') + 1);
0567:                // substring index = 0 if -1 is returned
0568:            }
0569:
0570:            public void linebreak() {
0571:                // if (verbose)
0572:                myout
0573:                        .println("=== 1st, 2nd:"
0574:                                + firstHeaderN
0575:                                + ", "
0576:                                + secondHeaderN
0577:                                + " ====================================================");
0578:            }
0579:
0580:            /**
0581:             * Print the test subtitle
0582:             *
0583:             * @param s descriptive text
0584:             * @param t the first THeader that contains data that get used and,
0585:             *  probably, modified
0586:             * @param n the second THeader that serves as a source of data that 
0587:             * replace data taken from the first THeader
0588:             */
0589:            /*
0590:             * public void testing(String s, THeader t, THeader n)q {
0591:             *    myout.println("### testing " + s +" '" + prtEncode(t.toString())
0592:             *            + "' '" + prtEncode(n.toString()) + "'");
0593:             * }
0594:             */
0595:
0596:            /**
0597:             * If got and expected do not match, set
0598:             * testResult[firstHeaderN][secondHeaderN][testN] to FAILED
0599:             *
0600:             * @param subTestN subtest number
0601:             * @param got the obtained string (gets compared to <code>expected</code>)
0602:             * @param expected the expected string
0603:             * @param shortDescr
0604:             * @param moreDescr some text for human readability
0605:             */
0606:            public void expect(int subTestN, String got, String expected,
0607:                    String shortDescr, String moreDescr) {
0608:                if (null == subTestName[subTestN]) {
0609:                    subTestName[subTestN] = shortDescr;
0610:                }
0611:                assertEquals("[" + shortDescr + "]" + "{" + moreDescr + "}",
0612:                        expected, got);
0613:                if (got == null ? expected == null : got.equals(expected)) {
0614:                    //            myout.println("passed: "+subTestN+" "+description);
0615:                } else {
0616:                    //  myout.println( "*** error at subtest "
0617:                    //                 + subTestN + " " + description +
0618:                    //                 " \nexpected: '" + expected +
0619:                    //                 "'\nobtained: '" + got + "'");
0620:                    testResult[firstHeaderN][secondHeaderN][testN] = FAILED;
0621:                    recordFailureReason(subTestN);
0622:                }
0623:            }
0624:
0625:            /**
0626:             * remembers which sub test has failed
0627:             * @param subTestNum
0628:             */
0629:            void recordFailureReason(int subTestNum) {
0630:                failureReason[firstHeaderN][secondHeaderN][testN] |= 1 << subTestNum;
0631:                /*
0632:                 * if (null == failureReason[firstHeaderN][secondHeaderN][testN]) {
0633:                 *    failureReason[firstHeaderN][secondHeaderN][testN] += 
0634:                 *              testName[testN];
0635:                 *  } else {
0636:                 *    failureReason[firstHeaderN][secondHeaderN][testN] += 
0637:                 *        " " + testName[testN];
0638:                 *  }
0639:                 */
0640:            }
0641:
0642:            /**
0643:             * convert a failure reason represented as a bit vector to a
0644:             * human-readable string with names of failed tests.
0645:             * @param fr failure reason
0646:             * @return
0647:             */
0648:            String failureReasonToString(int fr) {
0649:                String res = "";
0650:                for (int i = 0; i < nSubTests; i++) {
0651:                    if (0 != (fr & (1 << i))) {
0652:                        if (res.equals("")) {
0653:                            res = subTestName[i];
0654:                        } else {
0655:                            res += " " + subTestName[i];
0656:                        }
0657:                    }
0658:                }
0659:                if ("".equals(res))
0660:                    res = "OK";
0661:                // if (fr != 0) res += " " + Integer.toHexString(fr);
0662:                return res;
0663:            }
0664:
0665:            /**
0666:             * an auxiliary function.
0667:             * if ctl is -1 (specifies the whole range), return ifrange, else
0668:             * return ifexact.
0669:             * @param ctl
0670:             * @param ifrange
0671:             * @param ifexact
0672:             * @return
0673:             */
0674:            private int choose(int ctl, int ifrange, int ifexact) {
0675:                return ctl == -1 ? ifrange : ifexact;
0676:            }
0677:
0678:            /**
0679:             * return failure reasons encountered while running the specified test(s).
0680:             * @param fhn first header number, -1 for the whole range
0681:             * @param shn second header number, -1 for the whole range
0682:             * @param tn test number, -1 for the whole range
0683:             * @return
0684:             */
0685:            int getFailureReasons(int fhn, int shn, int tn) {
0686:                // System.out.println("getFailureReasons(" + fhn + ", " 
0687:                // + shn + ", " + tn + ")");
0688:
0689:                int cumulativeFailureReason = 0;
0690:                int nHeaderSamples = headerSample.length;
0691:                for (int firstHeaderN = choose(fhn, 0, fhn), firstHeaderNBound = choose(
0692:                        fhn, nHeaderSamples, fhn + 1); firstHeaderN < firstHeaderNBound; firstHeaderN++) {
0693:                    for (int secondHeaderN = choose(shn, 0, shn), secondHeaderNBound = choose(
0694:                            shn, nHeaderSamples, shn + 1); secondHeaderN < secondHeaderNBound; secondHeaderN++) {
0695:                        for (int testN = choose(tn, 0, tn), testNBound = choose(
0696:                                tn, nTests, tn + 1); testN < testNBound; testN++) {
0697:                            /*
0698:                             * System.out.print("indices: " + firstHeaderN + " " 
0699:                             *    + secondHeaderN + " " + testN);
0700:                             * System.out.print(" bounds : " + firstHeaderNBound + " " 
0701:                             *    + secondHeaderNBound + " " + testNBound);
0702:                             * System.out.print(" reason:" 
0703:                             *    + failureReason[firstHeaderN][secondHeaderN][testN]
0704:                             *    + "\n");
0705:                             */
0706:                            cumulativeFailureReason |= failureReason[firstHeaderN][secondHeaderN][testN];
0707:                        }
0708:                    }
0709:                }
0710:                return cumulativeFailureReason;
0711:            }
0712:
0713:            /**
0714:             * Throw a BlockedTestException if the test has failed at the
0715:             * pre-requisite stage. Why: we may discover a failure before
0716:             * we actually start the test, and we want such cases to be
0717:             * marked separately.
0718:             * Reads testResult[firstHeaderN][secondHeaderN][testN].
0719:             * @throws BlockedTestException
0720:             */
0721:            public void failureMeansBlocked() throws BlockedTestException {
0722:                // myout.println("failureMeansBlocked():");
0723:                if (testResult[firstHeaderN][secondHeaderN][testN] != NOTRUN) {
0724:                    // myout.println("failureMeansBlocked() yes!!!");
0725:                    // testResult[firstHeaderN][secondHeaderN][testN] = BLOCKED;
0726:                    throw new BlockedTestException();
0727:                }
0728:            }
0729:
0730:            /**
0731:             * same as expect, but for String arrays
0732:             * @param subTestN
0733:             * @param got
0734:             * @param expected
0735:             * @param shortDescr
0736:             * @param moreDescr
0737:             */
0738:            public void expecta(int subTestN, String[] got, String[] expected,
0739:                    String shortDescr, String moreDescr) {
0740:                // myout.println("areEqual(got, expected) = " 
0741:                //    + areEqual(got, expected));
0742:                if (null == subTestName[subTestN]) {
0743:                    subTestName[subTestN] = shortDescr;
0744:                }
0745:
0746:                if (!areEqual(got, expected)) {
0747:                    /*
0748:                     * DEBUG:
0749:                     * String msg = "*** error at subtest " + subTestN
0750:                     * + " " + shortDescr + moreDescr
0751:                     * + " \nexpected arr: ";
0752:                     * msg += stringizeStrArr(expected);
0753:                     * msg += "\nobtained arr: ";
0754:                     * msg += stringizeStrArr(got);
0755:                     * fail(msg);
0756:                     */
0757:                    fail(shortDescr);
0758:                } else {
0759:                    assertTrue(shortDescr + moreDescr, true);
0760:                    //  myout.println("passed: "+subTestN+" "+description);
0761:                }
0762:            }
0763:
0764:            /**
0765:             * compare two string arrays
0766:             * @param a
0767:             * @param b
0768:             * @return true if they are equal
0769:             */
0770:            static boolean areEqual(String[] a, String[] b) {
0771:                if (a == b) {
0772:                    return true;
0773:                }
0774:                if (a == null || b == null) {
0775:                    return false;
0776:                }
0777:                if (a.length != b.length) {
0778:                    return false;
0779:                }
0780:                for (int i = 0, len = a.length; i < len; i++) {
0781:                    if (!a[i].equals(b[i])) {
0782:                        return false;
0783:                    }
0784:                }
0785:                return true;
0786:            }
0787:
0788:            /**
0789:             * print a string array to Syatem.out
0790:             * @param a
0791:             */
0792:            void printStrArr(String[] a) {
0793:                myout.print("[" + a.length + "]" + "{");
0794:                for (int i = 0, len = a.length; i < len; i++) {
0795:                    myout.print("'" + a[i] + "' ");
0796:                }
0797:                myout.print("}");
0798:            }
0799:
0800:            /**
0801:             * convert a string array to string
0802:             * @param a
0803:             */
0804:            static String stringizeStrArr(String[] a) {
0805:                String res = "";
0806:                res = "[" + a.length + "]" + "{";
0807:                for (int i = 0, len = a.length; i < len; i++) {
0808:                    res += "'" + a[i] + "' ";
0809:                }
0810:                res += "}";
0811:                return res;
0812:            }
0813:
0814:            /**
0815:             * print a string array to Syatem.out, and perform a carriage return
0816:             * @param a
0817:             */
0818:            void printlnStrArr(String[] a) {
0819:                printStrArr(a);
0820:                myout.print("\n");
0821:            }
0822:
0823:            /**
0824:             * Compare data in the SipHeader h to the data in the THeader t,
0825:             * and modify testResult[firstHeaderN][secondHeaderN][testN] accordingly.
0826:             * Calls expect().
0827:             *
0828:             * This function is used first to verify the read access functions,
0829:             * and then to verify the results of write access functions.
0830:             * @param h
0831:             * @param t
0832:             * @param descr
0833:             */
0834:            public void verifyOutputs(SipHeader h, THeader t, String descr) {
0835:                /*
0836:                 *  String args = " SipH='" + prtEncode(h.toString())
0837:                 *      + "' TH='" + prtEncode(t.toString()) + "'";
0838:                 */
0839:                String args = " '" + prtEncode(t.toString()) + "'";
0840:                try {
0841:                    expect(1, h.getName(), t.getName(), "getName", args);
0842:                } catch (Throwable th) {
0843:                    expect(1, "**EXCEPTION**", t.getName(), "getName", args);
0844:                }
0845:                try {
0846:                    expect(2, h.getHeaderValue(), t.getHeaderValue(),
0847:                            "getHeaderValue", args);
0848:                } catch (Throwable th) {
0849:                    expect(2, "**EXCEPTION**", t.getHeaderValue(),
0850:                            "getHeaderValue", args);
0851:                }
0852:                try {
0853:                    expect(3, h.getValue(), t.getValue(), "getValue", args);
0854:                } catch (Throwable th) {
0855:                    expect(3, "**EXCEPTION**", t.getValue(), "getValue", args);
0856:                }
0857:                try {
0858:                    expect(4, h.toString(), t.toString(), "toString", args);
0859:                } catch (Throwable th) {
0860:                    expect(4, "**EXCEPTION**", t.toString(), "toString", args);
0861:                }
0862:                try {
0863:                    expecta(5, h.getParameterNames(), t.getParameterNames(),
0864:                            "getParameterNames", args);
0865:                } catch (Throwable th) {
0866:                    expecta(5, new String[] { "**EXCEPTION**" }, t
0867:                            .getParameterNames(), "getParameterNames", args);
0868:                }
0869:                for (int i = 0; i < 9; i++) {
0870:                    // myout.println("getParameterNames i:" + i);
0871:                    if (t.getPrmNam(i) != null) {
0872:                        try {
0873:                            expect(10 + i, h.getParameter(t.getPrmNam(i)), t
0874:                                    .getPrmVal(i), "getParameter#" + i, args);
0875:                        } catch (Throwable th) {
0876:                            expect(10 + i, "**EXCEPTION**", t.getPrmVal(i),
0877:                                    "getParameter#" + i, args);
0878:                        }
0879:                    }
0880:                }
0881:                //	expect(1,h., t.);
0882:                //	expect(1,h., t.);
0883:                //	expect(1,h., t.);
0884:            }
0885:
0886:            /**
0887:             * Common functionality for write function tester classes.
0888:             */
0889:            abstract class Tester {
0890:                /**
0891:                 * a constructor that does nothing
0892:                 * (esp. in view of that there isn't any data)
0893:                 */
0894:                public Tester() {
0895:                }
0896:
0897:                /**
0898:                 * diagnostic actions to be performed when an exception happens
0899:                 * @param t
0900:                 * @param name
0901:                 */
0902:                void onExc(Throwable t, String name) {
0903:                    myout.println("\n***{{ exception while testing " + name
0904:                            + "\n" + t + "\n}}***");
0905:                    t.printStackTrace();
0906:                    recordFailureReason(exceptionAndNoSubTests);
0907:                    if (null == subTestName[exceptionAndNoSubTests]) {
0908:                        subTestName[exceptionAndNoSubTests] = "EXCEPTION";
0909:                    }
0910:                }
0911:
0912:                /**
0913:                 * The framework function. Calls run() that gets overridden
0914:                 * in the derived classes.
0915:                 * @param t the first THeader that contains data that get used
0916:                 *           and, probably, modified
0917:                 * @param n the second THeader that serves as a source of data
0918:                 *           that replace data taken from the first THeader
0919:                 * @param descr0 test description: which arguments
0920:                 */
0921:                void test(THeader t, THeader n, String descr0) {
0922:                    testResult[firstHeaderN][secondHeaderN][testN] = NOTRUN;
0923:                    if (testName[testN] == null) {
0924:                        testName[testN] = className2testName(this .getClass()
0925:                                .getName());
0926:                    }
0927:                    String name = testName[testN];
0928:                    String descr = name + " " + descr0;
0929:                    declare(descr);
0930:                    // testing(name, t, n);
0931:                    try {
0932:                        doTest(t, n, name + " " + descr);
0933:                        /*
0934:                         * myout.println("%%% successful run: "
0935:                         *    + testResult[firstHeaderN][secondHeaderN][testN]);
0936:                         */
0937:                        if (testResult[firstHeaderN][secondHeaderN][testN] == NOTRUN) {
0938:                            // still '-'; not 'f', and in fact no exception
0939:                            // has been there
0940:                            testResult[firstHeaderN][secondHeaderN][testN] = SUCCESS;
0941:                        }
0942:                    } catch (BlockedTestException bte) {
0943:                        testResult[firstHeaderN][secondHeaderN][testN] = BLOCKED;
0944:                        /*
0945:                         * myout.println("%%% blocked test: " 
0946:                         *    + testResult[firstHeaderN][secondHeaderN][testN]);
0947:                         */
0948:                        fail(descr + "blocked");
0949:                    } catch (NothingToDoInTestException ntdite) {
0950:                        testResult[firstHeaderN][secondHeaderN][testN] = NOTHINGTODO;
0951:                        /*
0952:                         * myout.println("%%% nothing to do: "
0953:                         *    + testResult[firstHeaderN][secondHeaderN][testN]);
0954:                         */
0955:                        assertTrue(descr + "nothing to do", true);
0956:                    } catch (Throwable tt) {
0957:                        testResult[firstHeaderN][secondHeaderN][testN] = EXCEPTION;
0958:                        /*
0959:                         * myout.println("%%% unsuccessful run: "
0960:                         *    + testResult[firstHeaderN][secondHeaderN][testN]);
0961:                         */
0962:                        fail(descr + "exception");
0963:                        onExc(tt, name);
0964:                    }
0965:                }
0966:
0967:                /**
0968:                 * run the test within the test() framework function.
0969:                 * @param t the first THeader that contains data that get used and,
0970:                 *  probably, modified
0971:                 * @param n the second THeader that serves as a source of data that
0972:                 * replace data taken from the first THeader
0973:                 * @param descr
0974:                 * @throws BlockedTestException
0975:                 */
0976:                abstract void doTest(THeader t, THeader n, String descr)
0977:                        throws BlockedTestException, NothingToDoInTestException;
0978:            }
0979:
0980:            class Tester_construct extends Tester {
0981:                public Tester_construct() {
0982:                }
0983:
0984:                void doTest(THeader t, THeader n, String descr)
0985:                        throws BlockedTestException {
0986:                    /*
0987:                     * myout.println("Creating # " + t.getName() + " # " 
0988:                     *     + t.getHeaderValue() + " #"); 
0989:                     */
0990:                    SipHeader s = new SipHeader(t.getName(), t.getHeaderValue());
0991:                    verifyOutputs(s, t, descr);
0992:                }
0993:            }
0994:
0995:            class Tester_constructWithPrm extends Tester_construct {
0996:                String[] param1 = { "xprm1", "=", "Value1" };
0997:                String[] param2 = { "xprm2-pi", "=", "3.141592653589793238" };
0998:                String[] param3 = { "xprm3-text", "=",
0999:                        "\"And his sister's weird, she drives a lorry\"" };
1000:
1001:                public Tester_constructWithPrm() {
1002:                }
1003:
1004:                void test(THeader t, THeader n, String descr) {
1005:                    THeader tt = new THeader(t);
1006:                    tt.appendPrmWhole(param1);
1007:                    tt.appendPrmWhole(param2);
1008:                    tt.appendPrmWhole(param3);
1009:                    super .test(tt, n, descr);
1010:                }
1011:            }
1012:
1013:            class Tester_setName extends Tester {
1014:                public Tester_setName() {
1015:                }
1016:
1017:                void doTest(THeader t, THeader n, String descr)
1018:                        throws BlockedTestException {
1019:                    /*
1020:                     * myout.println("Test " + testN + " Creating # " + t.getName() 
1021:                     *   + " # " + t.getHeaderValue() + " #"); 
1022:                     */
1023:                    SipHeader s = new SipHeader(t.getName(), t.getHeaderValue());
1024:                    verifyOutputs(s, t, descr);
1025:                    failureMeansBlocked();
1026:
1027:                    THeader m = new THeader(t);
1028:                    m.setName(n.getName());
1029:
1030:                    s.setName(n.getName());
1031:                    verifyOutputs(s, m, descr);
1032:                }
1033:            }
1034:
1035:            class Tester_setValue extends Tester {
1036:                public Tester_setValue() {
1037:                }
1038:
1039:                void doTest(THeader t, THeader n, String descr)
1040:                        throws BlockedTestException {
1041:                    SipHeader s = new SipHeader(t.getName(), t.getHeaderValue());
1042:                    verifyOutputs(s, t, descr);
1043:                    failureMeansBlocked();
1044:
1045:                    THeader m = new THeader(t);
1046:                    /*
1047:                     * myout.println("s,m before: $" + prtEncode(s.toString()) + "$" 
1048:                     *    + prtEncode(m.toString()) + "$"); 
1049:                     * myout.println("setValue: $"
1050:                     *    + n.getValue() + "$"); 
1051:                     */
1052:                    m.setValue(n.getValue());
1053:                    s.setValue(n.getValue());
1054:
1055:                    /*
1056:                     *  myout.println("s,m after : $" + prtEncode(s.toString())
1057:                     *     + "$" + prtEncode(m.toString()) + "$");
1058:                     */
1059:                    verifyOutputs(s, m, descr);
1060:                }
1061:            }
1062:
1063:            class Tester_removeParameter extends Tester {
1064:                public Tester_removeParameter() {
1065:                }
1066:
1067:                void doTest(THeader t, THeader n, String descr)
1068:                        throws BlockedTestException, NothingToDoInTestException {
1069:                    String[] prm = n.getParameterNames();
1070:                    // printStrArr(prm);
1071:                    if (0 == prm.length) {
1072:                        // myout.println("nothing to do");
1073:                        throw new NothingToDoInTestException();
1074:                    }
1075:
1076:                    for (int i = 0; i < prm.length; i++) {
1077:                        SipHeader s = new SipHeader(t.getName(), t
1078:                                .getHeaderValue());
1079:                        THeader m = new THeader(t);
1080:                        verifyOutputs(s, m, descr);
1081:                        failureMeansBlocked();
1082:
1083:                        //  myout.println("s,m before: $" + s + "$" + m + "$");
1084:                        m.rmvPrm(i);
1085:                        s.removeParameter(t.getPrmNam(i));
1086:
1087:                        // myout.println("s,m after : $" + s + "$" + m + "$");
1088:                        verifyOutputs(s, m, descr);
1089:                        if (testResult[firstHeaderN][secondHeaderN][testN] != NOTRUN) {
1090:                            //   myout.println("s,m already wrong, exiting test");
1091:                            break;
1092:                        }
1093:                    }
1094:                }
1095:            }
1096:
1097:            class Tester_setParameter extends Tester {
1098:                public Tester_setParameter() {
1099:                }
1100:
1101:                void doTest(THeader t, THeader n, String descr)
1102:                        throws BlockedTestException, NothingToDoInTestException {
1103:                    String[] prm = n.getParameterNames();
1104:                    // printStrArr(prm);
1105:                    if (0 == prm.length) {
1106:                        // myout.println("nothing to do");
1107:                        throw new NothingToDoInTestException();
1108:                    }
1109:                    for (int i = 0; i < prm.length; i++) {
1110:                        SipHeader s = new SipHeader(t.getName(), t
1111:                                .getHeaderValue());
1112:                        THeader m = new THeader(t);
1113:                        verifyOutputs(s, m, descr);
1114:                        failureMeansBlocked();
1115:
1116:                        // myout.println("s,m before: !" + s + "!" + m + "!");
1117:                        m.setOrAddPrmWhole(n.getPrmWhole(i));
1118:                        s.setParameter(n.getPrmNam(i), n.getPrmVal(i));
1119:
1120:                        // myout.println("s,m after : !"+s+"!"+m+"!");
1121:                        verifyOutputs(s, m, descr);
1122:                        if (testResult[firstHeaderN][secondHeaderN][testN] != NOTRUN) {
1123:                            //  myout.println("s,m already wrong, exiting test");
1124:                            break;
1125:                        }
1126:                    }
1127:                }
1128:            }
1129:
1130:            /**
1131:             * Run all tests with the arguments t and n
1132:             * @param t specifies the header that gets constructed and modified
1133:             * @param n a header that serves as a data source for modifications
1134:             * @param descr text description of arguments t and n
1135:             */
1136:            public void verifyAll(THeader t, THeader n, String descr) {
1137:                testN = 0;
1138:                new Tester_construct().test(t, n, descr);
1139:                testN++;
1140:                new Tester_constructWithPrm().test(t, n, descr);
1141:                testN++;
1142:                new Tester_setName().test(t, n, descr);
1143:                testN++;
1144:                new Tester_setValue().test(t, n, descr);
1145:                testN++;
1146:                new Tester_removeParameter().test(t, n, descr);
1147:                testN++;
1148:                new Tester_setParameter().test(t, n, descr);
1149:                testN++;
1150:                if (testN != nTests) {
1151:                    throw new RuntimeException("mismatch in # of tests");
1152:                }
1153:            }
1154:
1155:            /**
1156:             * Body of the test 1.
1157:             *
1158:             * Test constructors of SipAddress class.
1159:             */
1160:            void Test1() {
1161:                for (int i = 0; i < headerSample.length; i++) {
1162:                    for (int j = 0; j < headerSample.length; j++) {
1163:                        firstHeaderN = i;
1164:                        secondHeaderN = j;
1165:                        linebreak();
1166:                        THeader t = new THeader(headerSample[i]);
1167:                        THeader n = new THeader(headerSample[j]);
1168:                        /*
1169:                         * DEBUG:
1170:                         * String argsDescr = "\nwithHdr: '"
1171:                         *  + prtEncode(n.toString()) 
1172:                         *  + "' (" + i + ")\ndataSrc: '"
1173:                         *  + prtEncode(t.toString()) 
1174:                         *  + "' (" + j +")\n";
1175:                         */
1176:                        String argsDescr = "test1";
1177:                        verifyAll(t, n, argsDescr);
1178:                    }
1179:                }
1180:            }
1181:
1182:            /*
1183:             *    void Test2() {
1184:             *        RandomAccessStream ras  = new RandomAccessStream();
1185:             *        try {
1186:             *            ras.connect("test.log",Connector.WRITE);
1187:             *            OutputStream os=ras.openOutputStream();
1188:             *            os.write("testing log".getBytes());
1189:             *            os.close();
1190:             *            ras.disconnect();
1191:             *        } catch (IOException e) {
1192:             *            e.printStackTrace();
1193:             *        }
1194:             *    }
1195:             */
1196:
1197:            MyOut myout = new MyOut();
1198:
1199:            class MyOut {
1200:                RandomAccessStream ras;
1201:                OutputStream os;
1202:                public static final String fileName = "funcmap.txt";
1203:
1204:                void init() {
1205:                    ras = new RandomAccessStream();
1206:                    try {
1207:                        File fs = new File();
1208:                        if (fs.exists(fileName)) {
1209:                            fs.delete(fileName);
1210:                        }
1211:                    } catch (IOException e) {
1212:                        System.err
1213:                                .print("problems when trying to delete old log file: "
1214:                                        + fileName);
1215:                    }
1216:                    try {
1217:                        ras.connect(fileName, Connector.WRITE);
1218:                        os = ras.openOutputStream();
1219:                    } catch (IOException e) {
1220:                        System.err.print("could not open log");
1221:                    }
1222:                }
1223:
1224:                void windup() {
1225:                    try {
1226:                        os.close();
1227:                        ras.disconnect();
1228:                    } catch (IOException e) {
1229:                        System.err.print("could not close log");
1230:                    }
1231:                }
1232:
1233:                void print(String s) {
1234:                    try {
1235:                        os.write(s.getBytes());
1236:                    } catch (IOException e) {
1237:                        System.err.print("could not write to log");
1238:                    }
1239:                }
1240:
1241:                void print(char c) {
1242:                    try {
1243:                        os.write(c);
1244:                    } catch (IOException e) {
1245:                        System.err.print("could not write to log");
1246:                    }
1247:                }
1248:
1249:                void println(String s) {
1250:                    print(s + "\n");
1251:                }
1252:
1253:                void println() {
1254:                    print("\n");
1255:                }
1256:            }
1257:
1258:            /**
1259:             * print the "functionality coverage map" indicating what tests
1260:             * fail on what data.
1261:             */
1262:            void printResults() {
1263:                myout.print("\n");
1264:                for (int k = 0; k < nTests; k++) {
1265:                    myout.print("---- test " + k + " -- " + testName[k]
1266:                            + " ---- \n");
1267:                    for (int i = 0; i < headerSample.length; i++) {
1268:                        myout.print("" + (i / 10 % 10));
1269:                    }
1270:                    myout.println();
1271:                    for (int i = 0; i < headerSample.length; i++) {
1272:                        myout.print("" + (i % 10));
1273:                    }
1274:                    myout.println();
1275:                    for (int i = 0; i < headerSample.length; i++) {
1276:                        for (int j = 0; j < headerSample.length; j++) {
1277:                            myout.print(testResult[i][j][k]);
1278:                        }
1279:                        myout.print(" ("
1280:                                + i
1281:                                + ")"
1282:                                + prtEncode(new THeader(headerSample[i])
1283:                                        .toString()) + "\n");
1284:                    }
1285:                    myout.print("\n");
1286:                }
1287:                myout.print("---- used headers ---- \n");
1288:                for (int i = 0; i < headerSample.length; i++) {
1289:                    for (int j = 0; j < i; j++) {
1290:                        myout.print(" ");
1291:                    }
1292:                    myout.print("" + i + ": ");
1293:                    myout.print(prtEncode(new THeader(headerSample[i])
1294:                            .toString()));
1295:                    myout.print("\n");
1296:                }
1297:                myout.print("\n");
1298:            }
1299:
1300:            void printAnalysis() {
1301:                try {
1302:                    myout.print("---- per-sample analysis ---- \n");
1303:                    for (int sn = 0; sn < headerSample.length; sn++) {
1304:                        myout
1305:                                .println("\n" + sn + ") "
1306:                                        + headerSample[sn][0][0]);
1307:                        myout.println(new THeader(headerSample[sn]).toString());
1308:                        for (int tn = 0; tn < nTests; tn++) {
1309:                            myout.print(testName[tn] + ": ");
1310:                            myout
1311:                                    .println(failureReasonToString(getFailureReasons(
1312:                                            sn, -1, tn)));
1313:                        }
1314:                    }
1315:                } catch (Throwable e) {
1316:                    System.out.println("in printAnalysis():");
1317:                    e.printStackTrace();
1318:                }
1319:
1320:                /*
1321:                 * myout.print("---- per-class analysis ---- \n");
1322:                 * for (int sampleNFrom=0, sampleNUpto=0; s
1323:                 *     ampleNFrom < headerSample.length;
1324:                 *     sampleNFrom = sampleNUpto) {
1325:                 *     myout.println(headerSample[sampleNFrom][0][0]);
1326:                 *  for (sampleNUpto = sampleNFrom; 
1327:                 *       sampleNUpto<headerSample.length
1328:                 *       && headerSample[sampleNFrom][0][0]
1329:                 *      .equals(headerSample[sampleNUpto][0][0]);
1330:                 *      sampleNUpto++) {
1331:                 *  }
1332:                 *  for (int tn = 0; tn < nTests; tn++) {
1333:                 *      myout.print(testName[tn]+": ");
1334:                 *  }
1335:                 *  for (int k = sampleNFrom; k < sampleNUpto; k++) {
1336:                 *  }
1337:                 * }
1338:                 */
1339:            }
1340:
1341:            /**
1342:             * Tests execute
1343:             */
1344:            public void runTests() {
1345:                // declare("Constructor SipAddress test");
1346:                testResult = new char[headerSample.length][headerSample.length][nTests];
1347:                failureReason = new int[headerSample.length][headerSample.length][nTests];
1348:                myout.init();
1349:                Test1();
1350:                printResults();
1351:                printAnalysis();
1352:                myout.windup();
1353:            }
1354:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.