Optika GUI Toolik Version of the Day
test/gui/datatypes/main.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 #include "Teuchos_XMLParameterListHelpers.hpp"
00042 #include "Teuchos_VerboseObject.hpp"
00043 #include "Teuchos_FancyOStream.hpp"
00044 #include "Teuchos_ValidatorXMLConverterDB.hpp"
00045 #include "Optika_GUI.hpp"
00046 
00047 namespace Optika{
00048 
00049 
00050 void RUN_OPTIKA_DATA_TYPE_TESTS(){
00051   TEUCHOS_ADD_NUMBERTYPE_VALIDATOR_CONVERTERS(short)
00052   using Teuchos::FancyOStream;
00053   using Teuchos::VerboseObjectBase;
00054   using Teuchos::FileNameValidator;
00055   using Teuchos::EnhancedNumberValidator;
00056   using Teuchos::StringValidator;
00057   using Teuchos::ArrayNumberValidator;
00058   using Teuchos::ArrayStringValidator;
00059   using Teuchos::ArrayFileNameValidator;
00060   using Teuchos::tuple;
00061   using Teuchos::rcp;
00062 
00063   RCP<FancyOStream> out = VerboseObjectBase::getDefaultOStream();
00064 
00065   RCP<ParameterList> My_List2 = RCP<ParameterList>(new ParameterList);
00066   ParameterList&
00067     validatorList = My_List2->sublist("Validator List", false, "Validator testing\nWorking June 27th 2009");
00068   RCP<FileNameValidator> filnameVali = 
00069     RCP<FileNameValidator>(new FileNameValidator);
00070   validatorList.set("filename", "", "filename tester", filnameVali);
00071   RCP<EnhancedNumberValidator<int> > intVali = 
00072     rcp(new EnhancedNumberValidator<int>(0,10,2));
00073   validatorList.set("Int", 8, "Int tester", intVali);
00074   RCP<EnhancedNumberValidator<short> > shortVali = 
00075     rcp(new EnhancedNumberValidator<short>(0,10,4));
00076   validatorList.set("Short", (short)4, "short tester", shortVali);
00077   RCP<EnhancedNumberValidator<float> > floatVali = 
00078     rcp(new EnhancedNumberValidator<float>(0.0f,20.0f,1e-2f, 6));
00079   validatorList.set("Float", (float)4.5, "float tester", floatVali);
00080   RCP<EnhancedNumberValidator<double> > doubleVali = 
00081     rcp(new EnhancedNumberValidator<double>(0,20,1e-2, 6));
00082   validatorList.set("Double", (double)4.5, "double tester", doubleVali);
00083   RCP<StringValidator> solverValidator2 = rcp(
00084       new StringValidator( tuple<std::string>( "GMRES", "CG", "TFQMR" )));
00085   validatorList.set(
00086     "Solver"
00087     ,"GMRES" // This will be validated by solverValidator right here!
00088     ,"The type of solver to use."
00089     ,solverValidator2
00090     );
00091   Array<std::string> validValues;
00092   validValues.append("value1");
00093   validValues.append("value2");
00094   validValues.append("value3");
00095   RCP<StringValidator> stringVali2 = RCP<StringValidator>(new StringValidator(validValues));
00096   validatorList.set("Easy String", "value1", "easy string validator tester", stringVali2);
00097 
00098   ParameterList&
00099     NoValiList = My_List2->sublist("No validator list",false,"sublist containing data types without validators on them for checking default behavior.");
00100   NoValiList.set("Int1", 8, "Int tester");
00101   NoValiList.set("Short1", (short)4, "short tester");
00102   NoValiList.set("Float1", (float)4.5, "float tester");
00103   NoValiList.set("Double1", (double)4.5, "double tester");
00104   NoValiList.set("Bool1", true);
00105   NoValiList.set("Bool", true);
00106   NoValiList.set("Free String", "fee");
00107   
00108   //Arrays
00109   RCP<StringValidator> easyStringValidator = RCP<StringValidator>(new StringValidator(tuple<std::string>("value1", "value2", "value3")));
00110   Array<int> intArray(10,0);
00111   Array<short> shortArray(10,3);
00112   Array<float> floatArray(10,4.4f);
00113   Array<double> doubleArray(10, 5.5);
00114   Array<std::string> stringArray(10,"CG");
00115   Array<std::string> easyStringArray(10, "value1");
00116   Array<std::string> freestringArray(10,"Blah");
00117   Array<std::string> filenameArray(3,"/net/home/f07/klnusbau/blah.txt");
00118   ParameterList&
00119     ArrayList = My_List2->sublist("Arrays", false, "sublist containing arrays.");
00120   ArrayList.set("IntArray", intArray, "intarray tester", RCP<ArrayNumberValidator<int> >(new ArrayNumberValidator<int>(intVali)));
00121   ArrayList.set("ShortArray", shortArray, "shortarray tester", RCP<ArrayNumberValidator<short> >(new ArrayNumberValidator<short>(shortVali)));
00122   ArrayList.set("DoubleArray", doubleArray, "doublearray tester", RCP<ArrayNumberValidator<double> >(new ArrayNumberValidator<double>(doubleVali)));
00123   ArrayList.set("FloatArray", floatArray, "floatarray tester", RCP<ArrayNumberValidator<float> >(new ArrayNumberValidator<float>(floatVali)));
00124   ArrayList.set("StringArray", stringArray, "string tester", 
00125   RCP<ArrayStringValidator>(new ArrayStringValidator(solverValidator2))); 
00126   ArrayList.set("EasyStringArray", easyStringArray, "testing the easy validator", RCP<ArrayStringValidator>(new ArrayStringValidator(easyStringValidator)));
00127   ArrayList.set("FreeStringArray", freestringArray, "free string array tester");
00128   ArrayList.set("Filename Array", filenameArray, "filename array tester",
00129     RCP<ArrayFileNameValidator>(new ArrayFileNameValidator(filnameVali)));
00130 
00131   getInput(My_List2);
00132   writeParameterListToXmlOStream(*My_List2, *out);
00133   My_List2->print(
00134     std::cout,ParameterList::PrintOptions().showDoc(true).indent(2).showTypes(true));
00135 
00136 
00137 
00138 }
00139 
00140 }
00141 
00142 int main(){
00143   Optika::RUN_OPTIKA_DATA_TYPE_TESTS();
00144   return 0;
00145 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Defines