OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "courgette/encoded_program.h" | 5 #include "courgette/encoded_program.h" |
6 | 6 |
7 #include "courgette/streams.h" | 7 #include "courgette/streams.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 TEST(EncodedProgramTest, Test) { | 10 TEST(EncodedProgramTest, Test) { |
11 // | 11 // |
12 // Create a simple program with a few addresses and references and | 12 // Create a simple program with a few addresses and references and |
13 // check that the bits produced are as expected. | 13 // check that the bits produced are as expected. |
14 // | 14 // |
15 courgette::EncodedProgram* program = new courgette::EncodedProgram(); | 15 courgette::EncodedProgram* program = new courgette::EncodedProgram(); |
16 | 16 |
17 uint32 base = 0x00900000; | 17 uint32 base = 0x00900000; |
18 program->set_image_base(base); | 18 program->set_image_base(base); |
19 | 19 |
20 program->DefineRel32Label(5, 0); // REL32 index 5 == base + 0 | 20 EXPECT_TRUE(program->DefineRel32Label(5, 0)); // REL32 index 5 == base + 0 |
21 program->DefineAbs32Label(7, 4); // ABS32 index 7 == base + 4 | 21 EXPECT_TRUE(program->DefineAbs32Label(7, 4)); // ABS32 index 7 == base + 4 |
22 program->EndLabels(); | 22 program->EndLabels(); |
23 | 23 |
24 program->AddOrigin(0); // Start at base. | 24 EXPECT_TRUE(program->AddOrigin(0)); // Start at base. |
25 program->AddAbs32(7); | 25 EXPECT_TRUE(program->AddAbs32(7)); |
26 program->AddRel32(5); | 26 EXPECT_TRUE(program->AddRel32(5)); |
27 | 27 |
28 // Serialize and deserialize. | 28 // Serialize and deserialize. |
29 | 29 |
30 courgette::SinkStreamSet sinks; | 30 courgette::SinkStreamSet sinks; |
31 program->WriteTo(&sinks); | 31 EXPECT_TRUE(program->WriteTo(&sinks)); |
32 | 32 |
33 courgette::SinkStream sink; | 33 courgette::SinkStream sink; |
34 bool can_collect = sinks.CopyTo(&sink); | 34 bool can_collect = sinks.CopyTo(&sink); |
35 EXPECT_TRUE(can_collect); | 35 EXPECT_TRUE(can_collect); |
36 | 36 |
37 const void* buffer = sink.Buffer(); | 37 const void* buffer = sink.Buffer(); |
38 size_t length = sink.Length(); | 38 size_t length = sink.Length(); |
39 | 39 |
40 courgette::SourceStreamSet sources; | 40 courgette::SourceStreamSet sources; |
41 bool can_get_source_streams = sources.Init(buffer, length); | 41 bool can_get_source_streams = sources.Init(buffer, length); |
(...skipping 13 matching lines...) Expand all Loading... |
55 | 55 |
56 EXPECT_EQ(8U, assembled_length); | 56 EXPECT_EQ(8U, assembled_length); |
57 | 57 |
58 static const uint8 golden[] = { | 58 static const uint8 golden[] = { |
59 0x04, 0x00, 0x90, 0x00, // ABS32 to base + 4 | 59 0x04, 0x00, 0x90, 0x00, // ABS32 to base + 4 |
60 0xF8, 0xFF, 0xFF, 0xFF // REL32 from next line to base + 2 | 60 0xF8, 0xFF, 0xFF, 0xFF // REL32 from next line to base + 2 |
61 }; | 61 }; |
62 | 62 |
63 EXPECT_EQ(0, memcmp(assembled_buffer, golden, 8)); | 63 EXPECT_EQ(0, memcmp(assembled_buffer, golden, 8)); |
64 } | 64 } |
OLD | NEW |