Source Code Cross Referenced for MessageDigest1Test.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » security » tests » java » security » 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 » Apache Harmony Java SE » org package » org.apache.harmony.security.tests.java.security 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:
018:        package org.apache.harmony.security.tests.java.security;
019:
020:        import java.nio.ByteBuffer;
021:        import java.security.DigestException;
022:        import java.security.MessageDigest;
023:
024:        import junit.framework.TestCase;
025:
026:        import org.apache.harmony.security.tests.support.MyMessageDigest1;
027:
028:        /**
029:         * Tests for <code>MessageDigest</code> constructor and methods
030:         */
031:        public class MessageDigest1Test extends TestCase {
032:
033:            /**
034:             * @tests java.security.MessageDigest#reset()
035:             */
036:            public void test_reset() {
037:                MyMessageDigest1 md = new MyMessageDigest1("ABC");
038:                md.reset();
039:                assertTrue(md.runEngineReset);
040:            }
041:
042:            /**
043:             * @tests java.security.MessageDigest#update(byte)
044:             */
045:            public void test_updateLB() {
046:                MyMessageDigest1 md = new MyMessageDigest1("ABC");
047:                md.update((byte) 1);
048:                assertTrue(md.runEngineUpdate1);
049:            }
050:
051:            /**
052:             * @tests java.security.MessageDigest#update(byte[], int, int)
053:             */
054:            public void test_updateLB$LILI() {
055:                MyMessageDigest1 md = new MyMessageDigest1("ABC");
056:                final byte[] bytes = { 1, 2, 3, 4, 5 };
057:                md.update(bytes, 1, 2);
058:                assertTrue(md.runEngineUpdate2);
059:
060:                // Regression for HARMONY-1120
061:                try {
062:                    // buf == null
063:                    md.update(null, 0, 1);
064:                    fail("No expected IllegalArgumentException");
065:                } catch (IllegalArgumentException e) {
066:                }
067:                try {
068:                    // offset + len > buf.length
069:                    md.update(bytes, 0, bytes.length + 1);
070:                    fail("No expected IllegalArgumentException");
071:                } catch (IllegalArgumentException e) {
072:                }
073:                try {
074:                    // offset + len > Integer.MAX_VALUE
075:                    md.update(bytes, Integer.MAX_VALUE, 1);
076:                    fail("No expected IllegalArgumentException");
077:                } catch (IllegalArgumentException e) {
078:                }
079:                // offset<0 and len<0 are passed to provider
080:                final int offset = -1;
081:                final int len = -1;
082:                md = new MyMessageDigest1("ABC") {
083:                    @Override
084:                    public void engineUpdate(byte[] arg0, int arg1, int arg2) {
085:                        assertSame("buf", bytes, arg0);
086:                        assertEquals("offset", offset, arg1);
087:                        assertEquals("len", len, arg2);
088:                        runEngineUpdate2 = true;
089:                    }
090:                };
091:                md.update(bytes, offset, len);
092:                assertTrue(md.runEngineUpdate2);
093:            }
094:
095:            /**
096:             * @tests java.security.MessageDigest#update(byte[])
097:             */
098:            public void test_updateLB$() {
099:                MyMessageDigest1 md = new MyMessageDigest1("ABC");
100:                byte[] b = { 1, 2, 3, 4, 5 };
101:                md.update(b);
102:                assertTrue(md.runEngineUpdate2);
103:            }
104:
105:            /**
106:             * @tests java.security.MessageDigest#update(ByteBuffer)
107:             */
108:            public void test_updateLjava_nio_ByteBuffer() {
109:                MyMessageDigest1 md = new MyMessageDigest1("ABC");
110:                byte[] b = { 1, 2, 3, 4, 5 };
111:                ByteBuffer byteBuffer = ByteBuffer.wrap(b);
112:
113:                int limit = byteBuffer.limit();
114:                md.update(byteBuffer);
115:                assertTrue(md.runEngineUpdate2);
116:                assertEquals(byteBuffer.limit(), byteBuffer.position());
117:                assertEquals(limit, byteBuffer.limit());
118:            }
119:
120:            /**
121:             * @tests java.security.MessageDigest#digest()
122:             */
123:            public void test_digest() {
124:                MyMessageDigest1 md = new MyMessageDigest1("ABC");
125:                assertEquals("incorrect result", 0, md.digest().length);
126:                assertTrue(md.runEngineDigest);
127:            }
128:
129:            /**
130:             * @tests java.security.MessageDigest#digest(byte[])
131:             */
132:            public void test_digestLB$() {
133:                MyMessageDigest1 md = new MyMessageDigest1("ABC");
134:                byte[] b = { 1, 2, 3, 4, 5 };
135:                assertEquals("incorrect result", 0, md.digest(b).length);
136:                assertTrue(md.runEngineDigest);
137:            }
138:
139:            /**
140:             * @tests java.security.MessageDigest#digest(byte[], int, int)
141:             */
142:            public void test_digestLB$LILI() throws Exception {
143:                MyMessageDigest1 md = new MyMessageDigest1("ABC");
144:                byte[] b = { 1, 2, 3, 4, 5 };
145:                assertEquals("incorrect result", 0, md.digest(b, 2, 3));
146:                assertTrue("digest failed", md.runEngineDigest);
147:
148:                // Regression for Harmony-1148
149:                md = new MyMessageDigest1();
150:                final byte[] bytes = new byte[] { 2, 4, 1 };
151:                try {
152:                    // buf == null
153:                    md.digest(null, 0, 1);
154:                    fail("No expected IllegalArgumentException");
155:                } catch (IllegalArgumentException e) {
156:                }
157:                try {
158:                    // offset + len > buf.length
159:                    md.digest(bytes, 0, bytes.length + 1);
160:                    fail("No expected IllegalArgumentException");
161:                } catch (IllegalArgumentException e) {
162:                }
163:                try {
164:                    // offset + len > Integer.MAX_VALUE
165:                    md.digest(bytes, Integer.MAX_VALUE, 1);
166:                    fail("No expected IllegalArgumentException");
167:                } catch (IllegalArgumentException e) {
168:                }
169:                // offset<0 and len<0 are passed to provider
170:                final int offset = -1;
171:                final int len = -1;
172:                final int status = 33;
173:                md = new MyMessageDigest1("ABC") {
174:                    @Override
175:                    public int engineDigest(byte[] arg0, int arg1, int arg2) {
176:                        assertSame("buf", bytes, arg0);
177:                        assertEquals("offset", offset, arg1);
178:                        assertEquals("len", len, arg2);
179:                        return status;
180:                    }
181:                };
182:                assertEquals("returned status", status, md.digest(bytes,
183:                        offset, len));
184:            }
185:
186:            /**
187:             * @tests java.security.MessageDigest#isEqual(byte[],byte[])
188:             */
189:            public void test_isEqualLB$LB$() {
190:                byte[] b1 = { 1, 2, 3, 4 };
191:                byte[] b2 = { 1, 2, 3, 4, 5 };
192:                byte[] b3 = { 1, 3, 3, 4 };
193:                byte[] b4 = { 1, 2, 3, 4 };
194:
195:                assertTrue(MessageDigest.isEqual(b1, b4));
196:                assertFalse(MessageDigest.isEqual(b1, b2));
197:                assertFalse(MessageDigest.isEqual(b1, b3));
198:            }
199:
200:            /**
201:             * @tests java.security.MessageDigest#getAlgorithm()
202:             */
203:            public void test_getAlgorithm() {
204:                MyMessageDigest1 md = new MyMessageDigest1("ABC");
205:                assertEquals("ABC", md.getAlgorithm());
206:            }
207:
208:            /**
209:             * @tests java.security.MessageDigest#getProvider()
210:             */
211:            public void test_getProvider() {
212:                MyMessageDigest1 md = new MyMessageDigest1("ABC");
213:                assertNull(md.getProvider());
214:            }
215:
216:            /**
217:             * @tests java.security.MessageDigest#getDigestLength()
218:             */
219:            public void test_getDigestLength() {
220:                MyMessageDigest1 md = new MyMessageDigest1("ABC");
221:                assertEquals(0, md.getDigestLength());
222:            }
223:
224:            /**
225:             * Tests SHA MessageDigest provider
226:             */
227:            public void testSHAProvider() throws Exception {
228:                MessageDigest md = MessageDigest.getInstance("SHA");
229:                byte[] bytes = new byte[] { 1, 1, 1, 1, 1 };
230:
231:                // Regression for HARMONY-1120
232:                // testing combination with provider
233:                try {
234:                    // offset < 0
235:                    md.update(bytes, -1, 1);
236:                    fail("No expected IndexOutOfBoundsException");
237:                } catch (IndexOutOfBoundsException e) {
238:                }
239:                // No exception for len < 0
240:                md.update(bytes, 1, -1);
241:
242:                //Regression for Harmony-1148
243:                md = MessageDigest.getInstance("SHA");
244:                try {
245:                    // offset < 0
246:                    md.digest(bytes, 0, -1);
247:                    fail("No expected DigestException");
248:                } catch (DigestException e) {
249:                }
250:                try {
251:                    // len < 0
252:                    md.digest(bytes, -1, 0);
253:                    fail("No expected DigestException");
254:                } catch (DigestException e) {
255:                }
256:
257:            }
258:        }
w___w_w_.j___a_v___a___2_s_._c__o___m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.