torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DigestStreamUnitTest.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 DigestStream class.
18 
19 #include <boost/test/unit_test.hpp>
20 #include <boost/smart_ptr.hpp>
25 
26 namespace torc {
27 namespace architecture {
28 
29 BOOST_AUTO_TEST_SUITE(architecture)
30 
31 /// \brief Unit test for the DigestStream class.
32 BOOST_AUTO_TEST_CASE(DigestStreamUnitTest) {
33  // functions tested:
34  // DigestStream(const boost::filesystem::path& inPath);
35  DigestStream digestStream(torc::common::DirectoryTree::getDevicesPath() / "xc5vlx30.db");
36  Versions versions;
37 
38  // functions tested:
39  // std::istream& read(uint8_t& outValue);
40  // std::istream& read(uint16_t& outValue);
41  // std::istream& read(uint32_t& outValue);
42  // std::istream& read(char* s, std::streamsize n);
43  BOOST_CHECK(versions.readVersions(digestStream, true) > 0);
44  std::string header;
45 
46  // functions tested:
47  // void readSectionHeader(string& outHeader);
48  // std::istream& read(uint8_t& outValue);
49  // std::istream& read(uint16_t& outValue);
50  // std::istream& read(uint32_t& outValue);
51  // std::istream& read(char* s, std::streamsize n);
52  digestStream.readSectionHeader(header);
53  BOOST_CHECK_EQUAL(header, ">>>> Family >>>>");
54  boost::uint16_t familyNameLength;
55  digestStream.read(familyNameLength);
56  BOOST_CHECK_EQUAL(familyNameLength, 7u);
57  boost::scoped_ptr<char> familyNamePtr(new char[familyNameLength]);
58  digestStream.read(familyNamePtr.get(), familyNameLength);
59  BOOST_CHECK(memcmp(familyNamePtr.get(), "Virtex5", familyNameLength) == 0);
60  digestStream.readSectionHeader(header);
61  BOOST_CHECK_EQUAL(header, ">>>> Speeds >>>>");
62  uint16_t speedGradeCount;
63  digestStream.read(speedGradeCount);
64  BOOST_CHECK_EQUAL(speedGradeCount, 3);
65 
66  // members tested:
67  // size_t mBytesRead;
68  // functions tested:
69  // size_t getBytesRead(void) const;
70  BOOST_CHECK(digestStream.getBytesRead() > 0u);
71 }
72 
73 BOOST_AUTO_TEST_SUITE_END()
74 
75 } // namespace architecture
76 } // namespace torc
static const boost::filesystem::path & getDevicesPath(void)
Returns the absolute path to the family and device database directory.
size_t readVersions(DigestStream &inStream, bool inShowVersion=false)
Read the version information.
Definition: Versions.cpp:25
std::istream & read(uint8_t &outValue)
Read and return a uint8_t.
BOOST_AUTO_TEST_CASE(ArcUnitTest)
Unit test for the Arc class.
Definition: ArcUnitTest.cpp:29
Header for the DirectoryTree class.
std::string string
Header for the Versions class.
void readSectionHeader(string &outHeader)
Read and return a section header.
Encapsulation of database version information.
Definition: Versions.hpp:37
Header for the DigestStream class.
Encapsulation of a device or family digest stream.
size_t getBytesRead(void) const
Returns the number of bytes read.
Device database types for Xilinx architectures.