torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AnnotatedUnitTest.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 Annotated class.
18 
19 #include <boost/test/unit_test.hpp>
20 #include <boost/cstdint.hpp>
22 
23 namespace torc {
24 namespace common {
25 
26 BOOST_AUTO_TEST_SUITE(common)
27 
28 /// \brief Unit test for the Annotated class.
29 BOOST_AUTO_TEST_CASE(AnnotatedUnitTest) {
30 
31  Annotated outer;
32  Annotated inner;
33 
34  boost::uint32_t key0 = 0;
35  boost::uint32_t key1 = 1;
36  boost::uint32_t innerkey = 2;
37 
38  boost::uint32_t value0 = 42;
39  boost::uint32_t innervalue = 99;
40 
41  inner.setAnnotation(innerkey, innervalue);
42 
43  outer.setAnnotation(key0, value0);
44  outer.setAnnotation(key1, inner);
45 
46  BOOST_CHECK_EQUAL(inner.hasAnnotation(innerkey), true);
47  BOOST_CHECK_EQUAL(inner.hasAnnotation(key0), false);
48 
49  BOOST_CHECK_EQUAL(outer.hasAnnotation(key0), true);
50  BOOST_CHECK_EQUAL(outer.hasAnnotation(key1), true);
51 
52  boost::uint32_t val0 = boost::any_cast<boost::uint32_t>(outer.getAnnotation(key0));
53  BOOST_CHECK_EQUAL(val0, value0);
54 
55  BOOST_CHECK_EQUAL(boost::any_cast<boost::uint32_t>((boost::any_cast<Annotated>(
56  outer.getAnnotation(key1))).getAnnotation(innerkey)), innervalue);
57 
58  outer.removeAnnotation(key0);
59  BOOST_CHECK_EQUAL(outer.hasAnnotation(key0), false);
60 
61 }
62 
63 BOOST_AUTO_TEST_SUITE_END()
64 
65 } // namespace common
66 } // namespace torc
void setAnnotation(uint32 inKey, boost::any inValue)
Set an annotation.
Definition: Annotated.hpp:47
boost::any getAnnotation(uint32 inKey)
Get an annotation. Returns an empty annotation if the index doesn't exist.
Definition: Annotated.hpp:45
Header for the Annotated class.
BOOST_AUTO_TEST_CASE(AnnotatedUnitTest)
Unit test for the Annotated class.
bool hasAnnotation(uint32 inKey)
Check if an annotation exists.
Definition: Annotated.hpp:51
void removeAnnotation(uint32 inKey)
Remove an annotation.
Definition: Annotated.hpp:49
Concept for any object that can be annotated.
Definition: Annotated.hpp:29