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 Arguments = Integer.MAX_VALUE, Integer.MAX_VALUE
84      */
testB1()85     public void testB1() {
86         T_if_eq_1 t = new T_if_eq_1();
87         assertEquals(1, t.run(Integer.MAX_VALUE, Integer.MAX_VALUE));
88     }
89 
90     /**
91      * @title Arguments = Integer.MIN_VALUE, Integer.MIN_VALUE
92      */
testB2()93     public void testB2() {
94         T_if_eq_1 t = new T_if_eq_1();
95         assertEquals(1, t.run(Integer.MIN_VALUE, Integer.MIN_VALUE));
96     }
97 
98     /**
99      * @title Arguments = 0, 1234567
100      */
testB3()101     public void testB3() {
102         T_if_eq_1 t = new T_if_eq_1();
103         assertEquals(1234, t.run(0, 1234567));
104     }
105 
106     /**
107      * @title Arguments = 0, 0
108      */
testB4()109     public void testB4() {
110         T_if_eq_1 t = new T_if_eq_1();
111         assertEquals(1, t.run(0, 0));
112     }
113 
114     /**
115      * @title Compare reference with null
116      */
testB5()117     public void testB5() {
118         T_if_eq_2 t = new T_if_eq_2();
119         String a = "a";
120         assertEquals(1234, t.run(null, a));
121     }
122 
123     /**
124      * @constraint A23
125      * @title  number of registers
126      */
testVFE1()127     public void testVFE1() {
128         load("dot.junit.opcodes.if_eq.d.T_if_eq_5", VerifyError.class);
129     }
130 
131 
132     /**
133      * @constraint B1
134      * @title  types of arguments - int, double
135      */
testVFE2()136     public void testVFE2() {
137         load("dot.junit.opcodes.if_eq.d.T_if_eq_7", VerifyError.class);
138     }
139 
140     /**
141      * @constraint B1
142      * @title  types of arguments - long, int
143      */
testVFE3()144     public void testVFE3() {
145         load("dot.junit.opcodes.if_eq.d.T_if_eq_8", VerifyError.class);
146     }
147 
148     /**
149      * @constraint B1
150      * @title  types of arguments - int, reference
151      */
testVFE4()152     public void testVFE4() {
153         load("dot.junit.opcodes.if_eq.d.T_if_eq_9", VerifyError.class);
154     }
155 
156     /**
157      * @constraint A6
158      * @title  branch target shall be inside the method
159      */
testVFE5()160     public void testVFE5() {
161         load("dot.junit.opcodes.if_eq.d.T_if_eq_10", VerifyError.class);
162     }
163 
164     /**
165      * @constraint A6
166      * @title  branch target shall not be "inside" instruction
167      */
testVFE6()168     public void testVFE6() {
169         load("dot.junit.opcodes.if_eq.d.T_if_eq_11", VerifyError.class);
170     }
171 
172     /**
173      * @constraint n/a
174      * @title  zero offset
175      */
testVFE7()176     public void testVFE7() {
177         load("dot.junit.opcodes.if_eq.d.T_if_eq_12", VerifyError.class);
178     }
179 
180     /**
181      * @constraint B1
182      * @title Types of arguments - int, float. The verifier checks that ints
183      * and floats are not used interchangeably.
184      */
testVFE8()185     public void testVFE8() {
186         load("dot.junit.opcodes.if_eq.d.T_if_eq_4", VerifyError.class);
187     }
188 }
189