Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Dependencies_SerializationTests.cpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Teuchos: Common Tools Package
5 // Copyright (2004) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
52 
54 
55 
56 namespace Teuchos{
57 
58 
59 typedef unsigned short int ushort;
60 typedef unsigned int uint;
61 typedef unsigned long int ulong;
62 typedef std::string myString_t;
63 typedef long long int llint;
64 typedef unsigned long long int ullint;
65 
66 #define BASIC_DEPENDENCY_TEST( \
67  DEPENDENCY, DEPTYPE, NUM_DEPENDEES, NUM_DEPENDENTS) \
68  std::string depXMLTag##DEPENDENCY = \
69  DummyObjectGetter< DEPTYPE >::getDummyObject()->getTypeAttributeValue(); \
70 \
71  TEST_ASSERT(DEPENDENCY->getTypeAttributeValue() == depXMLTag##DEPENDENCY ); \
72  TEST_ASSERT(DEPENDENCY->getDependents().size() == NUM_DEPENDENTS); \
73  TEST_ASSERT(DEPENDENCY->getDependees().size() == NUM_DEPENDEES); \
74 
75 #define VERIFY_DEPENDENT(DEPENDENCY, DEPENDENT) \
76  TEST_ASSERT( \
77  DEPENDENCY->getDependents().find(DEPENDENT) \
78  != \
79  DEPENDENCY->getDependents().end() \
80  ); \
81 
82 #define VERIFY_DEPENDEE(DEPENDENCY, DEPENDEE) \
83  TEST_ASSERT( \
84  DEPENDENCY->getDependees().find(DEPENDEE) \
85  != \
86  DEPENDENCY->getDependees().end()); \
87 
88 #define CREATE_DEPENDEE(POSTFIX, VALUE) \
89  RCP<ParameterEntry> dependeeParam##POSTFIX = rcp( \
90  new ParameterEntry( VALUE ));
91 
92 #define CREATE_DEPENDENT(POSTFIX, VALUE) \
93  RCP<ParameterEntry> dependentParam##POSTFIX = \
94  rcp(new ParameterEntry( VALUE )); \
95 
96 #define EXCEPTION_TEST_BOILERPLATE(DEPENDEE_VAL, DEPENDENT_VAL) \
97  CREATE_DEPENDEE(1, DEPENDEE_VAL); \
98  CREATE_DEPENDEE(Extra, DEPENDEE_VAL); \
99  CREATE_DEPENDENT(1, DEPENDENT_VAL); \
100 \
101  XMLParameterListWriter::EntryIDsMap writerEntryMap; \
102  writerEntryMap[dependeeParam1] = 1; \
103  writerEntryMap[dependentParam1] = 2; \
104  writerEntryMap[dependeeParamExtra] = 3; \
105  ValidatortoIDMap writerValiMap; \
106 \
107  XMLParameterListReader::EntryIDsMap readerEntryMap; \
108  readerEntryMap[1] = dependeeParam1; \
109  readerEntryMap[2] = dependentParam1; \
110  readerEntryMap[3] = dependeeParamExtra; \
111  IDtoValidatorMap readerValiMap; \
112 
113 #define CONVERT_DEP_TO_XML(DEPENDENCY) \
114  XMLObject DEPENDENCY##XML = DependencyXMLConverterDB::convertDependency( \
115  DEPENDENCY , writerEntryMap, writerValiMap); \
116 
117 #define TOO_MANY_DEPENDEE_TEST(DEPENDENCY) \
118  XMLObject extraDependee(DependencyXMLConverter::getDependeeTagName()); \
119  extraDependee.addAttribute<ParameterEntry::ParameterEntryID>( \
120  DependencyXMLConverter::getParameterIdAttributeName(), \
121  writerEntryMap[dependeeParamExtra]); \
122  XMLObject tooManyTempXML = DEPENDENCY##XML.deepCopy(); \
123  tooManyTempXML.addChild(extraDependee); \
124  \
125  TEST_THROW( \
126  DependencyXMLConverterDB::convertXML( \
127  tooManyTempXML , readerEntryMap, readerValiMap), \
128  TooManyDependeesException); \
129 
130 #define COPY_DEPTAG_WITHOUT_CHILD(TAG, CHILDTAG, NEWTAG) \
131  XMLObject NEWTAG(TAG.getTag()); \
132  NEWTAG.addAttribute( \
133  DependencyXMLConverter::getTypeAttributeName(), \
134  TAG.getAttribute(DependencyXMLConverter::getTypeAttributeName())); \
135  for(int i =0; i< TAG.numChildren(); i++){ \
136  if(TAG.getChild(i).getTag() != CHILDTAG) \
137  { \
138  NEWTAG.addChild(TAG.getChild(i).deepCopy()); \
139  } \
140  } \
141 
142 
143 #define INSERT_VALIDATOR_TO_MAPS(VALIDATOR) \
144  writerValiMap.insert( VALIDATOR ); \
145  readerValiMap.insert( \
146  IDtoValidatorMap::IDValidatorPair( \
147  writerValiMap.find( VALIDATOR )->second, VALIDATOR )); \
148 
149 
150 TEUCHOS_UNIT_TEST(Teuchos_Dependencies, SerializationTestMacros){
151  RCP<ParameterEntry> dependee1 = rcp(new ParameterEntry(true));
152  RCP<ParameterEntry> dependee2 = rcp(new ParameterEntry(true));
153  RCP<ParameterEntry> dependent1 = rcp(new ParameterEntry("blah"));
154  RCP<ParameterEntry> dependent2 = rcp(new ParameterEntry("blah"));
155  RCP<BoolVisualDependency> simpleDep =
156  rcp(new BoolVisualDependency(dependee1, dependent1));
157 
158 
159  Dependency::ParameterEntryList dependentList;
160  dependentList.insert(dependent1);
161  dependentList.insert(dependent2);
162 
163  RCP<BoolVisualDependency> complexDep =
164  rcp(new BoolVisualDependency(dependee2, dependentList));
165 
167  VERIFY_DEPENDEE(simpleDep, dependee1);
168  VERIFY_DEPENDENT(simpleDep, dependent1);
169 
170  BASIC_DEPENDENCY_TEST(complexDep, BoolVisualDependency, 1, 2);
171  VERIFY_DEPENDEE(complexDep, dependee2);
172  VERIFY_DEPENDENT(complexDep, dependent1);
173  VERIFY_DEPENDENT(complexDep, dependent2);
174 
175 }
176 
177 
178 TEUCHOS_UNIT_TEST(Teuchos_Dependencies, StringVisualDepSerialization){
179  std::string dependee1 = "string param";
180  std::string dependee2 = "string param2";
181  std::string dependent1 = "dependent param1";
182  std::string dependent2 = "dependent param2";
183  ParameterList myDepList("String Visual Dep List");
184  RCP<DependencySheet> myDepSheet = rcp(new DependencySheet);
185  myDepList.set(dependee1, "val1");
186  myDepList.set(dependee2, "val2");
187  myDepList.set(dependent1, 1.0);
188  myDepList.set(dependent2, 1.0);
189 
190  StringVisualDependency::ValueList valList1 = tuple<std::string>("val1");
191 
192  RCP<StringVisualDependency> basicStringVisDep = rcp(
194  myDepList.getEntryRCP(dependee1),
195  myDepList.getEntryRCP(dependent1),
196  valList1));
197 
198  Dependency::ParameterEntryList dependentList;
199  dependentList.insert(myDepList.getEntryRCP(dependent1));
200  dependentList.insert(myDepList.getEntryRCP(dependent2));
202  tuple<std::string>("val1", "val2");
203 
204  RCP<StringVisualDependency> complexStringVisDep = rcp(
206  myDepList.getEntryRCP(dependee2),
207  dependentList,
208  valList2,
209  false));
210 
211  myDepSheet->addDependency(basicStringVisDep);
212  myDepSheet->addDependency(complexStringVisDep);
213 
214  RCP<DependencySheet> readInDepSheet = rcp(new DependencySheet);
215 
216  XMLParameterListWriter plWriter;
217  XMLObject xmlOut = plWriter.toXML(myDepList, myDepSheet);
218  out << xmlOut.toString();
219 
220  RCP<ParameterList> readInList =
221  writeThenReadPL(myDepList, myDepSheet, readInDepSheet);
222 
223  RCP<ParameterEntry> readinDependee1 = readInList->getEntryRCP(dependee1);
224  RCP<ParameterEntry> readinDependent1 = readInList->getEntryRCP(dependent1);
225  RCP<ParameterEntry> readinDependee2 = readInList->getEntryRCP(dependee2);
226  RCP<ParameterEntry> readinDependent2 = readInList->getEntryRCP(dependent2);
227 
228  RCP<Dependency> readinDep1 =
229  *(readInDepSheet->getDependenciesForParameter(readinDependee1)->begin());
230 
231  RCP<Dependency> readinDep2 =
232  *(readInDepSheet->getDependenciesForParameter(readinDependee2)->begin());
233 
235  VERIFY_DEPENDEE(readinDep1, readinDependee1);
236  VERIFY_DEPENDENT(readinDep1, readinDependent1);
237 
239  VERIFY_DEPENDEE(readinDep2, readinDependee2);
240  VERIFY_DEPENDENT(readinDep2, readinDependent1);
241  VERIFY_DEPENDENT(readinDep2, readinDependent2);
242 
243  RCP<StringVisualDependency> castedDep1 =
244  rcp_dynamic_cast<StringVisualDependency>(readinDep1, true);
245  RCP<StringVisualDependency> castedDep2 =
246  rcp_dynamic_cast<StringVisualDependency>(readinDep2, true);
247 
249  castedDep1->getValues(), basicStringVisDep->getValues());
251  castedDep2->getValues(), complexStringVisDep->getValues());
252 
253  TEST_EQUALITY(castedDep1->getShowIf(), basicStringVisDep->getShowIf());
254  TEST_EQUALITY(castedDep2->getShowIf(), complexStringVisDep->getShowIf());
255 }
256 
257 TEUCHOS_UNIT_TEST(Teuchos_Dependencies, BoolVisualDepSerialization){
258  std::string dependee1 = "bool param";
259  std::string dependee2 = "bool param2";
260  std::string dependent1 = "dependent param1";
261  std::string dependent2 = "dependent param2";
262  ParameterList myDepList("Bool Visual Dep List");
263  RCP<DependencySheet> myDepSheet = rcp(new DependencySheet);
264  myDepList.set(dependee1, true);
265  myDepList.set(dependee2, true);
266  myDepList.set(dependent1, 1.0);
267  myDepList.set(dependent2, 1.0);
268 
269  RCP<BoolVisualDependency> trueBoolVisDep = rcp(
271  myDepList.getEntryRCP(dependee1),
272  myDepList.getEntryRCP(dependent1)));
273 
274  Dependency::ParameterEntryList dependentList;
275  dependentList.insert(myDepList.getEntryRCP(dependent1));
276  dependentList.insert(myDepList.getEntryRCP(dependent2));
277 
278  RCP<BoolVisualDependency> falseBoolVisDep = rcp(
280  myDepList.getEntryRCP(dependee2),
281  dependentList,
282  false));
283 
284  myDepSheet->addDependency(trueBoolVisDep);
285  myDepSheet->addDependency(falseBoolVisDep);
286 
287  RCP<DependencySheet> readInDepSheet = rcp(new DependencySheet);
288 
289  XMLParameterListWriter plWriter;
290  XMLObject xmlOut = plWriter.toXML(myDepList, myDepSheet);
291  out << xmlOut.toString();
292 
293  RCP<ParameterList> readInList =
294  writeThenReadPL(myDepList, myDepSheet, readInDepSheet);
295 
296  RCP<ParameterEntry> readinDependee1 = readInList->getEntryRCP(dependee1);
297  RCP<ParameterEntry> readinDependent1 = readInList->getEntryRCP(dependent1);
298  RCP<ParameterEntry> readinDependee2 = readInList->getEntryRCP(dependee2);
299  RCP<ParameterEntry> readinDependent2 = readInList->getEntryRCP(dependent2);
300 
301  RCP<Dependency> readinDep1 =
302  *(readInDepSheet->getDependenciesForParameter(readinDependee1)->begin());
303 
304  RCP<Dependency> readinDep2 =
305  *(readInDepSheet->getDependenciesForParameter(readinDependee2)->begin());
306 
307  BASIC_DEPENDENCY_TEST(readinDep1, BoolVisualDependency, 1, 1);
308  VERIFY_DEPENDEE(readinDep1, readinDependee1);
309  VERIFY_DEPENDENT(readinDep1, readinDependent1);
310 
311  BASIC_DEPENDENCY_TEST(readinDep2, BoolVisualDependency, 1, 2);
312  VERIFY_DEPENDEE(readinDep2, readinDependee2);
313  VERIFY_DEPENDENT(readinDep2, readinDependent1);
314  VERIFY_DEPENDENT(readinDep2, readinDependent2);
315 
316 
317  RCP<BoolVisualDependency> castedDep1 =
318  rcp_dynamic_cast<BoolVisualDependency>(readinDep1, true);
319  RCP<BoolVisualDependency> castedDep2 =
320  rcp_dynamic_cast<BoolVisualDependency>(readinDep2, true);
321 
322  TEST_EQUALITY(castedDep1->getShowIf(), trueBoolVisDep->getShowIf());
323  TEST_EQUALITY(castedDep2->getShowIf(), falseBoolVisDep->getShowIf());
324 }
325 
327  Teuchos_Dependencies,
328  NumberVisualDepSerialization,
329  T)
330 {
331  std::string dependee1 = "num param";
332  std::string dependee2 = "num param2";
333  std::string dependent1 = "dependent param1";
334  std::string dependent2 = "dependent param2";
335  ParameterList myDepList("Number Visual Dep List");
336  RCP<DependencySheet> myDepSheet = rcp(new DependencySheet);
337  myDepList.set(dependee1, ScalarTraits<T>::one());
338  myDepList.set(dependee2, ScalarTraits<T>::one());
339  myDepList.set(dependent1, true);
340  myDepList.set(dependent2, "vale");
341 
342  RCP<NumberVisualDependency<T> > simpleNumVisDep = rcp(
344  myDepList.getEntryRCP(dependee1),
345  myDepList.getEntryRCP(dependent1)));
346 
347  Dependency::ParameterEntryList dependentList;
348  dependentList.insert(myDepList.getEntryRCP(dependent1));
349  dependentList.insert(myDepList.getEntryRCP(dependent2));
350 
351  T ten = ScalarTraits<T>::one() *10;
352  RCP<SubtractionFunction<T> > subFunction = rcp(new SubtractionFunction<T>(ten));
353  RCP<NumberVisualDependency<T> > complexNumVisDep = rcp(
355  myDepList.getEntryRCP(dependee2),
356  dependentList,
357  true,
358  subFunction));
359 
360  myDepSheet->addDependency(simpleNumVisDep);
361  myDepSheet->addDependency(complexNumVisDep);
362 
363  RCP<DependencySheet> readInDepSheet = rcp(new DependencySheet);
364 
365  XMLParameterListWriter plWriter;
366  XMLObject xmlOut = plWriter.toXML(myDepList, myDepSheet);
367  out << xmlOut.toString();
368 
369  RCP<ParameterList> readInList =
370  writeThenReadPL(myDepList, myDepSheet, readInDepSheet);
371 
372  RCP<ParameterEntry> readinDependee1 = readInList->getEntryRCP(dependee1);
373  RCP<ParameterEntry> readinDependent1 = readInList->getEntryRCP(dependent1);
374  RCP<ParameterEntry> readinDependee2 = readInList->getEntryRCP(dependee2);
375  RCP<ParameterEntry> readinDependent2 = readInList->getEntryRCP(dependent2);
376 
377  RCP<Dependency> readinDep1 =
378  *(readInDepSheet->getDependenciesForParameter(readinDependee1)->begin());
379 
380  RCP<Dependency> readinDep2 =
381  *(readInDepSheet->getDependenciesForParameter(readinDependee2)->begin());
382 
384  VERIFY_DEPENDEE(readinDep1, readinDependee1);
385  VERIFY_DEPENDENT(readinDep1, readinDependent1);
386 
388  VERIFY_DEPENDEE(readinDep2, readinDependee2);
389  VERIFY_DEPENDENT(readinDep2, readinDependent1);
390  VERIFY_DEPENDENT(readinDep2, readinDependent2);
391 
392 
393  RCP<NumberVisualDependency<T> > castedDep1 =
394  rcp_dynamic_cast<NumberVisualDependency<T> >(readinDep1, true);
395  RCP<NumberVisualDependency<T> > castedDep2 =
396  rcp_dynamic_cast<NumberVisualDependency<T> >(readinDep2, true);
397 
398  TEST_EQUALITY(castedDep1->getShowIf(), simpleNumVisDep->getShowIf());
399  TEST_EQUALITY(castedDep2->getShowIf(), complexNumVisDep->getShowIf());
400 
401  RCP<const SimpleFunctionObject<T> > functionObject =
402  castedDep2->getFunctionObject();
403  TEST_ASSERT(functionObject != null);
404  RCP<const SubtractionFunction<T> > castedFunction =
405  rcp_dynamic_cast<const SubtractionFunction<T> >(functionObject);
406  TEST_ASSERT(castedFunction != null);
408  castedFunction->getModifiyingOperand(),
409  subFunction->getModifiyingOperand());
410 }
411 
412 #define NUMBER_VIS_TEST(T) \
413 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( \
414  Teuchos_Dependencies, NumberVisualDepSerialization, T)
415 
416 NUMBER_VIS_TEST(int)
417 NUMBER_VIS_TEST(double)
418 NUMBER_VIS_TEST(float)
420 
421 TEUCHOS_UNIT_TEST(Teuchos_Dependencies, ConditionVisualDepSerialization){
422  std::string dependee1 = "string param";
423  std::string dependee2 = "bool param";
424  std::string dependee3 = "int param";
425  std::string dependent1 = "dependent param1";
426  std::string dependent2 = "dependent param2";
427  std::string dependent3 = "dependent param3";
428  ParameterList myDepList("Condition Visual Dep List");
429  RCP<DependencySheet> myDepSheet = rcp(new DependencySheet);
430  myDepList.set(dependee1, "val1");
431  myDepList.set(dependee2, true);
432  myDepList.set(dependee3, 1);
433  myDepList.set(dependent1, 1.0);
434  myDepList.set(dependent2, 1.0);
435  myDepList.set(dependent3, (float)1.0);
436 
437  StringCondition::ValueList conditionVal1 =
438  tuple<std::string>("steve", "blah", "your face");
439  RCP<StringCondition> stringCon =
440  rcp(new StringCondition(
441  myDepList.getEntryRCP(dependee1), conditionVal1));
442 
443  RCP<BoolCondition> boolCon =
444  rcp(new BoolCondition(myDepList.getEntryRCP(dependee2)));
445 
446  RCP<NumberCondition<int> > numberCon =
447  rcp(new NumberCondition<int>(myDepList.getEntryRCP(dependee3)));
448 
450  tuple<RCP<const Condition> >(boolCon, numberCon);
451 
452  RCP<AndCondition> andCon = rcp(new AndCondition(conList));
453 
454  RCP<ConditionVisualDependency> simpleConVisDep = rcp(
456  stringCon,
457  myDepList.getEntryRCP(dependent1)));
458 
459  Dependency::ParameterEntryList dependentList;
460  dependentList.insert(myDepList.getEntryRCP(dependent2));
461  dependentList.insert(myDepList.getEntryRCP(dependent3));
462 
463  RCP<ConditionVisualDependency> complexConVisDep = rcp(
465  andCon,
466  dependentList,
467  false));
468 
469  myDepSheet->addDependency(simpleConVisDep);
470  myDepSheet->addDependency(complexConVisDep);
471 
472  RCP<DependencySheet> readInDepSheet = rcp(new DependencySheet);
473 
474  XMLParameterListWriter plWriter;
475  XMLObject xmlOut = plWriter.toXML(myDepList, myDepSheet);
476  out << xmlOut.toString();
477 
478  RCP<ParameterList> readInList =
479  writeThenReadPL(myDepList, myDepSheet, readInDepSheet);
480 
481  RCP<ParameterEntry> readinDependee1 = readInList->getEntryRCP(dependee1);
482  RCP<ParameterEntry> readinDependent1 = readInList->getEntryRCP(dependent1);
483  RCP<ParameterEntry> readinDependee2 = readInList->getEntryRCP(dependee2);
484  RCP<ParameterEntry> readinDependent2 = readInList->getEntryRCP(dependent2);
485  RCP<ParameterEntry> readinDependee3 = readInList->getEntryRCP(dependee3);
486  RCP<ParameterEntry> readinDependent3 = readInList->getEntryRCP(dependent3);
487 
488  RCP<Dependency> readinDep1 =
489  *(readInDepSheet->getDependenciesForParameter(readinDependee1)->begin());
490 
491  RCP<Dependency> readinDep2 =
492  *(readInDepSheet->getDependenciesForParameter(readinDependee2)->begin());
493 
494  RCP<Dependency> readinDep3 =
495  *(readInDepSheet->getDependenciesForParameter(readinDependee3)->begin());
496 
498  VERIFY_DEPENDEE(readinDep1, readinDependee1);
499  VERIFY_DEPENDENT(readinDep1, readinDependent1);
500 
501  TEST_ASSERT(readinDep2.get() == readinDep3.get());
502 
504  VERIFY_DEPENDEE(readinDep2, readinDependee2);
505  VERIFY_DEPENDEE(readinDep2, readinDependee3);
506  VERIFY_DEPENDENT(readinDep2, readinDependent2);
507  VERIFY_DEPENDENT(readinDep2, readinDependent3);
508 
509  RCP<ConditionVisualDependency> castedDep1 =
510  rcp_dynamic_cast<ConditionVisualDependency>(readinDep1, true);
511  RCP<ConditionVisualDependency> castedDep2 =
512  rcp_dynamic_cast<ConditionVisualDependency>(readinDep2, true);
513 
514  TEST_EQUALITY(castedDep1->getShowIf(), simpleConVisDep->getShowIf());
515  TEST_EQUALITY(castedDep2->getShowIf(), complexConVisDep->getShowIf());
516 
517  TEST_EQUALITY(castedDep1->getCondition()->getTypeAttributeValue(),
518  simpleConVisDep->getCondition()->getTypeAttributeValue());
519  TEST_EQUALITY(castedDep2->getCondition()->getTypeAttributeValue(),
520  complexConVisDep->getCondition()->getTypeAttributeValue());
521 }
522 
523 #define ArrayModifierTest(DEPENDENCYTYPE, ARRAY_TYPE) \
524 TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( \
525  Teuchos_Dependencies, \
526  DEPENDENCYTYPE##_serialization_tests, \
527  DependeeType, \
528  DependentType) \
529 { \
530  std::string dependee1 = "dependee param"; \
531  std::string dependee2 = "dependee param2"; \
532  std::string dependent1 = "dependent param1"; \
533  std::string dependent2 = "dependent param2"; \
534  ParameterList myDepList("Array modifier dep list"); \
535  RCP<DependencySheet> myDepSheet = rcp(new DependencySheet); \
536  myDepList.set(dependee1, ScalarTraits<DependeeType>::one()); \
537  myDepList.set(dependee2, ScalarTraits<DependeeType>::one()); \
538  myDepList.set(dependent1, ARRAY_TYPE<DependentType>()); \
539  myDepList.set(dependent2, ARRAY_TYPE<DependentType>()); \
540  \
541  \
542  RCP<DEPENDENCYTYPE<DependeeType, DependentType> > basicArrayDep = \
543  rcp(new DEPENDENCYTYPE<DependeeType, DependentType>( \
544  myDepList.getEntryRCP(dependee1), \
545  myDepList.getEntryRCP(dependent1))); \
546  \
547  DependeeType one = ScalarTraits< DependeeType >::one(); \
548  RCP<AdditionFunction< DependeeType > > functionTester = \
549  rcp(new AdditionFunction<DependeeType>(one)); \
550  \
551  RCP<DEPENDENCYTYPE<DependeeType, DependentType> > funcArrayDep = \
552  rcp(new DEPENDENCYTYPE<DependeeType, DependentType>( \
553  myDepList.getEntryRCP(dependee2), \
554  myDepList.getEntryRCP(dependent2), \
555  functionTester)); \
556  \
557  \
558  myDepSheet->addDependency(basicArrayDep); \
559  myDepSheet->addDependency(funcArrayDep); \
560  \
561  RCP<DependencySheet> readInDepSheet = rcp(new DependencySheet); \
562  \
563  XMLParameterListWriter plWriter; \
564  XMLObject xmlOut = plWriter.toXML(myDepList, myDepSheet); \
565  out << xmlOut.toString(); \
566  \
567  RCP<ParameterList> readInList = \
568  writeThenReadPL(myDepList, myDepSheet, readInDepSheet); \
569  \
570  RCP<ParameterEntry> readinDependee1 = readInList->getEntryRCP(dependee1); \
571  RCP<ParameterEntry> readinDependent1 = readInList->getEntryRCP(dependent1); \
572  RCP<ParameterEntry> readinDependee2 = readInList->getEntryRCP(dependee2); \
573  RCP<ParameterEntry> readinDependent2 = readInList->getEntryRCP(dependent2); \
574  \
575  RCP<Dependency> readinDep1 = \
576  *(readInDepSheet->getDependenciesForParameter(readinDependee1)->begin()); \
577  RCP<Dependency> readinDep2 = \
578  *(readInDepSheet->getDependenciesForParameter(readinDependee2)->begin()); \
579  \
580  typedef DEPENDENCYTYPE<DependeeType, DependentType> deptype; \
581  BASIC_DEPENDENCY_TEST(readinDep1, deptype, 1, 1); \
582  VERIFY_DEPENDEE(readinDep1, readinDependee1); \
583  VERIFY_DEPENDENT(readinDep1, readinDependent1); \
584  \
585  BASIC_DEPENDENCY_TEST(readinDep2, deptype, 1, 1); \
586  VERIFY_DEPENDEE(readinDep2, readinDependee2); \
587  VERIFY_DEPENDENT(readinDep2, readinDependent2); \
588  \
589  RCP<DEPENDENCYTYPE<DependeeType, DependentType> > castedDep1 = \
590  rcp_dynamic_cast<DEPENDENCYTYPE<DependeeType, DependentType> >( \
591  readinDep1); \
592  TEST_ASSERT(castedDep1 != null); \
593  \
594  RCP<DEPENDENCYTYPE<DependeeType, DependentType> > castedDep2 = \
595  rcp_dynamic_cast<DEPENDENCYTYPE<DependeeType, DependentType> >( \
596  readinDep2); \
597  TEST_ASSERT(castedDep2 != null); \
598  \
599  RCP<const SimpleFunctionObject< DependeeType > > readInFunc = \
600  castedDep2->getFunctionObject(); \
601  TEST_ASSERT(readInFunc != null); \
602  \
603  RCP<const AdditionFunction< DependeeType > > castedFunc = \
604  rcp_dynamic_cast<const AdditionFunction< DependeeType > >(readInFunc); \
605  TEST_ASSERT(castedFunc != null); \
606  TEST_EQUALITY( \
607  castedFunc->getModifiyingOperand(), \
608  functionTester->getModifiyingOperand()); \
609 }
610 
611 ArrayModifierTest(NumberArrayLengthDependency, Array)
612 
613 #define NUM_ARRAY_LENGTH_TEST(DependeeType, DependentType) \
614 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
615  Teuchos_Dependencies, \
616  NumberArrayLengthDependency_serialization_tests, \
617  DependeeType, \
618  DependentType)
619 
620 // Need to fix array serialization so we can test this with
621 // a dependent type of strings. Right now an array of emptyr strings does not
622 // seralize correctly
623 // KLN 09.17/2010
624 #define NUM_ARRAY_LENGTH_TEST_GROUP(DependeeType) \
625  NUM_ARRAY_LENGTH_TEST(DependeeType, int) \
626  NUM_ARRAY_LENGTH_TEST(DependeeType, float) \
627  NUM_ARRAY_LENGTH_TEST(DependeeType, double) \
628  NUM_ARRAY_LENGTH_TEST(DependeeType, llint)
629 
632 
633 ArrayModifierTest(TwoDRowDependency, TwoDArray)
634 
635 #define TWODROW_TEST(DependeeType, DependentType) \
636 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
637  Teuchos_Dependencies, \
638  TwoDRowDependency_serialization_tests, \
639  DependeeType, \
640  DependentType)
641 
642 // Need to fix array serialization so we can test this with
643 // a dependent type of strings. Right now an array of empty strings does not
644 // seralize correctly
645 // KLN 09.17/2010
646 #define TWODROW_TEST_GROUP(DependeeType) \
647  TWODROW_TEST(DependeeType, int) \
648  TWODROW_TEST(DependeeType, float) \
649  TWODROW_TEST(DependeeType, double) \
650  TWODROW_TEST(DependeeType, llint)
651 
654 
655 ArrayModifierTest(TwoDColDependency, TwoDArray)
656 
657 #define TWODCOL_TEST(DependeeType, DependentType) \
658 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
659  Teuchos_Dependencies, \
660  TwoDColDependency_serialization_tests, \
661  DependeeType, \
662  DependentType)
663 
664 // Need to fix array serialization so we can test this with
665 // a dependent type of strings. Right now an array of emptyr strings does not
666 // seralize correctly
667 // KLN 09.17/2010
668 #define TWODCOL_TEST_GROUP(DependeeType) \
669  TWODCOL_TEST(DependeeType, int) \
670  TWODCOL_TEST(DependeeType, float) \
671  TWODCOL_TEST(DependeeType, double) \
672  TWODCOL_TEST(DependeeType, llint)
673 
676 
677 TEUCHOS_UNIT_TEST(Teuchos_Dependencies, StringValidatorDepSerialization){
678  std::string dependee1 = "string param";
679  std::string dependee2 = "string param2";
680  std::string dependent1 = "dependent param1";
681  std::string dependent2 = "dependent param2";
682  ParameterList myDepList("String Vali Dep List");
683  RCP<DependencySheet> myDepSheet = rcp(new DependencySheet);
684  myDepList.set(dependee1, "val1");
685  myDepList.set(dependee2, "val2");
686  myDepList.set(dependent1, 2.0);
687  myDepList.set(dependent2, 3.0);
688 
691 
694 
697 
699  valuesAndValidators["val1"] = double1Vali;
700  valuesAndValidators["val2"] = double2Vali;
701 
702  RCP<StringValidatorDependency> basicStringValiDep = rcp(
704  myDepList.getEntryRCP(dependee1),
705  myDepList.getEntryRCP(dependent1),
706  valuesAndValidators));
707 
708  Dependency::ParameterEntryList dependentList;
709  dependentList.insert(myDepList.getEntryRCP(dependent1));
710  dependentList.insert(myDepList.getEntryRCP(dependent2));
711 
712  RCP<StringValidatorDependency> complexStringValiDep = rcp(
714  myDepList.getEntryRCP(dependee2),
715  dependentList,
716  valuesAndValidators,
717  defaultVali));
718 
719  myDepSheet->addDependency(basicStringValiDep);
720  myDepSheet->addDependency(complexStringValiDep);
721 
722  RCP<DependencySheet> readInDepSheet = rcp(new DependencySheet);
723 
724  XMLParameterListWriter plWriter;
725  XMLObject xmlOut = plWriter.toXML(myDepList, myDepSheet);
726  out << xmlOut.toString();
727 
728  RCP<ParameterList> readInList =
729  writeThenReadPL(myDepList, myDepSheet, readInDepSheet);
730 
731  RCP<ParameterEntry> readinDependee1 = readInList->getEntryRCP(dependee1);
732  RCP<ParameterEntry> readinDependent1 = readInList->getEntryRCP(dependent1);
733  RCP<ParameterEntry> readinDependee2 = readInList->getEntryRCP(dependee2);
734  RCP<ParameterEntry> readinDependent2 = readInList->getEntryRCP(dependent2);
735 
736  RCP<Dependency> readinDep1 =
737  *(readInDepSheet->getDependenciesForParameter(readinDependee1)->begin());
738 
739  RCP<Dependency> readinDep2 =
740  *(readInDepSheet->getDependenciesForParameter(readinDependee2)->begin());
741 
743  VERIFY_DEPENDEE(readinDep1, readinDependee1);
744  VERIFY_DEPENDENT(readinDep1, readinDependent1);
745 
747  VERIFY_DEPENDEE(readinDep2, readinDependee2);
748  VERIFY_DEPENDENT(readinDep2, readinDependent1);
749  VERIFY_DEPENDENT(readinDep2, readinDependent2);
750 
751 
752  RCP<StringValidatorDependency> castedDep1 =
753  rcp_dynamic_cast<StringValidatorDependency>(readinDep1, true);
754  RCP<StringValidatorDependency> castedDep2 =
755  rcp_dynamic_cast<StringValidatorDependency>(readinDep2, true);
756 
757  TEST_ASSERT(castedDep1->getValuesAndValidators().size() == 2);
758  TEST_ASSERT(castedDep2->getValuesAndValidators().size() == 2);
759  TEST_ASSERT(castedDep1->getDefaultValidator().is_null());
760  TEST_ASSERT(nonnull(castedDep2->getDefaultValidator()));
761 
763  rcp_dynamic_cast<const EnhancedNumberValidator<double> >(
764  castedDep1->getValuesAndValidators().find("val1")->second, true)->getMax(),
765  double1Vali->getMax());
767  rcp_dynamic_cast<const EnhancedNumberValidator<double> >(
768  castedDep2->getValuesAndValidators().find("val1")->second, true)->getMax(),
769  double1Vali->getMax());
770 
772  rcp_dynamic_cast<const EnhancedNumberValidator<double> >(
773  castedDep1->getValuesAndValidators().find("val2")->second, true)->getMax(),
774  double2Vali->getMax());
776  rcp_dynamic_cast<const EnhancedNumberValidator<double> >(
777  castedDep2->getValuesAndValidators().find("val2")->second, true)->getMax(),
778  double2Vali->getMax());
779 
781  rcp_dynamic_cast<const EnhancedNumberValidator<double> >(
782  castedDep2->getDefaultValidator(), true)->getMax(),
783  defaultVali->getMax());
784 
785 }
786 
787 TEUCHOS_UNIT_TEST(Teuchos_Dependencies, BoolValidatorDepSerialization){
788  std::string dependee1 = "bool param";
789  std::string dependee2 = "bool param2";
790  std::string dependent1 = "dependent param1";
791  std::string dependent2 = "dependent param2";
792  ParameterList myDepList("Bool Vali Dep List");
793  RCP<DependencySheet> myDepSheet = rcp(new DependencySheet);
794  myDepList.set(dependee1, true);
795  myDepList.set(dependee2, false);
796  myDepList.set(dependent1, 2.0);
797  myDepList.set(dependent2, 3.0);
798 
801 
804 
807 
808 
809  RCP<BoolValidatorDependency> simpleBoolValiDep = rcp(
811  myDepList.getEntryRCP(dependee1),
812  myDepList.getEntryRCP(dependent1),
813  true1Vali,
814  false1Vali));
815 
816  Dependency::ParameterEntryList dependentList;
817  dependentList.insert(myDepList.getEntryRCP(dependent1));
818  dependentList.insert(myDepList.getEntryRCP(dependent2));
819 
820  RCP<BoolValidatorDependency> complexBoolValiDep = rcp(
822  myDepList.getEntryRCP(dependee2),
823  dependentList,
824  true2Vali));
825 
826  myDepSheet->addDependency(simpleBoolValiDep);
827  myDepSheet->addDependency(complexBoolValiDep);
828 
829  RCP<DependencySheet> readInDepSheet = rcp(new DependencySheet);
830 
831  XMLParameterListWriter plWriter;
832  XMLObject xmlOut = plWriter.toXML(myDepList, myDepSheet);
833  out << xmlOut.toString();
834 
835  RCP<ParameterList> readInList =
836  writeThenReadPL(myDepList, myDepSheet, readInDepSheet);
837 
838  RCP<ParameterEntry> readinDependee1 = readInList->getEntryRCP(dependee1);
839  RCP<ParameterEntry> readinDependent1 = readInList->getEntryRCP(dependent1);
840  RCP<ParameterEntry> readinDependee2 = readInList->getEntryRCP(dependee2);
841  RCP<ParameterEntry> readinDependent2 = readInList->getEntryRCP(dependent2);
842 
843  RCP<Dependency> readinDep1 =
844  *(readInDepSheet->getDependenciesForParameter(readinDependee1)->begin());
845 
846  RCP<Dependency> readinDep2 =
847  *(readInDepSheet->getDependenciesForParameter(readinDependee2)->begin());
848 
850  VERIFY_DEPENDEE(readinDep1, readinDependee1);
851  VERIFY_DEPENDENT(readinDep1, readinDependent1);
852 
854  VERIFY_DEPENDEE(readinDep2, readinDependee2);
855  VERIFY_DEPENDENT(readinDep2, readinDependent1);
856  VERIFY_DEPENDENT(readinDep2, readinDependent2);
857 
858 
859  RCP<BoolValidatorDependency> castedDep1 =
860  rcp_dynamic_cast<BoolValidatorDependency>(readinDep1, true);
861  RCP<BoolValidatorDependency> castedDep2 =
862  rcp_dynamic_cast<BoolValidatorDependency>(readinDep2, true);
863 
864  TEST_ASSERT(nonnull(castedDep1->getTrueValidator()));
865  TEST_ASSERT(nonnull(castedDep1->getFalseValidator()));
866  TEST_ASSERT(nonnull(castedDep2->getTrueValidator()));
867  TEST_ASSERT(castedDep2->getFalseValidator().is_null());
869  rcp_dynamic_cast<const EnhancedNumberValidator<double> >(
870  castedDep1->getTrueValidator(), true)->getMax(),
871  true1Vali->getMax());
873  rcp_dynamic_cast<const EnhancedNumberValidator<double> >(
874  castedDep1->getFalseValidator(), true)->getMax(),
875  false1Vali->getMax());
877  rcp_dynamic_cast<const EnhancedNumberValidator<double> >(
878  castedDep2->getTrueValidator(), true)->getMax(),
879  true2Vali->getMax());
880 
881 }
882 
883 
885  Teuchos_Dependencies, RangeValidatorDepSerialization, T)
886 {
887  std::string dependee1 = "dependee param";
888  std::string dependee2 = "dependee param2";
889  std::string dependent1 = "dependent param1";
890  std::string dependent2 = "dependent param2";
891  ParameterList myDepList("Range Vali Dep List");
892  RCP<DependencySheet> myDepSheet = rcp(new DependencySheet);
893  myDepList.set(dependee1, ScalarTraits<T>::one());
894  myDepList.set(dependee2, ScalarTraits<T>::one());
895  myDepList.set(dependent1, 2.0);
896  myDepList.set(dependent2, 3.0);
897 
900 
903 
904  RCP<EnhancedNumberValidator<double> > defaultValidator =
906 
907  typename RangeValidatorDependency<T>::Range range1(0,10);
908  typename RangeValidatorDependency<T>::Range range2(11,50);
909 
911  rangeValiMap[range1] = double1Vali;
912  rangeValiMap[range2] = double2Vali;
913 
914  RCP<RangeValidatorDependency<T> > simpleRangeValiDep = rcp(
916  myDepList.getEntryRCP(dependee1),
917  myDepList.getEntryRCP(dependent1),
918  rangeValiMap));
919 
920  Dependency::ParameterEntryList dependentList;
921  dependentList.insert(myDepList.getEntryRCP(dependent1));
922  dependentList.insert(myDepList.getEntryRCP(dependent2));
923 
924  RCP<RangeValidatorDependency<T> > complexRangeValiDep = rcp(
926  myDepList.getEntryRCP(dependee2),
927  dependentList,
928  rangeValiMap,
929  defaultValidator));
930 
931  myDepSheet->addDependency(simpleRangeValiDep);
932  myDepSheet->addDependency(complexRangeValiDep);
933 
934  RCP<DependencySheet> readInDepSheet = rcp(new DependencySheet);
935 
936  XMLParameterListWriter plWriter;
937  XMLObject xmlOut = plWriter.toXML(myDepList, myDepSheet);
938  out << xmlOut.toString();
939 
940  RCP<ParameterList> readInList =
941  writeThenReadPL(myDepList, myDepSheet, readInDepSheet);
942 
943  RCP<ParameterEntry> readinDependee1 = readInList->getEntryRCP(dependee1);
944  RCP<ParameterEntry> readinDependent1 = readInList->getEntryRCP(dependent1);
945  RCP<ParameterEntry> readinDependee2 = readInList->getEntryRCP(dependee2);
946  RCP<ParameterEntry> readinDependent2 = readInList->getEntryRCP(dependent2);
947 
948  RCP<Dependency> readinDep1 =
949  *(readInDepSheet->getDependenciesForParameter(readinDependee1)->begin());
950 
951  RCP<Dependency> readinDep2 =
952  *(readInDepSheet->getDependenciesForParameter(readinDependee2)->begin());
953 
955  VERIFY_DEPENDEE(readinDep1, readinDependee1);
956  VERIFY_DEPENDENT(readinDep1, readinDependent1);
957 
959  VERIFY_DEPENDEE(readinDep2, readinDependee2);
960  VERIFY_DEPENDENT(readinDep2, readinDependent1);
961  VERIFY_DEPENDENT(readinDep2, readinDependent2);
962 
963 
964  RCP<RangeValidatorDependency<T> > castedDep1 =
965  rcp_dynamic_cast<RangeValidatorDependency<T> >(readinDep1, true);
966  RCP<RangeValidatorDependency<T> > castedDep2 =
967  rcp_dynamic_cast<RangeValidatorDependency<T> >(readinDep2, true);
968 
970  castedDep1->getRangeToValidatorMap();
971  TEST_EQUALITY(readinMap1.size(), 2);
973  readinMap1.begin();
974  TEST_EQUALITY(it->first.first, 0);
975  TEST_EQUALITY(it->first.second, 10);
976  it++;
977  TEST_EQUALITY(it->first.first, 11);
978  TEST_EQUALITY(it->first.second, 50);
979 
980 
982  readinMap1.find(range1)->second;
984  readinMap1.find(range2)->second;
986  rcp_dynamic_cast<const EnhancedNumberValidator<double> >(
987  range1Vali, true)->getMax(),
988  double1Vali->getMax());
990  rcp_dynamic_cast<const EnhancedNumberValidator<double> >(
991  range2Vali, true)->getMax(),
992  double2Vali->getMax());
993 
995  castedDep2->getRangeToValidatorMap();
996  it = readinMap2.begin();
997  TEST_EQUALITY(it->first.first, 0);
998  TEST_EQUALITY(it->first.second, 10);
999  it++;
1000  TEST_EQUALITY(it->first.first, 11);
1001  TEST_EQUALITY(it->first.second, 50);
1002 
1003  TEST_EQUALITY(
1004  rcp_dynamic_cast<const EnhancedNumberValidator<double> >(
1005  readinMap2.find(range1)->second, true)->getMax(),
1006  double1Vali->getMax());
1007  TEST_EQUALITY(
1008  rcp_dynamic_cast<const EnhancedNumberValidator<double> >(
1009  readinMap2.find(range2)->second, true)->getMax(),
1010  double2Vali->getMax());
1011 
1012  RCP<const EnhancedNumberValidator<double> > defaultReadInVali =
1013  rcp_dynamic_cast<const EnhancedNumberValidator<double> >(
1014  castedDep2->getDefaultValidator());
1015  TEST_EQUALITY( defaultReadInVali->getMax(), defaultValidator->getMax());
1016  TEST_EQUALITY( defaultReadInVali->getMin(), defaultValidator->getMin());
1017 }
1018 
1019 
1020 #define RANGE_VALIDATOR_TEST(T) \
1021 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( \
1022  Teuchos_Dependencies, RangeValidatorDepSerialization, T)
1023 
1025 RANGE_VALIDATOR_TEST(double)
1026 RANGE_VALIDATOR_TEST(float)
1028 
1029 /* General Testing*/
1030 TEUCHOS_UNIT_TEST(Teuchos_Dependencies, DependencySerializationExceptions){
1031 
1032  RCP<DependencySheet> depSheet = rcp(new DependencySheet);
1033 
1034  TEST_THROW(RCP<ParameterList> missingDependeeList =
1035  getParametersFromXmlFile("MissingDependeeTag.xml", depSheet),
1037  TEST_THROW(RCP<ParameterList> missingDependentsList =
1038  getParametersFromXmlFile("MissingDependentTag.xml", depSheet),
1040  TEST_THROW(RCP<ParameterList> missingDependeeList =
1041  getParametersFromXmlFile("MissingDependee.xml", depSheet),
1043  TEST_THROW(RCP<ParameterList> missingDependentList =
1044  getParametersFromXmlFile("MissingDependent.xml", depSheet),
1046 
1047  RCP<ParameterEntry> dependeeParam = rcp(new ParameterEntry(true));
1048  RCP<ParameterEntry> dependentParam = rcp(new ParameterEntry("blah"));
1049  RCP<BoolVisualDependency> boolVisDep =
1050  rcp(new BoolVisualDependency(dependeeParam, dependentParam));
1051 
1053  entryIDsMap[dependentParam] = 1;
1054  ValidatortoIDMap validatorIDsMap;
1055  BoolVisualDependencyXMLConverter boolVisConverter;
1056  TEST_THROW(
1057  boolVisConverter.fromDependencytoXML(
1058  boolVisDep, entryIDsMap, validatorIDsMap),
1060  entryIDsMap.erase(dependentParam);
1061  entryIDsMap[dependeeParam] = 3;
1062  TEST_THROW(
1063  boolVisConverter.fromDependencytoXML(
1064  boolVisDep, entryIDsMap, validatorIDsMap),
1066 }
1067 
1068 /* Testing serialization exceptions for NumberVisualDependencies */
1069 
1070 TEUCHOS_UNIT_TEST(Teuchos_Dependencies, NumberVisualDepSerializationExceptions){
1071 
1072  EXCEPTION_TEST_BOILERPLATE(4, "blah");
1073  RCP<Dependency> numVisDep =
1074  rcp(new NumberVisualDependency<int>(dependeeParam1, dependentParam1));
1075  CONVERT_DEP_TO_XML(numVisDep);
1076  TOO_MANY_DEPENDEE_TEST(numVisDep);
1077 
1078 }
1079 
1080 TEUCHOS_UNIT_TEST(Teuchos_Dependencies, BoolVisualDepSerializationExceptions){
1081  EXCEPTION_TEST_BOILERPLATE(true, "blah");
1082  RCP<Dependency> boolVisDep =
1083  rcp(new BoolVisualDependency(dependeeParam1, dependentParam1));
1084  CONVERT_DEP_TO_XML(boolVisDep);
1085  TOO_MANY_DEPENDEE_TEST(boolVisDep);
1086 }
1087 
1088 TEUCHOS_UNIT_TEST(Teuchos_Dependencies, StringVisualDepSerializationExceptions)
1089 {
1090  EXCEPTION_TEST_BOILERPLATE(std::string("balh"), 4);
1091  RCP<Dependency> stringVisDep =
1092  rcp(new StringVisualDependency(dependeeParam1, dependentParam1, "steve"));
1093  CONVERT_DEP_TO_XML(stringVisDep);
1094  TOO_MANY_DEPENDEE_TEST(stringVisDep);
1095 
1097  stringVisDepXML,
1099  missingValuesXML);
1100 
1101  TEST_THROW(
1103  missingValuesXML, readerEntryMap, readerValiMap),
1105 
1106 }
1107 
1109  Teuchos_Dependencies, ConditionVisualDepSerializationExceptions)
1110 {
1111  EXCEPTION_TEST_BOILERPLATE(true, 4);
1112  RCP<Condition> boolCon = rcp(new BoolCondition(dependeeParam1));
1113  RCP<Dependency> conVisDep =
1114  rcp(new ConditionVisualDependency(boolCon, dependentParam1));
1115  CONVERT_DEP_TO_XML(conVisDep);
1117  conVisDepXML,
1119  missingConXML);
1120 
1121  TEST_THROW(
1123  missingConXML, readerEntryMap, readerValiMap),
1125 }
1126 
1128  Teuchos_Dependencies, BoolValidatorDepSerializationExceptions)
1129 {
1130  EXCEPTION_TEST_BOILERPLATE(true, 7);
1133  RCP<EnhancedNumberValidator<int> > falseVali =
1135  INSERT_VALIDATOR_TO_MAPS(trueVali);
1136  INSERT_VALIDATOR_TO_MAPS(falseVali);
1137  RCP<Dependency> boolValiDep =
1139  dependeeParam1,
1140  dependentParam1,
1141  trueVali,
1142  falseVali));
1143  CONVERT_DEP_TO_XML(boolValiDep);
1144  TOO_MANY_DEPENDEE_TEST(boolValiDep);
1145 
1146  readerValiMap.erase(writerValiMap.find(trueVali)->second);
1147 
1148  TEST_THROW(
1150  boolValiDepXML, readerEntryMap, readerValiMap),
1152 
1153  readerValiMap.insert( IDtoValidatorMap::IDValidatorPair(
1154  writerValiMap.find(trueVali)->second, trueVali));
1155  readerValiMap.erase(writerValiMap.find(falseVali)->second);
1156 
1157  TEST_THROW(
1159  boolValiDepXML, readerEntryMap, readerValiMap),
1161 
1162 }
1163 
1165  Teuchos_Dependencies, StringValidatorDepSerializationExceptions)
1166 {
1167  EXCEPTION_TEST_BOILERPLATE(std::string("blah"), 4);
1168  RCP<FileNameValidator> scrapVali =
1170  RCP<FileNameValidator> scrapVali2 =
1173  valiMap["blah"] = scrapVali;
1174  INSERT_VALIDATOR_TO_MAPS(scrapVali);
1175  INSERT_VALIDATOR_TO_MAPS(scrapVali2);
1176 
1177  RCP<Dependency> stringValiDep =
1179  dependeeParam1, dependentParam1, valiMap, scrapVali2));
1180  CONVERT_DEP_TO_XML(stringValiDep);
1181 
1182  TOO_MANY_DEPENDEE_TEST(stringValiDep);
1183 
1185  stringValiDepXML,
1187  missingValuesXML);
1188 
1189  TEST_THROW(
1191  missingValuesXML, readerEntryMap, readerValiMap),
1193 
1194  readerValiMap.erase(writerValiMap.find(scrapVali)->second);
1195 
1196  TEST_THROW(
1198  stringValiDepXML, readerEntryMap, readerValiMap),
1200 
1201  readerValiMap.insert( IDtoValidatorMap::IDValidatorPair(
1202  writerValiMap.find(scrapVali)->second,scrapVali));
1203  readerValiMap.erase(writerValiMap.find(scrapVali2)->second);
1204 
1205  TEST_THROW(
1207  stringValiDepXML, readerEntryMap, readerValiMap),
1209 }
1210 
1212  Teuchos_Dependencies, RangeValidatorDepSerializationExceptions)
1213 {
1214  EXCEPTION_TEST_BOILERPLATE(3, "blah");
1215 
1216  RCP<FileNameValidator> scrapVali =
1218  RCP<FileNameValidator> otherScrapVali =
1220  RCP<FileNameValidator> defaultScrapVali =
1224  RangeValidatorDependency<int>::Range scrapRange(2,5);
1225  valiMap[scrapRange] = scrapVali;
1226  secondvaliMap[scrapRange] = otherScrapVali;
1227  writerValiMap.insert(scrapVali);
1228  writerValiMap.insert(otherScrapVali);
1229  writerValiMap.insert(defaultScrapVali);
1230  readerValiMap.insert(
1232  writerValiMap.find(scrapVali)->second,scrapVali));
1233  readerValiMap.insert(
1235  writerValiMap.find(otherScrapVali)->second,otherScrapVali));
1236  readerValiMap.insert(
1238  writerValiMap.find(defaultScrapVali)->second,defaultScrapVali));
1239 
1240  RCP<Dependency> rangeDep =
1242  dependeeParam1, dependentParam1, valiMap));
1243 
1244  RCP<Dependency> rangeDefaultDep =
1246  dependeeParam1, dependentParam1, secondvaliMap, defaultScrapVali));
1247 
1248  CONVERT_DEP_TO_XML(rangeDep);
1249  CONVERT_DEP_TO_XML(rangeDefaultDep);
1250 
1251  TOO_MANY_DEPENDEE_TEST(rangeDep);
1252 
1254  rangeDepXML,
1256  missingRangesXML
1257  )
1258 
1259  TEST_THROW(
1261  missingRangesXML, readerEntryMap, readerValiMap),
1263 
1264  readerValiMap.erase(writerValiMap.find(scrapVali)->second);
1265 
1266  TEST_THROW(
1268  rangeDepXML, readerEntryMap, readerValiMap),
1270 
1271  readerValiMap.erase(writerValiMap.find(defaultScrapVali)->second);
1272  TEST_THROW(
1274  rangeDefaultDepXML, readerEntryMap, readerValiMap),
1276 
1277 }
1278 
1280  Teuchos_Dependencies, NumArrayLengthDepSerializationExceptions)
1281 {
1283  RCP<Dependency> numArrayLengthDep =
1285  dependeeParam1, dependentParam1));
1286  CONVERT_DEP_TO_XML(numArrayLengthDep);
1287  TOO_MANY_DEPENDEE_TEST(numArrayLengthDep);
1288 }
1289 
1292  Teuchos_Dependencies, DepSheetTests)
1293 {
1294  ParameterList myDepList("String Visual Dep List");
1295  std::string dependee1 = "dependee1";
1296  std::string dependent1 = "dependent1";
1297  RCP<DependencySheet> myDepSheet = rcp(new DependencySheet("My List"));
1298  myDepList.set(dependee1, "val1");
1299  myDepList.set(dependent1, 2.0);
1300  StringVisualDependency::ValueList valList1 = tuple<std::string>("val1");
1301  RCP<StringVisualDependency> basicStringVisDep = rcp(
1303  myDepList.getEntryRCP(dependee1),
1304  myDepList.getEntryRCP(dependent1),
1305  valList1));
1306  myDepSheet->addDependency(basicStringVisDep);
1307 
1308  RCP<DependencySheet> readInDepSheet = rcp(new DependencySheet);
1309 
1310  XMLParameterListWriter plWriter;
1311  XMLObject xmlOut = plWriter.toXML(myDepList, myDepSheet);
1312  out << xmlOut.toString();
1313 
1314  RCP<ParameterList> readInList =
1315  writeThenReadPL(myDepList, myDepSheet, readInDepSheet);
1316  TEST_EQUALITY(readInDepSheet->getName(), myDepSheet->getName());
1317 }
1318 
1319 
1320 } //namespace Teuchos
1321 
#define COPY_DEPTAG_WITHOUT_CHILD(TAG, CHILDTAG, NEWTAG)
A Dependency sheet keeps track of dependencies between various ParameterEntries.
RCP< const ParameterEntryValidator > getDefaultValidator() const
Thrown when no dependes of a dependency can&#39;t be found when converting the dependency to or from XML...
XMLObject toXML(const ParameterList &p, RCP< const DependencySheet > depSheet=null) const
#define TEST_ASSERT(v1)
Assert the given statement is true.
static RCP< T > getDummyObject()
Retrieves a dummy object of type T.
A BoolValidatorDependency says the following about the relationship between two parameters: Dependeni...
#define INSERT_VALIDATOR_TO_MAPS(VALIDATOR)
Thrown when a StringVisualDependency is being converted from XML and no Values tag is found...
RCP< ParameterEntry > getEntryRCP(const std::string &name)
Retrieves the RCP for an entry with the name name if it exists.
A database for DependencyXMLConverters.
A string visual depdencies says the following about the relationship between two elements in a Parame...
unsigned long long int ullint
A bool visual dependency says the following about the relationship between two elements in a Paramete...
#define EXCEPTION_TEST_BOILERPLATE(DEPENDEE_VAL, DEPENDENT_VAL)
std::set< RCP< ParameterEntry >, RCPComp > ParameterEntryList
A list of Dependees.
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Set a parameter whose value has type T.
bool nonnull(const std::shared_ptr< T > &p)
Returns true if p.get()!=NULL.
This object is held as the &quot;value&quot; in the Teuchos::ParameterList std::map.
A Bool Logic Condition that returns the result or perfroming a logical AND on the conditions...
static const std::string & getXMLTagName()
#define RANGE_VALIDATOR_TEST(T)
#define TEST_EQUALITY(v1, v2)
Assert the equality of v1 and v2.
#define TEST_THROW(code, ExceptType)
Assert that the statement &#39;code&#39; throws the exception &#39;ExceptType&#39; (otherwise the test fails)...
bool getShowIf() const
Get&#39;s the value of the showIf variable.
const ValueToValidatorMap & getValuesAndValidators() const
retrieve a const reference to the ValueToValidator map being used by this StringValidatorDependency ...
Thrown when a dependent of a dependency cant be found when converting the dependency to or from XML...
T * get() const
Get the raw C++ pointer to the underlying object.
#define ArrayModifierTest(DEPENDENCYTYPE, ARRAY_TYPE)
#define VERIFY_DEPENDEE(DEPENDENCY, DEPENDEE)
std::map< std::string, RCP< const ParameterEntryValidator > > ValueToValidatorMap
Conveniece typedef.
A Number Condition is a Parameter Condition that evaluates whether or not a number parameter is great...
#define NUMBER_VIS_TEST(T)
Simple helper functions that make it easy to read and write XML to and from a parameterlist.
This structure defines some basic traits for a scalar field type.
const ValueList & getValues() const
get the List of values the dependee will be checked against.
A RangeValidatorDependency says the following about the relationship between two parameters: Dependen...
RCP< const ParameterEntryValidator > getFalseValidator() const
Gets the false validator.
void addDependency(RCP< Dependency > dependency)
Adds a dependency to the sheet.
A simple function object that subtracts a specififed value from the given arguement in the runFunctio...
TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL(RCPNodeHandle, basicConstruct_owns_mem, T)
static const std::string & getStringValuesTagName()
Gets the StringValues Tag.
TEUCHOS_UNIT_TEST(ConstNonconstObjectContainer, create)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
Templated Parameter List class.
Thrown when no dependents of a dependency are specified when converting the dependency from XML...
const std::string & getName() const
Gets the name of the dependency sheet.
std::string toString() const
Represent this node and its children as a std::string.
Representation of an XML data tree. XMLObject is a ref-counted handle to a XMLObjectImplem object...
A collection of standard DependencyXMLConverters.
A String Condition is a Parameter Condition that evaluates whether or not a string parameter has take...
#define TWODROW_TEST_GROUP(DependeeType)
std::map< RCP< const ParameterEntry >, ParameterEntry::ParameterEntryID, RCPConstComp > EntryIDsMap
Unit testing support.
#define NUM_ARRAY_LENGTH_TEST_GROUP(DependeeType)
Thrown when the rangesAndValidators tag for the RangeValidatorDepencyConverter can&#39;t be found...
A NumberArrayLengthDependency says the following about the relationship between two parameters: The l...
A class for mapping validators to integers.
#define TWODCOL_TEST_GROUP(DependeeType)
RCP< const ParameterEntryValidator > getTrueValidator() const
Gets the true validator.
#define BASIC_DEPENDENCY_TEST(DEPENDENCY, DEPTYPE,NUM_DEPENDEES, NUM_DEPENDENTS)
A list of parameters of arbitrary type.
A collection of standard dependencies.
A Bool Condition is a Parameter Condition that evaluates whether or not a Boolean parameter is ture...
RCP< const Condition > getCondition() const
Gets the condition being used in this dependency.
#define TEST_COMPARE_ARRAYS(a1, a2)
Assert that a1.size()==a2.size() and a[i]==b[i], i=0....
DataStructure keeping track of dependencies.
XMLObject fromDependencytoXML(const RCP< const Dependency > dependency, const XMLParameterListWriter::EntryIDsMap &entryIDsMap, ValidatortoIDMap &validatorIDsMap) const
Converters a given ParameterEntryValidator to XML.
A StringValidatorDependency says the following about the relationship between two parameters: Depende...
std::pair< ParameterEntryValidator::ValidatorID, RCP< ParameterEntryValidator > > IDValidatorPair
Class uesd to validate a particular type of number.
Thrown when converting a StrinvValidatorDependcny from XML and no valuesAndValidators tag is found...
#define VERIFY_DEPENDENT(DEPENDENCY, DEPENDENT)
Smart reference counting pointer class for automatic garbage collection.
A condition visual dependency says the following about the relationship between elements in a Paramet...
#define CONVERT_DEP_TO_XML(DEPENDENCY)
Thrown when converting a dependency that has validaotrs to and from XML. This excetpion indicates tha...
std::pair< T, T > Range
Convenience typedef.
static RCP< Dependency > convertXML(const XMLObject &xmlObject, const XMLParameterListReader::EntryIDsMap &entryIDsMap, const IDtoValidatorMap &validatorIDsMap)
Given an XMLObject converts the XMLObject to a Dependency.
TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT RCP< ParameterList > writeThenReadPL(ParameterList &myList)
Write a parameter list to xml and then read that xml back in via a string. The intent of this functio...
Thrown when no condtion tag is found when converting a ConditionVisualDependency from XML...
A number visual dependency says the following about the relationship between two elements in a Parame...
static T one()
Returns representation of one for this scalar type.
std::map< Range, RCP< const ParameterEntryValidator > > RangeToValidatorMap
Convenience typedef.
Standard Conditions to be used.
#define TOO_MANY_DEPENDEE_TEST(DEPENDENCY)
Thrown when no dependess of a dependency are specified when converting the dependency from XML...
RCP< const DepSet > getDependenciesForParameter(RCP< const ParameterEntry > dependee) const
Returns a set of all the dependencies associated with a particular dependee. If no dependencies with ...
Writes a ParameterList to an XML object.