Stephen Hines | f33f6de | 2014-02-14 18:00:16 -0800 | [diff] [blame] | 1 | //===- ELFBinaryReaderTest.cpp --------------------------------------------===// |
| 2 | // |
| 3 | // The MCLinker Project |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 9 | #include "mcld/LD/ELFBinaryReader.h" |
| 10 | #include "mcld/Module.h" |
| 11 | #include "mcld/LinkerScript.h" |
| 12 | #include "mcld/LinkerConfig.h" |
| 13 | #include "mcld/IRBuilder.h" |
| 14 | #include "mcld/GeneralOptions.h" |
| 15 | #include "mcld/MC/Input.h" |
Stephen Hines | f33f6de | 2014-02-14 18:00:16 -0800 | [diff] [blame] | 16 | |
| 17 | #include "ELFBinaryReaderTest.h" |
| 18 | |
| 19 | using namespace mcld; |
| 20 | using namespace mcld::test; |
| 21 | |
Stephen Hines | f33f6de | 2014-02-14 18:00:16 -0800 | [diff] [blame] | 22 | // Constructor can do set-up work for all test here. |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 23 | ELFBinaryReaderTest::ELFBinaryReaderTest() { |
Stephen Hines | f33f6de | 2014-02-14 18:00:16 -0800 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | // Destructor can do clean-up work that doesn't throw exceptions here. |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 27 | ELFBinaryReaderTest::~ELFBinaryReaderTest() { |
Stephen Hines | f33f6de | 2014-02-14 18:00:16 -0800 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | // SetUp() will be called immediately before each test. |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 31 | void ELFBinaryReaderTest::SetUp() { |
Stephen Hines | f33f6de | 2014-02-14 18:00:16 -0800 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | // TearDown() will be called immediately after each test. |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 35 | void ELFBinaryReaderTest::TearDown() { |
Stephen Hines | f33f6de | 2014-02-14 18:00:16 -0800 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | //===----------------------------------------------------------------------===// |
| 39 | // Testcases |
| 40 | //===----------------------------------------------------------------------===// |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 41 | TEST_F(ELFBinaryReaderTest, is_myformat) { |
Stephen Hines | f33f6de | 2014-02-14 18:00:16 -0800 | [diff] [blame] | 42 | LinkerScript script; |
| 43 | Module module("test", script); |
| 44 | LinkerConfig config; |
| 45 | IRBuilder builder(module, config); |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 46 | ELFBinaryReader* reader = new ELFBinaryReader(builder, config); |
Stephen Hines | f33f6de | 2014-02-14 18:00:16 -0800 | [diff] [blame] | 47 | |
| 48 | Input input("test.bin"); |
| 49 | |
| 50 | bool doContinue = false; |
| 51 | config.options().setBinaryInput(); |
| 52 | ASSERT_TRUE(reader->isMyFormat(input, doContinue)); |
| 53 | |
| 54 | config.options().setBinaryInput(false); |
| 55 | ASSERT_FALSE(reader->isMyFormat(input, doContinue)); |
| 56 | |
| 57 | delete reader; |
| 58 | } |