torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DesignUnitTest.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 Design class.
18 
19 #include <boost/test/unit_test.hpp>
21 #include "torc/physical/Design.hpp"
22 
23 namespace torc {
24 namespace physical {
25 
26 BOOST_AUTO_TEST_SUITE(physical)
27 
28 /// \brief Unit test for the Design class.
29 /// \todo Verify that all children can trace their lineage all the way up to the design.
30 BOOST_AUTO_TEST_CASE(DesignUnitTest) {
31  // functions tested:
32  // Design(const string& inName, const string& inDevice, const string& inPackage,
33  // const string& inSpeedGrade, const string& inXdlVersion);
34  // create a design
35  std::string designName = "design";
36  std::string deviceName = "device";
37  std::string devicePackage = "package";
38  std::string deviceSpeedGrade = "speed_grade";
39  std::string xdlVersion = "xdl_version";
40  std::string moduleName = "module1";
41  DesignSharedPtr designPtr = Factory::newDesignPtr(designName, "", "", "", "");
42  BOOST_REQUIRE(designPtr.get() != 0);
43 
44  // functions tested:
45  // const string& getDevice(void) const;
46  // const string& getPackage(void) const;
47  // const string& getSpeedGrade(void) const;
48  // const string& getXdlVersion(void) const;
49  // void setDevice(const string& inDevice);
50  // void setPackage(const string& inPackage);
51  // void setSpeedGrade(const string& inSpeedGrade);
52  // void setXdlVersion(const string& inXdlVersion);
53  BOOST_CHECK(designPtr->getDevice().empty());
54  BOOST_CHECK(designPtr->getPackage().empty());
55  BOOST_CHECK(designPtr->getSpeedGrade().empty());
56  BOOST_CHECK(designPtr->getXdlVersion().empty());
57  designPtr->setDevice(deviceName);
58  designPtr->setPackage(devicePackage);
59  designPtr->setSpeedGrade(deviceSpeedGrade);
60  designPtr->setXdlVersion(xdlVersion);
61  BOOST_CHECK_EQUAL(designPtr->getName(), designName);
62  BOOST_CHECK_EQUAL(designPtr->getDevice(), deviceName);
63  BOOST_CHECK_EQUAL(designPtr->getPackage(), devicePackage);
64  BOOST_CHECK_EQUAL(designPtr->getSpeedGrade(), deviceSpeedGrade);
65  BOOST_CHECK_EQUAL(designPtr->getXdlVersion(), xdlVersion);
66 
67  // functions tested:
68  // ModuleSharedPtrIterator findModule(const string& inName);
69  // bool addModule(ModuleSharedPtr& inModulePtr);
70  // size_t getModuleCount(void) const;
71  // create and add some modules to the design
72  ModuleSharedPtr module1Ptr = Factory::newModulePtr(moduleName, "anchor1");
73  ModuleSharedPtr module2aPtr = Factory::newModulePtr("module2", "anchor2");
74  ModuleSharedPtr module2bPtr = Factory::newModulePtr("module2", "anchor2");
75  BOOST_CHECK_EQUAL(designPtr->addModule(module1Ptr), true);
76  BOOST_CHECK_EQUAL(designPtr->addModule(module2aPtr), true);
77  BOOST_CHECK_EQUAL(designPtr->addModule(module2bPtr), false);
78  BOOST_CHECK(designPtr->getModuleCount() == 2);
79 
80  // functions tested:
81  // ModuleSharedPtrIterator findModule(const string& inName);
82  // ModuleSharedPtrConstIterator modulesBegin(void) const;
83  // ModuleSharedPtrConstIterator modulesEnd(void) const;
84  // ModuleSharedPtrIterator modulesBegin(void);
85  // ModuleSharedPtrIterator modulesEnd(void);
86  Design::ModuleSharedPtrConstIterator p = designPtr->modulesBegin();
87  Design::ModuleSharedPtrConstIterator e = designPtr->modulesEnd();
88  BOOST_CHECK(*p++ == module1Ptr);
89  BOOST_CHECK(*p++ == module2aPtr);
90  BOOST_CHECK(p == e);
91  BOOST_CHECK(*(designPtr->findModule(moduleName)) == module1Ptr);
92 
93  // functions tested:
94  // ModuleSharedPtrIterator findModule(const string& inName);
95  // bool removeModule(ModuleSharedPtr& inModulePtr);
96  // size_t getModuleCount(void) const;
97  // remove the modules
98  BOOST_CHECK_EQUAL(designPtr->removeModule(module1Ptr), true);
99  BOOST_CHECK_EQUAL(designPtr->removeModule(module2aPtr), true);
100  BOOST_CHECK_EQUAL(designPtr->removeModule(module2bPtr), false);
101  BOOST_CHECK(designPtr->getModuleCount() == 0);
102 }
103 
104 BOOST_AUTO_TEST_SUITE_END()
105 
106 } // namespace physical
107 } // namespace torc
ModuleSharedPtrVector::const_iterator ModuleSharedPtrConstIterator
Constant iterator for Module shared pointers.
std::string string
BOOST_AUTO_TEST_CASE(XdlUnpackUnitTest)
Unit test for the XdlUnpack class.
boost::shared_ptr< Module > ModuleSharedPtr
Shared pointer encapsulation of a Module.
Definition: Module.hpp:114
Header for the Design class.
boost::shared_ptr< Design > DesignSharedPtr
Shared pointer encapsulation of a Design.
static ModuleSharedPtr newModulePtr(const string &inName, const string &inAnchor)
Create and return a new Module shared pointer.
static DesignSharedPtr newDesignPtr(const string &inName, const string &inDevice, const string &inPackage, const string &inSpeedGrade, const string &inXdlVersion)
Create and return a new Design shared pointer.
Header for the Factory class.