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