torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ModuleUnitTest.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 Module class.
18 
19 #include <boost/test/unit_test.hpp>
21 #include "torc/physical/Module.hpp"
22 
23 namespace torc {
24 namespace physical {
25 
26 BOOST_AUTO_TEST_SUITE(physical)
27 
28 /// \brief Unit test for the Module class.
29 BOOST_AUTO_TEST_CASE(ModuleUnitTest) {
30  std::string port = "name1";
31  // create accessory instance and ports
32  InstanceSharedPtr instancePtr = Factory::newInstancePtr("name", "type", "tile", "site");
33  PortSharedPtr port1Ptr = Factory::newPortPtr(port, instancePtr, "pin");
34  PortSharedPtr port2aPtr = Factory::newPortPtr("name2", instancePtr, "pin");
35  PortSharedPtr port2bPtr = Factory::newPortPtr("name2", instancePtr, "pin");
36  // functions tested:
37  // Module(const string& inName, const string& inAnchor);
38  // create two modules
39  std::string name = "name";
40  std::string anchor = "anchor";
41  ModuleSharedPtr module1Ptr = Factory::newModulePtr(name, "");
42  ModuleSharedPtr module2Ptr = Factory::newModulePtr(name, anchor);
43  BOOST_REQUIRE(module1Ptr != 0);
44  BOOST_REQUIRE(module2Ptr != 0);
45 
46  // functions tested:
47  // const string& getAnchor(void) const;
48  // void setAnchor(const string& inAnchor);
49  BOOST_CHECK(module1Ptr->getAnchor().empty());
50  module1Ptr->setAnchor(anchor);
51  BOOST_CHECK(module1Ptr->getAnchor() == anchor);
52 
53  // functions tested:
54  // PortSharedPtrIterator findPort(const string& inName);
55  // bool addPort(PortSharedPtr& inPortPtr);
56  // size_t getPortCount(void) const;
57  BOOST_CHECK_EQUAL(module1Ptr->addPort(port1Ptr), true);
58  BOOST_CHECK_EQUAL(module1Ptr->addPort(port2aPtr), true);
59  BOOST_CHECK_EQUAL(module1Ptr->addPort(port2bPtr), false); // port name already exists
60  BOOST_CHECK(module1Ptr->getPortCount() == 2);
61 
62  // functions tested:
63  // PortSharedPtrConstIterator portsBegin(void) const;
64  // PortSharedPtrConstIterator portsEnd(void) const;
65  // PortSharedPtrIterator portsBegin(void);
66  // PortSharedPtrIterator portsEnd(void);
67  Module::PortSharedPtrConstIterator p = module1Ptr->portsBegin();
68  Module::PortSharedPtrConstIterator e = module1Ptr->portsEnd();
69  BOOST_CHECK(*p++ == port1Ptr);
70  BOOST_CHECK(*p++ == port2aPtr);
71  BOOST_CHECK(p == e);
72  BOOST_CHECK(*(module1Ptr->findPort(port)) == port1Ptr);
73 
74  // functions tested:
75  // PortSharedPtrIterator findPort(const string& inName);
76  // bool removePort(PortSharedPtr& inPortPtr);
77  // size_t getPortCount(void) const;
78  BOOST_CHECK_EQUAL(module1Ptr->removePort(port1Ptr), true);
79  BOOST_CHECK_EQUAL(module1Ptr->removePort(port2aPtr), true);
80  BOOST_CHECK_EQUAL(module1Ptr->removePort(port2bPtr), false);
81  BOOST_CHECK(module1Ptr->getPortCount() == 0);
82 
83  // functions tested:
84  // bool operator ==(const Module& rhs) const;
85  BOOST_CHECK(*module1Ptr == *module2Ptr); // comparison based on module names only
86 }
87 
88 BOOST_AUTO_TEST_SUITE_END()
89 
90 } // namespace physical
91 } // namespace torc
Header for the Module class.
static PortSharedPtr newPortPtr(const string &inName, InstanceSharedPtr inInstancePtr, const string &inPinName)
Create and return a new Port shared pointer.
PortSharedPtrVector::const_iterator PortSharedPtrConstIterator
Constant iterator to Port shared pointers.
Definition: Module.hpp:55
boost::shared_ptr< Port > PortSharedPtr
Shared pointer encapsulation of a Port.
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
static InstanceSharedPtr newInstancePtr(const string &inName, const string &inType, const string &inTile, const string &inSite, EInstanceBonding inBonding=eInstanceBondingUnknown, InstanceReferenceSharedPtr inInstanceReferencePtr=InstanceReferenceSharedPtr())
Construct and return a new Instance shared pointer.
boost::shared_ptr< Instance > InstanceSharedPtr
Shared pointer encapsulation of an Instance.
static ModuleSharedPtr newModulePtr(const string &inName, const string &inAnchor)
Create and return a new Module shared pointer.
Header for the Factory class.