Home | History | Annotate | Download | only in monitor_exit
      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      */
     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      */
     49     public void testE3() {
     50         loadAndRun("dot.junit.opcodes.monitor_exit.d.T_monitor_exit_3", NullPointerException.class);
     51     }
     52 
     53     /**
     54      * @constraint A23
     55      * @title  number of registers
     56      */
     57     public void testVFE1() {
     58         load("dot.junit.opcodes.monitor_exit.d.T_monitor_exit_4", VerifyError.class);
     59     }
     60 
     61 
     62 
     63     /**
     64      * @constraint B1
     65      * @title  type of arguments - int
     66      */
     67     public void testVFE2() {
     68         load("dot.junit.opcodes.monitor_exit.d.T_monitor_exit_5", VerifyError.class);
     69     }
     70 
     71     /**
     72      * @constraint B1
     73      * @title  type of arguments - float
     74      */
     75     public void testVFE3() {
     76         load("dot.junit.opcodes.monitor_exit.d.T_monitor_exit_6", VerifyError.class);
     77     }
     78 
     79     /**
     80      * @constraint B1
     81      * @title  type of arguments - long
     82      */
     83     public void testVFE4() {
     84         load("dot.junit.opcodes.monitor_exit.d.T_monitor_exit_7", VerifyError.class);
     85     }
     86 
     87     /**
     88      * @constraint B1
     89      * @title  type of arguments - double
     90      */
     91     public void testVFE5() {
     92         load("dot.junit.opcodes.monitor_exit.d.T_monitor_exit_8", VerifyError.class);
     93     }
     94 
     95 }
     96 
     97 
     98 class TestRunnable implements Runnable {
     99     private T_monitor_exit_1 t;
    100     private Object o;
    101 
    102     public TestRunnable(T_monitor_exit_1 t, Object o) {
    103         this.t = t;
    104         this.o = o;
    105     }
    106 
    107     public void run() {
    108         try {
    109             t.run(o);
    110         } catch (IllegalMonitorStateException imse) {
    111             // expected
    112             t.result = true;
    113         }
    114     }
    115 }
    116