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