OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "relocation_packer_leb128.h" |
| 6 |
| 7 #include <vector> |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 |
| 10 namespace relocation_packer { |
| 11 |
| 12 TEST(Leb128, Encoder) { |
| 13 std::vector<uint32_t> values; |
| 14 values.push_back(624485u); |
| 15 values.push_back(0u); |
| 16 values.push_back(1u); |
| 17 values.push_back(127u); |
| 18 values.push_back(128u); |
| 19 |
| 20 Leb128Encoder encoder; |
| 21 encoder.Enqueue(values); |
| 22 |
| 23 std::vector<uint8_t> encoding; |
| 24 encoder.GetEncoding(&encoding); |
| 25 |
| 26 EXPECT_EQ(8u, encoding.size()); |
| 27 // 624485 |
| 28 EXPECT_EQ(0xe5, encoding[0]); |
| 29 EXPECT_EQ(0x8e, encoding[1]); |
| 30 EXPECT_EQ(0x26, encoding[2]); |
| 31 // 0 |
| 32 EXPECT_EQ(0x00, encoding[3]); |
| 33 // 1 |
| 34 EXPECT_EQ(0x01, encoding[4]); |
| 35 // 127 |
| 36 EXPECT_EQ(0x7f, encoding[5]); |
| 37 // 128 |
| 38 EXPECT_EQ(0x80, encoding[6]); |
| 39 EXPECT_EQ(0x01, encoding[7]); |
| 40 |
| 41 encoder.Enqueue(4294967295u); |
| 42 |
| 43 encoding.clear(); |
| 44 encoder.GetEncoding(&encoding); |
| 45 |
| 46 EXPECT_EQ(13u, encoding.size()); |
| 47 // 4294967295 |
| 48 EXPECT_EQ(0xff, encoding[8]); |
| 49 EXPECT_EQ(0xff, encoding[9]); |
| 50 EXPECT_EQ(0xff, encoding[10]); |
| 51 EXPECT_EQ(0xff, encoding[11]); |
| 52 EXPECT_EQ(0x0f, encoding[12]); |
| 53 } |
| 54 |
| 55 TEST(Leb128, Decoder) { |
| 56 std::vector<uint8_t> encoding; |
| 57 // 624485 |
| 58 encoding.push_back(0xe5); |
| 59 encoding.push_back(0x8e); |
| 60 encoding.push_back(0x26); |
| 61 // 0 |
| 62 encoding.push_back(0x00); |
| 63 // 1 |
| 64 encoding.push_back(0x01); |
| 65 // 127 |
| 66 encoding.push_back(0x7f); |
| 67 // 128 |
| 68 encoding.push_back(0x80); |
| 69 encoding.push_back(0x01); |
| 70 // 4294967295 |
| 71 encoding.push_back(0xff); |
| 72 encoding.push_back(0xff); |
| 73 encoding.push_back(0xff); |
| 74 encoding.push_back(0xff); |
| 75 encoding.push_back(0x0f); |
| 76 |
| 77 Leb128Decoder decoder(encoding); |
| 78 |
| 79 EXPECT_EQ(624485u, decoder.Dequeue()); |
| 80 |
| 81 std::vector<uint32_t> dequeued; |
| 82 decoder.Dequeue(&dequeued); |
| 83 |
| 84 EXPECT_EQ(5u, dequeued.size()); |
| 85 EXPECT_EQ(0u, dequeued[0]); |
| 86 EXPECT_EQ(1u, dequeued[1]); |
| 87 EXPECT_EQ(127u, dequeued[2]); |
| 88 EXPECT_EQ(128u, dequeued[3]); |
| 89 EXPECT_EQ(4294967295u, dequeued[4]); |
| 90 } |
| 91 |
| 92 } // namespace relocation_packer |
OLD | NEW |