00001 // Torc - Copyright 2011 University of Southern California. All Rights Reserved. 00002 // $HeadURL: https://torc-isi.svn.sourceforge.net/svnroot/torc-isi/branches/staging/0.9/src/torc/architecture/DigestStreamUnitTest.cpp $ 00003 // $Id: DigestStreamUnitTest.cpp 10 2011-10-12 18:40:16Z nsteiner $ 00004 00005 // This program is free software: you can redistribute it and/or modify it under the terms of the 00006 // GNU General Public License as published by the Free Software Foundation, either version 3 of the 00007 // License, or (at your option) any later version. 00008 // 00009 // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 00010 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 00011 // the GNU General Public License for more details. 00012 // 00013 // You should have received a copy of the GNU General Public License along with this program. If 00014 // not, see <http://www.gnu.org/licenses/>. 00015 00016 /// \file 00017 /// \brief Unit test for the DigestStream class. 00018 00019 #include <boost/test/unit_test.hpp> 00020 #include <boost/smart_ptr.hpp> 00021 #include "torc/architecture/DigestStream.hpp" 00022 #include "torc/architecture/Versions.hpp" 00023 #include "torc/architecture/XilinxDatabaseTypes.hpp" 00024 #include "torc/common/DirectoryTree.hpp" 00025 00026 namespace torc { 00027 namespace architecture { 00028 00029 BOOST_AUTO_TEST_SUITE(architecture) 00030 00031 /// \brief Unit test for the DigestStream class. 00032 BOOST_AUTO_TEST_CASE(DigestStreamUnitTest) { 00033 // functions tested: 00034 // DigestStream(const boost::filesystem::path& inPath); 00035 DigestStream digestStream(torc::common::DirectoryTree::getDevicesPath() / "xc5vlx30.db"); 00036 Versions versions; 00037 00038 // functions tested: 00039 // std::istream& read(uint8_t& outValue); 00040 // std::istream& read(uint16_t& outValue); 00041 // std::istream& read(uint32_t& outValue); 00042 // std::istream& read(char* s, std::streamsize n); 00043 BOOST_CHECK(versions.readVersions(digestStream, true) > 0); 00044 std::string header; 00045 00046 // functions tested: 00047 // void readSectionHeader(string& outHeader); 00048 // std::istream& read(uint8_t& outValue); 00049 // std::istream& read(uint16_t& outValue); 00050 // std::istream& read(uint32_t& outValue); 00051 // std::istream& read(char* s, std::streamsize n); 00052 digestStream.readSectionHeader(header); 00053 BOOST_CHECK_EQUAL(header, ">>>> Family >>>>"); 00054 boost::uint16_t familyNameLength; 00055 digestStream.read(familyNameLength); 00056 BOOST_CHECK_EQUAL(familyNameLength, 7u); 00057 boost::scoped_ptr<char> familyNamePtr(new char[familyNameLength]); 00058 digestStream.read(familyNamePtr.get(), familyNameLength); 00059 BOOST_CHECK(memcmp(familyNamePtr.get(), "Virtex5", familyNameLength) == 0); 00060 digestStream.readSectionHeader(header); 00061 BOOST_CHECK_EQUAL(header, ">>>> Speeds >>>>"); 00062 uint16_t speedGradeCount; 00063 digestStream.read(speedGradeCount); 00064 BOOST_CHECK_EQUAL(speedGradeCount, 3); 00065 00066 // members tested: 00067 // size_t mBytesRead; 00068 // functions tested: 00069 // size_t getBytesRead(void) const; 00070 BOOST_CHECK(digestStream.getBytesRead() > 0u); 00071 } 00072 00073 BOOST_AUTO_TEST_SUITE_END() 00074 00075 } // namespace architecture 00076 } // namespace torc