BaseDexReaderSleb128Test.java revision 7301fbe30e6661c67c33552efd28a8d7587aba3d
1/*
2 * Copyright 2012, Google Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 *     * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *     * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
14 * distribution.
15 *     * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32package org.jf.dexlib2.dexbacked;
33
34import junit.framework.Assert;
35import org.jf.util.ExceptionWithContext;
36import org.junit.Test;
37
38public class BaseDexReaderSleb128Test {
39    @Test
40    public void testSleb128() {
41        performTest(0x0, new byte[]{0x0, 0x11}, 1);
42        performTest(0x1, new byte[]{0x1, 0x11}, 1);
43        performTest(0x3f, new byte[]{0x3f, 0x11}, 1);
44        performTest(0xffffffc0, new byte[]{0x40, 0x11}, 1);
45        performTest(0xfffffff0, new byte[]{0x70, 0x11}, 1);
46        performTest(0xffffffff, new byte[]{0x7f, 0x11}, 1);
47
48        performTest(0x80, new byte[]{(byte)0x80, 0x1, 0x11}, 2);
49        performTest(0x100, new byte[]{(byte)0x80, 0x2, 0x11}, 2);
50        performTest(0x800, new byte[]{(byte)0x80, 0x10, 0x11}, 2);
51        performTest(0x1f80, new byte[]{(byte)0x80, 0x3f, 0x11}, 2);
52        performTest(0xffffe000, new byte[]{(byte)0x80, 0x40, 0x11}, 2);
53        performTest(0xffffe080, new byte[]{(byte)0x80, 0x41, 0x11}, 2);
54        performTest(0xfffff800, new byte[]{(byte)0x80, 0x70, 0x11}, 2);
55        performTest(0xffffff80, new byte[]{(byte)0x80, 0x7f, 0x11}, 2);
56
57        performTest(0xff, new byte[]{(byte)0xff, 0x1, 0x11}, 2);
58        performTest(0x17f, new byte[]{(byte)0xff, 0x2, 0x11}, 2);
59        performTest(0x87f, new byte[]{(byte)0xff, 0x10, 0x11}, 2);
60        performTest(0x1fff, new byte[]{(byte)0xff, 0x3f, 0x11}, 2);
61        performTest(0xffffe07f, new byte[]{(byte)0xff, 0x40, 0x11}, 2);
62        performTest(0xffffe0ff, new byte[]{(byte)0xff, 0x41, 0x11}, 2);
63        performTest(0xfffff87f, new byte[]{(byte)0xff, 0x70, 0x11}, 2);
64        performTest(0xffffffff, new byte[]{(byte)0xff, 0x7f, 0x11}, 2);
65
66        performTest(0x4000, new byte[]{(byte)0x80, (byte)0x80, 0x1, 0x11}, 3);
67        performTest(0x8000, new byte[]{(byte)0x80, (byte)0x80, 0x2, 0x11}, 3);
68        performTest(0x40000, new byte[]{(byte)0x80, (byte)0x80, 0x10, 0x11}, 3);
69        performTest(0xfc000, new byte[]{(byte)0x80, (byte)0x80, 0x3f, 0x11}, 3);
70        performTest(0xfff00000, new byte[]{(byte)0x80, (byte)0x80, 0x40, 0x11}, 3);
71        performTest(0xfff04000, new byte[]{(byte)0x80, (byte)0x80, 0x41, 0x11}, 3);
72        performTest(0xfffc0000, new byte[]{(byte)0x80, (byte)0x80, 0x70, 0x11}, 3);
73        performTest(0xffffc000, new byte[]{(byte)0x80, (byte)0x80, 0x7f, 0x11}, 3);
74
75        performTest(0x7fff, new byte[]{(byte)0xff, (byte)0xff, 0x1, 0x11}, 3);
76        performTest(0xbfff, new byte[]{(byte)0xff, (byte)0xff, 0x2, 0x11}, 3);
77        performTest(0x43fff, new byte[]{(byte)0xff, (byte)0xff, 0x10, 0x11}, 3);
78        performTest(0xfffff, new byte[]{(byte)0xff, (byte)0xff, 0x3f, 0x11}, 3);
79        performTest(0xfff03fff, new byte[]{(byte)0xff, (byte)0xff, 0x40, 0x11}, 3);
80        performTest(0xfff07fff, new byte[]{(byte)0xff, (byte)0xff, 0x41, 0x11}, 3);
81        performTest(0xfffc3fff, new byte[]{(byte)0xff, (byte)0xff, 0x70, 0x11}, 3);
82        performTest(0xffffffff, new byte[]{(byte)0xff, (byte)0xff, 0x7f, 0x11}, 3);
83
84        performTest(0x200000, new byte[]{(byte)0x80, (byte)0x80, (byte)0x80, 0x1, 0x11}, 4);
85        performTest(0x400000, new byte[]{(byte)0x80, (byte)0x80, (byte)0x80, 0x2, 0x11}, 4);
86        performTest(0x2000000, new byte[]{(byte)0x80, (byte)0x80, (byte)0x80, 0x10, 0x11}, 4);
87        performTest(0x7e00000, new byte[]{(byte)0x80, (byte)0x80, (byte)0x80, 0x3f, 0x11}, 4);
88        performTest(0xf8000000, new byte[]{(byte)0x80, (byte)0x80, (byte)0x80, 0x40, 0x11}, 4);
89        performTest(0xf8200000, new byte[]{(byte)0x80, (byte)0x80, (byte)0x80, 0x41, 0x11}, 4);
90        performTest(0xfe000000, new byte[]{(byte)0x80, (byte)0x80, (byte)0x80, 0x70, 0x11}, 4);
91        performTest(0xffe00000, new byte[]{(byte)0x80, (byte)0x80, (byte)0x80, 0x7f, 0x11}, 4);
92
93        performTest(0x3fffff, new byte[]{(byte)0xff, (byte)0xff, (byte)0xff, 0x1, 0x11}, 4);
94        performTest(0x5fffff, new byte[]{(byte)0xff, (byte)0xff, (byte)0xff, 0x2, 0x11}, 4);
95        performTest(0x21fffff, new byte[]{(byte)0xff, (byte)0xff, (byte)0xff, 0x10, 0x11}, 4);
96        performTest(0x7ffffff, new byte[]{(byte)0xff, (byte)0xff, (byte)0xff, 0x3f, 0x11}, 4);
97        performTest(0xf81fffff, new byte[]{(byte)0xff, (byte)0xff, (byte)0xff, 0x40, 0x11}, 4);
98        performTest(0xf83fffff, new byte[]{(byte)0xff, (byte)0xff, (byte)0xff, 0x41, 0x11}, 4);
99        performTest(0xfe1fffff, new byte[]{(byte)0xff, (byte)0xff, (byte)0xff, 0x70, 0x11}, 4);
100        performTest(0xffffffff, new byte[]{(byte)0xff, (byte)0xff, (byte)0xff, 0x7f, 0x11}, 4);
101
102        performTest(0x10000000, new byte[]{(byte)0x80, (byte)0x80, (byte)0x80, (byte)0x80, 0x1, 0x11}, 5);
103        performTest(0x20000000, new byte[]{(byte)0x80, (byte)0x80, (byte)0x80, (byte)0x80, 0x2, 0x11}, 5);
104        performTest(0x70000000, new byte[]{(byte)0x80, (byte)0x80, (byte)0x80, (byte)0x80, 0x7, 0x11}, 5);
105        performTest(0x70000000, new byte[]{(byte)0x80, (byte)0x80, (byte)0x80, (byte)0x80, 0x17, 0x11}, 5);
106        performTest(0x70000000, new byte[]{(byte)0x80, (byte)0x80, (byte)0x80, (byte)0x80, 0x47, 0x11}, 5);
107        performTest(0x70000000, new byte[]{(byte)0x80, (byte)0x80, (byte)0x80, (byte)0x80, 0x77, 0x11}, 5);
108        performTest(0x80000000, new byte[]{(byte)0x80, (byte)0x80, (byte)0x80, (byte)0x80, 0x8, 0x11}, 5);
109        performTest(0xe0000000, new byte[]{(byte)0x80, (byte)0x80, (byte)0x80, (byte)0x80, 0xe, 0x11}, 5);
110        performTest(0xf0000000, new byte[]{(byte)0x80, (byte)0x80, (byte)0x80, (byte)0x80, 0xf, 0x11}, 5);
111
112        performTest(0x1fffffff, new byte[]{(byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, 0x1, 0x11}, 5);
113        performTest(0x2fffffff, new byte[]{(byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, 0x2, 0x11}, 5);
114        performTest(0x7fffffff, new byte[]{(byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, 0x7, 0x11}, 5);
115        performTest(0x7fffffff, new byte[]{(byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, 0x17, 0x11}, 5);
116        performTest(0x7fffffff, new byte[]{(byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, 0x47, 0x11}, 5);
117        performTest(0x7fffffff, new byte[]{(byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, 0x77, 0x11}, 5);
118        performTest(0x8fffffff, new byte[]{(byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, 0x8, 0x11}, 5);
119        performTest(0xefffffff, new byte[]{(byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, 0xe, 0x11}, 5);
120        performTest(0xffffffff, new byte[]{(byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, 0xf, 0x11}, 5);
121
122        performTest(0x8197d2, new byte[]{(byte)0xd2, (byte)0xaf, (byte)0x86, 0x4});
123        performTest(0x3cc8eb78, new byte[]{(byte)0xf8, (byte)0xd6, (byte)0xa3, (byte)0xe6, 0x3});
124        performTest(0x51307f32, new byte[]{(byte)0xb2, (byte)0xfe, (byte)0xc1, (byte)0x89, 0x5});
125        performTest(0x8893, new byte[]{(byte)0x93, (byte)0x91, 0x2});
126        performTest(0x80fb, new byte[]{(byte)0xfb, (byte)0x81, 0x2});
127        performTest(0x3d, new byte[]{0x3d});
128        performTest(0x987c, new byte[]{(byte)0xfc, (byte)0xb0, 0x2});
129        performTest(0x5b2478, new byte[]{(byte)0xf8, (byte)0xc8, (byte)0xec, 0x2});
130        performTest(0x65350ed9, new byte[]{(byte)0xd9, (byte)0x9d, (byte)0xd4, (byte)0xa9, 0x6});
131        performTest(0x3e, new byte[]{0x3e});
132        performTest(0x7b1e, new byte[]{(byte)0x9e, (byte)0xf6, 0x1});
133        performTest(0xb5, new byte[]{(byte)0xb5, 0x1});
134        performTest(0x96, new byte[]{(byte)0x96, 0x1});
135        performTest(0xa1, new byte[]{(byte)0xa1, 0x1});
136        performTest(0x4d50a85d, new byte[]{(byte)0xdd, (byte)0xd0, (byte)0xc2, (byte)0xea, 0x4});
137        performTest(0xc419, new byte[]{(byte)0x99, (byte)0x88, 0x3});
138        performTest(0xcf34, new byte[]{(byte)0xb4, (byte)0x9e, 0x3});
139        performTest(0x527d, new byte[]{(byte)0xfd, (byte)0xa4, 0x1});
140        performTest(0x5a2894, new byte[]{(byte)0x94, (byte)0xd1, (byte)0xe8, 0x2});
141        performTest(0xa6, new byte[]{(byte)0xa6, 0x1});
142        performTest(0x3e05, new byte[]{(byte)0x85, (byte)0xfc, 0x0});
143        performTest(0x5f, new byte[]{(byte)0xdf, 0x0});
144        performTest(0xe2d9af, new byte[]{(byte)0xaf, (byte)0xb3, (byte)0x8b, 0x7});
145        performTest(0xa853fe14, new byte[]{(byte)0x94, (byte)0xfc, (byte)0xcf, (byte)0xc2, 0xa});
146        performTest(0xa853fe14, new byte[]{(byte)0x94, (byte)0xfc, (byte)0xcf, (byte)0xc2, 0x7a});
147        performTest(0x117de731, new byte[]{(byte)0xb1, (byte)0xce, (byte)0xf7, (byte)0x8b, 0x1});
148        performTest(0xb7c9, new byte[]{(byte)0xc9, (byte)0xef, 0x2});
149        performTest(0xb1, new byte[]{(byte)0xb1, 0x1});
150        performTest(0x4f194d, new byte[]{(byte)0xcd, (byte)0xb2, (byte)0xbc, 0x2});
151        performTest(0x8d5733, new byte[]{(byte)0xb3, (byte)0xae, (byte)0xb5, 0x4});
152        performTest(0x2824e9ae, new byte[]{(byte)0xae, (byte)0xd3, (byte)0x93, (byte)0xc1, 0x2});
153        performTest(0x792e, new byte[]{(byte)0xae, (byte)0xf2, 0x1});
154        performTest(0xadef, new byte[]{(byte)0xef, (byte)0xdb, 0x2});
155        performTest(0x5c, new byte[]{(byte)0xdc, 0x0});
156        performTest(0x14f9ccf8, new byte[]{(byte)0xf8, (byte)0x99, (byte)0xe7, (byte)0xa7, 0x1});
157        performTest(0xd1, new byte[]{(byte)0xd1, 0x1});
158        performTest(0xba787ecd, new byte[]{(byte)0xcd, (byte)0xfd, (byte)0xe1, (byte)0xd3, 0x7b});
159        performTest(0x4f, new byte[]{(byte)0xcf, 0x0});
160        performTest(0xfb03, new byte[]{(byte)0x83, (byte)0xf6, 0x3});
161        performTest(0xee3f7cd8, new byte[]{(byte)0xd8, (byte)0xf9, (byte)0xfd, (byte)0xf1, 0x7e});
162        performTest(0x9a6e, new byte[]{(byte)0xee, (byte)0xb4, 0x2});
163        performTest(0x8f0983, new byte[]{(byte)0x83, (byte)0x93, (byte)0xbc, 0x4});
164        performTest(0x3a00e01f, new byte[]{(byte)0x9f, (byte)0xc0, (byte)0x83, (byte)0xd0, 0x3});
165        performTest(0x7f532d93, new byte[]{(byte)0x93, (byte)0xdb, (byte)0xcc, (byte)0xfa, 0x7});
166        performTest(0x179d8d, new byte[]{(byte)0x8d, (byte)0xbb, (byte)0xde, 0x0});
167        performTest(0xfc5, new byte[]{(byte)0xc5, 0x1f});
168        performTest(0x11, new byte[]{0x11});
169        performTest(0xc9b53e8, new byte[]{(byte)0xe8, (byte)0xa7, (byte)0xed, (byte)0xe4, 0x0});
170        performTest(0x97, new byte[]{(byte)0x97, 0x1});
171        performTest(0x52b3, new byte[]{(byte)0xb3, (byte)0xa5, 0x1});
172        performTest(0x92, new byte[]{(byte)0x92, 0x1});
173        performTest(0xd2, new byte[]{(byte)0xd2, 0x1});
174        performTest(0x13d330, new byte[]{(byte)0xb0, (byte)0xa6, (byte)0xcf, 0x0});
175        performTest(0x672f41, new byte[]{(byte)0xc1, (byte)0xde, (byte)0x9c, 0x3});
176        performTest(0xcf, new byte[]{(byte)0xcf, 0x1});
177        performTest(0x54ddb6dd, new byte[]{(byte)0xdd, (byte)0xed, (byte)0xf6, (byte)0xa6, 0x5});
178        performTest(0x7ebcae, new byte[]{(byte)0xae, (byte)0xf9, (byte)0xfa, 0x3});
179        performTest(0x38, new byte[]{0x38});
180        performTest(0x8118f4e7, new byte[]{(byte)0xe7, (byte)0xe9, (byte)0xe3, (byte)0x88, 0x78});
181        performTest(0xac, new byte[]{(byte)0xac, 0x1});
182        performTest(0xab309c, new byte[]{(byte)0x9c, (byte)0xe1, (byte)0xac, 0x5});
183        performTest(0x1bf9b2, new byte[]{(byte)0xb2, (byte)0xf3, (byte)0xef, 0x0});
184        performTest(0x8b3c70, new byte[]{(byte)0xf0, (byte)0xf8, (byte)0xac, 0x4});
185        performTest(0x7774, new byte[]{(byte)0xf4, (byte)0xee, 0x1});
186        performTest(0x33e839, new byte[]{(byte)0xb9, (byte)0xd0, (byte)0xcf, 0x1});
187        performTest(0x84d655a0, new byte[]{(byte)0xa0, (byte)0xab, (byte)0xd9, (byte)0xa6, 0x78});
188        performTest(0xf3543ef3, new byte[]{(byte)0xf3, (byte)0xfd, (byte)0xd0, (byte)0x9a, 0x7f});
189        performTest(0x1d777e, new byte[]{(byte)0xfe, (byte)0xee, (byte)0xf5, 0x0});
190        performTest(0xf7, new byte[]{(byte)0xf7, 0x1});
191        performTest(0x2444, new byte[]{(byte)0xc4, (byte)0xc8, 0x0});
192        performTest(0x536b, new byte[]{(byte)0xeb, (byte)0xa6, 0x1});
193        performTest(0xa8, new byte[]{(byte)0xa8, 0x1});
194        performTest(0xdbfc, new byte[]{(byte)0xfc, (byte)0xb7, 0x3});
195        performTest(0xe66db7, new byte[]{(byte)0xb7, (byte)0xdb, (byte)0x99, 0x7});
196        performTest(0xb7ca, new byte[]{(byte)0xca, (byte)0xef, 0x2});
197        performTest(0xe807d0e5, new byte[]{(byte)0xe5, (byte)0xa1, (byte)0x9f, (byte)0xc0, 0x7e});
198        performTest(0x6a4, new byte[]{(byte)0xa4, 0xd});
199        performTest(0x64, new byte[]{(byte)0xe4, 0x0});
200        performTest(0xf3fb75, new byte[]{(byte)0xf5, (byte)0xf6, (byte)0xcf, 0x7});
201        performTest(0xb72cb6b9, new byte[]{(byte)0xb9, (byte)0xed, (byte)0xb2, (byte)0xb9, 0x7b});
202        performTest(0xfd, new byte[]{(byte)0xfd, 0x1});
203        performTest(0xb48b, new byte[]{(byte)0x8b, (byte)0xe9, 0x2});
204        performTest(0x39c3, new byte[]{(byte)0xc3, (byte)0xf3, 0x0});
205        performTest(0x12b8afbd, new byte[]{(byte)0xbd, (byte)0xdf, (byte)0xe2, (byte)0x95, 0x1});
206        performTest(0x56f149, new byte[]{(byte)0xc9, (byte)0xe2, (byte)0xdb, 0x2});
207        performTest(0xbf, new byte[]{(byte)0xbf, 0x1});
208        performTest(0x3ac72481, new byte[]{(byte)0x81, (byte)0xc9, (byte)0x9c, (byte)0xd6, 0x3});
209        performTest(0xb69ca721, new byte[]{(byte)0xa1, (byte)0xce, (byte)0xf2, (byte)0xb4, 0x7b});
210        performTest(0x2380, new byte[]{(byte)0x80, (byte)0xc7, 0x0});
211        performTest(0x656268, new byte[]{(byte)0xe8, (byte)0xc4, (byte)0x95, 0x3});
212        performTest(0x71, new byte[]{(byte)0xf1, 0x0});
213        performTest(0xf06425, new byte[]{(byte)0xa5, (byte)0xc8, (byte)0xc1, 0x7});
214        performTest(0xb587cb, new byte[]{(byte)0xcb, (byte)0x8f, (byte)0xd6, 0x5});
215        performTest(0x8742, new byte[]{(byte)0xc2, (byte)0x8e, 0x2});
216        performTest(0xc6, new byte[]{(byte)0xc6, 0x1});
217        performTest(0xee62789f, new byte[]{(byte)0x9f, (byte)0xf1, (byte)0x89, (byte)0xf3, 0x7e});
218        performTest(0x470a, new byte[]{(byte)0x8a, (byte)0x8e, 0x1});
219        performTest(0x11ef5cdc, new byte[]{(byte)0xdc, (byte)0xb9, (byte)0xbd, (byte)0x8f, 0x1});
220        performTest(0xc44ea9, new byte[]{(byte)0xa9, (byte)0x9d, (byte)0x91, 0x6});
221        performTest(0x94477f78, new byte[]{(byte)0xf8, (byte)0xfe, (byte)0x9d, (byte)0xa2, 0x79});
222        performTest(0xe47a0b4f, new byte[]{(byte)0xcf, (byte)0x96, (byte)0xe8, (byte)0xa3, 0x7e});
223    }
224
225    @Test
226    public void testSleb128Failure() {
227        // test the case when the MSB of the last byte is set
228
229        performFailureTest(new byte[]{(byte)0x80, (byte)0x80, (byte)0x80, (byte)0x80, (byte)0x81, 0x11});
230        performFailureTest(new byte[]{(byte)0x80, (byte)0x80, (byte)0x80, (byte)0x80, (byte)0x82, 0x11});
231        performFailureTest(new byte[]{(byte)0x80, (byte)0x80, (byte)0x80, (byte)0x80, (byte)0x87, 0x11});
232        performFailureTest(new byte[]{(byte)0x80, (byte)0x80, (byte)0x80, (byte)0x80, (byte)0x97, 0x11});
233        performFailureTest(new byte[]{(byte)0x80, (byte)0x80, (byte)0x80, (byte)0x80, (byte)0xc7, 0x11});
234        performFailureTest(new byte[]{(byte)0x80, (byte)0x80, (byte)0x80, (byte)0x80, (byte)0xf7, 0x11});
235        performFailureTest(new byte[]{(byte)0x80, (byte)0x80, (byte)0x80, (byte)0x80, (byte)0x88, 0x11});
236        performFailureTest(new byte[]{(byte)0x80, (byte)0x80, (byte)0x80, (byte)0x80, (byte)0x8e, 0x11});
237        performFailureTest(new byte[]{(byte)0x80, (byte)0x80, (byte)0x80, (byte)0x80, (byte)0x8f, 0x11});
238        performFailureTest(new byte[]{(byte)0x80, (byte)0x80, (byte)0x80, (byte)0x80, (byte)0xff, 0x11});
239
240        performFailureTest(new byte[]{(byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0x81, 0x11});
241        performFailureTest(new byte[]{(byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0x82, 0x11});
242        performFailureTest(new byte[]{(byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0x87, 0x11});
243        performFailureTest(new byte[]{(byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0x97, 0x11});
244        performFailureTest(new byte[]{(byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xc7, 0x11});
245        performFailureTest(new byte[]{(byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xf7, 0x11});
246        performFailureTest(new byte[]{(byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0x88, 0x11});
247        performFailureTest(new byte[]{(byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0x8e, 0x11});
248        performFailureTest(new byte[]{(byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, 0x11});
249    }
250
251    private void performTest(int expectedValue, byte[] buf) {
252        performTest(expectedValue, buf, buf.length);
253    }
254
255    private void performTest(int expectedValue, byte[] buf, int expectedLength) {
256        BaseDexBuffer dexBuf = new BaseDexBuffer(buf);
257        BaseDexReader reader = dexBuf.readerAt(0);
258        Assert.assertEquals(expectedValue, reader.readSleb128());
259        Assert.assertEquals(expectedLength, reader.getOffset());
260    }
261
262    private void performFailureTest(byte[] buf) {
263        BaseDexBuffer dexBuf = new BaseDexBuffer(buf);
264        BaseDexReader reader = dexBuf.readerAt(0);
265        try {
266            reader.readSleb128();
267            Assert.fail();
268        } catch (ExceptionWithContext ex) {
269            // expected exception
270        }
271    }
272}
273