CompilerTest.java revision f6c387128427e121477c1b32ad35cdcaa5101ba3
1/*
2 *  Licensed to the Apache Software Foundation (ASF) under one or more
3 *  contributor license agreements.  See the NOTICE file distributed with
4 *  this work for additional information regarding copyright ownership.
5 *  The ASF licenses this file to You under the Apache License, Version 2.0
6 *  (the "License"); you may not use this file except in compliance with
7 *  the License.  You may obtain a copy of the License at
8 *
9 *     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
18package org.apache.harmony.luni.tests.java.lang;
19
20import dalvik.annotation.TestLevel;
21import dalvik.annotation.TestTargetNew;
22import dalvik.annotation.TestTargetClass;
23
24import junit.framework.TestCase;
25
26@TestTargetClass(Compiler.class)
27public class CompilerTest extends TestCase {
28
29    /**
30     * @tests java.lang.Compiler#command(java.lang.Object)
31     */
32    @TestTargetNew(
33        level = TestLevel.COMPLETE,
34        notes = "",
35        method = "command",
36        args = {java.lang.Object.class}
37    )
38    public void test_commandLjava_lang_Object() {
39
40        if(System.getProperty("java.compiler") != null) {
41            try {
42                assertNull("Incorrect behavior.", Compiler.command(new Object()));
43            } catch (Exception e) {
44                fail("Exception during test : " + e.getMessage());
45            }
46            // NullPointerException is not specified.
47            Compiler.command(null);
48        } else {
49            Compiler.command("");
50        }
51    }
52
53    /**
54     * @tests java.lang.Compiler#compileClass(java.lang.Class)
55     */
56    @TestTargetNew(
57        level = TestLevel.COMPLETE,
58        notes = "",
59        method = "compileClass",
60        args = {java.lang.Class.class}
61    )
62    public void test_compileClassLjava_lang_Class() {
63        try {
64            // Do not test return value, may return true or false depending on
65            // if the jit is enabled. Make the call to ensure it doesn't crash.
66            Compiler.compileClass(Compiler.class);
67        } catch (Exception e) {
68            fail("Exception during test.");
69        }
70
71        // NullPointerException is not specified.
72        Compiler.compileClass((Class) null);
73    }
74
75    /**
76     * @tests java.lang.Compiler#compileClasses(java.lang.String)
77     */
78    @TestTargetNew(
79        level = TestLevel.COMPLETE,
80        notes = "",
81        method = "compileClasses",
82        args = {java.lang.String.class}
83    )
84    public void test_compileClassesLjava_lang_String() {
85        try {
86            // Do not test return value, may return true or false depending on
87            // if the jit is enabled. Make the call to ensure it doesn't crash.
88            Compiler.compileClasses("Compiler");
89        } catch (Exception e) {
90            fail("Exception during test.");
91        }
92
93        // NullPointerException is not specified.
94        Compiler.compileClasses((String) null);
95    }
96
97    /**
98     * @tests java.lang.Compiler#disable()
99     */
100    @TestTargetNew(
101        level = TestLevel.NOT_NECESSARY,
102        notes = "Doesn't verify that disable() method causes the Compiler to cease operation.",
103        method = "disable",
104        args = {}
105    )
106    public void test_disable() {
107        try {
108            Compiler.disable();
109            Compiler.compileClass(Compiler.class);
110        } catch (Exception e) {
111            fail("Exception during test : " + e.getMessage());
112        }
113    }
114
115    /**
116     * @tests java.lang.Compiler#enable()
117     */
118    @TestTargetNew(
119        level = TestLevel.NOT_NECESSARY,
120        notes = "Doesn't verify that enable() method causes the Compiler to resume operation.",
121        method = "enable",
122        args = {}
123    )
124    public void test_enable() {
125        try {
126            Compiler.disable();
127            Compiler.enable();
128            Compiler.compileClass(Compiler.class);
129        } catch (Exception e) {
130            fail("Exception during test : " + e.getMessage());
131        }
132    }
133}
134