Optika GUI Toolik  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NonGUI_UnitTests.cpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Optika: A Tool For Developing Parameter Obtaining GUIs
5 // Copyright (2009) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, with Sandia Corporation, the
8 // U.S. Government retains certain rights in this software.
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 Kurtis Nusbaum (klnusbaum@gmail.com)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
43 #include "Optika_treeitem.hpp"
46 
47 namespace Optika{
48 
49 TEUCHOS_UNIT_TEST(Array_Helper_Functions, ArrayToQVariant){
50  Array<std::string> testArray = Teuchos::tuple<std::string>("blah1", "blah2");
51  ParameterEntry entry(testArray);
52  QVariant testVariant = arrayEntryToVariant(rcpFromRef(entry), stringId);
53  Array<std::string> extractedArray = testVariant.value<Array<std::string> >();
54  TEST_EQUALITY(testArray,extractedArray);
55  out << "Test Array: " << testArray << std::endl;
56  out << "Extracted Array: " << extractedArray << std::endl;
57 
58  TwoDArray<float> twoDtestArray(3,3,4.0);
59  ParameterEntry twoDEntry(twoDtestArray);
60  QVariant twoDVariant = arrayEntryToVariant(rcpFromRef(twoDEntry), floatId, true);
61  TwoDArray<float> twoDExtracted = twoDVariant.value<TwoDArray<float> >();
62  TEST_EQUALITY(twoDExtracted, twoDtestArray)
63  out << "TwoD Test: " << twoDtestArray << std::endl;
64  out << "TwoD Extracted: " << twoDExtracted << std::endl;
65 
66 }
67 
68 TEUCHOS_UNIT_TEST(Array_Helper_Functions, DetermineArrayType){
69  Array<int> intArray = Teuchos::tuple<int>(5,6,7,8);
70  ParameterEntry intParam(intArray);
72  determineArrayType(rcpFromRef(intParam)).toStdString(),
73  intId.toStdString());
74 
75  Array<double> doubleArray =
76  Teuchos::tuple<double>(5.0,6.4,7.5,8.9);
77  ParameterEntry doubleParam(doubleArray);
79  determineArrayType(rcpFromRef(doubleParam)).toStdString(),
80  doubleId.toStdString());
81 
82  Array<std::string> stringArray =
83  Teuchos::tuple<std::string>("hello", "one");
84  ParameterEntry stringParam(stringArray);
86  determineArrayType(rcpFromRef(stringParam)).toStdString(),
87  stringId.toStdString());
88  TwoDArray<float> floatTwoDArray(4,3,5.0);
89  ParameterEntry floatParam(floatTwoDArray);
91  determineArrayType(rcpFromRef(floatParam), true).toStdString(),
92  floatId.toStdString());
93 
94  TwoDArray<double> dDoubleArray(2,2,4.0);
95  ParameterEntry ddoubleParam(dDoubleArray);
97  determineArrayType(rcpFromRef(ddoubleParam), true).toStdString(),
98  doubleId.toStdString());
99 
100  TwoDArray<int> dIntArray(2,2,4);
101  ParameterEntry dintParam(dIntArray);
103  determineArrayType(rcpFromRef(dintParam), true).toStdString(),
104  intId.toStdString());
105 }
106 
107 TEUCHOS_UNIT_TEST(Array_Helper_Functions, GetArrayType){
109  intId.toStdString(),
110  getArrayType(arrayId + " " + intId).toStdString());
111 
113  doubleId.toStdString(),
114  getArrayType(arrayId + " " + doubleId).toStdString());
115 
117  stringId.toStdString(),
118  getArrayType(arrayId + " " + stringId).toStdString());
119 
120 }
121 
122 TEUCHOS_UNIT_TEST(Array_Helper_Functions, IsArrayEmpty){
123  Array<int> intArray;
124  ParameterEntry intArrayParam(intArray);
125  TEST_ASSERT(isArrayEmpty(rcpFromRef(intArrayParam), intId));
126 
127  Array<std::string> stringArray(4, "blah");
128  ParameterEntry stringArrayParam(stringArray);
129  TEST_ASSERT(!isArrayEmpty(rcpFromRef(stringArrayParam), stringId));
130 }
131 
132 TEUCHOS_UNIT_TEST(TreeItem_Functions, ArrayTypes){
133  RCP<ParameterEntry> twoDArrayParameter =
135  QString type = TreeItem::getTypeId(twoDArrayParameter);
137  type.toStdString(),
138  twoDArrayId.toStdString() + " " + intId.toStdString());
139 }
140 
141 
142 } //end namespace
TEUCHOS_UNIT_TEST(Array_Helper_Functions, ArrayToQVariant)
QString intId
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
QString determineArrayType(RCP< const ParameterEntry > parameter, bool twoD)
Determines the type of array stored in a parameter.
QVariant arrayEntryToVariant(RCP< const ParameterEntry > arrayEntry, QString type, bool twoD)
Creates a QVariant containing the array that is in arrayEntry.
QString floatId
QString twoDArrayId
bool testArray(const int n, Teuchos::FancyOStream &out)
QString doubleId
A item in the treemodel.
QString stringId
static QString getTypeId(const RCP< const ParameterEntry > parameter)
Gets the type id to be used for the TreeItem.
TEST_ASSERT(castedDep1->getValuesAndValidators().size()==2)
bool isArrayEmpty(RCP< const ParameterEntry > arrayEntry, QString type)
Determines wether or no the array inside a ParameterEntry is empty.
TEST_EQUALITY(rcp_dynamic_cast< const EnhancedNumberValidator< double > >(castedDep1->getValuesAndValidators().find("val1") ->second, true) ->getMax(), double1Vali->getMax())
QString arrayId
A collection of objects which apply the restriction of a EnhancedNumberValidator to a SpinBoxes and L...
QString getArrayType(QString itemType)
Given a type string, determines the template type of the Array.