Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: third_party/android_platform/relocation_packer/src/sleb128_unittest.cc

Issue 1027823002: Port Android relocation packer to chromium build (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "sleb128.h" 5 #include "sleb128.h"
6 6
7 #include <vector> 7 #include <vector>
8 #include "elf_traits.h" 8 #include "elf_traits.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "gtest/gtest.h"
10 10
11 namespace relocation_packer { 11 namespace relocation_packer {
12 12
13 TEST(Sleb128, Encoder) { 13 TEST(Sleb128, Encoder64) {
14 std::vector<ELF::Sxword> values; 14 std::vector<uint64_t> values;
15 values.push_back(624485); 15 values.push_back(624485U);
16 values.push_back(0); 16 values.push_back(0U);
17 values.push_back(1); 17 values.push_back(1U);
18 values.push_back(63); 18 values.push_back(63U);
19 values.push_back(64); 19 values.push_back(64U);
20 values.push_back(-1); 20 values.push_back(static_cast<uint64_t>(-1));
21 values.push_back(-624485); 21 values.push_back(static_cast<uint64_t>(-624485));
22 22
23 Sleb128Encoder encoder; 23 Sleb128Encoder<uint64_t> encoder;
24 encoder.EnqueueAll(values); 24 encoder.EnqueueAll(values);
25 25
26 encoder.Enqueue(2147483647); 26 encoder.Enqueue(2147483647U);
27 encoder.Enqueue(-2147483648); 27 encoder.Enqueue(static_cast<uint64_t>(-2147483648));
28 encoder.Enqueue(9223372036854775807ll); 28 encoder.Enqueue(9223372036854775807ULL);
29 encoder.Enqueue(-9223372036854775807ll - 1); 29 encoder.Enqueue(static_cast<uint64_t>(-9223372036854775807LL - 1));
30 30
31 std::vector<uint8_t> encoding; 31 std::vector<uint8_t> encoding;
32 encoder.GetEncoding(&encoding); 32 encoder.GetEncoding(&encoding);
33 33
34 EXPECT_EQ(42u, encoding.size()); 34 EXPECT_EQ(42u, encoding.size());
35 // 624485 35 // 624485
36 EXPECT_EQ(0xe5, encoding[0]); 36 EXPECT_EQ(0xe5, encoding[0]);
37 EXPECT_EQ(0x8e, encoding[1]); 37 EXPECT_EQ(0x8e, encoding[1]);
38 EXPECT_EQ(0x26, encoding[2]); 38 EXPECT_EQ(0x26, encoding[2]);
39 // 0 39 // 0
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 encoding.push_back(0x80); 136 encoding.push_back(0x80);
137 encoding.push_back(0x80); 137 encoding.push_back(0x80);
138 encoding.push_back(0x80); 138 encoding.push_back(0x80);
139 encoding.push_back(0x80); 139 encoding.push_back(0x80);
140 encoding.push_back(0x80); 140 encoding.push_back(0x80);
141 encoding.push_back(0x80); 141 encoding.push_back(0x80);
142 encoding.push_back(0x80); 142 encoding.push_back(0x80);
143 encoding.push_back(0x80); 143 encoding.push_back(0x80);
144 encoding.push_back(0x7f); 144 encoding.push_back(0x7f);
145 145
146 Sleb128Decoder decoder(encoding); 146 Sleb128Decoder<uint64_t> decoder(encoding, 0);
147 147
148 EXPECT_EQ(624485, decoder.Dequeue()); 148 EXPECT_EQ(624485U, decoder.Dequeue());
149 149
150 std::vector<ELF::Sxword> dequeued; 150 std::vector<uint64_t> dequeued;
151 decoder.DequeueAll(&dequeued); 151 decoder.DequeueAll(&dequeued);
152 152
153 EXPECT_EQ(10u, dequeued.size()); 153 EXPECT_EQ(10U, dequeued.size());
154 EXPECT_EQ(0, dequeued[0]); 154 EXPECT_EQ(0U, dequeued[0]);
155 EXPECT_EQ(1, dequeued[1]); 155 EXPECT_EQ(1U, dequeued[1]);
156 EXPECT_EQ(63, dequeued[2]); 156 EXPECT_EQ(63U, dequeued[2]);
157 EXPECT_EQ(64, dequeued[3]); 157 EXPECT_EQ(64U, dequeued[3]);
158 EXPECT_EQ(-1, dequeued[4]); 158 EXPECT_EQ(static_cast<uint64_t>(-1), dequeued[4]);
159 EXPECT_EQ(-624485, dequeued[5]); 159 EXPECT_EQ(static_cast<uint64_t>(-624485), dequeued[5]);
160 EXPECT_EQ(2147483647, dequeued[6]); 160 EXPECT_EQ(2147483647U, dequeued[6]);
161 EXPECT_EQ(-2147483648, dequeued[7]); 161 EXPECT_EQ(static_cast<uint64_t>(-2147483648), dequeued[7]);
162 EXPECT_EQ(9223372036854775807ll, dequeued[8]); 162 EXPECT_EQ(9223372036854775807ULL, dequeued[8]);
163 EXPECT_EQ(-9223372036854775807ll - 1, dequeued[9]); 163 EXPECT_EQ(static_cast<uint64_t>(-9223372036854775807LL - 1), dequeued[9]);
164 } 164 }
165 165
166 } // namespace relocation_packer 166 } // namespace relocation_packer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698