Teuchos Package Browser (Single Doxygen Collection) Version of the Day
Validator_UnitTest.cpp
Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 //
00004 //                    Teuchos: Common Tools Package
00005 //                 Copyright (2004) Sandia Corporation
00006 //
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
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 Michael A. Heroux (maherou@sandia.gov)
00038 //
00039 // ***********************************************************************
00040 // @HEADER
00041 #include "Teuchos_UnitTestHarness.hpp"
00042 #include "Teuchos_VerboseObject.hpp"
00043 #include "Teuchos_ParameterList.hpp"
00044 #include "Teuchos_StandardParameterEntryValidators.hpp"
00045 
00046 
00047 // 2010/07/30: rabartl: Here I just added all the unit tests to the Teuchos
00048 // namespace to remove some clutter.
00049 
00050 
00051 namespace Teuchos {
00052 
00053 
00057 TEUCHOS_UNIT_TEST(Teuchos_Validators, numberValidators)
00058 {
00059   /*
00060    * Testing Int Validator.
00061    */
00062   RCP<ParameterList> intList =
00063     rcp(new ParameterList("Int List"));
00064   RCP<EnhancedNumberValidator<int> > intVali =
00065     rcp(new EnhancedNumberValidator<int>(0,10,4));
00066   TEST_ASSERT(intVali->getMin() == 0);
00067   TEST_ASSERT(intVali->getMax() == 10);
00068   TEST_ASSERT(intVali->getStep() == 4);
00069   TEST_ASSERT(intVali->hasMin());
00070   TEST_ASSERT(intVali->hasMax());
00071   RCP<EnhancedNumberValidator<int> > intVali2 =
00072     rcp(new EnhancedNumberValidator<int>());
00073   TEST_ASSERT(!intVali2->hasMin());
00074   TEST_ASSERT(!intVali2->hasMax());
00075   TEST_ASSERT(intVali2->getMin() == std::numeric_limits<int>::min());
00076   TEST_ASSERT(intVali2->getMax() == std::numeric_limits<int>::max());
00077   TEST_ASSERT(intVali2->getStep() == EnhancedNumberTraits<int>::defaultStep());
00078   intList->set("Int Parameter", 5, "int parameter", intVali);
00079   TEST_NOTHROW(intList->validateParameters(*intList));
00080   TEST_THROW(intList->set("Int Parameter", 11),
00081     Exceptions::InvalidParameterValue);
00082   TEST_THROW(intList->set("Double Parameter", 5.0, "double parameter", intVali),
00083     Exceptions::InvalidParameterType);
00084 
00085   /*
00086    * Testing Short Validator.
00087    */
00088   RCP<ParameterList> shortList =
00089     rcp(new ParameterList("Short List"));
00090   RCP<EnhancedNumberValidator<short> > shortVali =
00091     rcp(new EnhancedNumberValidator<short>(0,10,4));
00092   TEST_ASSERT(shortVali->getMin() == 0);
00093   TEST_ASSERT(shortVali->getMax() == 10);
00094   TEST_ASSERT(shortVali->getStep() == 4);
00095   TEST_ASSERT(shortVali->hasMin());
00096   TEST_ASSERT(shortVali->hasMax());
00097   RCP<EnhancedNumberValidator<short> > shortVali2 =
00098     rcp(new EnhancedNumberValidator<short>());
00099   TEST_ASSERT(!shortVali2->hasMin());
00100   TEST_ASSERT(!shortVali2->hasMax());
00101   TEST_ASSERT(shortVali2->getMin() == std::numeric_limits<short>::min());
00102   TEST_ASSERT(shortVali2->getMax() == std::numeric_limits<short>::max());
00103   TEST_ASSERT(shortVali2->getStep() == EnhancedNumberTraits<short>::defaultStep());
00104   shortList->set("Short Parameter", (short)5, "short parameter", shortVali);
00105   TEST_NOTHROW(shortList->validateParameters(*shortList));
00106   TEST_THROW(shortList->set("Short Parameter", (short)11),
00107     Exceptions::InvalidParameterValue);
00108   TEST_THROW(shortList->set("Double Parameter", 5.0, "double parameter", shortVali),
00109     Exceptions::InvalidParameterType);
00110 
00111   /*
00112    * Testing Float Validator.
00113    */
00114   RCP<ParameterList> floatList = rcp(new ParameterList("Float List"));
00115   RCP<EnhancedNumberValidator<float> > floatVali =
00116     rcp(new EnhancedNumberValidator<float>(0,10.0,4.0,6));
00117   TEST_ASSERT(floatVali->getMin() == 0.0);
00118   TEST_ASSERT(floatVali->getMax() == 10.0);
00119   TEST_ASSERT(floatVali->getStep() == 4.0);
00120   TEST_ASSERT(floatVali->getPrecision() == 6);
00121   TEST_ASSERT(floatVali->hasMin());
00122   TEST_ASSERT(floatVali->hasMax());
00123   RCP<EnhancedNumberValidator<float> > floatVali2 =
00124     rcp(new EnhancedNumberValidator<float>());
00125   TEST_ASSERT(!floatVali2->hasMin());
00126   TEST_ASSERT(!floatVali2->hasMax());
00127   TEST_ASSERT(floatVali2->getMin() == EnhancedNumberTraits<float>::min());
00128   TEST_ASSERT(floatVali2->getMax() == EnhancedNumberTraits<float>::max());
00129   TEST_ASSERT(floatVali2->getStep() == EnhancedNumberTraits<float>::defaultStep());
00130   TEST_ASSERT(floatVali2->getPrecision() == EnhancedNumberTraits<float>::defaultPrecision());
00131   floatList->set("Float Parameter", (float)5.0, "float parameter", floatVali);
00132   TEST_NOTHROW(floatList->validateParameters(*floatList));
00133   TEST_THROW(floatList->set("Float Parameter", (float)11.0),
00134     Exceptions::InvalidParameterValue);
00135   TEST_THROW(floatList->set("Int Parameter", 5, "int parameter", floatVali),
00136     Exceptions::InvalidParameterType);
00137 
00138   /*
00139    * Testing Double Validator.
00140    */
00141   RCP<ParameterList> doubleList = rcp(new ParameterList("Double List"));
00142   RCP<EnhancedNumberValidator<double> > doubleVali =
00143     rcp(new EnhancedNumberValidator<double>(0,10.0,4.0,6));
00144   TEST_ASSERT(doubleVali->getMin() == 0.0);
00145   TEST_ASSERT(doubleVali->getMax() == 10.0);
00146   TEST_ASSERT(doubleVali->getStep() == 4.0);
00147   TEST_ASSERT(doubleVali->getPrecision() == 6);
00148   TEST_ASSERT(doubleVali->hasMin());
00149   TEST_ASSERT(doubleVali->hasMax());
00150   RCP<EnhancedNumberValidator<double> > doubleVali2 =
00151     rcp(new EnhancedNumberValidator<double>());
00152   TEST_ASSERT(!doubleVali2->hasMin());
00153   TEST_ASSERT(!doubleVali2->hasMax());
00154   TEST_ASSERT(doubleVali2->getMin() == EnhancedNumberTraits<double>::min());
00155   TEST_ASSERT(doubleVali2->getMax() == EnhancedNumberTraits<double>::max());
00156   TEST_ASSERT(doubleVali2->getStep() == EnhancedNumberTraits<double>::defaultStep());
00157   TEST_ASSERT(doubleVali2->getPrecision() == EnhancedNumberTraits<double>::defaultPrecision());
00158   doubleList->set("Double Parameter", (double)5.0, "double parameter", doubleVali);
00159   TEST_NOTHROW(doubleList->validateParameters(*doubleList));
00160   TEST_THROW(doubleList->set("Double Parameter", (double)11.0),
00161     Exceptions::InvalidParameterValue);
00162   TEST_THROW(doubleList->set("Int Parameter", 5, "int parameter", doubleVali),
00163     Exceptions::InvalidParameterType);
00164 }
00165 
00166 
00167 /*
00168  * Testing StringValidator.
00169  */
00170 TEUCHOS_UNIT_TEST(Teuchos_Validators, stringValidator)
00171 {
00172   RCP<ParameterList> stringList = rcp(new ParameterList("String List"));
00173   Array<std::string> stringVals = tuple<std::string>("str1", "str2", "str3");
00174   RCP<StringValidator> stringVali = rcp(new StringValidator(stringVals));
00175   RCP<const Array<std::string> > valiVals = stringVali->validStringValues();
00176   /*bool local_success = true;
00177   for(int i =0; i<valiVals.size() ++i){
00178     TEST_ARRAY_ELE_EQUALITY(*valiVals, i, stringVals[i]);
00179   }
00180   if (local_success) out << "passed\n";
00181   else success = false;*/
00182   TEST_COMPARE_ARRAYS(*valiVals, stringVals);
00183   TEST_NOTHROW(stringList->set("String param1", "str1", "a string parameter", stringVali));
00184   TEST_THROW(stringList->set("String param2", "not in list", "a string parameter", stringVali),
00185     Exceptions::InvalidParameterValue);
00186   TEST_THROW(stringList->set("int param", 5, "a int parameter", stringVali),
00187     Exceptions::InvalidParameterType);
00188 }
00189 
00190 
00191 /*
00192  * Testing FileNameValidator.
00193  */
00194 TEUCHOS_UNIT_TEST(Teuchos_Validators, fileNameValidator)
00195 {
00196   RCP<ParameterList> fileNameList = rcp(new ParameterList("Filename List"));
00197   RCP<FileNameValidator> fileNameVali = rcp(new FileNameValidator(true));
00198   TEST_ASSERT(fileNameVali->fileMustExist());
00199   fileNameVali->setFileMustExist(false);
00200   TEST_ASSERT(!fileNameVali->fileMustExist());
00201   TEST_NOTHROW(fileNameList->set("File name param", "../path", "file name parameter",
00202       fileNameVali));
00203   TEST_THROW(fileNameList->set("int param", 5, "int parameter", fileNameVali),
00204     Exceptions::InvalidParameterType);
00205   fileNameVali->setFileMustExist(true);
00206   TEST_NOTHROW(fileNameList->set("file name param", "testFile.txt", "a file name", fileNameVali));
00207   TEST_THROW(fileNameList->set("file name param", "doesntexist.txt", "a file name", fileNameVali),
00208     Exceptions::InvalidParameterValue);
00209 }
00210 
00211 
00212 /*
00213  * Testing Array Validators.
00214  */
00215 TEUCHOS_UNIT_TEST(Teuchos_Validators, arrayValidators)
00216 {
00217 
00218   /*
00219    * Testing StringArrayValidator.
00220    */
00221   RCP<ParameterList> stringList = rcp(new ParameterList("String List"));
00222   Array<std::string> stringVals = tuple<std::string>("str1", "str2", "str3");
00223   RCP<StringValidator> stringVali = rcp(new StringValidator(stringVals));
00224   RCP<ArrayStringValidator> stringArrayVali = rcp(new ArrayStringValidator(stringVali));
00225   TEST_ASSERT(stringVali.get() == stringArrayVali->getPrototype().get());
00226   Array<std::string> stringArray = tuple<std::string>("str2","str3","str1","str3","str2");
00227   TEST_NOTHROW(stringList->set("String Array Param", stringArray, "string array parameter", stringArrayVali));
00228   Array<std::string> badStringArray = tuple<std::string>("not valid","str3","str1","str3","str2");
00229   TEST_THROW(stringList->set("String Array Param", badStringArray, "string array parameter", stringArrayVali),
00230     Exceptions::InvalidParameterValue);
00231   TEST_THROW(stringList->set("Int param", 5, "int parameter", stringArrayVali),
00232     Exceptions::InvalidParameterType);
00233   Array<long> longArray = tuple<long>((long)5,(long)5,(long)3);
00234   TEST_THROW(stringList->set("Long array param", longArray, "long array parameter", stringArrayVali),
00235     Exceptions::InvalidParameterType);
00236   
00237   /*
00238    * Testing Int ArrayValidator.
00239    */
00240   RCP<ParameterList> intList = rcp(new ParameterList("Int List"));
00241   RCP<EnhancedNumberValidator<int> > intVali = rcp(new EnhancedNumberValidator<int>(0, 10));
00242   RCP<ArrayNumberValidator<int> > intArrayVali = rcp(new ArrayNumberValidator<int>(intVali));
00243   TEST_ASSERT(intVali.get() == intArrayVali->getPrototype().get());
00244   Array<int> intArray = tuple<int>(1,4,2,5);
00245   TEST_NOTHROW(intList->set("int array param", intArray, "int array parameter", intArrayVali));
00246   Array<int> intBadArray = tuple<int>(11,4,2,5);
00247   TEST_THROW(intList->set("int bad array param", intBadArray, "int bad array parameter", intArrayVali),
00248     Exceptions::InvalidParameterValue);
00249   TEST_THROW(stringList->set("Long array param", longArray, "long array parameter", intArrayVali),
00250     Exceptions::InvalidParameterType);
00251 
00252   /*
00253    * Testing Short ArrayValidator.
00254    */
00255   RCP<ParameterList> shortList = rcp(new ParameterList("Short List"));
00256   RCP<EnhancedNumberValidator<short> > shortVali =
00257     rcp(new EnhancedNumberValidator<short>(0, 10));
00258   RCP<ArrayNumberValidator<short> > shortArrayVali =
00259     rcp(new ArrayNumberValidator<short>(shortVali));
00260   TEST_ASSERT(shortVali.get() == shortArrayVali->getPrototype().get());
00261   Array<short> shortArray = tuple<short>(1,4,2,5);
00262   TEST_NOTHROW(shortList->set("short array param", shortArray, "short array parameter", shortArrayVali));
00263   Array<short> shortBadArray = tuple<short>(11,4,2,5);
00264   TEST_THROW(shortList->set("short bad array param", shortBadArray, "short bad array parameter", shortArrayVali),
00265     Exceptions::InvalidParameterValue);
00266   TEST_THROW(stringList->set("Long array param", longArray, "long array parameter", shortArrayVali),
00267     Exceptions::InvalidParameterType);
00268 
00269   /*
00270    * Testing Float ArrayValidator.
00271    */
00272   RCP<ParameterList> floatList = rcp(new ParameterList("Float List"));
00273   RCP<EnhancedNumberValidator<float> > floatVali =
00274     rcp(new EnhancedNumberValidator<float>(0.0, 10.0));
00275   RCP<ArrayNumberValidator<float> > floatArrayVali =
00276     rcp(new ArrayNumberValidator<float>(floatVali));
00277   TEST_ASSERT(floatVali.get() == floatArrayVali->getPrototype().get());
00278   Array<float> floatArray = tuple<float>(1.0,4.0,2.0,5.0);
00279   TEST_NOTHROW(floatList->set("float array param", floatArray, "float array parameter", floatArrayVali));
00280   Array<float> floatBadArray = tuple<float>(11.0,4.0,2.0,5.0);
00281   TEST_THROW(floatList->set("float bad array param", floatBadArray, "float bad array parameter", floatArrayVali),
00282     Exceptions::InvalidParameterValue);
00283   TEST_THROW(stringList->set("Long array param", longArray, "long array parameter", floatArrayVali),
00284     Exceptions::InvalidParameterType);
00285 
00286   /*
00287    * Testing Double ArrayValidator.
00288    */
00289   RCP<ParameterList> doubleList = rcp(new ParameterList("Double List"));
00290   RCP<EnhancedNumberValidator<double> > doubleVali =
00291     rcp(new EnhancedNumberValidator<double>(0.0, 10.0));
00292   RCP<ArrayNumberValidator<double> > doubleArrayVali =
00293     rcp(new ArrayNumberValidator<double>(doubleVali));
00294   TEST_ASSERT(doubleVali.get() == doubleArrayVali->getPrototype().get());
00295   Array<double> doubleArray = tuple<double>(1.0,4.0,2.0,5.0);
00296   TEST_NOTHROW(doubleList->set("double array param", doubleArray, "double array parameter", doubleArrayVali));
00297   Array<double> doubleBadArray = tuple<double>(11.0,4.0,2.0,5.0);
00298   TEST_THROW(doubleList->set("double bad array param", doubleBadArray, "double bad array parameter", doubleArrayVali),
00299     Exceptions::InvalidParameterValue);
00300   TEST_THROW(stringList->set("Long array param", longArray, "long array parameter", doubleArrayVali),
00301     Exceptions::InvalidParameterType);
00302 
00303   /*
00304    * Testing FileName ArrayValidator.
00305    */
00306   RCP<ParameterList> fileNameList = rcp(new ParameterList("Filename List"));
00307   RCP<FileNameValidator> fileNameVali = rcp(new FileNameValidator(true));
00308   RCP<ArrayFileNameValidator> arrayFileNameVali = rcp(new ArrayFileNameValidator(fileNameVali));
00309   TEST_ASSERT(arrayFileNameVali->getPrototype().get() == fileNameVali.get());
00310   Array<std::string> fileNameArray = tuple<std::string>("testFile.txt", "testFile2.txt", "testFile3.txt");
00311   Array<std::string> fileNameBadArray = tuple<std::string>("doesnexist.txt", "testFile2.txt", "testFile3.txt");
00312   TEST_NOTHROW(fileNameList->set("File name array", fileNameArray, "file name array parameter", arrayFileNameVali));
00313   TEST_THROW(fileNameList->set("Bad File name array", fileNameBadArray, "bad file name array parameter", arrayFileNameVali),
00314     Exceptions::InvalidParameterValue);
00315   TEST_THROW(stringList->set("Long array param", longArray, "long array parameter", arrayFileNameVali),
00316     Exceptions::InvalidParameterType);
00317 }
00318 
00319 /*
00320  * Testing TwoDArray Validators.
00321  */
00322 TEUCHOS_UNIT_TEST(Teuchos_Validators, twoDArrayValidators)
00323 {
00324 
00325   /*
00326    * Testing StringArrayValidator.
00327    */
00328   RCP<ParameterList> stringList = rcp(new ParameterList("String List"));
00329   Array<std::string> stringVals = tuple<std::string>("str1", "str2", "str3");
00330   RCP<StringValidator> stringVali = rcp(new StringValidator(stringVals));
00331   RCP<TwoDArrayStringValidator> stringArrayVali = 
00332     rcp(new TwoDArrayStringValidator(stringVali));
00333   TEST_ASSERT(stringVali.get() == stringArrayVali->getPrototype().get());
00334   TwoDArray<std::string> stringArray(2,2);
00335   stringArray(0,0) = "str2";
00336   stringArray(0,1) = "str1";
00337   stringArray(1,0) = "str3";
00338   stringArray(1,1) = "str2";
00339   TEST_NOTHROW(stringList->set("String Array Param", stringArray, "string array parameter", stringArrayVali));
00340   TwoDArray<std::string> badStringArray(2,2);
00341   badStringArray(0,0) = "str2";
00342   badStringArray(0,1) = "str1";
00343   badStringArray(1,0) = "str3";
00344   badStringArray(1,1) = "not valid";
00345   TEST_THROW(stringList->set("String Array Param", badStringArray, "string array parameter", stringArrayVali),
00346     Exceptions::InvalidParameterValue);
00347   TEST_THROW(stringList->set("Int param", 5, "int parameter", stringArrayVali),
00348     Exceptions::InvalidParameterType);
00349   TwoDArray<long> longArray(2,2);
00350   longArray(0,0) = (long)5;
00351   longArray(0,1) = (long)4;
00352   longArray(1,0) = (long)9;
00353   longArray(1,1) = (long)1;
00354   TEST_THROW(stringList->set("Long array param", longArray, "long array parameter", stringArrayVali),
00355     Exceptions::InvalidParameterType);
00356   
00357   /*
00358    * Testing Int ArrayValidator.
00359    */
00360   RCP<ParameterList> intList = rcp(new ParameterList("Int List"));
00361   RCP<EnhancedNumberValidator<int> > intVali = rcp(new EnhancedNumberValidator<int>(0, 10));
00362   RCP<TwoDArrayNumberValidator<int> > intArrayVali = 
00363     rcp(new TwoDArrayNumberValidator<int>(intVali));
00364   TEST_ASSERT(intVali.get() == intArrayVali->getPrototype().get());
00365   TwoDArray<int> intArray(2,2);
00366   intArray(0,0) = 1;
00367   intArray(0,1) = 4;
00368   intArray(1,0) = 2;
00369   intArray(1,1) = 5;
00370   TEST_NOTHROW(intList->set("int array param", intArray, "int array parameter", intArrayVali));
00371   TwoDArray<int> intBadArray(2,2);
00372   intBadArray(0,0) = 11;
00373   intBadArray(0,1) = 4;
00374   intBadArray(1,0) = 2;
00375   intBadArray(1,1) = 5;
00376   TEST_THROW(intList->set("int bad array param", intBadArray, "int bad array parameter", intArrayVali),
00377     Exceptions::InvalidParameterValue);
00378   TEST_THROW(stringList->set("Long array param", longArray, "long array parameter", intArrayVali),
00379     Exceptions::InvalidParameterType);
00380 
00381   /*
00382    * Testing Short ArrayValidator.
00383    */
00384   RCP<ParameterList> shortList = rcp(new ParameterList("Short List"));
00385   RCP<EnhancedNumberValidator<short> > shortVali =
00386     rcp(new EnhancedNumberValidator<short>(0, 10));
00387   RCP<TwoDArrayNumberValidator<short> > shortArrayVali =
00388     rcp(new TwoDArrayNumberValidator<short>(shortVali));
00389   TEST_ASSERT(shortVali.get() == shortArrayVali->getPrototype().get());
00390   TwoDArray<short> shortArray(2,2);
00391   shortArray(0,0) = 1;
00392   shortArray(0,1) = 4;
00393   shortArray(1,0) = 2;
00394   shortArray(1,1) = 5;
00395   TEST_NOTHROW(shortList->set("short array param", shortArray, "short array parameter", shortArrayVali));
00396   TwoDArray<short> shortBadArray(2,2);
00397   shortBadArray(0,0) = 11;
00398   shortBadArray(0,1) = 4;
00399   shortBadArray(1,0) = 2;
00400   shortBadArray(1,1) = 5;
00401   TEST_THROW(shortList->set("short bad array param", shortBadArray, "short bad array parameter", shortArrayVali),
00402     Exceptions::InvalidParameterValue);
00403   TEST_THROW(stringList->set("Long array param", longArray, "long array parameter", shortArrayVali),
00404     Exceptions::InvalidParameterType);
00405 
00406   /*
00407    * Testing Float ArrayValidator.
00408    */
00409   RCP<ParameterList> floatList = rcp(new ParameterList("Float List"));
00410   RCP<EnhancedNumberValidator<float> > floatVali =
00411     rcp(new EnhancedNumberValidator<float>(0.0, 10.0));
00412   RCP<TwoDArrayNumberValidator<float> > floatArrayVali =
00413     rcp(new TwoDArrayNumberValidator<float>(floatVali));
00414   TEST_ASSERT(floatVali.get() == floatArrayVali->getPrototype().get());
00415   TwoDArray<float> floatArray(2,2);
00416   floatArray(0,0) = 1.0;
00417   floatArray(0,1) = 4.0;
00418   floatArray(1,0) = 5.0;
00419   floatArray(1,1) = 2.0;
00420   TEST_NOTHROW(floatList->set("float array param", floatArray, "float array parameter", floatArrayVali));
00421   TwoDArray<float> floatBadArray(2,2);
00422   floatBadArray(0,0) = 11.0;
00423   floatBadArray(0,1) = 4.0;
00424   floatBadArray(1,0) = 5.0;
00425   floatBadArray(1,1) = 2.0;
00426   TEST_THROW(floatList->set("float bad array param", floatBadArray, "float bad array parameter", floatArrayVali),
00427     Exceptions::InvalidParameterValue);
00428   TEST_THROW(stringList->set("Long array param", longArray, "long array parameter", floatArrayVali),
00429     Exceptions::InvalidParameterType);
00430 
00431   /*
00432    * Testing Double ArrayValidator.
00433    */
00434   RCP<ParameterList> doubleList = rcp(new ParameterList("Double List"));
00435   RCP<EnhancedNumberValidator<double> > doubleVali =
00436     rcp(new EnhancedNumberValidator<double>(0.0, 10.0));
00437   RCP<TwoDArrayNumberValidator<double> > doubleArrayVali =
00438     rcp(new TwoDArrayNumberValidator<double>(doubleVali));
00439   TEST_ASSERT(doubleVali.get() == doubleArrayVali->getPrototype().get());
00440   TwoDArray<double> doubleArray(2,2);
00441   doubleArray(0,0) = 1.0;
00442   doubleArray(0,1) = 4.0;
00443   doubleArray(1,0) = 5.0;
00444   doubleArray(1,1) = 2.0;
00445   TEST_NOTHROW(doubleList->set("double array param", doubleArray, "double array parameter", doubleArrayVali));
00446   TwoDArray<double> doubleBadArray(2,2);
00447   doubleBadArray(0,0) = 11.0;
00448   doubleBadArray(0,1) = 4.0;
00449   doubleBadArray(1,0) = 5.0;
00450   doubleBadArray(1,1) = 2.0;
00451   TEST_THROW(doubleList->set("double bad array param", doubleBadArray, "double bad array parameter", doubleArrayVali),
00452     Exceptions::InvalidParameterValue);
00453   TEST_THROW(stringList->set("Long array param", longArray, "long array parameter", doubleArrayVali),
00454     Exceptions::InvalidParameterType);
00455 
00456   /*
00457    * Testing FileName ArrayValidator.
00458    */
00459   RCP<ParameterList> fileNameList = rcp(new ParameterList("Filename List"));
00460   RCP<FileNameValidator> fileNameVali = rcp(new FileNameValidator(true));
00461   RCP<TwoDArrayFileNameValidator> arrayFileNameVali = 
00462     rcp(new TwoDArrayFileNameValidator(fileNameVali));
00463   TEST_ASSERT(arrayFileNameVali->getPrototype().get() == fileNameVali.get());
00464   TwoDArray<std::string> fileNameArray(2,2);
00465   fileNameArray(0,0) = "testFile.txt";
00466   fileNameArray(0,1) = "testFile2.txt";
00467   fileNameArray(1,0) = "testFile3.txt";
00468   fileNameArray(1,1) = "testFile.txt";
00469   TwoDArray<std::string> fileNameBadArray(2,2);
00470   fileNameBadArray(0,0) = "doesntexist.txt";
00471   fileNameBadArray(0,1) = "testFile2.txt";
00472   fileNameBadArray(1,0) = "testFile3.txt";
00473   fileNameBadArray(1,1) = "testFile.txt";
00474   TEST_NOTHROW(fileNameList->set("File name array", fileNameArray, "file name array parameter", arrayFileNameVali));
00475   TEST_THROW(fileNameList->set("Bad File name array", fileNameBadArray, "bad file name array parameter", arrayFileNameVali),
00476     Exceptions::InvalidParameterValue);
00477   TEST_THROW(stringList->set("Long array param", longArray, "long array parameter", arrayFileNameVali),
00478     Exceptions::InvalidParameterType);
00479 }
00480 
00481 } // namespace Teuchos
00482 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines