1 // leb_unittest.cc -- test read_signed_LEB_128 and read_unsigned_LEB_128
3 // Copyright (C) 2012-2019 Free Software Foundation, Inc.
4 // Written by Cary Coutant <ccoutant@google.com>.
6 // This file is part of gold.
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 3 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 // MA 02110-1301, USA.
25 #include <sys/types.h>
27 #include "int_encoding.h"
31 namespace gold_testsuite
37 Leb128_test(Test_report
*)
42 static unsigned char u1
[] = { 0 }; // 0
43 static unsigned char u2
[] = { 1 }; // 1
44 static unsigned char u3
[] = { 126 }; // 126
45 static unsigned char u4
[] = { 127 }; // 127
46 static unsigned char u5
[] = { 0x80+0, 1 }; // 128
47 static unsigned char u6
[] = { 0x80+1, 1 }; // 129
48 static unsigned char u7
[] = { 0x80+57, 100 }; // 12857
49 static unsigned char u8
[] = { 0x80, 0x80, 0x80, 0x80,
50 0x80, 0x80, 0x80, 0x80,
51 0x80, 1}; // 1ULL << 63
54 static unsigned char s1
[] = { 0 }; // 0
55 static unsigned char s2
[] = { 1 }; // 1
56 static unsigned char s3
[] = { 0x7e }; // -2
57 static unsigned char s4
[] = { 0x80+127, 0 }; // 127
58 static unsigned char s5
[] = { 0x80+1, 0x7f }; // -127
59 static unsigned char s6
[] = { 0x80+0, 1 }; // 128
60 static unsigned char s7
[] = { 0x80+0, 0x7f }; // -128
61 static unsigned char s8
[] = { 0x80+1, 1 }; // 129
62 static unsigned char s9
[] = { 0xff, 0x7e }; // -129
64 CHECK(read_unsigned_LEB_128(u1
, &len
) == 0 && len
== sizeof(u1
));
65 CHECK(read_unsigned_LEB_128(u2
, &len
) == 1 && len
== sizeof(u2
));
66 CHECK(read_unsigned_LEB_128(u3
, &len
) == 126 && len
== sizeof(u3
));
67 CHECK(read_unsigned_LEB_128(u4
, &len
) == 127 && len
== sizeof(u4
));
68 CHECK(read_unsigned_LEB_128(u5
, &len
) == 128 && len
== sizeof(u5
));
69 CHECK(read_unsigned_LEB_128(u6
, &len
) == 129 && len
== sizeof(u6
));
70 CHECK(read_unsigned_LEB_128(u7
, &len
) == 12857 && len
== sizeof(u7
));
71 CHECK(read_unsigned_LEB_128(u8
, &len
) == (1ULL << 63) && len
== sizeof(u8
));
73 CHECK(read_signed_LEB_128(s1
, &len
) == 0 && len
== sizeof(s1
));
74 CHECK(read_signed_LEB_128(s2
, &len
) == 1 && len
== sizeof(s2
));
75 CHECK(read_signed_LEB_128(s3
, &len
) == -2 && len
== sizeof(s3
));
76 CHECK(read_signed_LEB_128(s4
, &len
) == 127 && len
== sizeof(s4
));
77 CHECK(read_signed_LEB_128(s5
, &len
) == -127 && len
== sizeof(s5
));
78 CHECK(read_signed_LEB_128(s6
, &len
) == 128 && len
== sizeof(s6
));
79 CHECK(read_signed_LEB_128(s7
, &len
) == -128 && len
== sizeof(s7
));
80 CHECK(read_signed_LEB_128(s8
, &len
) == 129 && len
== sizeof(s8
));
81 CHECK(read_signed_LEB_128(s9
, &len
) == -129 && len
== sizeof(s9
));
86 Register_test
leb128_register("LEB128", Leb128_test
);
88 } // End namespace gold_testsuite.
This page took 0.03276 seconds and 5 git commands to generate.