• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- InputTreeTest.cpp --------------------------------------------------===//
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 #include "mcld/MC/MCLDInputTree.h"
10 #include "mcld/MC/MCLDInfo.h"
11 #include <InputTreeTest.h>
12 
13 using namespace mcld;
14 using namespace mcldtest;
15 
16 
17 // Constructor can do set-up work for all test here.
InputTreeTest()18 InputTreeTest::InputTreeTest()
19 {
20 	// create testee. modify it if need
21 	m_pAttr = new mcld::AttributeFactory(2);
22         m_pAlloc = new mcld::InputFactory(10, *m_pAttr);
23 	m_pTestee = new InputTree(*m_pAlloc);
24 }
25 
26 // Destructor can do clean-up work that doesn't throw exceptions here.
~InputTreeTest()27 InputTreeTest::~InputTreeTest()
28 {
29 	delete m_pTestee;
30 	delete m_pAlloc;
31 	delete m_pAttr;
32 }
33 
34 // SetUp() will be called immediately before each test.
SetUp()35 void InputTreeTest::SetUp()
36 {
37 }
38 
39 // TearDown() will be called immediately after each test.
TearDown()40 void InputTreeTest::TearDown()
41 {
42 }
43 
44 //==========================================================================//
45 // Testcases
46 //
TEST_F(InputTreeTest,Basic_operation)47 TEST_F( InputTreeTest, Basic_operation ) {
48   InputTree::iterator node = m_pTestee->root();
49   m_pTestee->insert<InputTree::Inclusive>(node, "FileSpec", "path1");
50 
51   InputTree::const_iterator const_node = node;
52 
53   ASSERT_TRUE(isGroup(node));
54   ASSERT_TRUE(isGroup(const_node));
55   ASSERT_TRUE(m_pTestee->hasInput());
56   ASSERT_EQ(1, m_pTestee->numOfInputs());
57 
58   --node;
59 
60   m_pTestee->enterGroup(node, InputTree::Downward);
61 
62   InputTree::const_iterator const_node2 = node;
63 
64   ASSERT_FALSE(node.isRoot());
65 
66   ASSERT_FALSE(isGroup(node));
67   ASSERT_FALSE(isGroup(const_node2));
68   ASSERT_TRUE(m_pTestee->hasInput());
69   ASSERT_FALSE(m_pTestee->numOfInputs()==0);
70 
71   ASSERT_TRUE(m_pTestee->size()==2);
72 }
73 
TEST_F(InputTreeTest,forLoop_TEST)74 TEST_F( InputTreeTest, forLoop_TEST ) {
75   InputTree::iterator node = m_pTestee->root();
76 
77 
78   m_pTestee->insert<InputTree::Inclusive>(node, "FileSpec", "path1");
79   InputTree::const_iterator const_node = node;
80   --node;
81 
82   for(int i=0 ; i<100 ; ++i)
83   {
84     m_pTestee->insert<InputTree::Inclusive>(node,"FileSpec", "path1");
85     ++node;
86   }
87 
88   m_pTestee->enterGroup(node, InputTree::Downward);
89   --node;
90 
91   ASSERT_FALSE(node.isRoot());
92   ASSERT_TRUE(isGroup(node));
93   ASSERT_TRUE(m_pTestee->hasInput());
94   ASSERT_FALSE(m_pTestee->numOfInputs()==100);
95 
96   ASSERT_TRUE(m_pTestee->size()==102);
97 }
98 
TEST_F(InputTreeTest,Nesting_Case)99 TEST_F( InputTreeTest, Nesting_Case ) {
100   InputTree::iterator node = m_pTestee->root();
101 
102   for(int i=0 ; i<50 ; ++i)
103   {
104     m_pTestee->enterGroup(node, InputTree::Downward);
105     --node;
106 
107     m_pTestee->insert(node, InputTree::Afterward, "FileSpec", "path1");
108     ++node;
109   }
110 
111   ASSERT_FALSE(node.isRoot());
112   ASSERT_FALSE(isGroup(node));
113   ASSERT_TRUE(m_pTestee->hasInput());
114   ASSERT_TRUE(m_pTestee->numOfInputs()==50);
115   ASSERT_TRUE(m_pTestee->size()==100);
116 }
117 
TEST_F(InputTreeTest,DFSIterator_BasicTraversal)118 TEST_F( InputTreeTest, DFSIterator_BasicTraversal)
119 {
120 
121   InputTree::iterator node = m_pTestee->root();
122   m_pTestee->insert<InputTree::Inclusive>(node, "111", "/");
123   node.move<InputTree::Inclusive>();
124 
125   m_pTestee->insert<InputTree::Positional>(node, "10", "/");
126   m_pTestee->enterGroup<InputTree::Inclusive>(node);
127   node.move<InputTree::Inclusive>();
128   m_pTestee->insert<InputTree::Inclusive>(node, "7", "/");
129   m_pTestee->insert<InputTree::Positional>(node, "8", "/");
130 
131   InputTree::dfs_iterator dfs_it = m_pTestee->dfs_begin();
132   InputTree::dfs_iterator dfs_end = m_pTestee->dfs_end();
133   ASSERT_STREQ("111", (*dfs_it)->name().c_str());
134   ++dfs_it;
135   ASSERT_STREQ("7", (**dfs_it).name().c_str());
136   ++dfs_it;
137   ASSERT_STREQ("8", (**dfs_it).name().c_str());
138   ++dfs_it;
139   ASSERT_STREQ("10", (**dfs_it).name().c_str());
140   ++dfs_it;
141   ASSERT_TRUE(dfs_it ==  dfs_end);
142 }
143 
144