• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package dot.junit.opcodes.monitor_exit;
18 
19 import dot.junit.DxTestCase;
20 import dot.junit.DxUtil;
21 import dot.junit.opcodes.monitor_exit.d.T_monitor_exit_1;
22 import dot.junit.opcodes.monitor_exit.d.T_monitor_exit_3;
23 
24 public class Test_monitor_exit extends DxTestCase {
25 
26     /**
27      * @title thread is not monitor owner
28      */
testE1()29     public void testE1() throws InterruptedException {
30         //@uses dot.junit.opcodes.monitor_exit.TestRunnable
31         final T_monitor_exit_1 t = new T_monitor_exit_1();
32         final Object o = new Object();
33 
34         Runnable r = new TestRunnable(t, o);
35         synchronized (o) {
36             Thread th = new Thread(r);
37             th.start();
38             th.join();
39         }
40         if (t.result == false) {
41             fail("expected IllegalMonitorStateException");
42         }
43     }
44 
45 
46     /**
47      * @title expected NullPointerException
48      */
testE3()49     public void testE3() {
50         T_monitor_exit_3 t = new T_monitor_exit_3();
51         try {
52             t.run();
53             fail("expected NullPointerException");
54         } catch (NullPointerException npe) {
55             // expected
56         }
57     }
58 
59     /**
60      * @constraint A23
61      * @title  number of registers
62      */
testVFE1()63     public void testVFE1() {
64         try {
65             Class.forName("dot.junit.opcodes.monitor_exit.d.T_monitor_exit_4");
66             fail("expected a verification exception");
67         } catch (Throwable t) {
68             DxUtil.checkVerifyException(t);
69         }
70     }
71 
72 
73 
74     /**
75      * @constraint B1
76      * @title  type of arguments - int
77      */
testVFE2()78     public void testVFE2() {
79         try {
80             Class.forName("dot.junit.opcodes.monitor_exit.d.T_monitor_exit_5");
81             fail("expected a verification exception");
82         } catch (Throwable t) {
83             DxUtil.checkVerifyException(t);
84         }
85     }
86 
87     /**
88      * @constraint B1
89      * @title  type of arguments - float
90      */
testVFE3()91     public void testVFE3() {
92         try {
93             Class.forName("dot.junit.opcodes.monitor_exit.d.T_monitor_exit_6");
94             fail("expected a verification exception");
95         } catch (Throwable t) {
96             DxUtil.checkVerifyException(t);
97         }
98     }
99 
100     /**
101      * @constraint B1
102      * @title  type of arguments - long
103      */
testVFE4()104     public void testVFE4() {
105         try {
106             Class.forName("dot.junit.opcodes.monitor_exit.d.T_monitor_exit_7");
107             fail("expected a verification exception");
108         } catch (Throwable t) {
109             DxUtil.checkVerifyException(t);
110         }
111     }
112 
113     /**
114      * @constraint B1
115      * @title  type of arguments - double
116      */
testVFE5()117     public void testVFE5() {
118         try {
119             Class.forName("dot.junit.opcodes.monitor_exit.d.T_monitor_exit_8");
120             fail("expected a verification exception");
121         } catch (Throwable t) {
122             DxUtil.checkVerifyException(t);
123         }
124     }
125 
126 }
127 
128 
129 class TestRunnable implements Runnable {
130     private T_monitor_exit_1 t;
131     private Object o;
132 
TestRunnable(T_monitor_exit_1 t, Object o)133     public TestRunnable(T_monitor_exit_1 t, Object o) {
134         this.t = t;
135         this.o = o;
136     }
137 
run()138     public void run() {
139         try {
140             t.run(o);
141         } catch (IllegalMonitorStateException imse) {
142             // expected
143             t.result = true;
144         }
145     }
146 }
147