Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 1 | //===- GCFactoryListTraitsTest.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 MCLD_GC_FACTORY_LIST_TRAITS_TEST_H |
| 10 | #define MCLD_GC_FACTORY_LIST_TRAITS_TEST_H |
| 11 | |
| 12 | #include <gtest.h> |
| 13 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 14 | #include "mcld/Support/GCFactoryListTraits.h" |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 15 | |
| 16 | #include <llvm/ADT/ilist_node.h> |
| 17 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 18 | #include "mcld/Support/GCFactory.h" |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 19 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 20 | namespace mcldtest { |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 21 | |
| 22 | /** \class GCFactoryListTraitsTest |
| 23 | * \brief |
| 24 | * |
| 25 | * \see GCFactoryListTraits |
| 26 | */ |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 27 | class GCFactoryListTraitsTest : public ::testing::Test { |
| 28 | public: |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 29 | /** \class GCFactoryListTraitsTest |
| 30 | * \brief Node used in the test |
| 31 | * |
| 32 | */ |
| 33 | class NodeFactory; |
| 34 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 35 | class Node : public llvm::ilist_node<Node> { |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 36 | friend class NodeFactory; |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 37 | |
| 38 | private: |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 39 | unsigned m_Init; |
| 40 | unsigned m_Value; |
| 41 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 42 | public: |
| 43 | Node() : m_Init(0), m_Value(0) {} |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 44 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 45 | Node(unsigned pInit) : m_Init(pInit), m_Value(pInit) {} |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 46 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 47 | unsigned getInitialValue() const { return m_Init; } |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 48 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 49 | inline unsigned getValue() const { return m_Value; } |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 50 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 51 | inline void setValue(unsigned pValue) { m_Value = pValue; } |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | class NodeFactory : public mcld::GCFactory<Node, 0> { |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 55 | public: |
| 56 | NodeFactory() : mcld::GCFactory<Node, 0>(16) {} |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 57 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 58 | Node* produce(unsigned pInit) { |
| 59 | Node* result = allocate(); |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 60 | new (result) Node(pInit); |
| 61 | return result; |
| 62 | } |
| 63 | }; |
| 64 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 65 | // Constructor can do set-up work for all test here. |
| 66 | GCFactoryListTraitsTest(); |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 67 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 68 | // Destructor can do clean-up work that doesn't throw exceptions here. |
| 69 | virtual ~GCFactoryListTraitsTest(); |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 70 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 71 | // SetUp() will be called immediately before each test. |
| 72 | virtual void SetUp(); |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 73 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 74 | // TearDown() will be called immediately after each test. |
| 75 | virtual void TearDown(); |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 76 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 77 | const llvm::iplist<Node, mcld::GCFactoryListTraits<Node> >& getNodeList() |
| 78 | const { |
| 79 | return m_pNodeList; |
| 80 | } |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 81 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 82 | llvm::iplist<Node, mcld::GCFactoryListTraits<Node> >& getNodeList() { |
| 83 | return m_pNodeList; |
| 84 | } |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 85 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 86 | protected: |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 87 | NodeFactory m_NodeFactory; |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 88 | Node** m_pNodesAlloc; |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 89 | |
| 90 | llvm::iplist<Node, mcld::GCFactoryListTraits<Node> > m_pNodeList; |
| 91 | }; |
| 92 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 93 | } // namespace of mcldtest |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 94 | |
| 95 | #endif |