Optika GUI Toolik Version of the Day
NonGUI_UnitTests.cpp
Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 //         Optika: A Tool For Developing Parameter Obtaining GUIs
00005 //                Copyright (2009) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, with Sandia Corporation, the 
00008 // U.S. Government retains certain rights in this software.
00009 // 
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Kurtis Nusbaum (klnusbaum@gmail.com) 
00038 // 
00039 // ***********************************************************************
00040 // @HEADER
00041 
00042 #include "Teuchos_UnitTestHarness.hpp"
00043 #include "Optika_treeitem.hpp"
00044 #include "Optika_ArrayHelperFunctions.hpp"
00045 #include "Optika_ValidatorApplier.hpp"
00046 
00047 namespace Optika{
00048 
00049 TEUCHOS_UNIT_TEST(Array_Helper_Functions, ArrayToQVariant){
00050   Array<std::string> testArray = Teuchos::tuple<std::string>("blah1", "blah2");
00051   ParameterEntry entry(testArray);
00052   QVariant testVariant = arrayEntryToVariant(rcpFromRef(entry), stringId);
00053   Array<std::string> extractedArray = testVariant.value<Array<std::string> >();
00054   TEST_EQUALITY(testArray,extractedArray);
00055   out << "Test Array: " << testArray << std::endl;
00056   out << "Extracted Array: " << extractedArray << std::endl;
00057 
00058   TwoDArray<float> twoDtestArray(3,3,4.0);
00059   ParameterEntry twoDEntry(twoDtestArray);
00060   QVariant twoDVariant = arrayEntryToVariant(rcpFromRef(twoDEntry), floatId, true);
00061   TwoDArray<float> twoDExtracted = twoDVariant.value<TwoDArray<float> >();
00062   TEST_EQUALITY(twoDExtracted, twoDtestArray)
00063   out << "TwoD Test: " << twoDtestArray << std::endl;
00064   out << "TwoD Extracted: " << twoDExtracted << std::endl;
00065   
00066 }
00067 
00068 TEUCHOS_UNIT_TEST(Array_Helper_Functions, DetermineArrayType){
00069   Array<int> intArray  = Teuchos::tuple<int>(5,6,7,8);
00070   ParameterEntry intParam(intArray);
00071   TEST_EQUALITY(
00072     determineArrayType(rcpFromRef(intParam)).toStdString(), 
00073     intId.toStdString());
00074 
00075   Array<double> doubleArray = 
00076     Teuchos::tuple<double>(5.0,6.4,7.5,8.9);
00077   ParameterEntry doubleParam(doubleArray);
00078   TEST_EQUALITY(
00079     determineArrayType(rcpFromRef(doubleParam)).toStdString(), 
00080     doubleId.toStdString());
00081 
00082   Array<std::string> stringArray = 
00083     Teuchos::tuple<std::string>("hello", "one");
00084   ParameterEntry stringParam(stringArray);
00085   TEST_EQUALITY(
00086     determineArrayType(rcpFromRef(stringParam)).toStdString(), 
00087     stringId.toStdString());
00088   TwoDArray<float> floatTwoDArray(4,3,5.0);
00089   ParameterEntry floatParam(floatTwoDArray);
00090   TEST_EQUALITY(
00091     determineArrayType(rcpFromRef(floatParam), true).toStdString(), 
00092     floatId.toStdString());
00093 
00094   TwoDArray<double> dDoubleArray(2,2,4.0);
00095   ParameterEntry ddoubleParam(dDoubleArray);
00096   TEST_EQUALITY(
00097     determineArrayType(rcpFromRef(ddoubleParam), true).toStdString(), 
00098     doubleId.toStdString());
00099 
00100   TwoDArray<int> dIntArray(2,2,4);
00101   ParameterEntry dintParam(dIntArray);
00102   TEST_EQUALITY(
00103     determineArrayType(rcpFromRef(dintParam), true).toStdString(), 
00104     intId.toStdString());
00105 }
00106 
00107 TEUCHOS_UNIT_TEST(Array_Helper_Functions, GetArrayType){
00108   TEST_EQUALITY(
00109     intId.toStdString(), 
00110     getArrayType(arrayId + " " + intId).toStdString());
00111 
00112   TEST_EQUALITY(
00113     doubleId.toStdString(), 
00114     getArrayType(arrayId + " " + doubleId).toStdString());
00115 
00116   TEST_EQUALITY(
00117     stringId.toStdString(), 
00118     getArrayType(arrayId + " " + stringId).toStdString());
00119 
00120 }
00121 
00122 TEUCHOS_UNIT_TEST(Array_Helper_Functions, IsArrayEmpty){
00123   Array<int> intArray;
00124   ParameterEntry intArrayParam(intArray);
00125   TEST_ASSERT(isArrayEmpty(rcpFromRef(intArrayParam), intId));
00126 
00127   Array<std::string> stringArray(4, "blah");
00128   ParameterEntry stringArrayParam(stringArray);
00129   TEST_ASSERT(!isArrayEmpty(rcpFromRef(stringArrayParam), stringId));
00130 }
00131 
00132 TEUCHOS_UNIT_TEST(TreeItem_Functions, ArrayTypes){
00133   RCP<ParameterEntry> twoDArrayParameter = 
00134     rcp(new ParameterEntry(Teuchos::TwoDArray<int>(2,2,4)));
00135   QString type = TreeItem::getTypeId(twoDArrayParameter);
00136   TEST_EQUALITY(
00137     type.toStdString(), 
00138     twoDArrayId.toStdString() + " " + intId.toStdString());
00139 }
00140 
00141 
00142 } //end namespace
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Defines