Teuchos Package Browser (Single Doxygen Collection)
Version of the Day
Toggle main menu visibility
Loading...
Searching...
No Matches
parameterlist
test
FunctionObjects
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
42
#include "
Teuchos_VerboseObject.hpp
"
43
#include "
Teuchos_StandardFunctionObjects.hpp
"
44
#include "
Teuchos_FunctionObjectXMLConverterDB.hpp
"
45
#include "
Teuchos_UnitTestHarness.hpp
"
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
57
XMLObject
subFuncXML =
FunctionObjectXMLConverterDB::convertFunctionObject
(
58
intTester);
59
60
std::string type = subFuncXML.
getRequired
(
61
FunctionObjectXMLConverter::getTypeAttributeName
());
62
TEST_ASSERT
(type == intTester->getTypeAttributeValue() );
63
int
operand = subFuncXML.
getRequired
<
int
>(
64
SimpleFunctionXMLConverter<int>::getOperandAttributeName
());
65
TEST_ASSERT
(operand == intTester->getModifiyingOperand());
66
67
RCP<FunctionObject>
readIn =
68
FunctionObjectXMLConverterDB::convertXML
(subFuncXML);
69
RCP<SubtractionFunction<int>
> readInCasted =
70
rcp_dynamic_cast<SubtractionFunction<int>
>(readIn);
71
TEST_ASSERT
(readInCasted.
get
() != NULL);
72
TEST_ASSERT
(
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
82
XMLObject
addFuncXML =
FunctionObjectXMLConverterDB::convertFunctionObject
(
83
intTester);
84
85
std::string type = addFuncXML.
getRequired
(
86
FunctionObjectXMLConverter::getTypeAttributeName
());
87
TEST_ASSERT
(type == intTester->getTypeAttributeValue() );
88
int
operand = addFuncXML.
getRequired
<
int
>(
89
SimpleFunctionXMLConverter<int>::getOperandAttributeName
());
90
TEST_ASSERT
(operand == intTester->getModifiyingOperand());
91
92
RCP<FunctionObject>
readIn =
93
FunctionObjectXMLConverterDB::convertXML
(addFuncXML);
94
RCP<AdditionFunction<int>
> readInCasted =
95
rcp_dynamic_cast<AdditionFunction<int>
>(readIn);
96
TEST_ASSERT
(readInCasted.
get
() != NULL);
97
TEST_ASSERT
(
98
readInCasted->getModifiyingOperand()
99
==
100
intTester->getModifiyingOperand());
101
}
102
103
TEUCHOS_UNIT_TEST
(Teuchos_Functions, MultiplicationTests){
104
RCP<MultiplicationFunction<int>
> intTester =
rcp
(
105
new
MultiplicationFunction<int>
(10));
106
107
XMLObject
multiFuncXML =
FunctionObjectXMLConverterDB::convertFunctionObject
(
108
intTester);
109
110
std::string type = multiFuncXML.
getRequired
(
111
FunctionObjectXMLConverter::getTypeAttributeName
());
112
TEST_ASSERT
(type == intTester->getTypeAttributeValue() );
113
int
operand = multiFuncXML.
getRequired
<
int
>(
114
SimpleFunctionXMLConverter<int>::getOperandAttributeName
());
115
TEST_ASSERT
(operand == intTester->getModifiyingOperand());
116
117
RCP<FunctionObject>
readIn =
118
FunctionObjectXMLConverterDB::convertXML
(multiFuncXML);
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
132
XMLObject
divisFuncXML =
FunctionObjectXMLConverterDB::convertFunctionObject
(
133
intTester);
134
135
std::string type = divisFuncXML.
getRequired
(
136
FunctionObjectXMLConverter::getTypeAttributeName
());
137
TEST_ASSERT
(type == intTester->getTypeAttributeValue() );
138
int
operand = divisFuncXML.
getRequired
<
int
>(
139
SimpleFunctionXMLConverter<int>::getOperandAttributeName
());
140
TEST_ASSERT
(operand == intTester->getModifiyingOperand());
141
142
RCP<FunctionObject>
readIn =
143
FunctionObjectXMLConverterDB::convertXML
(divisFuncXML);
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
Teuchos_FunctionObjectXMLConverterDB.hpp
A database for FunctionObjectXMLConverters.
TEST_ASSERT
#define TEST_ASSERT(v1)
Assert the given statement is true.
Definition
Teuchos_LocalTestingHelpers.hpp:71
Teuchos_StandardFunctionObjects.hpp
Teuchos_UnitTestHarness.hpp
Unit testing support.
TEUCHOS_UNIT_TEST
#define TEUCHOS_UNIT_TEST(TEST_GROUP, TEST_NAME)
Macro for defining a (non-templated) unit test.
Definition
Teuchos_UnitTestHelpers.hpp:83
Teuchos_VerboseObject.hpp
Teuchos::AdditionFunction
A simple function object that adds a specififed value from the given arguement in the runFunction fun...
Definition
Teuchos_StandardFunctionObjects.hpp:198
Teuchos::DivisionFunction
A simple function object that divides a specififed value from the given arguement in the runFunction ...
Definition
Teuchos_StandardFunctionObjects.hpp:317
Teuchos::FunctionObjectXMLConverterDB::convertFunctionObject
static XMLObject convertFunctionObject(RCP< const FunctionObject > function)
Given a FunctionObject, converts the FunctionObject to XML.
Definition
Teuchos_FunctionObjectXMLConverterDB.cpp:88
Teuchos::FunctionObjectXMLConverterDB::convertXML
static RCP< FunctionObject > convertXML(const XMLObject &xmlObject)
Given an XMLObject, converts the XMLObject to a FunctionObject.
Definition
Teuchos_FunctionObjectXMLConverterDB.cpp:94
Teuchos::FunctionObjectXMLConverter::getTypeAttributeName
static const std::string & getTypeAttributeName()
Definition
Teuchos_FunctionObjectXMLConverter.hpp:111
Teuchos::MultiplicationFunction
A simple function object that multiplys a specififed value from the given arguement in the runFunctio...
Definition
Teuchos_StandardFunctionObjects.hpp:257
Teuchos::RCP
Smart reference counting pointer class for automatic garbage collection.
Definition
Teuchos_RCPDecl.hpp:429
Teuchos::RCP::rcp_dynamic_cast
RCP< T2 > rcp_dynamic_cast(const RCP< T1 > &p1, bool throw_on_fail=false)
Dynamic cast of underlying RCP type from T1* to T2*.
Teuchos::RCP::get
T * get() const
Get the raw C++ pointer to the underlying object.
Definition
Teuchos_RCP.hpp:397
Teuchos::SimpleFunctionXMLConverter::getOperandAttributeName
static std::string getOperandAttributeName()
Definition
Teuchos_StandardFunctionObjectXMLConverters.hpp:105
Teuchos::SubtractionFunction
A simple function object that subtracts a specififed value from the given arguement in the runFunctio...
Definition
Teuchos_StandardFunctionObjects.hpp:139
Teuchos::XMLObject
Representation of an XML data tree. XMLObject is a ref-counted handle to a XMLObjectImplem object,...
Definition
Teuchos_XMLObject.hpp:62
Teuchos::XMLObject::getRequired
const std::string & getRequired(const std::string &name) const
Get an attribute, throwing an std::exception if it is not found.
Definition
Teuchos_XMLObject.cpp:93
Teuchos
Definition
Teuchos_AbstractFactory.hpp:47
Teuchos::rcp
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
Definition
Teuchos_RCPDecl.hpp:1266
Generated by
1.17.0