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 private: 45 Node(unsigned pInit) : m_Init(pInit), m_Value(pInit) { } 46 47 public: 48 unsigned getInitialValue() const { 49 return m_Init; 50 } 51 52 inline unsigned getValue() const 53 { return m_Value; } 54 55 inline void setValue(unsigned pValue) 56 { m_Value = pValue; } 57 }; 58 59 class NodeFactory : public mcld::GCFactory<Node, 0> { 60 public: 61 NodeFactory() : mcld::GCFactory<Node, 0>(16) { } 62 63 Node *produce(unsigned pInit) { 64 Node *result = allocate(); 65 new (result) Node(pInit); 66 return result; 67 } 68 }; 69 70 // Constructor can do set-up work for all test here. 71 GCFactoryListTraitsTest(); 72 73 // Destructor can do clean-up work that doesn't throw exceptions here. 74 virtual ~GCFactoryListTraitsTest(); 75 76 // SetUp() will be called immediately before each test. 77 virtual void SetUp(); 78 79 // TearDown() will be called immediately after each test. 80 virtual void TearDown(); 81 82 const llvm::iplist<Node, mcld::GCFactoryListTraits<Node> > &getNodeList() const 83 { return m_pNodeList; } 84 85 llvm::iplist<Node, mcld::GCFactoryListTraits<Node> > &getNodeList() 86 { return m_pNodeList; } 87 88 protected: 89 NodeFactory m_NodeFactory; 90 Node **m_pNodesAlloc; 91 92 llvm::iplist<Node, mcld::GCFactoryListTraits<Node> > m_pNodeList; 93 }; 94 95 } // namespace of mcldtest 96 97 #endif 98 99