Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ParameterEntry_UnitTest.cpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Teuchos: Common Tools Package
4 //
5 // Copyright 2004 NTESS and the Teuchos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
12 #include "Teuchos_TwoDArray.hpp"
13 
14 namespace Teuchos {
15 
17 TEUCHOS_UNIT_TEST(Teuchos_ParameterEntry, move_constructor)
18 {
19  ParameterEntry source(std::string("nice-entry"));
20  TEST_EQUALITY(Teuchos::any_cast<std::string>(source.getAny()),"nice-entry");
21 
23  ParameterEntry move_constructed(std::move(source));
24  TEST_ASSERT (source.getAny().access_content() == nullptr);
25  TEST_EQUALITY(source.getAny().has_value(),false);
26  TEST_EQUALITY(Teuchos::any_cast<std::string>(move_constructed.getAny()),"nice-entry");
27 
29  ParameterEntry move_assigned;
30  move_assigned = std::move(move_constructed);
31  TEST_ASSERT (move_constructed.getAny().access_content() == nullptr);
32  TEST_EQUALITY(move_constructed.getAny().has_value(),false);
33  TEST_EQUALITY(Teuchos::any_cast<std::string>(move_assigned.getAny()),"nice-entry");
34 }
35 
37 TEUCHOS_UNIT_TEST(Teuchos_ParameterList, move_extract_value_from_any)
38 {
39  ParameterEntry source(std::string("nice-entry"));
40 
41  Teuchos::any::holder<std::string>* dyn_cast_content = dynamic_cast<Teuchos::any::holder<std::string>*>(
42  source.getAny().access_content());
43 
44  TEST_EQUALITY(dyn_cast_content->held, std::string("nice-entry"));
45 
47  std::string copy_extracted = Teuchos::any_cast<std::string>(source.getAny());
48  TEST_EQUALITY(dyn_cast_content->held, std::string("nice-entry"));
49  TEST_EQUALITY(copy_extracted , std::string("nice-entry"));
50 
52  std::string move_extracted = Teuchos::any_cast<std::string>(std::move(source.getAny()));
53  TEST_EQUALITY(dyn_cast_content->held, std::string());
54  TEST_EQUALITY(move_extracted , std::string("nice-entry"));
55 }
56 
57 TEUCHOS_UNIT_TEST( Teuchos_ParameterEntry, testTypeFunctions )
58 {
59  ParameterEntry intEntry;
60  intEntry.setValue(1);
61  TEST_ASSERT(intEntry.isType<int>());
62  TEST_ASSERT(!intEntry.isArray());
63  TEST_ASSERT(!intEntry.isTwoDArray());
64 
65  ParameterEntry doubleEntry;
66  doubleEntry.setValue(1.0);
67  TEST_ASSERT(doubleEntry.isType<double>());
68  TEST_ASSERT(!doubleEntry.isArray());
69  TEST_ASSERT(!doubleEntry.isTwoDArray());
70 
71  Array<int> intArray = tuple<int>(1,2,3);
72  ParameterEntry arrayEntry;
73  arrayEntry.setValue(intArray);
74  TEST_ASSERT(arrayEntry.isType<Array<int> >());
75  TEST_ASSERT(arrayEntry.isArray());
76  TEST_ASSERT(!arrayEntry.isTwoDArray());
77 
78  TwoDArray<double> twoDArray(3,3,3.0);
79  ParameterEntry twoDEntry(twoDArray);
80  TEST_ASSERT(twoDEntry.isType<TwoDArray<double> >());
81  TEST_ASSERT(twoDEntry.isTwoDArray());
82  TEST_ASSERT(!twoDEntry.isArray());
83 }
84 
85 
86 } // namespace Teuchos
87 
88 
89 
A thin wrapper around the Teuchos Array class that allows for 2 dimensional arrays.
#define TEST_ASSERT(v1)
Assert the given statement is true.
void setValue(T value, bool isDefault=false, const std::string &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Templated set method that uses the input value type to determine the type of parameter.
This object is held as the &quot;value&quot; in the Teuchos::ParameterList std::map.
bool isArray() const
Test if the type of data being contained is a Teuchos::Array.
bool has_value() const
Checks whether the object contains a value.
#define TEST_EQUALITY(v1, v2)
Assert the equality of v1 and v2.
bool isType() const
Test the type of the data being contained.
TEUCHOS_UNIT_TEST(ConstNonconstObjectContainer, create)
A thin wrapper around the Array class which causes it to be interpreted as a 2D Array.
Templated Parameter List class.
Unit testing support.
any & getAny(bool activeQry=true)
Direct access to the Teuchos::any data value underlying this object. The bool argument activeQry (def...
bool isTwoDArray() const
Test if the type of data being contained is a Teuchos::TwoDArray.