Source Code Cross Referenced for HexDumpTest.java in  » Net » Terracotta » com » tc » util » 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 » Net » Terracotta » com.tc.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice.  All rights reserved.
003:         */
004:        package com.tc.util;
005:
006:        import com.tc.test.TCTestCase;
007:
008:        import java.io.StringWriter;
009:
010:        /**
011:         * Unit test for {@link HexDump}.
012:         */
013:        public class HexDumpTest extends TCTestCase {
014:
015:            public void testZeroBytes() throws Exception {
016:                assertEquals("0 bytes: ", HexDump.dump(new byte[0]));
017:            }
018:
019:            public void testOneByte() throws Exception {
020:                assertEquals("1 byte: 9c  .", HexDump
021:                        .dump(new byte[] { ((byte) 0x9c) }));
022:            }
023:
024:            public void testTwoBytes() throws Exception {
025:                assertEquals("2 bytes: 4142  AB", HexDump.dump(new byte[] {
026:                        (byte) 'A', (byte) 'B' }));
027:            }
028:
029:            public void testThreeBytes() throws Exception {
030:                assertEquals("3 bytes: 4142 43  ABC", HexDump.dump(new byte[] {
031:                        (byte) 'A', (byte) 'B', (byte) 'C' }));
032:            }
033:
034:            public void testFifteenBytes() throws Exception {
035:                assertEquals(
036:                        "15 bytes: 4142 4344 4546 4748 494a 4b4c 4d4e 4f  ABCDEFGHIJKLMNO",
037:                        HexDump.dump(new byte[] { (byte) 'A', (byte) 'B',
038:                                (byte) 'C', (byte) 'D', (byte) 'E', (byte) 'F',
039:                                (byte) 'G', (byte) 'H', (byte) 'I', (byte) 'J',
040:                                (byte) 'K', (byte) 'L', (byte) 'M', (byte) 'N',
041:                                (byte) 'O' }));
042:            }
043:
044:            public void testSixteenBytes() throws Exception {
045:                assertEquals(
046:                        "16 bytes: 4142 4344 4546 4748 494a 4b4c 4d4e 4f50  ABCDEFGHIJKLMNOP",
047:                        HexDump.dump(new byte[] { (byte) 'A', (byte) 'B',
048:                                (byte) 'C', (byte) 'D', (byte) 'E', (byte) 'F',
049:                                (byte) 'G', (byte) 'H', (byte) 'I', (byte) 'J',
050:                                (byte) 'K', (byte) 'L', (byte) 'M', (byte) 'N',
051:                                (byte) 'O', (byte) 'P' }));
052:            }
053:
054:            public void testSeventeenBytes() throws Exception {
055:                assertEquals(
056:                        "17 bytes:\n"
057:                                + "00000000: 4142 4344 4546 4748 494a 4b4c 4d4e 4f50  ABCDEFGHIJKLMNOP\n"
058:                                + "00000010: 51                                       Q\n",
059:                        HexDump.dump(new byte[] { (byte) 'A', (byte) 'B',
060:                                (byte) 'C', (byte) 'D', (byte) 'E', (byte) 'F',
061:                                (byte) 'G', (byte) 'H', (byte) 'I', (byte) 'J',
062:                                (byte) 'K', (byte) 'L', (byte) 'M', (byte) 'N',
063:                                (byte) 'O', (byte) 'P', (byte) 'Q' }));
064:            }
065:
066:            public void testMoreBytes() throws Exception {
067:                assertEquals(
068:                        "35 bytes:\n"
069:                                + "00000000: 4142 4344 4546 4748 494a 4b4c 4d4e 4f50  ABCDEFGHIJKLMNOP\n"
070:                                + "00000010: 5152 5354 5556 5758 595a 5b5c 5d5e 5f60  QRSTUVWXYZ[\\]^_`\n"
071:                                + "00000020: 6162 63                                  abc\n",
072:                        HexDump.dump(new byte[] { (byte) 'A', (byte) 'B',
073:                                (byte) 'C', (byte) 'D', (byte) 'E', (byte) 'F',
074:                                (byte) 'G', (byte) 'H', (byte) 'I', (byte) 'J',
075:                                (byte) 'K', (byte) 'L', (byte) 'M', (byte) 'N',
076:                                (byte) 'O', (byte) 'P', (byte) 'Q', (byte) 'R',
077:                                (byte) 'S', (byte) 'T', (byte) 'U', (byte) 'V',
078:                                (byte) 'W', (byte) 'X', (byte) 'Y', (byte) 'Z',
079:                                (byte) '[', (byte) '\\', (byte) ']',
080:                                (byte) '^', (byte) '_', (byte) '`', (byte) 'a',
081:                                (byte) 'b', (byte) 'c' }));
082:            }
083:
084:            public void testAllValues() throws Exception {
085:                byte[] myArray = new byte[512];
086:
087:                for (int i = 0; i < myArray.length; ++i) {
088:                    myArray[i] = (byte) (i % 256);
089:                }
090:
091:                assertEquals(
092:                        "512 bytes:\n"
093:                                + "00000000: 0001 0203 0405 0607 0809 0a0b 0c0d 0e0f  ................\n"
094:                                + "00000010: 1011 1213 1415 1617 1819 1a1b 1c1d 1e1f  ................\n"
095:                                + "00000020: 2021 2223 2425 2627 2829 2a2b 2c2d 2e2f   !\"#$%&'()*+,-./\n"
096:                                + "00000030: 3031 3233 3435 3637 3839 3a3b 3c3d 3e3f  0123456789:;<=>?\n"
097:                                + "00000040: 4041 4243 4445 4647 4849 4a4b 4c4d 4e4f  @ABCDEFGHIJKLMNO\n"
098:                                + "00000050: 5051 5253 5455 5657 5859 5a5b 5c5d 5e5f  PQRSTUVWXYZ[\\]^_\n"
099:                                + "00000060: 6061 6263 6465 6667 6869 6a6b 6c6d 6e6f  `abcdefghijklmno\n"
100:                                + "00000070: 7071 7273 7475 7677 7879 7a7b 7c7d 7e7f  pqrstuvwxyz{|}~.\n"
101:                                + "00000080: 8081 8283 8485 8687 8889 8a8b 8c8d 8e8f  ................\n"
102:                                + "00000090: 9091 9293 9495 9697 9899 9a9b 9c9d 9e9f  ................\n"
103:                                + "000000a0: a0a1 a2a3 a4a5 a6a7 a8a9 aaab acad aeaf  ................\n"
104:                                + "000000b0: b0b1 b2b3 b4b5 b6b7 b8b9 babb bcbd bebf  ................\n"
105:                                + "000000c0: c0c1 c2c3 c4c5 c6c7 c8c9 cacb cccd cecf  ................\n"
106:                                + "000000d0: d0d1 d2d3 d4d5 d6d7 d8d9 dadb dcdd dedf  ................\n"
107:                                + "000000e0: e0e1 e2e3 e4e5 e6e7 e8e9 eaeb eced eeef  ................\n"
108:                                + "000000f0: f0f1 f2f3 f4f5 f6f7 f8f9 fafb fcfd feff  ................\n"
109:                                + "00000100: 0001 0203 0405 0607 0809 0a0b 0c0d 0e0f  ................\n"
110:                                + "00000110: 1011 1213 1415 1617 1819 1a1b 1c1d 1e1f  ................\n"
111:                                + "00000120: 2021 2223 2425 2627 2829 2a2b 2c2d 2e2f   !\"#$%&'()*+,-./\n"
112:                                + "00000130: 3031 3233 3435 3637 3839 3a3b 3c3d 3e3f  0123456789:;<=>?\n"
113:                                + "00000140: 4041 4243 4445 4647 4849 4a4b 4c4d 4e4f  @ABCDEFGHIJKLMNO\n"
114:                                + "00000150: 5051 5253 5455 5657 5859 5a5b 5c5d 5e5f  PQRSTUVWXYZ[\\]^_\n"
115:                                + "00000160: 6061 6263 6465 6667 6869 6a6b 6c6d 6e6f  `abcdefghijklmno\n"
116:                                + "00000170: 7071 7273 7475 7677 7879 7a7b 7c7d 7e7f  pqrstuvwxyz{|}~.\n"
117:                                + "00000180: 8081 8283 8485 8687 8889 8a8b 8c8d 8e8f  ................\n"
118:                                + "00000190: 9091 9293 9495 9697 9899 9a9b 9c9d 9e9f  ................\n"
119:                                + "000001a0: a0a1 a2a3 a4a5 a6a7 a8a9 aaab acad aeaf  ................\n"
120:                                + "000001b0: b0b1 b2b3 b4b5 b6b7 b8b9 babb bcbd bebf  ................\n"
121:                                + "000001c0: c0c1 c2c3 c4c5 c6c7 c8c9 cacb cccd cecf  ................\n"
122:                                + "000001d0: d0d1 d2d3 d4d5 d6d7 d8d9 dadb dcdd dedf  ................\n"
123:                                + "000001e0: e0e1 e2e3 e4e5 e6e7 e8e9 eaeb eced eeef  ................\n"
124:                                + "000001f0: f0f1 f2f3 f4f5 f6f7 f8f9 fafb fcfd feff  ................\n",
125:                        HexDump.dump(myArray));
126:            }
127:
128:            public void testOffsetAndLength() throws Exception {
129:                byte[] myArray = new byte[512];
130:
131:                for (int i = 0; i < myArray.length; ++i) {
132:                    myArray[i] = (byte) (i % 256);
133:                }
134:
135:                assertEquals(
136:                        "35 bytes:\n"
137:                                + "00000000: 4142 4344 4546 4748 494a 4b4c 4d4e 4f50  ABCDEFGHIJKLMNOP\n"
138:                                + "00000010: 5152 5354 5556 5758 595a 5b5c 5d5e 5f60  QRSTUVWXYZ[\\]^_`\n"
139:                                + "00000020: 6162 63                                  abc\n",
140:                        HexDump.dump(myArray, 0x41, 35));
141:
142:                assertEquals(
143:                        "35 bytes:\n"
144:                                + "00000000: 4142 4344 4546 4748 494a 4b4c 4d4e 4f50  ABCDEFGHIJKLMNOP\n"
145:                                + "00000010: 5152 5354 5556 5758 595a 5b5c 5d5e 5f60  QRSTUVWXYZ[\\]^_`\n"
146:                                + "00000020: 6162 63                                  abc\n",
147:                        HexDump.dump(myArray, 0x141, 35));
148:            }
149:
150:            public void testWriter() throws Exception {
151:                StringWriter writer = new StringWriter();
152:                HexDump.dump(new byte[] { (byte) 'A', (byte) 'B', (byte) 'C' },
153:                        writer);
154:                String myString = writer.toString();
155:                assertEquals("3 bytes: 4142 43  ABC", myString);
156:            }
157:
158:            public void testOffsetAndLengthWithWriter() throws Exception {
159:                byte[] myArray = new byte[512];
160:
161:                for (int i = 0; i < myArray.length; ++i) {
162:                    myArray[i] = (byte) (i % 256);
163:                }
164:
165:                StringWriter writer = new StringWriter();
166:                HexDump.dump(myArray, 0x41, 35, writer);
167:                String myString = writer.toString();
168:                assertEquals(
169:                        "35 bytes:\n"
170:                                + "00000000: 4142 4344 4546 4748 494a 4b4c 4d4e 4f50  ABCDEFGHIJKLMNOP\n"
171:                                + "00000010: 5152 5354 5556 5758 595a 5b5c 5d5e 5f60  QRSTUVWXYZ[\\]^_`\n"
172:                                + "00000020: 6162 63                                  abc\n",
173:                        myString);
174:
175:                writer = new StringWriter();
176:                HexDump.dump(myArray, 0x141, 35, writer);
177:                myString = writer.toString();
178:                assertEquals(
179:                        "35 bytes:\n"
180:                                + "00000000: 4142 4344 4546 4748 494a 4b4c 4d4e 4f50  ABCDEFGHIJKLMNOP\n"
181:                                + "00000010: 5152 5354 5556 5758 595a 5b5c 5d5e 5f60  QRSTUVWXYZ[\\]^_`\n"
182:                                + "00000020: 6162 63                                  abc\n",
183:                        myString);
184:
185:            }
186:
187:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.