[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / llvm / unittests / Support / LEB128Test.cpp
blob986d29358458d26d3cb00546929f0da73717cc47
1 //===- llvm/unittest/Support/LEB128Test.cpp - LEB128 function tests -------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "llvm/Support/LEB128.h"
10 #include "llvm/Support/DataTypes.h"
11 #include "llvm/Support/raw_ostream.h"
12 #include "gtest/gtest.h"
13 #include <string>
14 using namespace llvm;
16 namespace {
18 TEST(LEB128Test, EncodeSLEB128) {
19 #define EXPECT_SLEB128_EQ(EXPECTED, VALUE, PAD) \
20 do { \
21 std::string Expected(EXPECTED, sizeof(EXPECTED) - 1); \
23 /* encodeSLEB128(uint64_t, raw_ostream &, unsigned) */ \
24 std::string Actual1; \
25 raw_string_ostream Stream(Actual1); \
26 encodeSLEB128(VALUE, Stream, PAD); \
27 Stream.flush(); \
28 EXPECT_EQ(Expected, Actual1); \
30 /* encodeSLEB128(uint64_t, uint8_t *, unsigned) */ \
31 uint8_t Buffer[32]; \
32 unsigned Size = encodeSLEB128(VALUE, Buffer, PAD); \
33 std::string Actual2(reinterpret_cast<const char *>(Buffer), Size); \
34 EXPECT_EQ(Expected, Actual2); \
35 } while (0)
37 // Encode SLEB128
38 EXPECT_SLEB128_EQ("\x00", 0, 0);
39 EXPECT_SLEB128_EQ("\x01", 1, 0);
40 EXPECT_SLEB128_EQ("\x7f", -1, 0);
41 EXPECT_SLEB128_EQ("\x3f", 63, 0);
42 EXPECT_SLEB128_EQ("\x41", -63, 0);
43 EXPECT_SLEB128_EQ("\x40", -64, 0);
44 EXPECT_SLEB128_EQ("\xbf\x7f", -65, 0);
45 EXPECT_SLEB128_EQ("\xc0\x00", 64, 0);
47 // Encode SLEB128 with some extra padding bytes
48 EXPECT_SLEB128_EQ("\x80\x00", 0, 2);
49 EXPECT_SLEB128_EQ("\x80\x80\x00", 0, 3);
50 EXPECT_SLEB128_EQ("\xff\x80\x00", 0x7f, 3);
51 EXPECT_SLEB128_EQ("\xff\x80\x80\x00", 0x7f, 4);
52 EXPECT_SLEB128_EQ("\x80\x81\x00", 0x80, 3);
53 EXPECT_SLEB128_EQ("\x80\x81\x80\x00", 0x80, 4);
54 EXPECT_SLEB128_EQ("\xc0\x7f", -0x40, 2);
56 EXPECT_SLEB128_EQ("\xc0\xff\x7f", -0x40, 3);
57 EXPECT_SLEB128_EQ("\x80\xff\x7f", -0x80, 3);
58 EXPECT_SLEB128_EQ("\x80\xff\xff\x7f", -0x80, 4);
60 #undef EXPECT_SLEB128_EQ
63 TEST(LEB128Test, EncodeULEB128) {
64 #define EXPECT_ULEB128_EQ(EXPECTED, VALUE, PAD) \
65 do { \
66 std::string Expected(EXPECTED, sizeof(EXPECTED) - 1); \
68 /* encodeULEB128(uint64_t, raw_ostream &, unsigned) */ \
69 std::string Actual1; \
70 raw_string_ostream Stream(Actual1); \
71 encodeULEB128(VALUE, Stream, PAD); \
72 Stream.flush(); \
73 EXPECT_EQ(Expected, Actual1); \
75 /* encodeULEB128(uint64_t, uint8_t *, unsigned) */ \
76 uint8_t Buffer[32]; \
77 unsigned Size = encodeULEB128(VALUE, Buffer, PAD); \
78 std::string Actual2(reinterpret_cast<const char *>(Buffer), Size); \
79 EXPECT_EQ(Expected, Actual2); \
80 } while (0)
82 // Encode ULEB128
83 EXPECT_ULEB128_EQ("\x00", 0, 0);
84 EXPECT_ULEB128_EQ("\x01", 1, 0);
85 EXPECT_ULEB128_EQ("\x3f", 63, 0);
86 EXPECT_ULEB128_EQ("\x40", 64, 0);
87 EXPECT_ULEB128_EQ("\x7f", 0x7f, 0);
88 EXPECT_ULEB128_EQ("\x80\x01", 0x80, 0);
89 EXPECT_ULEB128_EQ("\x81\x01", 0x81, 0);
90 EXPECT_ULEB128_EQ("\x90\x01", 0x90, 0);
91 EXPECT_ULEB128_EQ("\xff\x01", 0xff, 0);
92 EXPECT_ULEB128_EQ("\x80\x02", 0x100, 0);
93 EXPECT_ULEB128_EQ("\x81\x02", 0x101, 0);
95 // Encode ULEB128 with some extra padding bytes
96 EXPECT_ULEB128_EQ("\x80\x00", 0, 2);
97 EXPECT_ULEB128_EQ("\x80\x80\x00", 0, 3);
98 EXPECT_ULEB128_EQ("\xff\x00", 0x7f, 2);
99 EXPECT_ULEB128_EQ("\xff\x80\x00", 0x7f, 3);
100 EXPECT_ULEB128_EQ("\x80\x81\x00", 0x80, 3);
101 EXPECT_ULEB128_EQ("\x80\x81\x80\x00", 0x80, 4);
103 #undef EXPECT_ULEB128_EQ
106 TEST(LEB128Test, DecodeULEB128) {
107 #define EXPECT_DECODE_ULEB128_EQ(EXPECTED, VALUE) \
108 do { \
109 unsigned ActualSize = 0; \
110 uint64_t Actual = decodeULEB128(reinterpret_cast<const uint8_t *>(VALUE), \
111 &ActualSize); \
112 EXPECT_EQ(sizeof(VALUE) - 1, ActualSize); \
113 EXPECT_EQ(EXPECTED, Actual); \
114 } while (0)
116 // Don't crash
117 EXPECT_EQ(0u, decodeULEB128(nullptr, nullptr, nullptr));
119 // Decode ULEB128
120 EXPECT_DECODE_ULEB128_EQ(0u, "\x00");
121 EXPECT_DECODE_ULEB128_EQ(1u, "\x01");
122 EXPECT_DECODE_ULEB128_EQ(63u, "\x3f");
123 EXPECT_DECODE_ULEB128_EQ(64u, "\x40");
124 EXPECT_DECODE_ULEB128_EQ(0x7fu, "\x7f");
125 EXPECT_DECODE_ULEB128_EQ(0x80u, "\x80\x01");
126 EXPECT_DECODE_ULEB128_EQ(0x81u, "\x81\x01");
127 EXPECT_DECODE_ULEB128_EQ(0x90u, "\x90\x01");
128 EXPECT_DECODE_ULEB128_EQ(0xffu, "\xff\x01");
129 EXPECT_DECODE_ULEB128_EQ(0x100u, "\x80\x02");
130 EXPECT_DECODE_ULEB128_EQ(0x101u, "\x81\x02");
131 EXPECT_DECODE_ULEB128_EQ(4294975616ULL, "\x80\xc1\x80\x80\x10");
133 // Decode ULEB128 with extra padding bytes
134 EXPECT_DECODE_ULEB128_EQ(0u, "\x80\x00");
135 EXPECT_DECODE_ULEB128_EQ(0u, "\x80\x80\x00");
136 EXPECT_DECODE_ULEB128_EQ(0x7fu, "\xff\x00");
137 EXPECT_DECODE_ULEB128_EQ(0x7fu, "\xff\x80\x00");
138 EXPECT_DECODE_ULEB128_EQ(0x80u, "\x80\x81\x00");
139 EXPECT_DECODE_ULEB128_EQ(0x80u, "\x80\x81\x80\x00");
140 EXPECT_DECODE_ULEB128_EQ(0x80u, "\x80\x81\x80\x80\x80\x80\x80\x80\x80\x00");
141 EXPECT_DECODE_ULEB128_EQ(0x80000000'00000000ul,
142 "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x01");
144 #undef EXPECT_DECODE_ULEB128_EQ
147 TEST(LEB128Test, DecodeInvalidULEB128) {
148 #define EXPECT_INVALID_ULEB128(VALUE, ERROR_OFFSET) \
149 do { \
150 const uint8_t *Value = reinterpret_cast<const uint8_t *>(VALUE); \
151 const char *Error = nullptr; \
152 unsigned ErrorOffset = 0; \
153 uint64_t Actual = \
154 decodeULEB128(Value, &ErrorOffset, Value + strlen(VALUE), &Error); \
155 EXPECT_NE(Error, nullptr); \
156 EXPECT_EQ(0ul, Actual); \
157 EXPECT_EQ(ERROR_OFFSET, ErrorOffset); \
158 } while (0)
160 // Buffer overflow.
161 EXPECT_INVALID_ULEB128("", 0u);
162 EXPECT_INVALID_ULEB128("\x80", 1u);
164 // Does not fit in 64 bits.
165 EXPECT_INVALID_ULEB128("\x80\x80\x80\x80\x80\x80\x80\x80\x80\x02", 9u);
166 EXPECT_INVALID_ULEB128("\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x02", 10u);
168 #undef EXPECT_INVALID_ULEB128
171 TEST(LEB128Test, DecodeSLEB128) {
172 #define EXPECT_DECODE_SLEB128_EQ(EXPECTED, VALUE) \
173 do { \
174 unsigned ActualSize = 0; \
175 int64_t Actual = decodeSLEB128(reinterpret_cast<const uint8_t *>(VALUE), \
176 &ActualSize); \
177 EXPECT_EQ(sizeof(VALUE) - 1, ActualSize); \
178 EXPECT_EQ(EXPECTED, Actual); \
179 } while (0)
181 // Don't crash
182 EXPECT_EQ(0, decodeSLEB128(nullptr, nullptr, nullptr));
184 // Decode SLEB128
185 EXPECT_DECODE_SLEB128_EQ(0L, "\x00");
186 EXPECT_DECODE_SLEB128_EQ(1L, "\x01");
187 EXPECT_DECODE_SLEB128_EQ(63L, "\x3f");
188 EXPECT_DECODE_SLEB128_EQ(-64L, "\x40");
189 EXPECT_DECODE_SLEB128_EQ(-63L, "\x41");
190 EXPECT_DECODE_SLEB128_EQ(-1L, "\x7f");
191 EXPECT_DECODE_SLEB128_EQ(128L, "\x80\x01");
192 EXPECT_DECODE_SLEB128_EQ(129L, "\x81\x01");
193 EXPECT_DECODE_SLEB128_EQ(-129L, "\xff\x7e");
194 EXPECT_DECODE_SLEB128_EQ(-128L, "\x80\x7f");
195 EXPECT_DECODE_SLEB128_EQ(-127L, "\x81\x7f");
196 EXPECT_DECODE_SLEB128_EQ(64L, "\xc0\x00");
197 EXPECT_DECODE_SLEB128_EQ(-12345L, "\xc7\x9f\x7f");
199 // Decode unnormalized SLEB128 with extra padding bytes.
200 EXPECT_DECODE_SLEB128_EQ(0L, "\x80\x00");
201 EXPECT_DECODE_SLEB128_EQ(0L, "\x80\x80\x00");
202 EXPECT_DECODE_SLEB128_EQ(0x7fL, "\xff\x00");
203 EXPECT_DECODE_SLEB128_EQ(0x7fL, "\xff\x80\x00");
204 EXPECT_DECODE_SLEB128_EQ(0x80L, "\x80\x81\x00");
205 EXPECT_DECODE_SLEB128_EQ(0x80L, "\x80\x81\x80\x00");
206 EXPECT_DECODE_SLEB128_EQ(0x80L, "\x80\x81\x80\x80\x80\x80\x80\x80\x80\x00");
207 EXPECT_DECODE_SLEB128_EQ(-2L, "\xFE\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x7F");
208 EXPECT_DECODE_SLEB128_EQ(INT64_MIN,
209 "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x7F");
210 EXPECT_DECODE_SLEB128_EQ(INT64_MAX,
211 "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00");
213 #undef EXPECT_DECODE_SLEB128_EQ
216 TEST(LEB128Test, DecodeInvalidSLEB128) {
217 #define EXPECT_INVALID_SLEB128(VALUE, ERROR_OFFSET) \
218 do { \
219 const uint8_t *Value = reinterpret_cast<const uint8_t *>(VALUE); \
220 const char *Error = nullptr; \
221 unsigned ErrorOffset = 0; \
222 uint64_t Actual = \
223 decodeSLEB128(Value, &ErrorOffset, Value + strlen(VALUE), &Error); \
224 EXPECT_NE(Error, nullptr); \
225 EXPECT_EQ(0ul, Actual); \
226 EXPECT_EQ(ERROR_OFFSET, ErrorOffset); \
227 } while (0)
229 // Buffer overflow.
230 EXPECT_INVALID_SLEB128("", 0u);
231 EXPECT_INVALID_SLEB128("\x80", 1u);
233 // Does not fit in 64 bits.
234 EXPECT_INVALID_SLEB128("\x80\x80\x80\x80\x80\x80\x80\x80\x80\x01", 9u);
235 EXPECT_INVALID_SLEB128("\x80\x80\x80\x80\x80\x80\x80\x80\x80\x7E", 9u);
236 EXPECT_INVALID_SLEB128("\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x02", 10u);
237 EXPECT_INVALID_SLEB128("\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x7E", 9u);
238 EXPECT_INVALID_SLEB128("\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x01", 9u);
239 EXPECT_INVALID_SLEB128("\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x7E", 10u);
240 EXPECT_INVALID_SLEB128("\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00", 10u);
242 #undef EXPECT_INVALID_SLEB128
245 TEST(LEB128Test, SLEB128Size) {
246 // Positive Value Testing Plan:
247 // (1) 128 ^ n - 1 ........ need (n+1) bytes
248 // (2) 128 ^ n ............ need (n+1) bytes
249 // (3) 128 ^ n * 63 ....... need (n+1) bytes
250 // (4) 128 ^ n * 64 - 1 ... need (n+1) bytes
251 // (5) 128 ^ n * 64 ....... need (n+2) bytes
253 EXPECT_EQ(1u, getSLEB128Size(0x0LL));
254 EXPECT_EQ(1u, getSLEB128Size(0x1LL));
255 EXPECT_EQ(1u, getSLEB128Size(0x3fLL));
256 EXPECT_EQ(1u, getSLEB128Size(0x3fLL));
257 EXPECT_EQ(2u, getSLEB128Size(0x40LL));
259 EXPECT_EQ(2u, getSLEB128Size(0x7fLL));
260 EXPECT_EQ(2u, getSLEB128Size(0x80LL));
261 EXPECT_EQ(2u, getSLEB128Size(0x1f80LL));
262 EXPECT_EQ(2u, getSLEB128Size(0x1fffLL));
263 EXPECT_EQ(3u, getSLEB128Size(0x2000LL));
265 EXPECT_EQ(3u, getSLEB128Size(0x3fffLL));
266 EXPECT_EQ(3u, getSLEB128Size(0x4000LL));
267 EXPECT_EQ(3u, getSLEB128Size(0xfc000LL));
268 EXPECT_EQ(3u, getSLEB128Size(0xfffffLL));
269 EXPECT_EQ(4u, getSLEB128Size(0x100000LL));
271 EXPECT_EQ(4u, getSLEB128Size(0x1fffffLL));
272 EXPECT_EQ(4u, getSLEB128Size(0x200000LL));
273 EXPECT_EQ(4u, getSLEB128Size(0x7e00000LL));
274 EXPECT_EQ(4u, getSLEB128Size(0x7ffffffLL));
275 EXPECT_EQ(5u, getSLEB128Size(0x8000000LL));
277 EXPECT_EQ(5u, getSLEB128Size(0xfffffffLL));
278 EXPECT_EQ(5u, getSLEB128Size(0x10000000LL));
279 EXPECT_EQ(5u, getSLEB128Size(0x3f0000000LL));
280 EXPECT_EQ(5u, getSLEB128Size(0x3ffffffffLL));
281 EXPECT_EQ(6u, getSLEB128Size(0x400000000LL));
283 EXPECT_EQ(6u, getSLEB128Size(0x7ffffffffLL));
284 EXPECT_EQ(6u, getSLEB128Size(0x800000000LL));
285 EXPECT_EQ(6u, getSLEB128Size(0x1f800000000LL));
286 EXPECT_EQ(6u, getSLEB128Size(0x1ffffffffffLL));
287 EXPECT_EQ(7u, getSLEB128Size(0x20000000000LL));
289 EXPECT_EQ(7u, getSLEB128Size(0x3ffffffffffLL));
290 EXPECT_EQ(7u, getSLEB128Size(0x40000000000LL));
291 EXPECT_EQ(7u, getSLEB128Size(0xfc0000000000LL));
292 EXPECT_EQ(7u, getSLEB128Size(0xffffffffffffLL));
293 EXPECT_EQ(8u, getSLEB128Size(0x1000000000000LL));
295 EXPECT_EQ(8u, getSLEB128Size(0x1ffffffffffffLL));
296 EXPECT_EQ(8u, getSLEB128Size(0x2000000000000LL));
297 EXPECT_EQ(8u, getSLEB128Size(0x7e000000000000LL));
298 EXPECT_EQ(8u, getSLEB128Size(0x7fffffffffffffLL));
299 EXPECT_EQ(9u, getSLEB128Size(0x80000000000000LL));
301 EXPECT_EQ(9u, getSLEB128Size(0xffffffffffffffLL));
302 EXPECT_EQ(9u, getSLEB128Size(0x100000000000000LL));
303 EXPECT_EQ(9u, getSLEB128Size(0x3f00000000000000LL));
304 EXPECT_EQ(9u, getSLEB128Size(0x3fffffffffffffffLL));
305 EXPECT_EQ(10u, getSLEB128Size(0x4000000000000000LL));
307 EXPECT_EQ(10u, getSLEB128Size(0x7fffffffffffffffLL));
308 EXPECT_EQ(10u, getSLEB128Size(INT64_MAX));
310 // Negative Value Testing Plan:
311 // (1) - 128 ^ n - 1 ........ need (n+1) bytes
312 // (2) - 128 ^ n ............ need (n+1) bytes
313 // (3) - 128 ^ n * 63 ....... need (n+1) bytes
314 // (4) - 128 ^ n * 64 ....... need (n+1) bytes (different from positive one)
315 // (5) - 128 ^ n * 65 - 1 ... need (n+2) bytes (if n > 0)
316 // (6) - 128 ^ n * 65 ....... need (n+2) bytes
318 EXPECT_EQ(1u, getSLEB128Size(0x0LL));
319 EXPECT_EQ(1u, getSLEB128Size(-0x1LL));
320 EXPECT_EQ(1u, getSLEB128Size(-0x3fLL));
321 EXPECT_EQ(1u, getSLEB128Size(-0x40LL));
322 EXPECT_EQ(1u, getSLEB128Size(-0x40LL)); // special case
323 EXPECT_EQ(2u, getSLEB128Size(-0x41LL));
325 EXPECT_EQ(2u, getSLEB128Size(-0x7fLL));
326 EXPECT_EQ(2u, getSLEB128Size(-0x80LL));
327 EXPECT_EQ(2u, getSLEB128Size(-0x1f80LL));
328 EXPECT_EQ(2u, getSLEB128Size(-0x2000LL));
329 EXPECT_EQ(3u, getSLEB128Size(-0x207fLL));
330 EXPECT_EQ(3u, getSLEB128Size(-0x2080LL));
332 EXPECT_EQ(3u, getSLEB128Size(-0x3fffLL));
333 EXPECT_EQ(3u, getSLEB128Size(-0x4000LL));
334 EXPECT_EQ(3u, getSLEB128Size(-0xfc000LL));
335 EXPECT_EQ(3u, getSLEB128Size(-0x100000LL));
336 EXPECT_EQ(4u, getSLEB128Size(-0x103fffLL));
337 EXPECT_EQ(4u, getSLEB128Size(-0x104000LL));
339 EXPECT_EQ(4u, getSLEB128Size(-0x1fffffLL));
340 EXPECT_EQ(4u, getSLEB128Size(-0x200000LL));
341 EXPECT_EQ(4u, getSLEB128Size(-0x7e00000LL));
342 EXPECT_EQ(4u, getSLEB128Size(-0x8000000LL));
343 EXPECT_EQ(5u, getSLEB128Size(-0x81fffffLL));
344 EXPECT_EQ(5u, getSLEB128Size(-0x8200000LL));
346 EXPECT_EQ(5u, getSLEB128Size(-0xfffffffLL));
347 EXPECT_EQ(5u, getSLEB128Size(-0x10000000LL));
348 EXPECT_EQ(5u, getSLEB128Size(-0x3f0000000LL));
349 EXPECT_EQ(5u, getSLEB128Size(-0x400000000LL));
350 EXPECT_EQ(6u, getSLEB128Size(-0x40fffffffLL));
351 EXPECT_EQ(6u, getSLEB128Size(-0x410000000LL));
353 EXPECT_EQ(6u, getSLEB128Size(-0x7ffffffffLL));
354 EXPECT_EQ(6u, getSLEB128Size(-0x800000000LL));
355 EXPECT_EQ(6u, getSLEB128Size(-0x1f800000000LL));
356 EXPECT_EQ(6u, getSLEB128Size(-0x20000000000LL));
357 EXPECT_EQ(7u, getSLEB128Size(-0x207ffffffffLL));
358 EXPECT_EQ(7u, getSLEB128Size(-0x20800000000LL));
360 EXPECT_EQ(7u, getSLEB128Size(-0x3ffffffffffLL));
361 EXPECT_EQ(7u, getSLEB128Size(-0x40000000000LL));
362 EXPECT_EQ(7u, getSLEB128Size(-0xfc0000000000LL));
363 EXPECT_EQ(7u, getSLEB128Size(-0x1000000000000LL));
364 EXPECT_EQ(8u, getSLEB128Size(-0x103ffffffffffLL));
365 EXPECT_EQ(8u, getSLEB128Size(-0x1040000000000LL));
367 EXPECT_EQ(8u, getSLEB128Size(-0x1ffffffffffffLL));
368 EXPECT_EQ(8u, getSLEB128Size(-0x2000000000000LL));
369 EXPECT_EQ(8u, getSLEB128Size(-0x7e000000000000LL));
370 EXPECT_EQ(8u, getSLEB128Size(-0x80000000000000LL));
371 EXPECT_EQ(9u, getSLEB128Size(-0x81ffffffffffffLL));
372 EXPECT_EQ(9u, getSLEB128Size(-0x82000000000000LL));
374 EXPECT_EQ(9u, getSLEB128Size(-0xffffffffffffffLL));
375 EXPECT_EQ(9u, getSLEB128Size(-0x100000000000000LL));
376 EXPECT_EQ(9u, getSLEB128Size(-0x3f00000000000000LL));
377 EXPECT_EQ(9u, getSLEB128Size(-0x4000000000000000LL));
378 EXPECT_EQ(10u, getSLEB128Size(-0x40ffffffffffffffLL));
379 EXPECT_EQ(10u, getSLEB128Size(-0x4100000000000000LL));
381 EXPECT_EQ(10u, getSLEB128Size(-0x7fffffffffffffffLL));
382 EXPECT_EQ(10u, getSLEB128Size(-0x8000000000000000LL));
383 EXPECT_EQ(10u, getSLEB128Size(INT64_MIN));
386 TEST(LEB128Test, ULEB128Size) {
387 // Testing Plan:
388 // (1) 128 ^ n ............ need (n+1) bytes
389 // (2) 128 ^ n * 64 ....... need (n+1) bytes
390 // (3) 128 ^ (n+1) - 1 .... need (n+1) bytes
392 EXPECT_EQ(1u, getULEB128Size(0)); // special case
394 EXPECT_EQ(1u, getULEB128Size(0x1ULL));
395 EXPECT_EQ(1u, getULEB128Size(0x40ULL));
396 EXPECT_EQ(1u, getULEB128Size(0x7fULL));
398 EXPECT_EQ(2u, getULEB128Size(0x80ULL));
399 EXPECT_EQ(2u, getULEB128Size(0x2000ULL));
400 EXPECT_EQ(2u, getULEB128Size(0x3fffULL));
402 EXPECT_EQ(3u, getULEB128Size(0x4000ULL));
403 EXPECT_EQ(3u, getULEB128Size(0x100000ULL));
404 EXPECT_EQ(3u, getULEB128Size(0x1fffffULL));
406 EXPECT_EQ(4u, getULEB128Size(0x200000ULL));
407 EXPECT_EQ(4u, getULEB128Size(0x8000000ULL));
408 EXPECT_EQ(4u, getULEB128Size(0xfffffffULL));
410 EXPECT_EQ(5u, getULEB128Size(0x10000000ULL));
411 EXPECT_EQ(5u, getULEB128Size(0x400000000ULL));
412 EXPECT_EQ(5u, getULEB128Size(0x7ffffffffULL));
414 EXPECT_EQ(6u, getULEB128Size(0x800000000ULL));
415 EXPECT_EQ(6u, getULEB128Size(0x20000000000ULL));
416 EXPECT_EQ(6u, getULEB128Size(0x3ffffffffffULL));
418 EXPECT_EQ(7u, getULEB128Size(0x40000000000ULL));
419 EXPECT_EQ(7u, getULEB128Size(0x1000000000000ULL));
420 EXPECT_EQ(7u, getULEB128Size(0x1ffffffffffffULL));
422 EXPECT_EQ(8u, getULEB128Size(0x2000000000000ULL));
423 EXPECT_EQ(8u, getULEB128Size(0x80000000000000ULL));
424 EXPECT_EQ(8u, getULEB128Size(0xffffffffffffffULL));
426 EXPECT_EQ(9u, getULEB128Size(0x100000000000000ULL));
427 EXPECT_EQ(9u, getULEB128Size(0x4000000000000000ULL));
428 EXPECT_EQ(9u, getULEB128Size(0x7fffffffffffffffULL));
430 EXPECT_EQ(10u, getULEB128Size(0x8000000000000000ULL));
432 EXPECT_EQ(10u, getULEB128Size(UINT64_MAX));
435 } // anonymous namespace