torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ArrayUnitTest.cpp
Go to the documentation of this file.
1 // Torc - Copyright 2011-2013 University of Southern California. All Rights Reserved.
2 // $HeadURL$
3 // $Id$
4 
5 // This program is free software: you can redistribute it and/or modify it under the terms of the
6 // GNU General Public License as published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
11 // the GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License along with this program. If
14 // not, see <http://www.gnu.org/licenses/>.
15 
16 /// \file
17 /// \brief Unit test for the Array class.
18 
19 #include <boost/test/unit_test.hpp>
20 #define DEBUG // test the debug functionality as well
23 #include <iostream>
24 
25 namespace torc {
26 namespace architecture {
27 
28 BOOST_AUTO_TEST_SUITE(architecture)
29 
30 using namespace torc::architecture::xilinx;
31 
32 /// \brief Unit test for the Array class.
33 BOOST_AUTO_TEST_CASE(ArrayUnitTest) {
34  // functions not tested:
35  // ~Array<T>(void);
36 
37  // functions tested:
38  // Array<T>(void);
39  // Array<T>(uint32_t inSize);
40  // void allocate(uint32_t inSize);
41  // void deallocate(void);
42  uint32_t size5 = 5;
43  uint32_t size3 = 3;
44  typedef Array<int> int_array_t;
45  typedef Array<Tilewire> tilewire_array_t;
46  int_array_t intArray;
47  tilewire_array_t tilewireArray(size3);
48 
49  // macros tested:
50  // enforceBounds(index)
51  bool boundsEnforced = false;
52  try {
53  // if bounds checking is enabled and correct, we won't be able to read index 3
54  Tilewire outOfRange = tilewireArray[size3];
55  (void) outOfRange;
56  } catch(std::out_of_range oor) {
57  std::cerr << "Bounds checking generated message \"" << oor.what() << "\"" << std::endl;
58  boundsEnforced = true;
59  }
60  BOOST_CHECK(boundsEnforced);
61 
62  // functions tested:
63  // inline int getSize(void) const;
64  // inline void setSize(uint32_t inSize);
65  BOOST_CHECK_EQUAL(intArray.getSize(), 0u);
66  BOOST_CHECK_EQUAL(tilewireArray.getSize(), size3);
67  intArray.setSize(size5);
68  BOOST_CHECK_EQUAL(intArray.getSize(), size5);
69 
70  // functions tested:
71  // T& operator [](uint32_t inIndex);
72  // T* begin(void);
73  // T* end(void);
74  intArray[0] = 0;
75  intArray[1] = 1;
76  intArray[2] = 2;
77  intArray[3] = 3;
78  intArray[4] = 4;
79  int_array_t::iterator ip = intArray.begin();
80  int_array_t::iterator ie = intArray.end();
81  BOOST_CHECK(*ip++ == 0);
82  BOOST_CHECK(*ip++ == 1);
83  BOOST_CHECK(*ip++ == 2);
84  BOOST_CHECK(*ip++ == 3);
85  BOOST_CHECK(*ip++ == 4);
86  BOOST_CHECK_EQUAL(ip, ie);
87 
88  // functions tested:
89  // const T& operator [](uint32_t inIndex) const;
90  // const T* begin(void) const;
91  // const T* end(void) const;
92  Tilewire tilewire1(TileIndex(1), WireIndex(1));
93  Tilewire tilewire2(TileIndex(1), WireIndex(2));
94  Tilewire tilewire3(TileIndex(4), WireIndex(9));
95  tilewireArray[0] = tilewire1;
96  tilewireArray[1] = tilewire2;
97  tilewireArray[2] = tilewire3;
98  tilewire_array_t::const_iterator tp = tilewireArray.begin();
99  tilewire_array_t::const_iterator te = tilewireArray.end();
100  BOOST_CHECK(*tp++ == tilewireArray[0]);
101  BOOST_CHECK(*tp++ == tilewireArray[1]);
102  BOOST_CHECK(*tp++ == tilewireArray[2]);
103  BOOST_CHECK_EQUAL(tp, te);
104 
105  // template tested:
106  // template <class T> class Array2D;
107  int i = 1;
108  typedef Array2D<int> int_array2d_t;
109  int_array2d_t intArray2d(2);
110  intArray2d[0].setSize(3);
111  intArray2d[1].setSize(1);
112  intArray2d[0][0] = i++;
113  intArray2d[0][1] = i++;
114  intArray2d[0][2] = i++;
115  intArray2d[1][0] = i++;
116  Array<Array<int> >::const_iterator l1p = intArray2d.begin();
117  int_array2d_t::const_iterator l1e = intArray2d.end();
118  i = 1;
119  while(l1p < l1e) {
120  int_array_t::const_iterator l2p = l1p->begin();
121  int_array_t::const_iterator l2e = l1p->end();
122  while(l2p < l2e) {
123  BOOST_CHECK_EQUAL(*l2p++, i++);
124  }
125  l1p++;
126  }
127 }
128 
129 BOOST_AUTO_TEST_SUITE_END()
130 
131 } // namespace architecture
132 } // namespace torc
Encapsulation of a tile index in an unsigned 32-bit integer.
T * end(void)
Returns the non-constant end iterator.
Definition: Array.hpp:97
Encapsulation of a wire index in an unsigned 16-bit integer.
BOOST_AUTO_TEST_CASE(TilewireUnitTest)
Unit test for the Tilewire class.
Encapsulation of a device tile and wire pair.
Definition: Tilewire.hpp:39
Encapsulation of a 2D static array.
Definition: Array.hpp:125
Header for the Tilewire class.
Header for the Array class.
T * begin(void)
Returns the non-constant begin iterator.
Definition: Array.hpp:95
Encapsulation of a static array.
Definition: Array.hpp:39