• 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.instance_of;
18 
19 import dot.junit.DxTestCase;
20 import dot.junit.DxUtil;
21 import dot.junit.opcodes.instance_of.d.T_instance_of_1;
22 import dot.junit.opcodes.instance_of.d.T_instance_of_2;
23 import dot.junit.opcodes.instance_of.d.T_instance_of_3;
24 import dot.junit.opcodes.instance_of.d.T_instance_of_7;
25 
26 public class Test_instance_of extends DxTestCase {
27 
28 
29     /**
30      * @title (Object)String instanceof String
31      */
testN1()32     public void testN1() {
33         T_instance_of_1 t = new T_instance_of_1();
34         String s = "";
35         assertTrue(t.run(s));
36     }
37 
38     /**
39      * @title null instanceof String
40      */
testN2()41     public void testN2() {
42         T_instance_of_1 t = new T_instance_of_1();
43         assertFalse(t.run(null));
44     }
45 
46     /**
47      * @title check assignment compatibility rules
48      */
testN4()49     public void testN4() {
50         T_instance_of_2 t = new T_instance_of_2();
51         assertTrue(t.run());
52     }
53 
54     /**
55      * @title T_instance_of_1 instanceof String
56      */
testE1()57     public void testE1() {
58         T_instance_of_1 t = new T_instance_of_1();
59         assertFalse(t.run(t));
60     }
61 
62     /**
63      * @title Attempt to access inaccessible class.
64      */
testE2()65     public void testE2() {
66         //@uses dot.junit.opcodes.instance_of.TestStubs$TestStub
67         //@uses dot.junit.opcodes.instance_of.d.T_instance_of_3
68         try {
69             T_instance_of_3 tt = new T_instance_of_3();
70             tt.run();
71             fail("expected a verification exception");
72         } catch (IllegalAccessError e) {
73             // expected
74         } catch(VerifyError e) {
75             // expected
76         }
77     }
78 
79     /**
80      * @title Attempt to access undefined class.
81      */
testE3()82     public void testE3() {
83         try {
84             T_instance_of_7 tt = new T_instance_of_7();
85             tt.run();
86             fail("expected a verification exception");
87         } catch (NoClassDefFoundError e) {
88             // expected
89         } catch(VerifyError e) {
90             // expected
91         }
92     }
93 
94     /**
95      * @constraint A19
96      * @title constant pool index
97      */
testVFE1()98     public void testVFE1() {
99         try {
100             Class.forName("dot.junit.opcodes.instance_of.d.T_instance_of_4");
101             fail("expected a verification exception");
102         } catch (Throwable t) {
103             DxUtil.checkVerifyException(t);
104         }
105     }
106 
107     /**
108      *
109      * @constraint B1
110      * @title type of argument - int
111      */
testVFE2()112     public void testVFE2() {
113         try {
114             Class.forName("dot.junit.opcodes.instance_of.d.T_instance_of_5");
115             fail("expected a verification exception");
116         } catch (Throwable t) {
117             DxUtil.checkVerifyException(t);
118         }
119     }
120 
121     /**
122      *
123      * @constraint B1
124      * @title type of argument - long
125      */
testVFE3()126     public void testVFE3() {
127         try {
128             Class.forName("dot.junit.opcodes.instance_of.d.T_instance_of_8");
129             fail("expected a verification exception");
130         } catch (Throwable t) {
131             DxUtil.checkVerifyException(t);
132         }
133     }
134 
135     /**
136      *
137      * @constraint B1
138      * @title number of registers
139      */
testVFE4()140     public void testVFE4() {
141         try {
142             Class.forName("dot.junit.opcodes.instance_of.d.T_instance_of_6");
143             fail("expected a verification exception");
144         } catch (Throwable t) {
145             DxUtil.checkVerifyException(t);
146         }
147     }
148 
149 
150 }
151