torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FrameUnitTest.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 Frame class.
18 
19 #include <boost/test/unit_test.hpp>
20 #include "torc/bitstream/Frame.hpp"
21 
22 namespace torc {
23 namespace bitstream {
24 
25 BOOST_AUTO_TEST_SUITE(bitstream)
26 
27 /// \brief Unit test for the Frame class.
28 BOOST_AUTO_TEST_CASE(FrameUnitTest) {
29  // members tested:
30  // bool mIsUsed;
31  // bool mIsDirty;
32  // uint32_t mLength;
33  // WORD_TYPE* mWords;
34  // functions tested:
35  // Frame(uint32_t inLength, word_t* inWords = 0);
36  // ~Frame(void);
37  // uint32_t getLength(void) const;
38  // const word_t* getWords(void) const;
39  // bool isUsed(void) const;
40  // bool isDirty(void) const;
41  // word_t operator[] (int index);
42  BOOST_REQUIRE(true);
43  const boost::uint32_t length = 3;
44  VirtexFrame::word_t data[length] = { 0, 1, 2 };
45  VirtexFrame virtexFrame1(length, data);
46  BOOST_CHECK_EQUAL(virtexFrame1.getLength(), length);
47  BOOST_CHECK_EQUAL(virtexFrame1.isUsed(), true);
48  BOOST_CHECK_EQUAL(virtexFrame1.isDirty(), false);
49  const VirtexFrame::word_t* p1 = virtexFrame1.getWords();
50  for(boost::uint32_t i = 0; i < length; i++) {
51  BOOST_CHECK_EQUAL(virtexFrame1[i], data[i]);
52  BOOST_CHECK_EQUAL(*(p1 + i), data[i]);
53  }
54  VirtexFrame virtexFrame2(length);
55  virtexFrame2.setDirty();
56  BOOST_CHECK_EQUAL(virtexFrame2.getLength(), length);
57  BOOST_CHECK_EQUAL(virtexFrame2.isUsed(), true);
58  BOOST_CHECK_EQUAL(virtexFrame2.isDirty(), true);
59  const VirtexFrame::word_t* p2 = virtexFrame2.getWords();
60  BOOST_CHECK(p2 == 0);
61  for(boost::uint32_t i = 0; i < length; i++) {
62  BOOST_CHECK_EQUAL(virtexFrame2[i], 0u);
63  }
64 }
65 
66 BOOST_AUTO_TEST_SUITE_END()
67 
68 } // namespace bitstream
69 } // namespace torc
bool isUsed(void) const
Returns a non-const raw word pointer.
Definition: Frame.hpp:73
const word_t * getWords(void) const
Returns a const raw word pointer.
Definition: Frame.hpp:69
void setDirty(bool inIsDirty=true)
Marks the frame dirty or clean, and if dirty automatically marks it used.
Definition: Frame.hpp:79
Header for the Frame class.
uint32_t getLength(void) const
Returns the length of the frame in words.
Definition: Frame.hpp:67
bool isDirty(void) const
Returns true if the frame has been modified, or false otherwise.
Definition: Frame.hpp:75
BOOST_AUTO_TEST_CASE(hexCharacterToDec)
Bitstream frame.
Definition: Frame.hpp:31
WORD_TYPE word_t
Frame word type.
Definition: Frame.hpp:48