Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 1 | //===- LinearAllocatorTest.h ----------------------------------------------===// |
| 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 | //===----------------------------------------------------------------------===// |
| 9 | #ifndef LINEAR_ALLOCATOR_TEST_H |
| 10 | #define LINEAR_ALLOCATOR_TEST_H |
| 11 | |
| 12 | #include <gtest.h> |
| 13 | #include "mcld/Support/Allocators.h" |
| 14 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 15 | namespace mcldtest { |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 16 | |
| 17 | /** \class LinearAllocatorTest |
| 18 | * \brief The testcase for LinearAllocator |
| 19 | * |
Stephen Hines | 551ae4e | 2014-04-24 14:41:24 -0700 | [diff] [blame] | 20 | * \see LinearAllocator |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 21 | */ |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 22 | class LinearAllocatorTest : public ::testing::Test { |
| 23 | public: |
| 24 | struct Data { |
| 25 | Data() : one(1), two(2), three(3), four(4) {} |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 26 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 27 | Data(unsigned int pOne, |
| 28 | unsigned int pTwo, |
| 29 | unsigned char pThree, |
| 30 | unsigned char pFour) { |
| 31 | one = pOne; |
| 32 | two = pTwo; |
| 33 | three = pThree; |
| 34 | four = pFour; |
| 35 | } |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 36 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 37 | ~Data() { |
| 38 | one = -1; |
| 39 | two = -2; |
| 40 | three = -3; |
| 41 | four = -4; |
| 42 | } |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 43 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 44 | unsigned int one; |
| 45 | unsigned int two; |
| 46 | unsigned char three; |
| 47 | unsigned char four; |
| 48 | }; |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 49 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 50 | public: |
| 51 | // Constructor can do set-up work for all test here. |
| 52 | LinearAllocatorTest(); |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 53 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 54 | // Destructor can do clean-up work that doesn't throw exceptions here. |
| 55 | virtual ~LinearAllocatorTest(); |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 56 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 57 | // SetUp() will be called immediately before each test. |
| 58 | virtual void SetUp(); |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 59 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 60 | // TearDown() will be called immediately after each test. |
| 61 | virtual void TearDown(); |
| 62 | |
| 63 | protected: |
| 64 | enum TemplateArgsType { CHUNK_SIZE = 32 }; |
| 65 | typedef mcld::LinearAllocator<Data, CHUNK_SIZE> Alloc; |
| 66 | |
| 67 | protected: |
| 68 | Alloc* m_pTestee; |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 69 | }; |
| 70 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 71 | } // namespace of mcldtest |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 72 | |
| 73 | #endif |