Teuchos Package Browser (Single Doxygen Collection) Version of the Day
Dependencies_SerializationTests.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 
00042 #include "Teuchos_VerboseObject.hpp"
00043 #include "Teuchos_XMLParameterListHelpers.hpp"
00044 #include "Teuchos_StandardDependencies.hpp"
00045 #include "Teuchos_DependencySheet.hpp"
00046 #include "Teuchos_StandardConditions.hpp"
00047 #include "Teuchos_StandardDependencies.hpp"
00048 #include "Teuchos_UnitTestHarness.hpp"
00049 #include "Teuchos_DependencyXMLConverterDB.hpp"
00050 #include "Teuchos_StandardDependencyXMLConverters.hpp"
00051 #include "Teuchos_ParameterList.hpp"
00052 
00053 #include "Teuchos_XMLParameterListTestHelpers.hpp"
00054 
00055 
00056 namespace Teuchos{
00057 
00058 
00059 typedef unsigned short int ushort;
00060 typedef unsigned int uint;
00061 typedef unsigned long int ulong;
00062 typedef std::string myString_t;
00063 #ifdef HAVE_TEUCHOS_LONG_LONG_INT
00064 typedef long long int llint;
00065 typedef unsigned long long int ullint;
00066 #endif
00067 
00068 #define BASIC_DEPENDENCY_TEST( \
00069   DEPENDENCY, DEPTYPE,  NUM_DEPENDEES, NUM_DEPENDENTS) \
00070   std::string depXMLTag##DEPENDENCY = \
00071     DummyObjectGetter< DEPTYPE >::getDummyObject()->getTypeAttributeValue(); \
00072 \
00073   TEST_ASSERT(DEPENDENCY->getTypeAttributeValue() == depXMLTag##DEPENDENCY ); \
00074   TEST_ASSERT(DEPENDENCY->getDependents().size() == NUM_DEPENDENTS); \
00075   TEST_ASSERT(DEPENDENCY->getDependees().size() == NUM_DEPENDEES); \
00076 
00077 #define VERIFY_DEPENDENT(DEPENDENCY, DEPENDENT) \
00078   TEST_ASSERT( \
00079     DEPENDENCY->getDependents().find(DEPENDENT)  \
00080     != \
00081     DEPENDENCY->getDependents().end() \
00082   ); \
00083   
00084 #define VERIFY_DEPENDEE(DEPENDENCY, DEPENDEE) \
00085   TEST_ASSERT( \
00086     DEPENDENCY->getDependees().find(DEPENDEE)  \
00087     != \
00088     DEPENDENCY->getDependees().end()); \
00089 
00090 #define CREATE_DEPENDEE(POSTFIX, VALUE) \
00091    RCP<ParameterEntry> dependeeParam##POSTFIX = rcp(  \
00092     new ParameterEntry( VALUE )); 
00093 
00094 #define CREATE_DEPENDENT(POSTFIX, VALUE) \
00095   RCP<ParameterEntry> dependentParam##POSTFIX =   \
00096     rcp(new ParameterEntry( VALUE )); \
00097   
00098 #define EXCEPTION_TEST_BOILERPLATE(DEPENDEE_VAL, DEPENDENT_VAL) \
00099   CREATE_DEPENDEE(1, DEPENDEE_VAL); \
00100   CREATE_DEPENDEE(Extra, DEPENDEE_VAL); \
00101   CREATE_DEPENDENT(1, DEPENDENT_VAL); \
00102 \
00103   XMLParameterListWriter::EntryIDsMap writerEntryMap; \
00104   writerEntryMap[dependeeParam1] = 1; \
00105   writerEntryMap[dependentParam1] = 2; \
00106   writerEntryMap[dependeeParamExtra] = 3; \
00107   ValidatortoIDMap writerValiMap; \
00108 \
00109   XMLParameterListReader::EntryIDsMap readerEntryMap; \
00110   readerEntryMap[1] = dependeeParam1; \
00111   readerEntryMap[2] = dependentParam1; \
00112   readerEntryMap[3] = dependeeParamExtra; \
00113   IDtoValidatorMap readerValiMap; \
00114   
00115 #define CONVERT_DEP_TO_XML(DEPENDENCY) \
00116   XMLObject DEPENDENCY##XML = DependencyXMLConverterDB::convertDependency( \
00117     DEPENDENCY , writerEntryMap, writerValiMap);  \
00118 
00119 #define TOO_MANY_DEPENDEE_TEST(DEPENDENCY) \
00120   XMLObject extraDependee(DependencyXMLConverter::getDependeeTagName());  \
00121   extraDependee.addAttribute<ParameterEntry::ParameterEntryID>(  \
00122     DependencyXMLConverter::getParameterIdAttributeName(), \
00123     writerEntryMap[dependeeParamExtra]);  \
00124   XMLObject tooManyTempXML = DEPENDENCY##XML.deepCopy(); \
00125   tooManyTempXML.addChild(extraDependee);  \
00126   \
00127   TEST_THROW(  \
00128     DependencyXMLConverterDB::convertXML(  \
00129       tooManyTempXML , readerEntryMap, readerValiMap),  \
00130     TooManyDependeesException);  \
00131 
00132 #define COPY_DEPTAG_WITHOUT_CHILD(TAG, CHILDTAG, NEWTAG) \
00133   XMLObject NEWTAG(TAG.getTag()); \
00134   NEWTAG.addAttribute( \
00135     DependencyXMLConverter::getTypeAttributeName(), \
00136     TAG.getAttribute(DependencyXMLConverter::getTypeAttributeName())); \
00137   for(int i =0; i< TAG.numChildren(); i++){ \
00138     if(TAG.getChild(i).getTag() != CHILDTAG) \
00139     { \
00140       NEWTAG.addChild(TAG.getChild(i).deepCopy()); \
00141     } \
00142   } \
00143 
00144  
00145 #define INSERT_VALIDATOR_TO_MAPS(VALIDATOR) \
00146   writerValiMap.insert( VALIDATOR ); \
00147   readerValiMap.insert( \
00148     IDtoValidatorMap::IDValidatorPair( \
00149       writerValiMap.find( VALIDATOR )->second, VALIDATOR )); \
00150 
00151 
00152 TEUCHOS_UNIT_TEST(Teuchos_Dependencies, SerializationTestMacros){
00153   RCP<ParameterEntry> dependee1 = rcp(new ParameterEntry(true));
00154   RCP<ParameterEntry> dependee2 = rcp(new ParameterEntry(true));
00155   RCP<ParameterEntry> dependent1 = rcp(new ParameterEntry("blah"));
00156   RCP<ParameterEntry> dependent2 = rcp(new ParameterEntry("blah"));
00157   RCP<BoolVisualDependency> simpleDep = 
00158     rcp(new BoolVisualDependency(dependee1, dependent1));
00159 
00160 
00161   Dependency::ParameterEntryList dependentList;
00162   dependentList.insert(dependent1);
00163   dependentList.insert(dependent2);
00164 
00165   RCP<BoolVisualDependency> complexDep = 
00166     rcp(new BoolVisualDependency(dependee2, dependentList));
00167 
00168   BASIC_DEPENDENCY_TEST(simpleDep, BoolVisualDependency, 1, 1);
00169   VERIFY_DEPENDEE(simpleDep, dependee1);
00170   VERIFY_DEPENDENT(simpleDep, dependent1);
00171 
00172   BASIC_DEPENDENCY_TEST(complexDep, BoolVisualDependency, 1, 2);
00173   VERIFY_DEPENDEE(complexDep, dependee2);
00174   VERIFY_DEPENDENT(complexDep, dependent1);
00175   VERIFY_DEPENDENT(complexDep, dependent2);
00176 
00177 }
00178 
00179 
00180 TEUCHOS_UNIT_TEST(Teuchos_Dependencies, StringVisualDepSerialization){
00181   std::string dependee1 = "string param";
00182   std::string dependee2 = "string param2";
00183   std::string dependent1 = "dependent param1";
00184   std::string dependent2 = "dependent param2";
00185   ParameterList myDepList("String Visual Dep List");
00186   RCP<DependencySheet> myDepSheet = rcp(new DependencySheet);
00187   myDepList.set(dependee1, "val1");
00188   myDepList.set(dependee2, "val2");
00189   myDepList.set(dependent1, 1.0);
00190   myDepList.set(dependent2, 1.0);
00191 
00192   StringVisualDependency::ValueList valList1 = tuple<std::string>("val1");
00193 
00194   RCP<StringVisualDependency> basicStringVisDep = rcp(
00195     new StringVisualDependency(
00196       myDepList.getEntryRCP(dependee1),
00197       myDepList.getEntryRCP(dependent1),
00198       valList1));
00199 
00200   Dependency::ParameterEntryList dependentList;
00201   dependentList.insert(myDepList.getEntryRCP(dependent1));
00202   dependentList.insert(myDepList.getEntryRCP(dependent2));
00203   StringVisualDependency::ValueList valList2 = 
00204     tuple<std::string>("val1", "val2");
00205 
00206   RCP<StringVisualDependency> complexStringVisDep = rcp(
00207     new StringVisualDependency(
00208       myDepList.getEntryRCP(dependee2),
00209       dependentList,
00210       valList2,
00211       false));
00212 
00213   myDepSheet->addDependency(basicStringVisDep);
00214   myDepSheet->addDependency(complexStringVisDep);
00215 
00216   RCP<DependencySheet> readInDepSheet = rcp(new DependencySheet);
00217 
00218   XMLParameterListWriter plWriter;
00219   XMLObject xmlOut = plWriter.toXML(myDepList, myDepSheet);
00220   out << xmlOut.toString();
00221 
00222   RCP<ParameterList> readInList = 
00223     writeThenReadPL(myDepList, myDepSheet, readInDepSheet); 
00224 
00225   RCP<ParameterEntry> readinDependee1 = readInList->getEntryRCP(dependee1);
00226   RCP<ParameterEntry> readinDependent1 = readInList->getEntryRCP(dependent1);
00227   RCP<ParameterEntry> readinDependee2 = readInList->getEntryRCP(dependee2);
00228   RCP<ParameterEntry> readinDependent2 = readInList->getEntryRCP(dependent2);
00229   
00230   RCP<Dependency> readinDep1 =
00231     *(readInDepSheet->getDependenciesForParameter(readinDependee1)->begin());
00232 
00233   RCP<Dependency> readinDep2 =
00234     *(readInDepSheet->getDependenciesForParameter(readinDependee2)->begin());
00235 
00236   BASIC_DEPENDENCY_TEST(readinDep1, StringVisualDependency, 1, 1);
00237   VERIFY_DEPENDEE(readinDep1, readinDependee1);
00238   VERIFY_DEPENDENT(readinDep1, readinDependent1);
00239 
00240   BASIC_DEPENDENCY_TEST(readinDep2, StringVisualDependency, 1, 2);
00241   VERIFY_DEPENDEE(readinDep2, readinDependee2);
00242   VERIFY_DEPENDENT(readinDep2, readinDependent1);
00243   VERIFY_DEPENDENT(readinDep2, readinDependent2);
00244     
00245   RCP<StringVisualDependency> castedDep1 =
00246     rcp_dynamic_cast<StringVisualDependency>(readinDep1, true);
00247   RCP<StringVisualDependency> castedDep2 =
00248     rcp_dynamic_cast<StringVisualDependency>(readinDep2, true);
00249 
00250   TEST_COMPARE_ARRAYS(
00251     castedDep1->getValues(), basicStringVisDep->getValues());
00252   TEST_COMPARE_ARRAYS(
00253     castedDep2->getValues(), complexStringVisDep->getValues());
00254 
00255   TEST_EQUALITY(castedDep1->getShowIf(), basicStringVisDep->getShowIf());
00256   TEST_EQUALITY(castedDep2->getShowIf(), complexStringVisDep->getShowIf());
00257 }
00258 
00259 TEUCHOS_UNIT_TEST(Teuchos_Dependencies, BoolVisualDepSerialization){
00260   std::string dependee1 = "bool param";
00261   std::string dependee2 = "bool param2";
00262   std::string dependent1 = "dependent param1";
00263   std::string dependent2 = "dependent param2";
00264   ParameterList myDepList("Bool Visual Dep List");
00265   RCP<DependencySheet> myDepSheet = rcp(new DependencySheet);
00266   myDepList.set(dependee1, true);
00267   myDepList.set(dependee2, true);
00268   myDepList.set(dependent1, 1.0);
00269   myDepList.set(dependent2, 1.0);
00270 
00271   RCP<BoolVisualDependency> trueBoolVisDep = rcp(
00272     new BoolVisualDependency(
00273       myDepList.getEntryRCP(dependee1),
00274       myDepList.getEntryRCP(dependent1)));
00275 
00276   Dependency::ParameterEntryList dependentList;
00277   dependentList.insert(myDepList.getEntryRCP(dependent1));
00278   dependentList.insert(myDepList.getEntryRCP(dependent2));
00279 
00280   RCP<BoolVisualDependency> falseBoolVisDep = rcp(
00281     new BoolVisualDependency(
00282       myDepList.getEntryRCP(dependee2),
00283       dependentList,
00284       false));
00285 
00286   myDepSheet->addDependency(trueBoolVisDep);
00287   myDepSheet->addDependency(falseBoolVisDep);
00288 
00289   RCP<DependencySheet> readInDepSheet = rcp(new DependencySheet);
00290 
00291   XMLParameterListWriter plWriter;
00292   XMLObject xmlOut = plWriter.toXML(myDepList, myDepSheet);
00293   out << xmlOut.toString();
00294 
00295   RCP<ParameterList> readInList = 
00296     writeThenReadPL(myDepList, myDepSheet, readInDepSheet); 
00297 
00298   RCP<ParameterEntry> readinDependee1 = readInList->getEntryRCP(dependee1);
00299   RCP<ParameterEntry> readinDependent1 = readInList->getEntryRCP(dependent1);
00300   RCP<ParameterEntry> readinDependee2 = readInList->getEntryRCP(dependee2);
00301   RCP<ParameterEntry> readinDependent2 = readInList->getEntryRCP(dependent2);
00302   
00303   RCP<Dependency> readinDep1 =
00304     *(readInDepSheet->getDependenciesForParameter(readinDependee1)->begin());
00305 
00306   RCP<Dependency> readinDep2 =
00307     *(readInDepSheet->getDependenciesForParameter(readinDependee2)->begin());
00308 
00309   BASIC_DEPENDENCY_TEST(readinDep1, BoolVisualDependency, 1, 1);
00310   VERIFY_DEPENDEE(readinDep1, readinDependee1);
00311   VERIFY_DEPENDENT(readinDep1, readinDependent1);
00312 
00313   BASIC_DEPENDENCY_TEST(readinDep2, BoolVisualDependency, 1, 2);
00314   VERIFY_DEPENDEE(readinDep2, readinDependee2);
00315   VERIFY_DEPENDENT(readinDep2, readinDependent1);
00316   VERIFY_DEPENDENT(readinDep2, readinDependent2);
00317     
00318     
00319   RCP<BoolVisualDependency> castedDep1 =
00320     rcp_dynamic_cast<BoolVisualDependency>(readinDep1, true);
00321   RCP<BoolVisualDependency> castedDep2 =
00322     rcp_dynamic_cast<BoolVisualDependency>(readinDep2, true);
00323 
00324   TEST_EQUALITY(castedDep1->getShowIf(), trueBoolVisDep->getShowIf());
00325   TEST_EQUALITY(castedDep2->getShowIf(), falseBoolVisDep->getShowIf());
00326 }
00327 
00328 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL(
00329   Teuchos_Dependencies, 
00330   NumberVisualDepSerialization, 
00331   T)
00332 {
00333   std::string dependee1 = "num param";
00334   std::string dependee2 = "num param2";
00335   std::string dependent1 = "dependent param1";
00336   std::string dependent2 = "dependent param2";
00337   ParameterList myDepList("Number Visual Dep List");
00338   RCP<DependencySheet> myDepSheet = rcp(new DependencySheet);
00339   myDepList.set(dependee1, ScalarTraits<T>::one());
00340   myDepList.set(dependee2, ScalarTraits<T>::one());
00341   myDepList.set(dependent1, true);
00342   myDepList.set(dependent2, "vale");
00343 
00344   RCP<NumberVisualDependency<T> > simpleNumVisDep = rcp(
00345     new NumberVisualDependency<T>(
00346       myDepList.getEntryRCP(dependee1),
00347       myDepList.getEntryRCP(dependent1)));
00348 
00349   Dependency::ParameterEntryList dependentList;
00350   dependentList.insert(myDepList.getEntryRCP(dependent1));
00351   dependentList.insert(myDepList.getEntryRCP(dependent2));
00352 
00353   T ten = ScalarTraits<T>::one() *10;
00354   RCP<SubtractionFunction<T> > subFunction = rcp(new SubtractionFunction<T>(ten));
00355   RCP<NumberVisualDependency<T> > complexNumVisDep = rcp(
00356     new NumberVisualDependency<T>(
00357       myDepList.getEntryRCP(dependee2),
00358       dependentList,
00359       true,
00360       subFunction));
00361 
00362   myDepSheet->addDependency(simpleNumVisDep);
00363   myDepSheet->addDependency(complexNumVisDep);
00364 
00365   RCP<DependencySheet> readInDepSheet = rcp(new DependencySheet);
00366 
00367   XMLParameterListWriter plWriter;
00368   XMLObject xmlOut = plWriter.toXML(myDepList, myDepSheet);
00369   out << xmlOut.toString();
00370 
00371   RCP<ParameterList> readInList = 
00372     writeThenReadPL(myDepList, myDepSheet, readInDepSheet); 
00373 
00374   RCP<ParameterEntry> readinDependee1 = readInList->getEntryRCP(dependee1);
00375   RCP<ParameterEntry> readinDependent1 = readInList->getEntryRCP(dependent1);
00376   RCP<ParameterEntry> readinDependee2 = readInList->getEntryRCP(dependee2);
00377   RCP<ParameterEntry> readinDependent2 = readInList->getEntryRCP(dependent2);
00378   
00379   RCP<Dependency> readinDep1 =
00380     *(readInDepSheet->getDependenciesForParameter(readinDependee1)->begin());
00381 
00382   RCP<Dependency> readinDep2 =
00383     *(readInDepSheet->getDependenciesForParameter(readinDependee2)->begin());
00384 
00385   BASIC_DEPENDENCY_TEST(readinDep1, NumberVisualDependency<T>, 1, 1);
00386   VERIFY_DEPENDEE(readinDep1, readinDependee1);
00387   VERIFY_DEPENDENT(readinDep1, readinDependent1);
00388 
00389   BASIC_DEPENDENCY_TEST(readinDep2, NumberVisualDependency<T>, 1, 2);
00390   VERIFY_DEPENDEE(readinDep2, readinDependee2);
00391   VERIFY_DEPENDENT(readinDep2, readinDependent1);
00392   VERIFY_DEPENDENT(readinDep2, readinDependent2);
00393     
00394     
00395   RCP<NumberVisualDependency<T> > castedDep1 =
00396     rcp_dynamic_cast<NumberVisualDependency<T> >(readinDep1, true);
00397   RCP<NumberVisualDependency<T> > castedDep2 =
00398     rcp_dynamic_cast<NumberVisualDependency<T> >(readinDep2, true);
00399 
00400   TEST_EQUALITY(castedDep1->getShowIf(), simpleNumVisDep->getShowIf());
00401   TEST_EQUALITY(castedDep2->getShowIf(), complexNumVisDep->getShowIf());
00402 
00403   RCP<const SimpleFunctionObject<T> > functionObject = 
00404     castedDep2->getFunctionObject();
00405   TEST_ASSERT(functionObject != null);
00406   RCP<const SubtractionFunction<T> > castedFunction =
00407     rcp_dynamic_cast<const SubtractionFunction<T> >(functionObject);
00408   TEST_ASSERT(castedFunction != null);
00409   TEST_EQUALITY(
00410     castedFunction->getModifiyingOperand(), 
00411     subFunction->getModifiyingOperand());
00412 }
00413 
00414 #define NUMBER_VIS_TEST(T) \
00415 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( \
00416   Teuchos_Dependencies, NumberVisualDepSerialization, T)
00417 
00418 NUMBER_VIS_TEST(int)
00419 NUMBER_VIS_TEST(double)
00420 NUMBER_VIS_TEST(float)
00421 #ifdef HAVE_TEUCHOS_LONG_LONG_INT
00422 NUMBER_VIS_TEST(llint)
00423 #endif
00424 
00425 TEUCHOS_UNIT_TEST(Teuchos_Dependencies, ConditionVisualDepSerialization){
00426   std::string dependee1 = "string param";
00427   std::string dependee2 = "bool param";
00428   std::string dependee3 = "int param";
00429   std::string dependent1 = "dependent param1";
00430   std::string dependent2 = "dependent param2";
00431   std::string dependent3 = "dependent param3";
00432   ParameterList myDepList("Condition Visual Dep List");
00433   RCP<DependencySheet> myDepSheet = rcp(new DependencySheet);
00434   myDepList.set(dependee1, "val1");
00435   myDepList.set(dependee2, true);
00436   myDepList.set(dependee3, 1);
00437   myDepList.set(dependent1, 1.0);
00438   myDepList.set(dependent2, 1.0);
00439   myDepList.set(dependent3, (float)1.0);
00440 
00441   StringCondition::ValueList conditionVal1 = 
00442     tuple<std::string>("steve", "blah", "your face");
00443   RCP<StringCondition> stringCon = 
00444     rcp(new StringCondition(
00445       myDepList.getEntryRCP(dependee1), conditionVal1));
00446 
00447   RCP<BoolCondition> boolCon = 
00448     rcp(new BoolCondition(myDepList.getEntryRCP(dependee2)));
00449 
00450   RCP<NumberCondition<int> > numberCon = 
00451     rcp(new NumberCondition<int>(myDepList.getEntryRCP(dependee3)));
00452 
00453   Condition::ConstConditionList conList = 
00454     tuple<RCP<const Condition> >(boolCon, numberCon);
00455 
00456   RCP<AndCondition> andCon = rcp(new AndCondition(conList));
00457 
00458   RCP<ConditionVisualDependency> simpleConVisDep = rcp(
00459     new ConditionVisualDependency(
00460       stringCon,
00461       myDepList.getEntryRCP(dependent1)));
00462 
00463   Dependency::ParameterEntryList dependentList;
00464   dependentList.insert(myDepList.getEntryRCP(dependent2));
00465   dependentList.insert(myDepList.getEntryRCP(dependent3));
00466 
00467   RCP<ConditionVisualDependency> complexConVisDep = rcp(
00468     new ConditionVisualDependency(
00469       andCon,
00470       dependentList,
00471       false));
00472 
00473   myDepSheet->addDependency(simpleConVisDep);
00474   myDepSheet->addDependency(complexConVisDep);
00475 
00476   RCP<DependencySheet> readInDepSheet = rcp(new DependencySheet);
00477 
00478   XMLParameterListWriter plWriter;
00479   XMLObject xmlOut = plWriter.toXML(myDepList, myDepSheet);
00480   out << xmlOut.toString();
00481 
00482   RCP<ParameterList> readInList = 
00483     writeThenReadPL(myDepList, myDepSheet, readInDepSheet); 
00484 
00485   RCP<ParameterEntry> readinDependee1 = readInList->getEntryRCP(dependee1);
00486   RCP<ParameterEntry> readinDependent1 = readInList->getEntryRCP(dependent1);
00487   RCP<ParameterEntry> readinDependee2 = readInList->getEntryRCP(dependee2);
00488   RCP<ParameterEntry> readinDependent2 = readInList->getEntryRCP(dependent2);
00489   RCP<ParameterEntry> readinDependee3 = readInList->getEntryRCP(dependee3);
00490   RCP<ParameterEntry> readinDependent3 = readInList->getEntryRCP(dependent3);
00491   
00492   RCP<Dependency> readinDep1 =
00493     *(readInDepSheet->getDependenciesForParameter(readinDependee1)->begin());
00494 
00495   RCP<Dependency> readinDep2 =
00496     *(readInDepSheet->getDependenciesForParameter(readinDependee2)->begin());
00497 
00498   RCP<Dependency> readinDep3 =
00499     *(readInDepSheet->getDependenciesForParameter(readinDependee3)->begin());
00500 
00501   BASIC_DEPENDENCY_TEST(readinDep1, ConditionVisualDependency, 1, 1);
00502   VERIFY_DEPENDEE(readinDep1, readinDependee1);
00503   VERIFY_DEPENDENT(readinDep1, readinDependent1);
00504 
00505   TEST_ASSERT(readinDep2.get() == readinDep3.get());
00506 
00507   BASIC_DEPENDENCY_TEST(readinDep2, ConditionVisualDependency, 2, 2);
00508   VERIFY_DEPENDEE(readinDep2, readinDependee2);
00509   VERIFY_DEPENDEE(readinDep2, readinDependee3);
00510   VERIFY_DEPENDENT(readinDep2, readinDependent2);
00511   VERIFY_DEPENDENT(readinDep2, readinDependent3);
00512     
00513   RCP<ConditionVisualDependency> castedDep1 =
00514     rcp_dynamic_cast<ConditionVisualDependency>(readinDep1, true);
00515   RCP<ConditionVisualDependency> castedDep2 =
00516     rcp_dynamic_cast<ConditionVisualDependency>(readinDep2, true);
00517 
00518   TEST_EQUALITY(castedDep1->getShowIf(), simpleConVisDep->getShowIf());
00519   TEST_EQUALITY(castedDep2->getShowIf(), complexConVisDep->getShowIf());
00520 
00521   TEST_EQUALITY(castedDep1->getCondition()->getTypeAttributeValue(),
00522     simpleConVisDep->getCondition()->getTypeAttributeValue());
00523   TEST_EQUALITY(castedDep2->getCondition()->getTypeAttributeValue(), 
00524     complexConVisDep->getCondition()->getTypeAttributeValue());
00525 }
00526 
00527 #define ArrayModifierTest(DEPENDENCYTYPE, ARRAY_TYPE) \
00528 TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( \
00529   Teuchos_Dependencies,  \
00530   DEPENDENCYTYPE##_serialization_tests,  \
00531   DependeeType, \
00532   DependentType) \
00533 { \
00534   std::string dependee1 = "dependee param"; \
00535   std::string dependee2 = "dependee param2"; \
00536   std::string dependent1 = "dependent param1"; \
00537   std::string dependent2 = "dependent param2"; \
00538   ParameterList myDepList("Array modifier dep list"); \
00539   RCP<DependencySheet> myDepSheet = rcp(new DependencySheet); \
00540   myDepList.set(dependee1, ScalarTraits<DependeeType>::one()); \
00541   myDepList.set(dependee2, ScalarTraits<DependeeType>::one()); \
00542   myDepList.set(dependent1, ARRAY_TYPE<DependentType>()); \
00543   myDepList.set(dependent2, ARRAY_TYPE<DependentType>()); \
00544  \
00545  \
00546   RCP<DEPENDENCYTYPE<DependeeType, DependentType> > basicArrayDep = \
00547     rcp(new DEPENDENCYTYPE<DependeeType, DependentType>( \
00548       myDepList.getEntryRCP(dependee1), \
00549       myDepList.getEntryRCP(dependent1))); \
00550  \
00551   DependeeType one = ScalarTraits< DependeeType >::one(); \
00552   RCP<AdditionFunction< DependeeType > > functionTester =  \
00553     rcp(new AdditionFunction<DependeeType>(one)); \
00554  \
00555   RCP<DEPENDENCYTYPE<DependeeType, DependentType> > funcArrayDep = \
00556     rcp(new DEPENDENCYTYPE<DependeeType, DependentType>( \
00557       myDepList.getEntryRCP(dependee2), \
00558       myDepList.getEntryRCP(dependent2), \
00559       functionTester)); \
00560    \
00561  \
00562   myDepSheet->addDependency(basicArrayDep); \
00563   myDepSheet->addDependency(funcArrayDep); \
00564  \
00565   RCP<DependencySheet> readInDepSheet = rcp(new DependencySheet); \
00566  \
00567   XMLParameterListWriter plWriter; \
00568   XMLObject xmlOut = plWriter.toXML(myDepList, myDepSheet); \
00569   out << xmlOut.toString(); \
00570  \
00571   RCP<ParameterList> readInList =  \
00572     writeThenReadPL(myDepList, myDepSheet, readInDepSheet);  \
00573  \
00574   RCP<ParameterEntry> readinDependee1 = readInList->getEntryRCP(dependee1); \
00575   RCP<ParameterEntry> readinDependent1 = readInList->getEntryRCP(dependent1); \
00576   RCP<ParameterEntry> readinDependee2 = readInList->getEntryRCP(dependee2); \
00577   RCP<ParameterEntry> readinDependent2 = readInList->getEntryRCP(dependent2); \
00578    \
00579   RCP<Dependency> readinDep1 = \
00580     *(readInDepSheet->getDependenciesForParameter(readinDependee1)->begin()); \
00581   RCP<Dependency> readinDep2 = \
00582     *(readInDepSheet->getDependenciesForParameter(readinDependee2)->begin()); \
00583  \
00584   typedef DEPENDENCYTYPE<DependeeType, DependentType> deptype; \
00585   BASIC_DEPENDENCY_TEST(readinDep1, deptype, 1, 1); \
00586   VERIFY_DEPENDEE(readinDep1, readinDependee1); \
00587   VERIFY_DEPENDENT(readinDep1, readinDependent1); \
00588  \
00589   BASIC_DEPENDENCY_TEST(readinDep2, deptype, 1, 1); \
00590   VERIFY_DEPENDEE(readinDep2, readinDependee2); \
00591   VERIFY_DEPENDENT(readinDep2, readinDependent2); \
00592  \
00593   RCP<DEPENDENCYTYPE<DependeeType, DependentType> > castedDep1 = \
00594     rcp_dynamic_cast<DEPENDENCYTYPE<DependeeType, DependentType> >( \
00595       readinDep1); \
00596   TEST_ASSERT(castedDep1 != null); \
00597  \
00598   RCP<DEPENDENCYTYPE<DependeeType, DependentType> > castedDep2 = \
00599     rcp_dynamic_cast<DEPENDENCYTYPE<DependeeType, DependentType> >( \
00600       readinDep2); \
00601   TEST_ASSERT(castedDep2 != null); \
00602  \
00603   RCP<const SimpleFunctionObject< DependeeType > > readInFunc = \
00604     castedDep2->getFunctionObject(); \
00605   TEST_ASSERT(readInFunc != null); \
00606  \
00607   RCP<const AdditionFunction< DependeeType > > castedFunc =  \
00608     rcp_dynamic_cast<const AdditionFunction< DependeeType > >(readInFunc); \
00609   TEST_ASSERT(castedFunc != null); \
00610   TEST_EQUALITY( \
00611     castedFunc->getModifiyingOperand(),  \
00612     functionTester->getModifiyingOperand()); \
00613 } 
00614 
00615 ArrayModifierTest(NumberArrayLengthDependency, Array)
00616 
00617 #define NUM_ARRAY_LENGTH_TEST(DependeeType, DependentType) \
00618 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
00619   Teuchos_Dependencies, \
00620   NumberArrayLengthDependency_serialization_tests, \
00621   DependeeType, \
00622   DependentType) 
00623 
00624 // Need to fix array serialization so we can test this with
00625 // a dependent type of strings. Right now an array of emptyr strings does not
00626 // seralize correctly
00627 // KLN 09.17/2010
00628 #ifdef HAVE_TEUCHOS_LONG_LONG_INT
00629 #define NUM_ARRAY_LENGTH_TEST_GROUP(DependeeType) \
00630   NUM_ARRAY_LENGTH_TEST(DependeeType, int) \
00631   NUM_ARRAY_LENGTH_TEST(DependeeType, float) \
00632   NUM_ARRAY_LENGTH_TEST(DependeeType, double) \
00633   NUM_ARRAY_LENGTH_TEST(DependeeType, llint) 
00634 #else
00635 #define NUM_ARRAY_LENGTH_TEST_GROUP(DependeeType) \
00636   NUM_ARRAY_LENGTH_TEST(DependeeType, int) \
00637   NUM_ARRAY_LENGTH_TEST(DependeeType, double) \
00638   NUM_ARRAY_LENGTH_TEST(DependeeType, float)
00639 #endif
00640 
00641 NUM_ARRAY_LENGTH_TEST_GROUP(int)
00642 #ifdef HAVE_TEUCHOS_LONG_LONG_INT
00643 NUM_ARRAY_LENGTH_TEST_GROUP(llint)
00644 #endif
00645 
00646 ArrayModifierTest(TwoDRowDependency, TwoDArray)
00647 
00648 #define TWODROW_TEST(DependeeType, DependentType) \
00649 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
00650   Teuchos_Dependencies, \
00651   TwoDRowDependency_serialization_tests, \
00652   DependeeType, \
00653   DependentType) 
00654 
00655 // Need to fix array serialization so we can test this with
00656 // a dependent type of strings. Right now an array of emptyr strings does not
00657 // seralize correctly
00658 // KLN 09.17/2010
00659 #ifdef HAVE_TEUCHOS_LONG_LONG_INT
00660 #define TWODROW_TEST_GROUP(DependeeType) \
00661   TWODROW_TEST(DependeeType, int) \
00662   TWODROW_TEST(DependeeType, float) \
00663   TWODROW_TEST(DependeeType, double) \
00664   TWODROW_TEST(DependeeType, llint) 
00665 #else
00666 #define TWODROW_TEST_GROUP(DependeeType) \
00667   TWODROW_TEST(DependeeType, int) \
00668   TWODROW_TEST(DependeeType, double) \
00669   TWODROW_TEST(DependeeType, float)
00670 #endif
00671 
00672 TWODROW_TEST_GROUP(int)
00673 #ifdef HAVE_TEUCHOS_LONG_LONG_INT
00674 TWODROW_TEST_GROUP(llint)
00675 #endif
00676 
00677 ArrayModifierTest(TwoDColDependency, TwoDArray)
00678 
00679 #define TWODCOL_TEST(DependeeType, DependentType) \
00680 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
00681   Teuchos_Dependencies, \
00682   TwoDColDependency_serialization_tests, \
00683   DependeeType, \
00684   DependentType) 
00685 
00686 // Need to fix array serialization so we can test this with
00687 // a dependent type of strings. Right now an array of emptyr strings does not
00688 // seralize correctly
00689 // KLN 09.17/2010
00690 #ifdef HAVE_TEUCHOS_LONG_LONG_INT
00691 #define TWODCOL_TEST_GROUP(DependeeType) \
00692   TWODCOL_TEST(DependeeType, int) \
00693   TWODCOL_TEST(DependeeType, float) \
00694   TWODCOL_TEST(DependeeType, double) \
00695   TWODCOL_TEST(DependeeType, llint) 
00696 #else
00697 #define TWODCOL_TEST_GROUP(DependeeType) \
00698   TWODCOL_TEST(DependeeType, int) \
00699   TWODCOL_TEST(DependeeType, double) \
00700   TWODCOL_TEST(DependeeType, float)
00701 #endif
00702 
00703 TWODCOL_TEST_GROUP(int)
00704 #ifdef HAVE_TEUCHOS_LONG_LONG_INT
00705 TWODCOL_TEST_GROUP(llint)
00706 #endif
00707 
00708 TEUCHOS_UNIT_TEST(Teuchos_Dependencies, StringValidatorDepSerialization){
00709   std::string dependee1 = "string param";
00710   std::string dependee2 = "string param2";
00711   std::string dependent1 = "dependent param1";
00712   std::string dependent2 = "dependent param2";
00713   ParameterList myDepList("String Vali Dep List");
00714   RCP<DependencySheet> myDepSheet = rcp(new DependencySheet);
00715   myDepList.set(dependee1, "val1");
00716   myDepList.set(dependee2, "val2");
00717   myDepList.set(dependent1, 2.0);
00718   myDepList.set(dependent2, 3.0);
00719 
00720   RCP<EnhancedNumberValidator<double> > double1Vali =
00721     rcp(new EnhancedNumberValidator<double>(0,10));
00722 
00723   RCP<EnhancedNumberValidator<double> > double2Vali =
00724     rcp(new EnhancedNumberValidator<double>(0,30));
00725 
00726   RCP<EnhancedNumberValidator<double> > defaultVali =
00727     rcp(new EnhancedNumberValidator<double>(4,90));
00728 
00729   StringValidatorDependency::ValueToValidatorMap valuesAndValidators;
00730   valuesAndValidators["val1"] = double1Vali;
00731   valuesAndValidators["val2"] = double2Vali;
00732 
00733   RCP<StringValidatorDependency> basicStringValiDep = rcp(
00734     new StringValidatorDependency(
00735       myDepList.getEntryRCP(dependee1),
00736       myDepList.getEntryRCP(dependent1),
00737       valuesAndValidators));
00738 
00739   Dependency::ParameterEntryList dependentList;
00740   dependentList.insert(myDepList.getEntryRCP(dependent1));
00741   dependentList.insert(myDepList.getEntryRCP(dependent2));
00742 
00743   RCP<StringValidatorDependency> complexStringValiDep = rcp(
00744     new StringValidatorDependency(
00745       myDepList.getEntryRCP(dependee2),
00746       dependentList,
00747       valuesAndValidators,
00748       defaultVali));
00749 
00750   myDepSheet->addDependency(basicStringValiDep);
00751   myDepSheet->addDependency(complexStringValiDep);
00752 
00753   RCP<DependencySheet> readInDepSheet = rcp(new DependencySheet);
00754 
00755   XMLParameterListWriter plWriter;
00756   XMLObject xmlOut = plWriter.toXML(myDepList, myDepSheet);
00757   out << xmlOut.toString();
00758 
00759   RCP<ParameterList> readInList = 
00760     writeThenReadPL(myDepList, myDepSheet, readInDepSheet); 
00761 
00762   RCP<ParameterEntry> readinDependee1 = readInList->getEntryRCP(dependee1);
00763   RCP<ParameterEntry> readinDependent1 = readInList->getEntryRCP(dependent1);
00764   RCP<ParameterEntry> readinDependee2 = readInList->getEntryRCP(dependee2);
00765   RCP<ParameterEntry> readinDependent2 = readInList->getEntryRCP(dependent2);
00766   
00767   RCP<Dependency> readinDep1 =
00768     *(readInDepSheet->getDependenciesForParameter(readinDependee1)->begin());
00769 
00770   RCP<Dependency> readinDep2 =
00771     *(readInDepSheet->getDependenciesForParameter(readinDependee2)->begin());
00772 
00773   BASIC_DEPENDENCY_TEST(readinDep1, StringValidatorDependency, 1, 1);
00774   VERIFY_DEPENDEE(readinDep1, readinDependee1);
00775   VERIFY_DEPENDENT(readinDep1, readinDependent1);
00776 
00777   BASIC_DEPENDENCY_TEST(readinDep2, StringValidatorDependency, 1, 2);
00778   VERIFY_DEPENDEE(readinDep2, readinDependee2);
00779   VERIFY_DEPENDENT(readinDep2, readinDependent1);
00780   VERIFY_DEPENDENT(readinDep2, readinDependent2);
00781     
00782     
00783   RCP<StringValidatorDependency> castedDep1 =
00784     rcp_dynamic_cast<StringValidatorDependency>(readinDep1, true);
00785   RCP<StringValidatorDependency> castedDep2 =
00786     rcp_dynamic_cast<StringValidatorDependency>(readinDep2, true);
00787 
00788   TEST_ASSERT(castedDep1->getValuesAndValidators().size() == 2);
00789   TEST_ASSERT(castedDep2->getValuesAndValidators().size() == 2);
00790   TEST_ASSERT(castedDep1->getDefaultValidator().is_null());
00791   TEST_ASSERT(nonnull(castedDep2->getDefaultValidator()));
00792 
00793   TEST_EQUALITY(
00794     rcp_dynamic_cast<const EnhancedNumberValidator<double> >(
00795       castedDep1->getValuesAndValidators().find("val1")->second, true)->getMax(),
00796     double1Vali->getMax());
00797   TEST_EQUALITY(
00798     rcp_dynamic_cast<const EnhancedNumberValidator<double> >(
00799       castedDep2->getValuesAndValidators().find("val1")->second, true)->getMax(),
00800     double1Vali->getMax());
00801 
00802   TEST_EQUALITY(
00803     rcp_dynamic_cast<const EnhancedNumberValidator<double> >(
00804       castedDep1->getValuesAndValidators().find("val2")->second, true)->getMax(),
00805     double2Vali->getMax());
00806   TEST_EQUALITY(
00807     rcp_dynamic_cast<const EnhancedNumberValidator<double> >(
00808       castedDep2->getValuesAndValidators().find("val2")->second, true)->getMax(),
00809     double2Vali->getMax());
00810 
00811   TEST_EQUALITY(
00812     rcp_dynamic_cast<const EnhancedNumberValidator<double> >(
00813       castedDep2->getDefaultValidator(), true)->getMax(),
00814     defaultVali->getMax());
00815 
00816 }
00817 
00818 TEUCHOS_UNIT_TEST(Teuchos_Dependencies, BoolValidatorDepSerialization){
00819   std::string dependee1 = "bool param";
00820   std::string dependee2 = "bool param2";
00821   std::string dependent1 = "dependent param1";
00822   std::string dependent2 = "dependent param2";
00823   ParameterList myDepList("Bool Vali Dep List");
00824   RCP<DependencySheet> myDepSheet = rcp(new DependencySheet);
00825   myDepList.set(dependee1, true);
00826   myDepList.set(dependee2, false);
00827   myDepList.set(dependent1, 2.0);
00828   myDepList.set(dependent2, 3.0);
00829 
00830   RCP<EnhancedNumberValidator<double> > true1Vali =
00831     rcp(new EnhancedNumberValidator<double>(0,10));
00832 
00833   RCP<EnhancedNumberValidator<double> > false1Vali =
00834     rcp(new EnhancedNumberValidator<double>(0,30));
00835 
00836   RCP<EnhancedNumberValidator<double> > true2Vali =
00837     rcp(new EnhancedNumberValidator<double>(4,90));
00838 
00839 
00840   RCP<BoolValidatorDependency> simpleBoolValiDep = rcp(
00841     new BoolValidatorDependency(
00842       myDepList.getEntryRCP(dependee1),
00843       myDepList.getEntryRCP(dependent1),
00844       true1Vali,
00845       false1Vali));
00846 
00847   Dependency::ParameterEntryList dependentList;
00848   dependentList.insert(myDepList.getEntryRCP(dependent1));
00849   dependentList.insert(myDepList.getEntryRCP(dependent2));
00850 
00851   RCP<BoolValidatorDependency> complexBoolValiDep = rcp(
00852     new BoolValidatorDependency(
00853       myDepList.getEntryRCP(dependee2),
00854       dependentList,
00855       true2Vali));
00856 
00857   myDepSheet->addDependency(simpleBoolValiDep);
00858   myDepSheet->addDependency(complexBoolValiDep);
00859 
00860   RCP<DependencySheet> readInDepSheet = rcp(new DependencySheet);
00861 
00862   XMLParameterListWriter plWriter;
00863   XMLObject xmlOut = plWriter.toXML(myDepList, myDepSheet);
00864   out << xmlOut.toString();
00865 
00866   RCP<ParameterList> readInList = 
00867     writeThenReadPL(myDepList, myDepSheet, readInDepSheet); 
00868 
00869   RCP<ParameterEntry> readinDependee1 = readInList->getEntryRCP(dependee1);
00870   RCP<ParameterEntry> readinDependent1 = readInList->getEntryRCP(dependent1);
00871   RCP<ParameterEntry> readinDependee2 = readInList->getEntryRCP(dependee2);
00872   RCP<ParameterEntry> readinDependent2 = readInList->getEntryRCP(dependent2);
00873   
00874   RCP<Dependency> readinDep1 =
00875     *(readInDepSheet->getDependenciesForParameter(readinDependee1)->begin());
00876 
00877   RCP<Dependency> readinDep2 =
00878     *(readInDepSheet->getDependenciesForParameter(readinDependee2)->begin());
00879 
00880   BASIC_DEPENDENCY_TEST(readinDep1, BoolValidatorDependency, 1, 1);
00881   VERIFY_DEPENDEE(readinDep1, readinDependee1);
00882   VERIFY_DEPENDENT(readinDep1, readinDependent1);
00883 
00884   BASIC_DEPENDENCY_TEST(readinDep2, BoolValidatorDependency, 1, 2);
00885   VERIFY_DEPENDEE(readinDep2, readinDependee2);
00886   VERIFY_DEPENDENT(readinDep2, readinDependent1);
00887   VERIFY_DEPENDENT(readinDep2, readinDependent2);
00888     
00889     
00890   RCP<BoolValidatorDependency> castedDep1 =
00891     rcp_dynamic_cast<BoolValidatorDependency>(readinDep1, true);
00892   RCP<BoolValidatorDependency> castedDep2 =
00893     rcp_dynamic_cast<BoolValidatorDependency>(readinDep2, true);
00894 
00895   TEST_ASSERT(nonnull(castedDep1->getTrueValidator()));
00896   TEST_ASSERT(nonnull(castedDep1->getFalseValidator()));
00897   TEST_ASSERT(nonnull(castedDep2->getTrueValidator()));
00898   TEST_ASSERT(castedDep2->getFalseValidator().is_null());
00899   TEST_EQUALITY(
00900     rcp_dynamic_cast<const EnhancedNumberValidator<double> >(
00901       castedDep1->getTrueValidator(), true)->getMax(),
00902     true1Vali->getMax());
00903   TEST_EQUALITY(
00904     rcp_dynamic_cast<const EnhancedNumberValidator<double> >(
00905       castedDep1->getFalseValidator(), true)->getMax(),
00906     false1Vali->getMax());
00907   TEST_EQUALITY(
00908     rcp_dynamic_cast<const EnhancedNumberValidator<double> >(
00909       castedDep2->getTrueValidator(), true)->getMax(),
00910     true2Vali->getMax());
00911 
00912 }
00913 
00914 
00915 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL(
00916   Teuchos_Dependencies, RangeValidatorDepSerialization, T)
00917 {
00918   std::string dependee1 = "dependee param";
00919   std::string dependee2 = "dependee param2";
00920   std::string dependent1 = "dependent param1";
00921   std::string dependent2 = "dependent param2";
00922   ParameterList myDepList("Range Vali Dep List");
00923   RCP<DependencySheet> myDepSheet = rcp(new DependencySheet);
00924   myDepList.set(dependee1, ScalarTraits<T>::one());
00925   myDepList.set(dependee2, ScalarTraits<T>::one());
00926   myDepList.set(dependent1, 2.0);
00927   myDepList.set(dependent2, 3.0);
00928 
00929   RCP<EnhancedNumberValidator<double> > double1Vali =
00930     rcp(new EnhancedNumberValidator<double>(0,10));
00931 
00932   RCP<EnhancedNumberValidator<double> > double2Vali =
00933     rcp(new EnhancedNumberValidator<double>(0,30));
00934 
00935   RCP<EnhancedNumberValidator<double> > defaultValidator =
00936     rcp(new EnhancedNumberValidator<double>(0,50));
00937 
00938   typename RangeValidatorDependency<T>::Range range1(0,10);
00939   typename RangeValidatorDependency<T>::Range range2(11,50);
00940 
00941   typename RangeValidatorDependency<T>::RangeToValidatorMap rangeValiMap;
00942   rangeValiMap[range1] = double1Vali;
00943   rangeValiMap[range2] = double2Vali;
00944 
00945   RCP<RangeValidatorDependency<T> > simpleRangeValiDep = rcp(
00946     new RangeValidatorDependency<T> (
00947       myDepList.getEntryRCP(dependee1),
00948       myDepList.getEntryRCP(dependent1),
00949       rangeValiMap));
00950 
00951   Dependency::ParameterEntryList dependentList;
00952   dependentList.insert(myDepList.getEntryRCP(dependent1));
00953   dependentList.insert(myDepList.getEntryRCP(dependent2));
00954 
00955   RCP<RangeValidatorDependency<T> > complexRangeValiDep = rcp(
00956     new RangeValidatorDependency<T> (
00957       myDepList.getEntryRCP(dependee2),
00958       dependentList,
00959       rangeValiMap,
00960       defaultValidator));
00961 
00962   myDepSheet->addDependency(simpleRangeValiDep);
00963   myDepSheet->addDependency(complexRangeValiDep);
00964 
00965   RCP<DependencySheet> readInDepSheet = rcp(new DependencySheet);
00966 
00967   XMLParameterListWriter plWriter;
00968   XMLObject xmlOut = plWriter.toXML(myDepList, myDepSheet);
00969   out << xmlOut.toString();
00970 
00971   RCP<ParameterList> readInList = 
00972     writeThenReadPL(myDepList, myDepSheet, readInDepSheet); 
00973 
00974   RCP<ParameterEntry> readinDependee1 = readInList->getEntryRCP(dependee1);
00975   RCP<ParameterEntry> readinDependent1 = readInList->getEntryRCP(dependent1);
00976   RCP<ParameterEntry> readinDependee2 = readInList->getEntryRCP(dependee2);
00977   RCP<ParameterEntry> readinDependent2 = readInList->getEntryRCP(dependent2);
00978   
00979   RCP<Dependency> readinDep1 =
00980     *(readInDepSheet->getDependenciesForParameter(readinDependee1)->begin());
00981 
00982   RCP<Dependency> readinDep2 =
00983     *(readInDepSheet->getDependenciesForParameter(readinDependee2)->begin());
00984 
00985   BASIC_DEPENDENCY_TEST(readinDep1, RangeValidatorDependency<T>, 1, 1);
00986   VERIFY_DEPENDEE(readinDep1, readinDependee1);
00987   VERIFY_DEPENDENT(readinDep1, readinDependent1);
00988 
00989   BASIC_DEPENDENCY_TEST(readinDep2, RangeValidatorDependency<T>, 1, 2);
00990   VERIFY_DEPENDEE(readinDep2, readinDependee2);
00991   VERIFY_DEPENDENT(readinDep2, readinDependent1);
00992   VERIFY_DEPENDENT(readinDep2, readinDependent2);
00993     
00994     
00995   RCP<RangeValidatorDependency<T> > castedDep1 =
00996     rcp_dynamic_cast<RangeValidatorDependency<T> >(readinDep1, true);
00997   RCP<RangeValidatorDependency<T> > castedDep2 =
00998     rcp_dynamic_cast<RangeValidatorDependency<T> >(readinDep2, true);
00999 
01000   typename RangeValidatorDependency<T>::RangeToValidatorMap readinMap1 = 
01001     castedDep1->getRangeToValidatorMap();
01002   TEST_EQUALITY(readinMap1.size(), 2);
01003   typename RangeValidatorDependency<T>::RangeToValidatorMap::const_iterator it =
01004     readinMap1.begin();
01005   TEST_EQUALITY(it->first.first, 0);
01006   TEST_EQUALITY(it->first.second, 10);
01007   it++;
01008   TEST_EQUALITY(it->first.first, 11);
01009   TEST_EQUALITY(it->first.second, 50);
01010 
01011     
01012   RCP<const ParameterEntryValidator> range1Vali = 
01013     readinMap1.find(range1)->second;
01014   RCP<const ParameterEntryValidator> range2Vali = 
01015     readinMap1.find(range2)->second;
01016   TEST_EQUALITY(
01017     rcp_dynamic_cast<const EnhancedNumberValidator<double> >(
01018       range1Vali, true)->getMax(),
01019     double1Vali->getMax());
01020   TEST_EQUALITY(
01021     rcp_dynamic_cast<const EnhancedNumberValidator<double> >(
01022       range2Vali, true)->getMax(),
01023     double2Vali->getMax());
01024 
01025   typename RangeValidatorDependency<T>::RangeToValidatorMap readinMap2 = 
01026     castedDep2->getRangeToValidatorMap();
01027   it = readinMap2.begin();
01028   TEST_EQUALITY(it->first.first, 0);
01029   TEST_EQUALITY(it->first.second, 10);
01030   it++;
01031   TEST_EQUALITY(it->first.first, 11);
01032   TEST_EQUALITY(it->first.second, 50);
01033 
01034   TEST_EQUALITY(
01035     rcp_dynamic_cast<const EnhancedNumberValidator<double> >(
01036       readinMap2.find(range1)->second, true)->getMax(),
01037     double1Vali->getMax());
01038   TEST_EQUALITY(
01039     rcp_dynamic_cast<const EnhancedNumberValidator<double> >(
01040       readinMap2.find(range2)->second, true)->getMax(),
01041     double2Vali->getMax());
01042 
01043   RCP<const EnhancedNumberValidator<double> > defaultReadInVali =
01044     rcp_dynamic_cast<const EnhancedNumberValidator<double> >(
01045       castedDep2->getDefaultValidator());
01046   TEST_EQUALITY( defaultReadInVali->getMax(), defaultValidator->getMax());
01047   TEST_EQUALITY( defaultReadInVali->getMin(), defaultValidator->getMin());
01048 }
01049 
01050 
01051 #define RANGE_VALIDATOR_TEST(T) \
01052 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( \
01053   Teuchos_Dependencies, RangeValidatorDepSerialization, T)
01054   
01055 RANGE_VALIDATOR_TEST(int)
01056 RANGE_VALIDATOR_TEST(double)
01057 RANGE_VALIDATOR_TEST(float)
01058 #ifdef HAVE_TEUCHOS_LONG_LONG_INT
01059 RANGE_VALIDATOR_TEST(llint)
01060 #endif
01061 
01062 /* General Testing*/
01063 TEUCHOS_UNIT_TEST(Teuchos_Dependencies, DependencySerializationExceptions){
01064   
01065   RCP<DependencySheet> depSheet = rcp(new DependencySheet);
01066 
01067   TEST_THROW(RCP<ParameterList> missingDependeeList = 
01068        getParametersFromXmlFile("MissingDependeeTag.xml", depSheet),
01069        MissingDependeesException);
01070   TEST_THROW(RCP<ParameterList> missingDependentsList = 
01071        getParametersFromXmlFile("MissingDependentTag.xml", depSheet),
01072        MissingDependentsException);
01073   TEST_THROW(RCP<ParameterList> missingDependeeList = 
01074        getParametersFromXmlFile("MissingDependee.xml", depSheet),
01075        MissingDependeeException);
01076   TEST_THROW(RCP<ParameterList> missingDependentList = 
01077        getParametersFromXmlFile("MissingDependent.xml", depSheet),
01078        MissingDependentException);
01079 
01080   RCP<ParameterEntry> dependeeParam = rcp(new ParameterEntry(true));
01081   RCP<ParameterEntry> dependentParam = rcp(new ParameterEntry("blah"));
01082   RCP<BoolVisualDependency> boolVisDep = 
01083     rcp(new BoolVisualDependency(dependeeParam, dependentParam));
01084 
01085   XMLParameterListWriter::EntryIDsMap entryIDsMap;
01086   entryIDsMap[dependentParam] = 1;
01087   ValidatortoIDMap validatorIDsMap;
01088   BoolVisualDependencyXMLConverter boolVisConverter;
01089   TEST_THROW(
01090     boolVisConverter.fromDependencytoXML(
01091     boolVisDep, entryIDsMap, validatorIDsMap),
01092     MissingDependeeException);
01093   entryIDsMap.erase(dependentParam);
01094   entryIDsMap[dependeeParam] = 3;
01095   TEST_THROW(
01096     boolVisConverter.fromDependencytoXML(
01097     boolVisDep, entryIDsMap, validatorIDsMap),
01098     MissingDependentException);
01099 }
01100 
01101 /* Testing serialization exceptions for NumberVisualDependencies */
01102 
01103 TEUCHOS_UNIT_TEST(Teuchos_Dependencies, NumberVisualDepSerializationExceptions){ 
01104  
01105   EXCEPTION_TEST_BOILERPLATE(4, "blah");
01106   RCP<Dependency> numVisDep =  
01107     rcp(new NumberVisualDependency<int>(dependeeParam1, dependentParam1));
01108   CONVERT_DEP_TO_XML(numVisDep);
01109   TOO_MANY_DEPENDEE_TEST(numVisDep);
01110 
01111 }
01112 
01113 TEUCHOS_UNIT_TEST(Teuchos_Dependencies, BoolVisualDepSerializationExceptions){ 
01114   EXCEPTION_TEST_BOILERPLATE(true, "blah");
01115   RCP<Dependency> boolVisDep =  
01116     rcp(new BoolVisualDependency(dependeeParam1, dependentParam1));
01117   CONVERT_DEP_TO_XML(boolVisDep);
01118   TOO_MANY_DEPENDEE_TEST(boolVisDep);
01119 }
01120 
01121 TEUCHOS_UNIT_TEST(Teuchos_Dependencies, StringVisualDepSerializationExceptions)
01122 {
01123   EXCEPTION_TEST_BOILERPLATE(std::string("balh"), 4);
01124   RCP<Dependency> stringVisDep =  
01125     rcp(new StringVisualDependency(dependeeParam1, dependentParam1, "steve"));
01126   CONVERT_DEP_TO_XML(stringVisDep);
01127   TOO_MANY_DEPENDEE_TEST(stringVisDep);
01128 
01129   COPY_DEPTAG_WITHOUT_CHILD(
01130     stringVisDepXML,
01131     StringVisualDependencyXMLConverter::getStringValuesTagName(),
01132     missingValuesXML);
01133 
01134   TEST_THROW(
01135     DependencyXMLConverterDB::convertXML(
01136       missingValuesXML, readerEntryMap, readerValiMap),
01137     ValuesTagMissingException);
01138 
01139 }
01140 
01141 TEUCHOS_UNIT_TEST(
01142   Teuchos_Dependencies, ConditionVisualDepSerializationExceptions)
01143 {
01144   EXCEPTION_TEST_BOILERPLATE(true, 4);
01145   RCP<Condition> boolCon = rcp(new BoolCondition(dependeeParam1));
01146   RCP<Dependency> conVisDep =
01147     rcp(new ConditionVisualDependency(boolCon, dependentParam1));
01148   CONVERT_DEP_TO_XML(conVisDep);
01149   COPY_DEPTAG_WITHOUT_CHILD(
01150     conVisDepXML,
01151     Condition::getXMLTagName(),
01152     missingConXML);
01153 
01154   TEST_THROW(
01155     DependencyXMLConverterDB::convertXML(
01156       missingConXML, readerEntryMap, readerValiMap),
01157     MissingConditionTagException);
01158 }
01159 
01160 TEUCHOS_UNIT_TEST(
01161   Teuchos_Dependencies, BoolValidatorDepSerializationExceptions)
01162 {
01163   EXCEPTION_TEST_BOILERPLATE(true, 7);
01164   RCP<EnhancedNumberValidator<int> > trueVali = 
01165     rcp(new EnhancedNumberValidator<int>);
01166   RCP<EnhancedNumberValidator<int> > falseVali = 
01167     rcp(new EnhancedNumberValidator<int>);
01168   INSERT_VALIDATOR_TO_MAPS(trueVali);
01169   INSERT_VALIDATOR_TO_MAPS(falseVali);
01170   RCP<Dependency> boolValiDep =  
01171     rcp(new BoolValidatorDependency(
01172       dependeeParam1, 
01173       dependentParam1, 
01174       trueVali,
01175       falseVali));
01176   CONVERT_DEP_TO_XML(boolValiDep);
01177   TOO_MANY_DEPENDEE_TEST(boolValiDep);
01178 
01179   readerValiMap.erase(writerValiMap.find(trueVali)->second);
01180 
01181   TEST_THROW(
01182     DependencyXMLConverterDB::convertXML(
01183       boolValiDepXML, readerEntryMap, readerValiMap),
01184     MissingValidatorException);
01185 
01186   readerValiMap.insert( IDtoValidatorMap::IDValidatorPair(
01187       writerValiMap.find(trueVali)->second, trueVali));
01188   readerValiMap.erase(writerValiMap.find(falseVali)->second);
01189 
01190   TEST_THROW(
01191     DependencyXMLConverterDB::convertXML(
01192       boolValiDepXML, readerEntryMap, readerValiMap),
01193     MissingValidatorException);
01194 
01195 }
01196 
01197 TEUCHOS_UNIT_TEST(
01198   Teuchos_Dependencies, StringValidatorDepSerializationExceptions)
01199 {
01200   EXCEPTION_TEST_BOILERPLATE(std::string("blah"), 4);
01201   RCP<FileNameValidator> scrapVali = 
01202     DummyObjectGetter<FileNameValidator>::getDummyObject();
01203   RCP<FileNameValidator> scrapVali2 = 
01204     DummyObjectGetter<FileNameValidator>::getDummyObject();
01205   StringValidatorDependency::ValueToValidatorMap valiMap;
01206   valiMap["blah"] = scrapVali;
01207   INSERT_VALIDATOR_TO_MAPS(scrapVali);
01208   INSERT_VALIDATOR_TO_MAPS(scrapVali2);
01209 
01210   RCP<Dependency> stringValiDep =  
01211     rcp( new StringValidatorDependency(
01212       dependeeParam1, dependentParam1, valiMap, scrapVali2));
01213   CONVERT_DEP_TO_XML(stringValiDep);
01214 
01215   TOO_MANY_DEPENDEE_TEST(stringValiDep);
01216 
01217   COPY_DEPTAG_WITHOUT_CHILD(
01218     stringValiDepXML,
01219     StringValidatorDependencyXMLConverter::getValuesAndValidatorsTag(),
01220     missingValuesXML);
01221 
01222   TEST_THROW(
01223     DependencyXMLConverterDB::convertXML(
01224       missingValuesXML, readerEntryMap, readerValiMap),
01225     MissingValuesAndValidatorsTagException);
01226 
01227   readerValiMap.erase(writerValiMap.find(scrapVali)->second);
01228 
01229   TEST_THROW(
01230     DependencyXMLConverterDB::convertXML(
01231       stringValiDepXML, readerEntryMap, readerValiMap),
01232     MissingValidatorException);
01233 
01234   readerValiMap.insert( IDtoValidatorMap::IDValidatorPair(
01235       writerValiMap.find(scrapVali)->second,scrapVali));
01236   readerValiMap.erase(writerValiMap.find(scrapVali2)->second);
01237 
01238   TEST_THROW(
01239     DependencyXMLConverterDB::convertXML(
01240       stringValiDepXML, readerEntryMap, readerValiMap),
01241     MissingValidatorException);
01242 }
01243 
01244 TEUCHOS_UNIT_TEST(
01245   Teuchos_Dependencies, RangeValidatorDepSerializationExceptions)
01246 {
01247   EXCEPTION_TEST_BOILERPLATE(3, "blah");
01248 
01249   RCP<FileNameValidator> scrapVali = 
01250     DummyObjectGetter<FileNameValidator>::getDummyObject();
01251   RCP<FileNameValidator> otherScrapVali =
01252     DummyObjectGetter<FileNameValidator>::getDummyObject();
01253   RCP<FileNameValidator> defaultScrapVali =
01254     DummyObjectGetter<FileNameValidator>::getDummyObject();
01255   RangeValidatorDependency<int>::RangeToValidatorMap valiMap;
01256   RangeValidatorDependency<int>::RangeToValidatorMap secondvaliMap;
01257   RangeValidatorDependency<int>::Range scrapRange(2,5);
01258   valiMap[scrapRange] = scrapVali;
01259   secondvaliMap[scrapRange] = otherScrapVali;
01260   writerValiMap.insert(scrapVali);
01261   writerValiMap.insert(otherScrapVali);
01262   writerValiMap.insert(defaultScrapVali);
01263   readerValiMap.insert(
01264     IDtoValidatorMap::IDValidatorPair(
01265       writerValiMap.find(scrapVali)->second,scrapVali));
01266   readerValiMap.insert(
01267     IDtoValidatorMap::IDValidatorPair(
01268       writerValiMap.find(otherScrapVali)->second,otherScrapVali));
01269   readerValiMap.insert(
01270     IDtoValidatorMap::IDValidatorPair(
01271       writerValiMap.find(defaultScrapVali)->second,defaultScrapVali));
01272 
01273   RCP<Dependency> rangeDep = 
01274    rcp(new RangeValidatorDependency<int>(
01275     dependeeParam1, dependentParam1, valiMap));
01276 
01277   RCP<Dependency> rangeDefaultDep = 
01278    rcp(new RangeValidatorDependency<int>(
01279     dependeeParam1, dependentParam1, secondvaliMap, defaultScrapVali));
01280 
01281   CONVERT_DEP_TO_XML(rangeDep);
01282   CONVERT_DEP_TO_XML(rangeDefaultDep);
01283 
01284   TOO_MANY_DEPENDEE_TEST(rangeDep);
01285 
01286   COPY_DEPTAG_WITHOUT_CHILD(
01287     rangeDepXML, 
01288     RangeValidatorDependencyXMLConverter<int>::getRangesAndValidatorsTag(),
01289     missingRangesXML
01290   )
01291 
01292   TEST_THROW(
01293     DependencyXMLConverterDB::convertXML(
01294       missingRangesXML, readerEntryMap, readerValiMap),
01295     MissingRangesAndValidatorsTagException);
01296 
01297   readerValiMap.erase(writerValiMap.find(scrapVali)->second);
01298 
01299   TEST_THROW(
01300     DependencyXMLConverterDB::convertXML(
01301      rangeDepXML, readerEntryMap, readerValiMap),
01302     MissingValidatorException);
01303 
01304   readerValiMap.erase(writerValiMap.find(defaultScrapVali)->second);
01305   TEST_THROW(
01306     DependencyXMLConverterDB::convertXML(
01307      rangeDefaultDepXML, readerEntryMap, readerValiMap),
01308     MissingValidatorException);
01309 
01310 }
01311 
01312 TEUCHOS_UNIT_TEST(
01313   Teuchos_Dependencies, NumArrayLengthDepSerializationExceptions)
01314 {
01315   EXCEPTION_TEST_BOILERPLATE(4, Array<double>(4, 3.0));
01316   RCP<Dependency> numArrayLengthDep =  
01317     rcp(new NumberArrayLengthDependency<int, double>(
01318       dependeeParam1, dependentParam1));
01319   CONVERT_DEP_TO_XML(numArrayLengthDep);
01320   TOO_MANY_DEPENDEE_TEST(numArrayLengthDep);
01321 }
01322 
01324 TEUCHOS_UNIT_TEST(
01325   Teuchos_Dependencies, DepSheetTests)
01326 {
01327   ParameterList myDepList("String Visual Dep List");
01328   std::string dependee1 = "dependee1";
01329   std::string dependent1 = "dependent1";
01330   RCP<DependencySheet> myDepSheet = rcp(new DependencySheet("My List"));
01331   myDepList.set(dependee1, "val1");
01332   myDepList.set(dependent1, 2.0);
01333   StringVisualDependency::ValueList valList1 = tuple<std::string>("val1");
01334   RCP<StringVisualDependency> basicStringVisDep = rcp(
01335     new StringVisualDependency(
01336       myDepList.getEntryRCP(dependee1),
01337       myDepList.getEntryRCP(dependent1),
01338       valList1));
01339   myDepSheet->addDependency(basicStringVisDep);
01340 
01341   RCP<DependencySheet> readInDepSheet = rcp(new DependencySheet);
01342 
01343   XMLParameterListWriter plWriter;
01344   XMLObject xmlOut = plWriter.toXML(myDepList, myDepSheet);
01345   out << xmlOut.toString();
01346 
01347   RCP<ParameterList> readInList = 
01348     writeThenReadPL(myDepList, myDepSheet, readInDepSheet); 
01349   TEST_EQUALITY(readInDepSheet->getName(), myDepSheet->getName());
01350 }
01351 
01352 
01353 } //namespace Teuchos
01354 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines