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