blob: 9326b5b3731d867217b655a82e6ee1fe95f136f2 [file] [log] [blame]
Shih-wei Liao5460a1f2012-03-16 22:41:16 -07001//===- 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 Hines37b74a32014-11-26 18:48:20 -080014#include "mcld/Support/GCFactoryListTraits.h"
Shih-wei Liao5460a1f2012-03-16 22:41:16 -070015
16#include <llvm/ADT/ilist_node.h>
17
Stephen Hines37b74a32014-11-26 18:48:20 -080018#include "mcld/Support/GCFactory.h"
Shih-wei Liao5460a1f2012-03-16 22:41:16 -070019
Stephen Hines37b74a32014-11-26 18:48:20 -080020namespace mcldtest {
Shih-wei Liao5460a1f2012-03-16 22:41:16 -070021
22/** \class GCFactoryListTraitsTest
23 * \brief
24 *
25 * \see GCFactoryListTraits
26 */
Stephen Hines37b74a32014-11-26 18:48:20 -080027class GCFactoryListTraitsTest : public ::testing::Test {
28 public:
Shih-wei Liao5460a1f2012-03-16 22:41:16 -070029 /** \class GCFactoryListTraitsTest
30 * \brief Node used in the test
31 *
32 */
33 class NodeFactory;
34
Stephen Hines37b74a32014-11-26 18:48:20 -080035 class Node : public llvm::ilist_node<Node> {
Shih-wei Liao5460a1f2012-03-16 22:41:16 -070036 friend class NodeFactory;
Stephen Hines37b74a32014-11-26 18:48:20 -080037
38 private:
Shih-wei Liao5460a1f2012-03-16 22:41:16 -070039 unsigned m_Init;
40 unsigned m_Value;
41
Stephen Hines37b74a32014-11-26 18:48:20 -080042 public:
43 Node() : m_Init(0), m_Value(0) {}
Shih-wei Liao22add6f2012-12-15 17:21:00 -080044
Stephen Hines37b74a32014-11-26 18:48:20 -080045 Node(unsigned pInit) : m_Init(pInit), m_Value(pInit) {}
Shih-wei Liao5460a1f2012-03-16 22:41:16 -070046
Stephen Hines37b74a32014-11-26 18:48:20 -080047 unsigned getInitialValue() const { return m_Init; }
Shih-wei Liao5460a1f2012-03-16 22:41:16 -070048
Stephen Hines37b74a32014-11-26 18:48:20 -080049 inline unsigned getValue() const { return m_Value; }
Shih-wei Liao5460a1f2012-03-16 22:41:16 -070050
Stephen Hines37b74a32014-11-26 18:48:20 -080051 inline void setValue(unsigned pValue) { m_Value = pValue; }
Shih-wei Liao5460a1f2012-03-16 22:41:16 -070052 };
53
54 class NodeFactory : public mcld::GCFactory<Node, 0> {
Stephen Hines37b74a32014-11-26 18:48:20 -080055 public:
56 NodeFactory() : mcld::GCFactory<Node, 0>(16) {}
Shih-wei Liao5460a1f2012-03-16 22:41:16 -070057
Stephen Hines37b74a32014-11-26 18:48:20 -080058 Node* produce(unsigned pInit) {
59 Node* result = allocate();
Shih-wei Liao5460a1f2012-03-16 22:41:16 -070060 new (result) Node(pInit);
61 return result;
62 }
63 };
64
Stephen Hines37b74a32014-11-26 18:48:20 -080065 // Constructor can do set-up work for all test here.
66 GCFactoryListTraitsTest();
Shih-wei Liao5460a1f2012-03-16 22:41:16 -070067
Stephen Hines37b74a32014-11-26 18:48:20 -080068 // Destructor can do clean-up work that doesn't throw exceptions here.
69 virtual ~GCFactoryListTraitsTest();
Shih-wei Liao5460a1f2012-03-16 22:41:16 -070070
Stephen Hines37b74a32014-11-26 18:48:20 -080071 // SetUp() will be called immediately before each test.
72 virtual void SetUp();
Shih-wei Liao5460a1f2012-03-16 22:41:16 -070073
Stephen Hines37b74a32014-11-26 18:48:20 -080074 // TearDown() will be called immediately after each test.
75 virtual void TearDown();
Shih-wei Liao5460a1f2012-03-16 22:41:16 -070076
Stephen Hines37b74a32014-11-26 18:48:20 -080077 const llvm::iplist<Node, mcld::GCFactoryListTraits<Node> >& getNodeList()
78 const {
79 return m_pNodeList;
80 }
Shih-wei Liao5460a1f2012-03-16 22:41:16 -070081
Stephen Hines37b74a32014-11-26 18:48:20 -080082 llvm::iplist<Node, mcld::GCFactoryListTraits<Node> >& getNodeList() {
83 return m_pNodeList;
84 }
Shih-wei Liao5460a1f2012-03-16 22:41:16 -070085
Stephen Hines37b74a32014-11-26 18:48:20 -080086 protected:
Shih-wei Liao5460a1f2012-03-16 22:41:16 -070087 NodeFactory m_NodeFactory;
Stephen Hines37b74a32014-11-26 18:48:20 -080088 Node** m_pNodesAlloc;
Shih-wei Liao5460a1f2012-03-16 22:41:16 -070089
90 llvm::iplist<Node, mcld::GCFactoryListTraits<Node> > m_pNodeList;
91};
92
Stephen Hines37b74a32014-11-26 18:48:20 -080093} // namespace of mcldtest
Shih-wei Liao5460a1f2012-03-16 22:41:16 -070094
95#endif