• 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.if_eq;
18 
19 import dot.junit.DxTestCase;
20 import dot.junit.DxUtil;
21 import dot.junit.opcodes.if_eq.d.T_if_eq_1;
22 import dot.junit.opcodes.if_eq.d.T_if_eq_2;
23 import dot.junit.opcodes.if_eq.d.T_if_eq_4;
24 
25 public class Test_if_eq extends DxTestCase {
26 
27     /**
28      * @title Arguments = 5, 6
29      */
testN1()30     public void testN1() {
31         T_if_eq_1 t = new T_if_eq_1();
32         /*
33          * Compare with 1234 to check that in case of failed comparison
34          * execution proceeds at the address following if_eq instruction
35          */
36         assertEquals(1234, t.run(5, 6));
37     }
38 
39     /**
40      * @title Arguments = 0x0f0e0d0c, 0x0f0e0d0c
41      */
testN2()42     public void testN2() {
43         T_if_eq_1 t = new T_if_eq_1();
44         assertEquals(1, t.run(0x0f0e0d0c, 0x0f0e0d0c));
45     }
46 
47     /**
48      * @title Arguments = 5, -5
49      */
testN3()50     public void testN3() {
51         T_if_eq_1 t = new T_if_eq_1();
52         assertEquals(1234, t.run(5, -5));
53     }
54 
55     /**
56      * @title Arguments = 0x01001234, 0x1234
57      */
testN4()58     public void testN4() {
59         T_if_eq_1 t = new T_if_eq_1();
60         assertEquals(1234, t.run(0x01001234, 0x1234));
61     }
62 
63     /**
64      * @title compare references
65      */
testN5()66     public void testN5() {
67         T_if_eq_2 t = new T_if_eq_2();
68         String a = "a";
69         String b = "b";
70         assertEquals(1234, t.run(a, b));
71     }
72 
73     /**
74      * @title compare references
75      */
testN6()76     public void testN6() {
77         T_if_eq_2 t = new T_if_eq_2();
78         String a = "a";
79         assertEquals(1, t.run(a, a));
80     }
81 
82     /**
83      * @title Types of arguments - int, float. Dalvik doens't distinguish 32-bits types internally,
84      * so this operation of int and float makes no sense but shall not crash the VM.
85      */
testN7()86     public void testN7() {
87         T_if_eq_4 t = new T_if_eq_4();
88         assertEquals(1234, t.run(1f, 1));
89     }
90 
91     /**
92      * @title Arguments = Integer.MAX_VALUE, Integer.MAX_VALUE
93      */
testB1()94     public void testB1() {
95         T_if_eq_1 t = new T_if_eq_1();
96         assertEquals(1, t.run(Integer.MAX_VALUE, Integer.MAX_VALUE));
97     }
98 
99     /**
100      * @title Arguments = Integer.MIN_VALUE, Integer.MIN_VALUE
101      */
testB2()102     public void testB2() {
103         T_if_eq_1 t = new T_if_eq_1();
104         assertEquals(1, t.run(Integer.MIN_VALUE, Integer.MIN_VALUE));
105     }
106 
107     /**
108      * @title Arguments = 0, 1234567
109      */
testB3()110     public void testB3() {
111         T_if_eq_1 t = new T_if_eq_1();
112         assertEquals(1234, t.run(0, 1234567));
113     }
114 
115     /**
116      * @title Arguments = 0, 0
117      */
testB4()118     public void testB4() {
119         T_if_eq_1 t = new T_if_eq_1();
120         assertEquals(1, t.run(0, 0));
121     }
122 
123     /**
124      * @title Compare reference with null
125      */
testB5()126     public void testB5() {
127         T_if_eq_2 t = new T_if_eq_2();
128         String a = "a";
129         assertEquals(1234, t.run(null, a));
130     }
131 
132     /**
133      * @constraint A23
134      * @title  number of registers
135      */
testVFE1()136     public void testVFE1() {
137         try {
138             Class.forName("dot.junit.opcodes.if_eq.d.T_if_eq_5");
139             fail("expected a verification exception");
140         } catch (Throwable t) {
141             DxUtil.checkVerifyException(t);
142         }
143     }
144 
145 
146     /**
147      * @constraint B1
148      * @title  types of arguments - int, double
149      */
testVFE2()150     public void testVFE2() {
151         try {
152             Class.forName("dot.junit.opcodes.if_eq.d.T_if_eq_7");
153             fail("expected a verification exception");
154         } catch (Throwable t) {
155             DxUtil.checkVerifyException(t);
156         }
157     }
158 
159     /**
160      * @constraint B1
161      * @title  types of arguments - long, int
162      */
testVFE3()163     public void testVFE3() {
164         try {
165             Class.forName("dot.junit.opcodes.if_eq.d.T_if_eq_8");
166             fail("expected a verification exception");
167         } catch (Throwable t) {
168             DxUtil.checkVerifyException(t);
169         }
170     }
171 
172     /**
173      * @constraint B1
174      * @title  types of arguments - int, reference
175      */
testVFE4()176     public void testVFE4() {
177         try {
178             Class.forName("dot.junit.opcodes.if_eq.d.T_if_eq_9");
179             fail("expected a verification exception");
180         } catch (Throwable t) {
181             DxUtil.checkVerifyException(t);
182         }
183     }
184 
185     /**
186      * @constraint A6
187      * @title  branch target shall be inside the method
188      */
testVFE5()189     public void testVFE5() {
190         try {
191             Class.forName("dot.junit.opcodes.if_eq.d.T_if_eq_10");
192             fail("expected a verification exception");
193         } catch (Throwable t) {
194             DxUtil.checkVerifyException(t);
195         }
196     }
197 
198     /**
199      * @constraint A6
200      * @title  branch target shall not be "inside" instruction
201      */
testVFE6()202     public void testVFE6() {
203         try {
204             Class.forName("dot.junit.opcodes.if_eq.d.T_if_eq_11");
205             fail("expected a verification exception");
206         } catch (Throwable t) {
207             DxUtil.checkVerifyException(t);
208         }
209     }
210 
211     /**
212      * @constraint n/a
213      * @title  zero offset
214      */
testVFE7()215     public void testVFE7() {
216         try {
217             Class.forName("dot.junit.opcodes.if_eq.d.T_if_eq_12");
218             fail("expected a verification exception");
219         } catch (Throwable t) {
220             DxUtil.checkVerifyException(t);
221         }
222     }
223 }
224