Teuchos Package Browser (Single Doxygen Collection) Version of the Day
Validator_SerializationTest.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 #include "Teuchos_XMLParameterListExceptions.hpp"
00046 #include "Teuchos_XMLParameterListCoreHelpers.hpp"
00047 #include "Teuchos_XMLParameterListWriter.hpp"
00048 #include "Teuchos_ValidatorXMLConverterDB.hpp"
00049 #include "Teuchos_StandardValidatorXMLConverters.hpp"
00050 
00051 #include "Teuchos_XMLParameterListTestHelpers.hpp"
00052 
00053 using Teuchos::writeThenReadPL;
00054 
00055 
00056 namespace Teuchos {
00057 
00058 class UNDEFINED_PARAMETERENTRY_VALIDATOR : public ParameterEntryValidator
00059 {
00060 
00061   public:
00062 
00063   void printDoc(const std::string& docString, std::ostream& out) const {}
00064 
00065   ValidStringsList validStringValues() const{
00066     return rcp(new Array<std::string>(1,""));
00067   }
00068 
00069   void validate(
00070     ParameterEntry  const& entry,
00071     std::string const& paramName,
00072     std::string const& sublistName
00073     ) const {}
00074 
00075   const std::string getXMLTypeName() const{
00076     return "UNDEFINEDTYPE";
00077   }
00078 
00079 };
00080 
00081 TEUCHOS_UNIT_TEST(Teuchos_Validator, exceptionTests)
00082 {
00083   ValidatorXMLConverterDB::printKnownConverters(out);
00084   out << std::endl;
00085 
00086   UNDEFINED_PARAMETERENTRY_VALIDATOR badValidator;
00087   TEST_THROW(ValidatorXMLConverterDB::getConverter(badValidator), CantFindValidatorConverterException);
00088 
00089   TEST_THROW(RCP<ParameterList>
00090     missingValidatorList = getParametersFromXmlFile("MissingValidator.xml"),
00091     MissingValidatorDefinitionException);
00092 
00093   TEST_THROW(RCP<ParameterList>
00094     missingPrototypeList = getParametersFromXmlFile("MissingPrototypeValidator.xml"),
00095         MissingValidatorDefinitionException);
00096 
00097   TEST_THROW(RCP<ParameterList>
00098     conflicitingValiIdsList = getParametersFromXmlFile("ConflictingValidatorIDs.xml"),
00099     DuplicateValidatorIDsException);
00100 
00101   TEST_THROW(RCP<ParameterList>
00102     stringValidatorBadTagList = getParametersFromXmlFile("StringValidatorBadTag.xml"),
00103     BadTagException);
00104 
00105   TEST_THROW(RCP<ParameterList>
00106     stringValidatorBadTagList = getParametersFromXmlFile("StringToIntegralValidatorBadTag.xml"),
00107     BadTagException);
00108 
00109   #ifdef HAVE_TEUCHOS_DEBUG
00110 
00111   StringValidatorXMLConverter stringConverter;
00112   AnyNumberValidatorXMLConverter anyNumberConverter;
00113   ValidatortoIDMap writerDummyMap;
00114   IDtoValidatorMap readerDummyMap;
00115   RCP<AnyNumberParameterEntryValidator> anyNumberValidator =
00116     anyNumberParameterEntryValidator();
00117   writerDummyMap.insert(anyNumberValidator);
00118   TEST_THROW(
00119     stringConverter.fromValidatortoXML(anyNumberValidator, writerDummyMap),
00120     BadValidatorXMLConverterException);
00121   XMLObject anyNumberXML =
00122     anyNumberConverter.fromValidatortoXML(anyNumberValidator, writerDummyMap);
00123   TEST_THROW(
00124     stringConverter.fromXMLtoValidator(anyNumberXML, readerDummyMap),
00125     BadValidatorXMLConverterException);
00126 
00127   #endif
00128 
00129 }
00130 
00131 TEUCHOS_UNIT_TEST(Teuchos_Validator, fileNameValidatorConverter)
00132 {
00133   std::string defaultParameterName = "default";
00134   std::string nonDefaultParameterName = "non default";
00135 
00136   RCP<FileNameValidator> defaultValidator =
00137     rcp(new FileNameValidator);
00138   RCP<FileNameValidator> nonDefaultValidator =
00139     rcp(new FileNameValidator(true));
00140   ParameterList myList("FileName Validator List");
00141   myList.set("default", "", "parameter for default validator",
00142     defaultValidator);
00143   myList.set("non default", "blah.txt", "parameter for non default validator",
00144     nonDefaultValidator);
00145 
00146   RCP<ParameterList> readInPL = writeThenReadPL(myList);
00147 
00148   RCP<const FileNameValidator> readinDefault =
00149     rcp_dynamic_cast<const FileNameValidator>(
00150       readInPL->getEntry(defaultParameterName).validator(), true);
00151   TEST_EQUALITY(readinDefault->fileMustExist(), defaultValidator->fileMustExist());
00152 
00153   RCP<const FileNameValidator> readinNonDefault =
00154     rcp_dynamic_cast<const FileNameValidator>(
00155       readInPL->getEntry(nonDefaultParameterName).validator(), true);
00156   TEST_EQUALITY(readinNonDefault->fileMustExist(), nonDefaultValidator->fileMustExist());
00157 }
00158 
00159 
00160 TEUCHOS_UNIT_TEST(Teuchos_Validator, stringValidatorConverter)
00161 {
00162   std::string defaultParameterName = "default";
00163   std::string nonDefaultParameterName = "non default";
00164 
00165   RCP<StringValidator> nonDefaultValidator = rcp(
00166     new StringValidator(tuple<std::string>("value1", "cheese", "kurtis", "is", "awesome")));
00167   ParameterList myList("String Validator List");
00168   myList.set("non default", "kurtis", "parameter for non default validator",
00169     nonDefaultValidator);
00170 
00171   RCP<ParameterList> readInPL = writeThenReadPL(myList);
00172 
00173   RCP<const StringValidator> readinNonDefault =
00174     rcp_dynamic_cast<const StringValidator>(
00175       readInPL->getEntry(nonDefaultParameterName).validator(), true);
00176   TEST_COMPARE_ARRAYS(*(readinNonDefault->validStringValues()),
00177     *(nonDefaultValidator->validStringValues()));
00178 }
00179 
00180 
00181 TEUCHOS_UNIT_TEST(Teuchos_Validator, anynumberValidatorConverter)
00182 {
00183   std::string xmlFileName = "AnyNumberValidatorList.xml";
00184   std::string defaultParameterName = "default";
00185   std::string nonDefaultParameterName = "preferred and accepted";
00186   RCP<AnyNumberParameterEntryValidator> defaultValidator =
00187     rcp(new AnyNumberParameterEntryValidator());
00188   AnyNumberParameterEntryValidator::AcceptedTypes acceptedTypes;
00189   acceptedTypes.allowDouble(false);
00190   RCP<AnyNumberParameterEntryValidator> nonDefaultValidator =
00191     rcp(
00192       new AnyNumberParameterEntryValidator(
00193         AnyNumberParameterEntryValidator::PREFER_INT,
00194         acceptedTypes
00195         )
00196       );
00197 
00198   ParameterList myList("AnyNumberValidatorList");
00199   myList.set(defaultParameterName, 10.0,
00200     "A parameter with the default AnyNumberValidator on it", defaultValidator);
00201   myList.set(nonDefaultParameterName, 1,
00202     "A prameter with an AnyNumberValidator on it that has the preferred and accepted types differnet from the default",
00203     nonDefaultValidator);
00204 
00205   RCP<ParameterList> readInPL = writeThenReadPL(myList);
00206 
00207   RCP<const AnyNumberParameterEntryValidator> readinDefaultValidator =
00208     rcp_dynamic_cast<const AnyNumberParameterEntryValidator>(
00209       readInPL->getEntry(defaultParameterName).validator(), true);
00210   TEST_EQUALITY(readinDefaultValidator->isDoubleAllowed(),
00211     defaultValidator->isDoubleAllowed());
00212   TEST_EQUALITY(readinDefaultValidator->isIntAllowed(),
00213     defaultValidator->isIntAllowed());
00214   TEST_EQUALITY(readinDefaultValidator->isStringAllowed(),
00215     defaultValidator->isStringAllowed());
00216   TEST_EQUALITY(readinDefaultValidator->getPreferredType(),
00217     defaultValidator->getPreferredType());
00218 
00219   RCP<const AnyNumberParameterEntryValidator> readinNonDefaultValidator =
00220     rcp_dynamic_cast<const AnyNumberParameterEntryValidator>(
00221       readInPL->getEntry(nonDefaultParameterName).validator(), true);
00222   TEST_EQUALITY(readinNonDefaultValidator->isDoubleAllowed(),
00223     nonDefaultValidator->isDoubleAllowed());
00224   TEST_EQUALITY(readinNonDefaultValidator->isIntAllowed(),
00225     nonDefaultValidator->isIntAllowed());
00226   TEST_EQUALITY(readinNonDefaultValidator->isStringAllowed(),
00227     nonDefaultValidator->isStringAllowed());
00228   TEST_EQUALITY(readinNonDefaultValidator->getPreferredType(),
00229     nonDefaultValidator->getPreferredType());
00230 }
00231 
00232 
00233 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL(Teuchos_Validator, EnhancedNumberValidatorConverter, T)
00234 {
00235   std::string xmlFileName = TypeNameTraits<T>::name() + "EnhancedValidatorList.xml";
00236   std::string defaultParameterName = "default";
00237   std::string minmaxParameterName = "min max";
00238   std::string stepPrecParameterName = "step and prec";
00239   ParameterList myList;
00240   RCP<EnhancedNumberValidator< T > > defaultValidator =
00241     rcp( new EnhancedNumberValidator< T >());
00242   RCP<EnhancedNumberValidator< T > > minMaxValidator =
00243     rcp( new EnhancedNumberValidator< T >(0,10));
00244   RCP<EnhancedNumberValidator< T > > stepAndPrecValidator =
00245     rcp( new EnhancedNumberValidator< T >(0,10,4,4));
00246   myList.set(defaultParameterName, ( T )6, "parameter with default validator",
00247     defaultValidator);
00248   myList.set(minmaxParameterName, ( T )10, "parameter with min and max validator",
00249     minMaxValidator);
00250   myList.set(stepPrecParameterName, ( T )10, "parameter with min, max, "
00251     "step, and prec validator",
00252     stepAndPrecValidator);
00253 
00254   RCP<ParameterList> readInPL = writeThenReadPL(myList);
00255 
00256   TEST_EQUALITY(
00257     rcp_dynamic_cast<const EnhancedNumberValidator< T > >(
00258       readInPL->getEntry(defaultParameterName).validator(), true)->getMin(),
00259     rcp_dynamic_cast<const EnhancedNumberValidator< T > >(
00260       myList.getEntry(defaultParameterName).validator(), true)->getMin()
00261   );
00262   TEST_EQUALITY(
00263     rcp_dynamic_cast<const EnhancedNumberValidator< T > >(
00264       readInPL->getEntry(defaultParameterName).validator(), true)->getMax(),
00265     rcp_dynamic_cast<const EnhancedNumberValidator< T > >(
00266       myList.getEntry(defaultParameterName).validator(), true)->getMax()
00267   );
00268   TEST_EQUALITY(
00269     rcp_dynamic_cast<const EnhancedNumberValidator< T > >(
00270       readInPL->getEntry(defaultParameterName).validator(), true)->getStep()
00271     ,
00272     rcp_dynamic_cast<const EnhancedNumberValidator< T > >(
00273       myList.getEntry(defaultParameterName).validator(), true)->getStep()
00274   );
00275   TEST_EQUALITY(
00276     rcp_dynamic_cast<const EnhancedNumberValidator< T > >(
00277       readInPL->getEntry(
00278         defaultParameterName).validator(), true)->getPrecision(),
00279     rcp_dynamic_cast<const EnhancedNumberValidator< T > >(
00280       myList.getEntry(
00281         defaultParameterName).validator(), true)->getPrecision()
00282   );
00283   TEST_EQUALITY(
00284     rcp_dynamic_cast<const EnhancedNumberValidator< T > >(
00285       readInPL->getEntry(defaultParameterName).validator(), true)->hasMin(),
00286     rcp_dynamic_cast<const EnhancedNumberValidator< T > >(
00287       myList.getEntry(defaultParameterName).validator(), true)->hasMin()
00288   );
00289   TEST_EQUALITY(
00290     rcp_dynamic_cast<const EnhancedNumberValidator< T > >(
00291       readInPL->getEntry(defaultParameterName).validator(), true)->hasMax(),
00292     rcp_dynamic_cast<const EnhancedNumberValidator< T > >(
00293       myList.getEntry(defaultParameterName).validator(), true)->hasMax()
00294   );
00295 
00296   TEST_EQUALITY(
00297     rcp_dynamic_cast<const EnhancedNumberValidator< T > >(
00298       readInPL->getEntry(minmaxParameterName).validator(), true)->getMin(),
00299     rcp_dynamic_cast<const EnhancedNumberValidator< T > >(
00300       myList.getEntry(minmaxParameterName).validator(), true)->getMin()
00301   );
00302   TEST_EQUALITY(
00303     rcp_dynamic_cast<const EnhancedNumberValidator< T > >(
00304       readInPL->getEntry(minmaxParameterName).validator(), true)->getMax(),
00305     rcp_dynamic_cast<const EnhancedNumberValidator< T > >(
00306       myList.getEntry(minmaxParameterName).validator(), true)->getMax()
00307   );
00308   TEST_EQUALITY(
00309     rcp_dynamic_cast<const EnhancedNumberValidator< T > >(
00310       readInPL->getEntry(minmaxParameterName).validator(), true)->getStep(),
00311     rcp_dynamic_cast<const EnhancedNumberValidator< T > >(
00312       myList.getEntry(minmaxParameterName).validator(), true)->getStep()
00313   );
00314   TEST_EQUALITY(
00315     rcp_dynamic_cast<const EnhancedNumberValidator< T > >(
00316       readInPL->getEntry(
00317         minmaxParameterName).validator(), true)->getPrecision(),
00318     rcp_dynamic_cast<const EnhancedNumberValidator< T > >(
00319       myList.getEntry(
00320         minmaxParameterName).validator(), true)->getPrecision()
00321   );
00322   TEST_EQUALITY(
00323     rcp_dynamic_cast<const EnhancedNumberValidator< T > >(
00324       readInPL->getEntry(minmaxParameterName).validator(), true)->hasMin(),
00325     rcp_dynamic_cast<const EnhancedNumberValidator< T > >(
00326       myList.getEntry(minmaxParameterName).validator(), true)->hasMin()
00327   );
00328   TEST_EQUALITY(
00329     rcp_dynamic_cast<const EnhancedNumberValidator< T > >(
00330       readInPL->getEntry(minmaxParameterName).validator(), true)->hasMax(),
00331     rcp_dynamic_cast<const EnhancedNumberValidator< T > >(
00332       myList.getEntry(minmaxParameterName).validator(), true)->hasMax()
00333   );
00334 
00335   TEST_EQUALITY(
00336     rcp_dynamic_cast<const EnhancedNumberValidator< T > >(
00337       readInPL->getEntry(stepPrecParameterName).validator(), true)->getMin(),
00338     rcp_dynamic_cast<const EnhancedNumberValidator< T > >(
00339       myList.getEntry(stepPrecParameterName).validator(), true)->getMin()
00340   );
00341   TEST_EQUALITY(
00342     rcp_dynamic_cast<const EnhancedNumberValidator< T > >(
00343       readInPL->getEntry(stepPrecParameterName).validator(), true)->getMax(),
00344     rcp_dynamic_cast<const EnhancedNumberValidator< T > >(
00345       myList.getEntry(stepPrecParameterName).validator(), true)->getMax()
00346   );
00347   TEST_EQUALITY(
00348     rcp_dynamic_cast<const EnhancedNumberValidator< T > >(
00349       readInPL->getEntry(stepPrecParameterName).validator(), true)->getStep()
00350     ,
00351     rcp_dynamic_cast<const EnhancedNumberValidator< T > >(
00352       myList.getEntry(stepPrecParameterName).validator(), true)->getStep()
00353   );
00354   TEST_EQUALITY(
00355     rcp_dynamic_cast<const EnhancedNumberValidator< T > >(
00356       readInPL->getEntry(
00357         stepPrecParameterName).validator(), true)->getPrecision(),
00358     rcp_dynamic_cast<const EnhancedNumberValidator< T > >(
00359       myList.getEntry(
00360         stepPrecParameterName).validator(), true)->getPrecision());
00361 
00362 }
00363 
00364 
00365 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL(Teuchos_Validator, NumberArrayValidatorConverterTest, T)
00366 {
00367   std::string arrayParameterName = "array";
00368   ParameterList myList;
00369 
00370   const T arrayValidatorLen = as<T>(11);
00371   RCP<ArrayNumberValidator< T > > arrayValidator =
00372     rcp(new ArrayNumberValidator< T >(
00373       rcp(new EnhancedNumberValidator<T>(as<T>(0), arrayValidatorLen))));
00374   myList.set(arrayParameterName,
00375     Array< T >(4, 10), "array parameter", arrayValidator);
00376 
00377   RCP<ParameterList> readInPL = writeThenReadPL(myList);
00378 
00379   RCP<const EnhancedNumberValidator< T > > readInPrototypeValidator =
00380     rcp_dynamic_cast<const ArrayValidator<EnhancedNumberValidator<T>, T > >(
00381       readInPL->getEntry(
00382         arrayParameterName).validator(), true)->getPrototype();
00383   RCP<const EnhancedNumberValidator< T > > actualPrototypeValidator =
00384     arrayValidator->getPrototype();
00385 
00386   TEST_EQUALITY(
00387     readInPrototypeValidator->getMin(),
00388     actualPrototypeValidator->getMin()
00389   );
00390   TEST_EQUALITY(
00391     readInPrototypeValidator->getMax(),
00392     actualPrototypeValidator->getMax()
00393   );
00394   TEST_EQUALITY(
00395     readInPrototypeValidator->getStep(),
00396     actualPrototypeValidator->getStep()
00397   );
00398   TEST_EQUALITY(
00399     readInPrototypeValidator->getPrecision(),
00400     actualPrototypeValidator->getPrecision()
00401   );
00402   TEST_EQUALITY(
00403     readInPrototypeValidator->hasMin(),
00404     actualPrototypeValidator->hasMin()
00405   );
00406   TEST_EQUALITY(
00407     readInPrototypeValidator->hasMax(),
00408     actualPrototypeValidator->hasMax()
00409   );
00410 }
00411 
00412 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL(Teuchos_Validator, TwoDArrayNumberValidatorConverterTest, T)
00413 {
00414   std::string arrayParameterName = "array";
00415   ParameterList myList;
00416 
00417   const T arrayValidatorLen = as<T>(11);
00418   RCP<TwoDArrayNumberValidator< T > > arrayValidator =
00419     rcp(new TwoDArrayNumberValidator< T >(
00420       rcp(new EnhancedNumberValidator<T>(as<T>(0), arrayValidatorLen))));
00421   myList.set(arrayParameterName,
00422     TwoDArray< T >(4,4, 10), "array parameter", arrayValidator);
00423 
00424   RCP<ParameterList> readInPL = writeThenReadPL(myList);
00425 
00426   RCP<const EnhancedNumberValidator< T > > readInPrototypeValidator =
00427     rcp_dynamic_cast<const TwoDArrayValidator<EnhancedNumberValidator<T>, T > >(
00428       readInPL->getEntry(
00429         arrayParameterName).validator(), true)->getPrototype();
00430   RCP<const EnhancedNumberValidator< T > > actualPrototypeValidator =
00431     arrayValidator->getPrototype();
00432 
00433   TEST_EQUALITY(
00434     readInPrototypeValidator->getMin(),
00435     actualPrototypeValidator->getMin()
00436   );
00437   TEST_EQUALITY(
00438     readInPrototypeValidator->getMax(),
00439     actualPrototypeValidator->getMax()
00440   );
00441   TEST_EQUALITY(
00442     readInPrototypeValidator->getStep(),
00443     actualPrototypeValidator->getStep()
00444   );
00445   TEST_EQUALITY(
00446     readInPrototypeValidator->getPrecision(),
00447     actualPrototypeValidator->getPrecision()
00448   );
00449   TEST_EQUALITY(
00450     readInPrototypeValidator->hasMin(),
00451     actualPrototypeValidator->hasMin()
00452   );
00453   TEST_EQUALITY(
00454     readInPrototypeValidator->hasMax(),
00455     actualPrototypeValidator->hasMax()
00456   );
00457 }
00458 
00459 
00460 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL(Teuchos_Validator, StringToIntegralConverterTest, T)
00461 {
00462   std::string defaultStringToIntegralParameterName = "defaultsti";
00463   std::string stringToIntegralParameterName = "sti";
00464   ParameterList myList;
00465   RCP<StringToIntegralParameterEntryValidator< T > > defaultStiValidator = rcp(
00466     new StringToIntegralParameterEntryValidator< T >(
00467       tuple<std::string>("value1", "value2", "value3"), stringToIntegralParameterName));
00468   RCP<StringToIntegralParameterEntryValidator< T > > stiValidator = rcp(
00469     new StringToIntegralParameterEntryValidator< T >(
00470       tuple<std::string>("value3", "value4", "value5"),
00471       tuple<std::string>("the third value", "the fourth value", "the fifth value"),
00472       tuple< T >(3,4,5),
00473       stringToIntegralParameterName));
00474   myList.set(defaultStringToIntegralParameterName,
00475     "value1", "parameter with default sti validator", defaultStiValidator);
00476   myList.set(stringToIntegralParameterName, "value3", "parameter with sti validator",
00477     stiValidator);
00478 
00479   RCP<ParameterList> readInPL = writeThenReadPL(myList);
00480 
00481 
00482   RCP<const StringToIntegralParameterEntryValidator< T > >
00483   readInDefaultStiValidator =
00484     rcp_dynamic_cast<const StringToIntegralParameterEntryValidator< T > >(
00485       readInPL->getEntry(
00486         defaultStringToIntegralParameterName).validator(), true);
00487   RCP<const StringToIntegralParameterEntryValidator< T > >
00488   readInStiValidator =
00489     rcp_dynamic_cast<const StringToIntegralParameterEntryValidator< T > >(
00490       readInPL->getEntry(
00491         stringToIntegralParameterName).validator(), true);
00492 
00493   Array<std::string> readInDefaultValidStrings =
00494     *(readInDefaultStiValidator->validStringValues());
00495   Array<std::string> defaultValidStrings =
00496     *(defaultStiValidator->validStringValues());
00497   TEST_COMPARE_ARRAYS(readInDefaultValidStrings, defaultValidStrings);
00498 
00499   TEST_ASSERT(readInDefaultStiValidator->getStringDocs().is_null());
00500   TEST_EQUALITY( readInDefaultStiValidator->getDefaultParameterName(),
00501     defaultStiValidator->getDefaultParameterName());
00502   for(int i=0; i<defaultValidStrings.size(); ++i){
00503     TEST_EQUALITY(defaultStiValidator->getIntegralValue(defaultValidStrings[i]),
00504       readInDefaultStiValidator->getIntegralValue(defaultValidStrings[i]));
00505   }
00506 
00507   Array<std::string> readInValidStrings = *(readInStiValidator->validStringValues());
00508   Array<std::string> validStrings = *(stiValidator->validStringValues());
00509   TEST_COMPARE_ARRAYS(readInValidStrings, validStrings);
00510 
00511   TEST_COMPARE_ARRAYS(*(readInStiValidator->getStringDocs()),
00512     *(stiValidator->getStringDocs()));
00513   TEST_EQUALITY( readInStiValidator->getDefaultParameterName(),
00514     stiValidator->getDefaultParameterName());
00515   for(int i=0; i<validStrings.size(); ++i){
00516     TEST_EQUALITY(stiValidator->getIntegralValue(validStrings[i]),
00517       readInStiValidator->getIntegralValue(validStrings[i]));
00518   }
00519 
00520 }
00521 
00522 TEUCHOS_UNIT_TEST(Teuchos_Validator, existingPrototypeTest){
00523   ParameterList pl("ExsitingPrototypeList");
00524   RCP<StringValidator> stringVali = rcp(new StringValidator());
00525   RCP<ArrayValidator<StringValidator, std::string> > arrayStringVali
00526     = rcp(new ArrayValidator<StringValidator, std::string>(stringVali));
00527   Array<std::string> strArray = tuple<std::string>("blah", "blah", "blah");
00528   pl.set("string param", "hi", "a string param", stringVali);
00529   pl.set("string array param", strArray,
00530     "a string array parameter", arrayStringVali);
00531   RCP<ParameterList> readInPL = writeThenReadPL(pl);
00532   RCP<const ArrayValidator<StringValidator, std::string> >
00533     inArrayValidator =
00534     rcp_dynamic_cast<const ArrayValidator<StringValidator, std::string> >(
00535       readInPL->getEntry("string array param").validator(), true);
00536   TEST_ASSERT(readInPL->getEntry("string param").validator()
00537     == inArrayValidator->getPrototype());
00538 }
00539 
00540 
00541 #define FULL_NUMBER_TYPE_TEST( T ) \
00542 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT(Teuchos_Validator, EnhancedNumberValidatorConverter, T ) \
00543 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT(Teuchos_Validator, NumberArrayValidatorConverterTest, T ) \
00544 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT(Teuchos_Validator, StringToIntegralConverterTest, T )
00545 
00546 #define NONINTEGRAL_NUMBER_TYPE_TEST( T ) \
00547 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT(Teuchos_Validator, EnhancedNumberValidatorConverter, T ) \
00548 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT(Teuchos_Validator, NumberArrayValidatorConverterTest, T )
00549 
00550 typedef unsigned int uint;
00551 typedef unsigned short ushort;
00552 typedef unsigned long ulong;
00553 
00554 
00555 FULL_NUMBER_TYPE_TEST(int)
00556 NONINTEGRAL_NUMBER_TYPE_TEST(double)
00557 NONINTEGRAL_NUMBER_TYPE_TEST(float)
00558 #ifdef HAVE_TEUCHOS_LONG_LONG_INT
00559 typedef long long int llint;
00560 FULL_NUMBER_TYPE_TEST(llint)
00561 #endif
00562 
00563 
00564 } // namespace Teuchos
00565 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines