01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.harmony.pack200.tests;
18:
19: import java.io.DataInputStream;
20: import java.io.IOException;
21: import java.io.InputStream;
22:
23: import junit.framework.TestCase;
24:
25: import org.apache.harmony.pack200.Segment;
26:
27: public class ClassVersionTest extends TestCase {
28: private static final int JAVA_15 = 49;
29:
30: public void testCorrectVersionOfSegment() throws IOException {
31: InputStream in = Segment.class
32: .getResourceAsStream("/org/apache/harmony/pack200/Segment.class");
33: DataInputStream din = new DataInputStream(in);
34:
35: assertEquals(0xCAFEBABE, din.readInt());
36: din.readShort(); // MINOR -- don't care
37: assertTrue(
38: "Class file has been compiled with Java 1.5 compatibility"
39: + " instead of 1.4 or lower",
40: din.readShort() < JAVA_15);
41: }
42:
43: public void testCorrectVersionOfTest() throws IOException {
44: InputStream in = Segment.class
45: .getResourceAsStream("/org/apache/harmony/pack200/tests/ClassVersionTest.class");
46: DataInputStream din = new DataInputStream(in);
47:
48: assertEquals(0xCAFEBABE, din.readInt());
49: din.readShort(); // MINOR -- don't care
50: assertTrue(
51: "Class file has been compiled with Java 1.5 compatibility"
52: + " instead of 1.4 or lower",
53: din.readShort() < JAVA_15);
54: }
55:
56: public void testCorrectVersionOfAdapter() throws IOException {
57: // tests that both the file is on the classpath and that it's been
58: // compiled correctly, but without actually loading the class
59: InputStream in = Segment.class
60: .getResourceAsStream("/org/apache/harmony/pack200/Pack200Adapter.class");
61: if (in != null) { // If running in Eclipse and Java5 stuff not built/available
62: DataInputStream din = new DataInputStream(in);
63:
64: assertEquals(0xCAFEBABE, din.readInt());
65: din.readShort(); // MINOR -- don't care
66: assertTrue("Class file needs 1.5 compatibility", din
67: .readShort() >= JAVA_15);
68: }
69: }
70: }
|