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

Side by Side Diff: third_party/android_platform/relocation_packer/src/leb128_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 "leb128.h" 5 #include "leb128.h"
6 6
7 #include <vector> 7 #include <vector>
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "gtest/gtest.h"
9 9
10 namespace relocation_packer { 10 namespace relocation_packer {
11 11
12 TEST(Leb128, Encoder) { 12 TEST(Leb128, Encoder64) {
13 std::vector<ELF::Xword> values; 13 std::vector<uint64_t> values;
14 values.push_back(624485); 14 values.push_back(624485);
15 values.push_back(0); 15 values.push_back(0);
16 values.push_back(1); 16 values.push_back(1);
17 values.push_back(127); 17 values.push_back(127);
18 values.push_back(128); 18 values.push_back(128);
19 19
20 Leb128Encoder encoder; 20 Leb128Encoder<uint64_t> encoder;
21 encoder.EnqueueAll(values); 21 encoder.EnqueueAll(values);
22 22
23 encoder.Enqueue(4294967295); 23 encoder.Enqueue(4294967295);
24 encoder.Enqueue(18446744073709551615ul); 24 encoder.Enqueue(18446744073709551615ul);
25 25
26 std::vector<uint8_t> encoding; 26 std::vector<uint8_t> encoding;
27 encoder.GetEncoding(&encoding); 27 encoder.GetEncoding(&encoding);
28 28
29 EXPECT_EQ(23, encoding.size()); 29 EXPECT_EQ(23U, encoding.size());
30 // 624485 30 // 624485
31 EXPECT_EQ(0xe5, encoding[0]); 31 EXPECT_EQ(0xe5, encoding[0]);
32 EXPECT_EQ(0x8e, encoding[1]); 32 EXPECT_EQ(0x8e, encoding[1]);
33 EXPECT_EQ(0x26, encoding[2]); 33 EXPECT_EQ(0x26, encoding[2]);
34 // 0 34 // 0
35 EXPECT_EQ(0x00, encoding[3]); 35 EXPECT_EQ(0x00, encoding[3]);
36 // 1 36 // 1
37 EXPECT_EQ(0x01, encoding[4]); 37 EXPECT_EQ(0x01, encoding[4]);
38 // 127 38 // 127
39 EXPECT_EQ(0x7f, encoding[5]); 39 EXPECT_EQ(0x7f, encoding[5]);
(...skipping 12 matching lines...) Expand all
52 EXPECT_EQ(0xff, encoding[15]); 52 EXPECT_EQ(0xff, encoding[15]);
53 EXPECT_EQ(0xff, encoding[16]); 53 EXPECT_EQ(0xff, encoding[16]);
54 EXPECT_EQ(0xff, encoding[17]); 54 EXPECT_EQ(0xff, encoding[17]);
55 EXPECT_EQ(0xff, encoding[18]); 55 EXPECT_EQ(0xff, encoding[18]);
56 EXPECT_EQ(0xff, encoding[19]); 56 EXPECT_EQ(0xff, encoding[19]);
57 EXPECT_EQ(0xff, encoding[20]); 57 EXPECT_EQ(0xff, encoding[20]);
58 EXPECT_EQ(0xff, encoding[21]); 58 EXPECT_EQ(0xff, encoding[21]);
59 EXPECT_EQ(0x01, encoding[22]); 59 EXPECT_EQ(0x01, encoding[22]);
60 } 60 }
61 61
62 TEST(Leb128, Decoder) { 62 TEST(Leb128, Decoder64) {
63 std::vector<uint8_t> encoding; 63 std::vector<uint8_t> encoding;
64 // 624485 64 // 624485
65 encoding.push_back(0xe5); 65 encoding.push_back(0xe5);
66 encoding.push_back(0x8e); 66 encoding.push_back(0x8e);
67 encoding.push_back(0x26); 67 encoding.push_back(0x26);
68 // 0 68 // 0
69 encoding.push_back(0x00); 69 encoding.push_back(0x00);
70 // 1 70 // 1
71 encoding.push_back(0x01); 71 encoding.push_back(0x01);
72 // 127 72 // 127
(...skipping 12 matching lines...) Expand all
85 encoding.push_back(0xff); 85 encoding.push_back(0xff);
86 encoding.push_back(0xff); 86 encoding.push_back(0xff);
87 encoding.push_back(0xff); 87 encoding.push_back(0xff);
88 encoding.push_back(0xff); 88 encoding.push_back(0xff);
89 encoding.push_back(0xff); 89 encoding.push_back(0xff);
90 encoding.push_back(0xff); 90 encoding.push_back(0xff);
91 encoding.push_back(0xff); 91 encoding.push_back(0xff);
92 encoding.push_back(0xff); 92 encoding.push_back(0xff);
93 encoding.push_back(0x01); 93 encoding.push_back(0x01);
94 94
95 Leb128Decoder decoder(encoding); 95 Leb128Decoder<uint64_t> decoder(encoding, 0);
96 96
97 EXPECT_EQ(624485, decoder.Dequeue()); 97 EXPECT_EQ(624485U, decoder.Dequeue());
98 98
99 std::vector<ELF::Xword> dequeued; 99 std::vector<uint64_t> dequeued;
100 decoder.DequeueAll(&dequeued); 100 decoder.DequeueAll(&dequeued);
101 101
102 EXPECT_EQ(6, dequeued.size()); 102 EXPECT_EQ(6U, dequeued.size());
103 EXPECT_EQ(0, dequeued[0]); 103 EXPECT_EQ(0U, dequeued[0]);
104 EXPECT_EQ(1, dequeued[1]); 104 EXPECT_EQ(1U, dequeued[1]);
105 EXPECT_EQ(127, dequeued[2]); 105 EXPECT_EQ(127U, dequeued[2]);
106 EXPECT_EQ(128, dequeued[3]); 106 EXPECT_EQ(128U, dequeued[3]);
107 EXPECT_EQ(4294967295, dequeued[4]); 107 EXPECT_EQ(4294967295U, dequeued[4]);
108 EXPECT_EQ(18446744073709551615ul, dequeued[5]); 108 EXPECT_EQ(18446744073709551615UL, dequeued[5]);
109 } 109 }
110 110
111 } // namespace relocation_packer 111 } // namespace relocation_packer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698