Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FunctionObject_Serialization_UnitTests.cpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Teuchos: Common Tools Package
5 // Copyright (2004) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
46 
47 
48 namespace Teuchos{
49 
53 TEUCHOS_UNIT_TEST(Teuchos_Functions, SubtractionTests){
54  RCP<SubtractionFunction<int> > intTester = rcp(
55  new SubtractionFunction<int>(10));
56 
58  intTester);
59 
60  std::string type = subFuncXML.getRequired(
62  TEST_ASSERT(type == intTester->getTypeAttributeValue() );
63  int operand = subFuncXML.getRequired<int>(
65  TEST_ASSERT(operand == intTester->getModifiyingOperand());
66 
67  RCP<FunctionObject> readIn =
69  RCP<SubtractionFunction<int> > readInCasted =
70  rcp_dynamic_cast<SubtractionFunction<int> >(readIn);
71  TEST_ASSERT(readInCasted.get() != NULL);
73  readInCasted->getModifiyingOperand()
74  ==
75  intTester->getModifiyingOperand());
76 }
77 
78 TEUCHOS_UNIT_TEST(Teuchos_Functions, AdditionTests){
79  RCP<AdditionFunction<int> > intTester = rcp(
80  new AdditionFunction<int>(10));
81 
83  intTester);
84 
85  std::string type = addFuncXML.getRequired(
87  TEST_ASSERT(type == intTester->getTypeAttributeValue() );
88  int operand = addFuncXML.getRequired<int>(
90  TEST_ASSERT(operand == intTester->getModifiyingOperand());
91 
92  RCP<FunctionObject> readIn =
94  RCP<AdditionFunction<int> > readInCasted =
95  rcp_dynamic_cast<AdditionFunction<int> >(readIn);
96  TEST_ASSERT(readInCasted.get() != NULL);
98  readInCasted->getModifiyingOperand()
99  ==
100  intTester->getModifiyingOperand());
101 }
102 
103 TEUCHOS_UNIT_TEST(Teuchos_Functions, MultiplicationTests){
104  RCP<MultiplicationFunction<int> > intTester = rcp(
106 
108  intTester);
109 
110  std::string type = multiFuncXML.getRequired(
112  TEST_ASSERT(type == intTester->getTypeAttributeValue() );
113  int operand = multiFuncXML.getRequired<int>(
115  TEST_ASSERT(operand == intTester->getModifiyingOperand());
116 
117  RCP<FunctionObject> readIn =
119  RCP<MultiplicationFunction<int> > readInCasted =
120  rcp_dynamic_cast<MultiplicationFunction<int> >(readIn);
121  TEST_ASSERT(readInCasted.get() != NULL);
122  TEST_ASSERT(
123  readInCasted->getModifiyingOperand()
124  ==
125  intTester->getModifiyingOperand());
126 }
127 
128 TEUCHOS_UNIT_TEST(Teuchos_Functions, DivisionTests){
129  RCP<DivisionFunction<int> > intTester = rcp(
130  new DivisionFunction<int>(10));
131 
133  intTester);
134 
135  std::string type = divisFuncXML.getRequired(
137  TEST_ASSERT(type == intTester->getTypeAttributeValue() );
138  int operand = divisFuncXML.getRequired<int>(
140  TEST_ASSERT(operand == intTester->getModifiyingOperand());
141 
142  RCP<FunctionObject> readIn =
144  RCP<DivisionFunction<int> > readInCasted =
145  rcp_dynamic_cast<DivisionFunction<int> >(readIn);
146  TEST_ASSERT(readInCasted.get() != NULL);
147  TEST_ASSERT(
148  readInCasted->getModifiyingOperand()
149  ==
150  intTester->getModifiyingOperand());
151 }
152 
153 
154 
155 } //namespace Teuchos
156 
#define TEST_ASSERT(v1)
Assert the given statement is true.
static XMLObject convertFunctionObject(RCP< const FunctionObject > function)
Given a FunctionObject, converts the FunctionObject to XML.
A simple function object that multiplys a specififed value from the given arguement in the runFunctio...
A simple function object that adds a specififed value from the given arguement in the runFunction fun...
T * get() const
Get the raw C++ pointer to the underlying object.
A database for FunctionObjectXMLConverters.
A simple function object that subtracts a specififed value from the given arguement in the runFunctio...
TEUCHOS_UNIT_TEST(ConstNonconstObjectContainer, create)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
Representation of an XML data tree. XMLObject is a ref-counted handle to a XMLObjectImplem object...
Unit testing support.
A simple function object that divides a specififed value from the given arguement in the runFunction ...
Smart reference counting pointer class for automatic garbage collection.
static RCP< FunctionObject > convertXML(const XMLObject &xmlObject)
Given an XMLObject, converts the XMLObject to a FunctionObject.
const std::string & getRequired(const std::string &name) const
Get an attribute, throwing an std::exception if it is not found.