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 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Kurtis Nusbaum (klnusbaum@gmail.com) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
00028 
00029 #include "Teuchos_UnitTestHarness.hpp"
00030 #include "Optika_treeitem.hpp"
00031 #include "Optika_ArrayHelperFunctions.hpp"
00032 #include "Optika_ValidatorApplier.hpp"
00033 
00034 namespace Optika{
00035 
00036 TEUCHOS_UNIT_TEST(Array_Helper_Functions, ArrayToQVariant){
00037   Array<std::string> testArray = Teuchos::tuple<std::string>("blah1", "blah2");
00038   ParameterEntry entry(testArray);
00039   QVariant testVariant = arrayEntryToVariant(rcpFromRef(entry), stringId);
00040   Array<std::string> extractedArray = testVariant.value<Array<std::string> >();
00041   TEST_EQUALITY(testArray,extractedArray);
00042   out << "Test Array: " << testArray << std::endl;
00043   out << "Extracted Array: " << extractedArray << std::endl;
00044 
00045   TwoDArray<float> twoDtestArray(3,3,4.0);
00046   ParameterEntry twoDEntry(twoDtestArray);
00047   QVariant twoDVariant = arrayEntryToVariant(rcpFromRef(twoDEntry), floatId, true);
00048   TwoDArray<float> twoDExtracted = twoDVariant.value<TwoDArray<float> >();
00049   TEST_EQUALITY(twoDExtracted, twoDtestArray)
00050   out << "TwoD Test: " << twoDtestArray << std::endl;
00051   out << "TwoD Extracted: " << twoDExtracted << std::endl;
00052   
00053 }
00054 
00055 TEUCHOS_UNIT_TEST(Array_Helper_Functions, DetermineArrayType){
00056   Array<int> intArray  = Teuchos::tuple<int>(5,6,7,8);
00057   ParameterEntry intParam(intArray);
00058   TEST_EQUALITY(
00059     determineArrayType(rcpFromRef(intParam)).toStdString(), 
00060     intId.toStdString());
00061 
00062   Array<double> doubleArray = 
00063     Teuchos::tuple<double>(5.0,6.4,7.5,8.9);
00064   ParameterEntry doubleParam(doubleArray);
00065   TEST_EQUALITY(
00066     determineArrayType(rcpFromRef(doubleParam)).toStdString(), 
00067     doubleId.toStdString());
00068 
00069   Array<std::string> stringArray = 
00070     Teuchos::tuple<std::string>("hello", "one");
00071   ParameterEntry stringParam(stringArray);
00072   TEST_EQUALITY(
00073     determineArrayType(rcpFromRef(stringParam)).toStdString(), 
00074     stringId.toStdString());
00075   TwoDArray<float> floatTwoDArray(4,3,5.0);
00076   ParameterEntry floatParam(floatTwoDArray);
00077   TEST_EQUALITY(
00078     determineArrayType(rcpFromRef(floatParam), true).toStdString(), 
00079     floatId.toStdString());
00080 
00081   TwoDArray<double> dDoubleArray(2,2,4.0);
00082   ParameterEntry ddoubleParam(dDoubleArray);
00083   TEST_EQUALITY(
00084     determineArrayType(rcpFromRef(ddoubleParam), true).toStdString(), 
00085     doubleId.toStdString());
00086 
00087   TwoDArray<int> dIntArray(2,2,4);
00088   ParameterEntry dintParam(dIntArray);
00089   TEST_EQUALITY(
00090     determineArrayType(rcpFromRef(dintParam), true).toStdString(), 
00091     intId.toStdString());
00092 }
00093 
00094 TEUCHOS_UNIT_TEST(Array_Helper_Functions, GetArrayType){
00095   TEST_EQUALITY(
00096     intId.toStdString(), 
00097     getArrayType(arrayId + " " + intId).toStdString());
00098 
00099   TEST_EQUALITY(
00100     doubleId.toStdString(), 
00101     getArrayType(arrayId + " " + doubleId).toStdString());
00102 
00103   TEST_EQUALITY(
00104     stringId.toStdString(), 
00105     getArrayType(arrayId + " " + stringId).toStdString());
00106 
00107 }
00108 
00109 TEUCHOS_UNIT_TEST(Array_Helper_Functions, IsArrayEmpty){
00110   Array<int> intArray;
00111   ParameterEntry intArrayParam(intArray);
00112   TEST_ASSERT(isArrayEmpty(rcpFromRef(intArrayParam), intId));
00113 
00114   Array<std::string> stringArray(4, "blah");
00115   ParameterEntry stringArrayParam(stringArray);
00116   TEST_ASSERT(!isArrayEmpty(rcpFromRef(stringArrayParam), stringId));
00117 }
00118 
00119 TEUCHOS_UNIT_TEST(TreeItem_Functions, ArrayTypes){
00120   RCP<ParameterEntry> twoDArrayParameter = 
00121     rcp(new ParameterEntry(Teuchos::TwoDArray<int>(2,2,4)));
00122   QString type = TreeItem::getTypeId(twoDArrayParameter);
00123   TEST_EQUALITY(
00124     type.toStdString(), 
00125     twoDArrayId.toStdString() + " " + intId.toStdString());
00126 }
00127 
00128 
00129 } //end namespace
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Defines