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