Source Code Cross Referenced for CodeAttributeTest.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » pack200 » tests » 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.pack200.tests 
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:        package org.apache.harmony.pack200.tests;
018:
019:        import java.util.ArrayList;
020:        import java.util.List;
021:
022:        import junit.framework.TestCase;
023:
024:        import org.apache.harmony.pack200.CpBands;
025:        import org.apache.harmony.pack200.Segment;
026:        import org.apache.harmony.pack200.SegmentConstantPool;
027:        import org.apache.harmony.pack200.bytecode.ByteCode;
028:        import org.apache.harmony.pack200.bytecode.CodeAttribute;
029:        import org.apache.harmony.pack200.bytecode.LocalVariableTableAttribute;
030:        import org.apache.harmony.pack200.bytecode.OperandManager;
031:
032:        /**
033:         * Tests for CodeAttribute
034:         */
035:        public class CodeAttributeTest extends TestCase {
036:
037:            public class MockCodeAttribute extends CodeAttribute {
038:
039:                public MockCodeAttribute(int maxStack, int maxLocals,
040:                        byte[] codePacked, Segment segment,
041:                        OperandManager operandManager, List exceptionTable) {
042:                    super (maxStack, maxLocals, codePacked, segment,
043:                            operandManager, exceptionTable);
044:                }
045:
046:                public int getLength() {
047:                    return super .getLength();
048:                }
049:            }
050:
051:            public class MockCpBands extends CpBands {
052:                public MockCpBands(Segment segment) {
053:                    super (segment);
054:                }
055:
056:                public String[] getCpFieldClass() {
057:                    return new String[] { "Un", "Deux", "Trois", "Quatre",
058:                            "Cinq", "Six", "Sept", "Huit", "Neuf" };
059:                }
060:
061:                public String[] getCpFieldDescriptor() {
062:                    return new String[] { "Un:un", "Deux:deux", "Trois:trois" };
063:                }
064:
065:                public String[] getCpMethodClass() {
066:                    return new String[] { "Un", "Deux", "Trois", "Quatre",
067:                            "Cinq", "Six", "Sept", "Huit", "Neuf" };
068:                }
069:
070:                public String[] getCpMethodDescriptor() {
071:                    return new String[] { "Un:un", "Deux:deux", "Trois:trois" };
072:                }
073:
074:                public String[] getCpString() {
075:                    return new String[] { "Un", "Deux", "Trois", "Quatre",
076:                            "Cinq", "Six", "Sept", "Huit", "Neuf" };
077:                }
078:            }
079:
080:            public class MockOperandManager extends OperandManager {
081:
082:                public MockOperandManager() {
083:                    super (new int[] {}, // bcCaseCount
084:                            new int[] {}, // bcCaseValues
085:                            new int[] {}, // bcByte
086:                            new int[] {}, // bcShort
087:                            new int[] {}, // bcLocal
088:                            new int[] {}, // bcLabel
089:                            new int[] {}, // bcIntRef
090:                            new int[] {}, // bcFloatRef
091:                            new int[] {}, // bcLongRef
092:                            new int[] {}, // bcDoubleRef
093:                            new int[] { 0, 1, 2, 3, 4 }, // bcStringRef
094:                            new int[] {}, // bcClassRef
095:                            new int[] {}, // bcFieldRef
096:                            new int[] {}, // bcMethodRef
097:                            new int[] {}, // bcIMethodRef
098:                            new int[] { 0, 0, 0, 0, 0, 0 }, // bcThisField
099:                            new int[] {}, // bcSuperField
100:                            new int[] { 0 }, // bcThisMethod
101:                            new int[] {}, // bcSuperMethod
102:                            new int[] {} // bcInitRef
103:                            , null);
104:                }
105:            }
106:
107:            public class MockSegment extends Segment {
108:                public SegmentConstantPool getConstantPool() {
109:                    return new MockSegmentConstantPool(cpBands);
110:                }
111:            }
112:
113:            public class MockSegmentConstantPool extends SegmentConstantPool {
114:                public MockSegmentConstantPool(CpBands bands) {
115:                    super (bands);
116:                }
117:
118:                protected int matchSpecificPoolEntryIndex(String[] nameArray,
119:                        String compareString, int desiredIndex) {
120:                    return 1;
121:                }
122:            }
123:
124:            Segment segment = new MockSegment();
125:            CpBands cpBands = new MockCpBands(segment);
126:
127:            public byte[] mixedByteArray = { -47, // aload_0_getstatic_this 0, 1
128:                    -46, // aload_0_putstatic_this 4, 5
129:                    1, // aconst_null 8
130:                    -45, // aload_0_getfield_this 9, 10
131:                    // Should always end with a multibyte
132:                    // instruction
133:                    -44, // aload_0_putfield_this (int) 13, 14
134:            };
135:
136:            public byte[] singleByteArray = { 42, // aload_0 0
137:                    1, // aconst_null 1
138:                    18, // ldc 2
139:                    -49, // return 4
140:            };
141:
142:            public void testLength() {
143:                OperandManager operandManager = new MockOperandManager();
144:                operandManager.setSegment(segment);
145:                operandManager.setCurrentClass("java/lang/Foo");
146:
147:                MockCodeAttribute attribute = new MockCodeAttribute(3, // maxStack
148:                        2, // maxLocals
149:                        mixedByteArray, // codePacked
150:                        segment, // segment
151:                        operandManager, // operandManager
152:                        new ArrayList());
153:                assertEquals(29, attribute.getLength());
154:
155:                attribute.attributes.add(new LocalVariableTableAttribute(0,
156:                        null, null, null, null, null));
157:                assertEquals(37, attribute.getLength());
158:            }
159:
160:            public void testMixedByteCodes() {
161:                OperandManager operandManager = new MockOperandManager();
162:                operandManager.setSegment(segment);
163:                operandManager.setCurrentClass("java/lang/Foo");
164:
165:                CodeAttribute attribute = new CodeAttribute(3, // maxStack
166:                        2, // maxLocals
167:                        mixedByteArray, // codePacked
168:                        segment, // segment
169:                        operandManager, // operandManager
170:                        new ArrayList());
171:                assertEquals(2, attribute.maxLocals);
172:                assertEquals(3, attribute.maxStack);
173:                assertEquals("aload_0_putfield_this",
174:                        ((ByteCode) attribute.byteCodes.get(4)).toString());
175:
176:                int expectedLabels[] = new int[] { 0, 1, 4, 5, 8, 9, 10, 13, 14 };
177:                for (int index = 0; index < expectedLabels.length; index++) {
178:                    assertEquals(expectedLabels[index],
179:                            ((Integer) attribute.byteCodeOffsets.get(index))
180:                                    .intValue());
181:                }
182:            }
183:
184:            public void testSingleByteCodes() {
185:                OperandManager operandManager = new MockOperandManager();
186:                operandManager.setSegment(segment);
187:                operandManager.setCurrentClass("java/lang/Foo");
188:
189:                CodeAttribute attribute = new CodeAttribute(4, // maxStack
190:                        3, // maxLocals
191:                        singleByteArray, // codePacked
192:                        segment, // segment
193:                        operandManager, // operandManager
194:                        new ArrayList());
195:                assertEquals(3, attribute.maxLocals);
196:                assertEquals(4, attribute.maxStack);
197:                assertEquals("invokespecial_this",
198:                        ((ByteCode) attribute.byteCodes.get(3)).toString());
199:
200:                int expectedLabels[] = new int[] { 0, 1, 2, 4 };
201:                for (int index = 0; index < expectedLabels.length; index++) {
202:                    assertEquals(expectedLabels[index],
203:                            ((Integer) attribute.byteCodeOffsets.get(index))
204:                                    .intValue());
205:                }
206:            }
207:
208:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.