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 // Teuchos: Common Tools Package
4 //
5 // Copyright 2004 NTESS and the Teuchos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
20 
22 
23 
24 namespace Teuchos{
25 
26 
27 typedef unsigned short int ushort;
28 typedef unsigned int uint;
29 typedef unsigned long int ulong;
30 typedef std::string myString_t;
31 typedef long long int llint;
32 typedef unsigned long long int ullint;
33 
34 #define BASIC_DEPENDENCY_TEST( \
35  DEPENDENCY, DEPTYPE, NUM_DEPENDEES, NUM_DEPENDENTS) \
36  std::string depXMLTag##DEPENDENCY = \
37  DummyObjectGetter< DEPTYPE >::getDummyObject()->getTypeAttributeValue(); \
38 \
39  TEST_ASSERT(DEPENDENCY->getTypeAttributeValue() == depXMLTag##DEPENDENCY ); \
40  TEST_ASSERT(DEPENDENCY->getDependents().size() == NUM_DEPENDENTS); \
41  TEST_ASSERT(DEPENDENCY->getDependees().size() == NUM_DEPENDEES); \
42 
43 #define VERIFY_DEPENDENT(DEPENDENCY, DEPENDENT) \
44  TEST_ASSERT( \
45  DEPENDENCY->getDependents().find(DEPENDENT) \
46  != \
47  DEPENDENCY->getDependents().end() \
48  ); \
49 
50 #define VERIFY_DEPENDEE(DEPENDENCY, DEPENDEE) \
51  TEST_ASSERT( \
52  DEPENDENCY->getDependees().find(DEPENDEE) \
53  != \
54  DEPENDENCY->getDependees().end()); \
55 
56 #define CREATE_DEPENDEE(POSTFIX, VALUE) \
57  RCP<ParameterEntry> dependeeParam##POSTFIX = rcp( \
58  new ParameterEntry( VALUE ));
59 
60 #define CREATE_DEPENDENT(POSTFIX, VALUE) \
61  RCP<ParameterEntry> dependentParam##POSTFIX = \
62  rcp(new ParameterEntry( VALUE )); \
63 
64 #define EXCEPTION_TEST_BOILERPLATE(DEPENDEE_VAL, DEPENDENT_VAL) \
65  CREATE_DEPENDEE(1, DEPENDEE_VAL); \
66  CREATE_DEPENDEE(Extra, DEPENDEE_VAL); \
67  CREATE_DEPENDENT(1, DEPENDENT_VAL); \
68 \
69  XMLParameterListWriter::EntryIDsMap writerEntryMap; \
70  writerEntryMap[dependeeParam1] = 1; \
71  writerEntryMap[dependentParam1] = 2; \
72  writerEntryMap[dependeeParamExtra] = 3; \
73  ValidatortoIDMap writerValiMap; \
74 \
75  XMLParameterListReader::EntryIDsMap readerEntryMap; \
76  readerEntryMap[1] = dependeeParam1; \
77  readerEntryMap[2] = dependentParam1; \
78  readerEntryMap[3] = dependeeParamExtra; \
79  IDtoValidatorMap readerValiMap; \
80 
81 #define CONVERT_DEP_TO_XML(DEPENDENCY) \
82  XMLObject DEPENDENCY##XML = DependencyXMLConverterDB::convertDependency( \
83  DEPENDENCY , writerEntryMap, writerValiMap); \
84 
85 #define TOO_MANY_DEPENDEE_TEST(DEPENDENCY) \
86  XMLObject extraDependee(DependencyXMLConverter::getDependeeTagName()); \
87  extraDependee.addAttribute<ParameterEntry::ParameterEntryID>( \
88  DependencyXMLConverter::getParameterIdAttributeName(), \
89  writerEntryMap[dependeeParamExtra]); \
90  XMLObject tooManyTempXML = DEPENDENCY##XML.deepCopy(); \
91  tooManyTempXML.addChild(extraDependee); \
92  \
93  TEST_THROW( \
94  DependencyXMLConverterDB::convertXML( \
95  tooManyTempXML , readerEntryMap, readerValiMap), \
96  TooManyDependeesException); \
97 
98 #define COPY_DEPTAG_WITHOUT_CHILD(TAG, CHILDTAG, NEWTAG) \
99  XMLObject NEWTAG(TAG.getTag()); \
100  NEWTAG.addAttribute( \
101  DependencyXMLConverter::getTypeAttributeName(), \
102  TAG.getAttribute(DependencyXMLConverter::getTypeAttributeName())); \
103  for(int i =0; i< TAG.numChildren(); i++){ \
104  if(TAG.getChild(i).getTag() != CHILDTAG) \
105  { \
106  NEWTAG.addChild(TAG.getChild(i).deepCopy()); \
107  } \
108  } \
109 
110 
111 #define INSERT_VALIDATOR_TO_MAPS(VALIDATOR) \
112  writerValiMap.insert( VALIDATOR ); \
113  readerValiMap.insert( \
114  IDtoValidatorMap::IDValidatorPair( \
115  writerValiMap.find( VALIDATOR )->second, VALIDATOR )); \
116 
117 
118 TEUCHOS_UNIT_TEST(Teuchos_Dependencies, SerializationTestMacros){
119  RCP<ParameterEntry> dependee1 = rcp(new ParameterEntry(true));
120  RCP<ParameterEntry> dependee2 = rcp(new ParameterEntry(true));
121  RCP<ParameterEntry> dependent1 = rcp(new ParameterEntry("blah"));
122  RCP<ParameterEntry> dependent2 = rcp(new ParameterEntry("blah"));
123  RCP<BoolVisualDependency> simpleDep =
124  rcp(new BoolVisualDependency(dependee1, dependent1));
125 
126 
127  Dependency::ParameterEntryList dependentList;
128  dependentList.insert(dependent1);
129  dependentList.insert(dependent2);
130 
131  RCP<BoolVisualDependency> complexDep =
132  rcp(new BoolVisualDependency(dependee2, dependentList));
133 
135  VERIFY_DEPENDEE(simpleDep, dependee1);
136  VERIFY_DEPENDENT(simpleDep, dependent1);
137 
138  BASIC_DEPENDENCY_TEST(complexDep, BoolVisualDependency, 1, 2);
139  VERIFY_DEPENDEE(complexDep, dependee2);
140  VERIFY_DEPENDENT(complexDep, dependent1);
141  VERIFY_DEPENDENT(complexDep, dependent2);
142 
143 }
144 
145 
146 TEUCHOS_UNIT_TEST(Teuchos_Dependencies, StringVisualDepSerialization){
147  std::string dependee1 = "string param";
148  std::string dependee2 = "string param2";
149  std::string dependent1 = "dependent param1";
150  std::string dependent2 = "dependent param2";
151  ParameterList myDepList("String Visual Dep List");
152  RCP<DependencySheet> myDepSheet = rcp(new DependencySheet);
153  myDepList.set(dependee1, "val1");
154  myDepList.set(dependee2, "val2");
155  myDepList.set(dependent1, 1.0);
156  myDepList.set(dependent2, 1.0);
157 
158  StringVisualDependency::ValueList valList1 = tuple<std::string>("val1");
159 
160  RCP<StringVisualDependency> basicStringVisDep = rcp(
162  myDepList.getEntryRCP(dependee1),
163  myDepList.getEntryRCP(dependent1),
164  valList1));
165 
166  Dependency::ParameterEntryList dependentList;
167  dependentList.insert(myDepList.getEntryRCP(dependent1));
168  dependentList.insert(myDepList.getEntryRCP(dependent2));
170  tuple<std::string>("val1", "val2");
171 
172  RCP<StringVisualDependency> complexStringVisDep = rcp(
174  myDepList.getEntryRCP(dependee2),
175  dependentList,
176  valList2,
177  false));
178 
179  myDepSheet->addDependency(basicStringVisDep);
180  myDepSheet->addDependency(complexStringVisDep);
181 
182  RCP<DependencySheet> readInDepSheet = rcp(new DependencySheet);
183 
184  XMLParameterListWriter plWriter;
185  XMLObject xmlOut = plWriter.toXML(myDepList, myDepSheet);
186  out << xmlOut.toString();
187 
188  RCP<ParameterList> readInList =
189  writeThenReadPL(myDepList, myDepSheet, readInDepSheet);
190 
191  RCP<ParameterEntry> readinDependee1 = readInList->getEntryRCP(dependee1);
192  RCP<ParameterEntry> readinDependent1 = readInList->getEntryRCP(dependent1);
193  RCP<ParameterEntry> readinDependee2 = readInList->getEntryRCP(dependee2);
194  RCP<ParameterEntry> readinDependent2 = readInList->getEntryRCP(dependent2);
195 
196  RCP<Dependency> readinDep1 =
197  *(readInDepSheet->getDependenciesForParameter(readinDependee1)->begin());
198 
199  RCP<Dependency> readinDep2 =
200  *(readInDepSheet->getDependenciesForParameter(readinDependee2)->begin());
201 
203  VERIFY_DEPENDEE(readinDep1, readinDependee1);
204  VERIFY_DEPENDENT(readinDep1, readinDependent1);
205 
207  VERIFY_DEPENDEE(readinDep2, readinDependee2);
208  VERIFY_DEPENDENT(readinDep2, readinDependent1);
209  VERIFY_DEPENDENT(readinDep2, readinDependent2);
210 
211  RCP<StringVisualDependency> castedDep1 =
212  rcp_dynamic_cast<StringVisualDependency>(readinDep1, true);
213  RCP<StringVisualDependency> castedDep2 =
214  rcp_dynamic_cast<StringVisualDependency>(readinDep2, true);
215 
217  castedDep1->getValues(), basicStringVisDep->getValues());
219  castedDep2->getValues(), complexStringVisDep->getValues());
220 
221  TEST_EQUALITY(castedDep1->getShowIf(), basicStringVisDep->getShowIf());
222  TEST_EQUALITY(castedDep2->getShowIf(), complexStringVisDep->getShowIf());
223 }
224 
225 TEUCHOS_UNIT_TEST(Teuchos_Dependencies, BoolVisualDepSerialization){
226  std::string dependee1 = "bool param";
227  std::string dependee2 = "bool param2";
228  std::string dependent1 = "dependent param1";
229  std::string dependent2 = "dependent param2";
230  ParameterList myDepList("Bool Visual Dep List");
231  RCP<DependencySheet> myDepSheet = rcp(new DependencySheet);
232  myDepList.set(dependee1, true);
233  myDepList.set(dependee2, true);
234  myDepList.set(dependent1, 1.0);
235  myDepList.set(dependent2, 1.0);
236 
237  RCP<BoolVisualDependency> trueBoolVisDep = rcp(
239  myDepList.getEntryRCP(dependee1),
240  myDepList.getEntryRCP(dependent1)));
241 
242  Dependency::ParameterEntryList dependentList;
243  dependentList.insert(myDepList.getEntryRCP(dependent1));
244  dependentList.insert(myDepList.getEntryRCP(dependent2));
245 
246  RCP<BoolVisualDependency> falseBoolVisDep = rcp(
248  myDepList.getEntryRCP(dependee2),
249  dependentList,
250  false));
251 
252  myDepSheet->addDependency(trueBoolVisDep);
253  myDepSheet->addDependency(falseBoolVisDep);
254 
255  RCP<DependencySheet> readInDepSheet = rcp(new DependencySheet);
256 
257  XMLParameterListWriter plWriter;
258  XMLObject xmlOut = plWriter.toXML(myDepList, myDepSheet);
259  out << xmlOut.toString();
260 
261  RCP<ParameterList> readInList =
262  writeThenReadPL(myDepList, myDepSheet, readInDepSheet);
263 
264  RCP<ParameterEntry> readinDependee1 = readInList->getEntryRCP(dependee1);
265  RCP<ParameterEntry> readinDependent1 = readInList->getEntryRCP(dependent1);
266  RCP<ParameterEntry> readinDependee2 = readInList->getEntryRCP(dependee2);
267  RCP<ParameterEntry> readinDependent2 = readInList->getEntryRCP(dependent2);
268 
269  RCP<Dependency> readinDep1 =
270  *(readInDepSheet->getDependenciesForParameter(readinDependee1)->begin());
271 
272  RCP<Dependency> readinDep2 =
273  *(readInDepSheet->getDependenciesForParameter(readinDependee2)->begin());
274 
275  BASIC_DEPENDENCY_TEST(readinDep1, BoolVisualDependency, 1, 1);
276  VERIFY_DEPENDEE(readinDep1, readinDependee1);
277  VERIFY_DEPENDENT(readinDep1, readinDependent1);
278 
279  BASIC_DEPENDENCY_TEST(readinDep2, BoolVisualDependency, 1, 2);
280  VERIFY_DEPENDEE(readinDep2, readinDependee2);
281  VERIFY_DEPENDENT(readinDep2, readinDependent1);
282  VERIFY_DEPENDENT(readinDep2, readinDependent2);
283 
284 
285  RCP<BoolVisualDependency> castedDep1 =
286  rcp_dynamic_cast<BoolVisualDependency>(readinDep1, true);
287  RCP<BoolVisualDependency> castedDep2 =
288  rcp_dynamic_cast<BoolVisualDependency>(readinDep2, true);
289 
290  TEST_EQUALITY(castedDep1->getShowIf(), trueBoolVisDep->getShowIf());
291  TEST_EQUALITY(castedDep2->getShowIf(), falseBoolVisDep->getShowIf());
292 }
293 
295  Teuchos_Dependencies,
296  NumberVisualDepSerialization,
297  T)
298 {
299  std::string dependee1 = "num param";
300  std::string dependee2 = "num param2";
301  std::string dependent1 = "dependent param1";
302  std::string dependent2 = "dependent param2";
303  ParameterList myDepList("Number Visual Dep List");
304  RCP<DependencySheet> myDepSheet = rcp(new DependencySheet);
305  myDepList.set(dependee1, ScalarTraits<T>::one());
306  myDepList.set(dependee2, ScalarTraits<T>::one());
307  myDepList.set(dependent1, true);
308  myDepList.set(dependent2, "vale");
309 
310  RCP<NumberVisualDependency<T> > simpleNumVisDep = rcp(
312  myDepList.getEntryRCP(dependee1),
313  myDepList.getEntryRCP(dependent1)));
314 
315  Dependency::ParameterEntryList dependentList;
316  dependentList.insert(myDepList.getEntryRCP(dependent1));
317  dependentList.insert(myDepList.getEntryRCP(dependent2));
318 
319  T ten = ScalarTraits<T>::one() *10;
320  RCP<SubtractionFunction<T> > subFunction = rcp(new SubtractionFunction<T>(ten));
321  RCP<NumberVisualDependency<T> > complexNumVisDep = rcp(
323  myDepList.getEntryRCP(dependee2),
324  dependentList,
325  true,
326  subFunction));
327 
328  myDepSheet->addDependency(simpleNumVisDep);
329  myDepSheet->addDependency(complexNumVisDep);
330 
331  RCP<DependencySheet> readInDepSheet = rcp(new DependencySheet);
332 
333  XMLParameterListWriter plWriter;
334  XMLObject xmlOut = plWriter.toXML(myDepList, myDepSheet);
335  out << xmlOut.toString();
336 
337  RCP<ParameterList> readInList =
338  writeThenReadPL(myDepList, myDepSheet, readInDepSheet);
339 
340  RCP<ParameterEntry> readinDependee1 = readInList->getEntryRCP(dependee1);
341  RCP<ParameterEntry> readinDependent1 = readInList->getEntryRCP(dependent1);
342  RCP<ParameterEntry> readinDependee2 = readInList->getEntryRCP(dependee2);
343  RCP<ParameterEntry> readinDependent2 = readInList->getEntryRCP(dependent2);
344 
345  RCP<Dependency> readinDep1 =
346  *(readInDepSheet->getDependenciesForParameter(readinDependee1)->begin());
347 
348  RCP<Dependency> readinDep2 =
349  *(readInDepSheet->getDependenciesForParameter(readinDependee2)->begin());
350 
352  VERIFY_DEPENDEE(readinDep1, readinDependee1);
353  VERIFY_DEPENDENT(readinDep1, readinDependent1);
354 
356  VERIFY_DEPENDEE(readinDep2, readinDependee2);
357  VERIFY_DEPENDENT(readinDep2, readinDependent1);
358  VERIFY_DEPENDENT(readinDep2, readinDependent2);
359 
360 
361  RCP<NumberVisualDependency<T> > castedDep1 =
362  rcp_dynamic_cast<NumberVisualDependency<T> >(readinDep1, true);
363  RCP<NumberVisualDependency<T> > castedDep2 =
364  rcp_dynamic_cast<NumberVisualDependency<T> >(readinDep2, true);
365 
366  TEST_EQUALITY(castedDep1->getShowIf(), simpleNumVisDep->getShowIf());
367  TEST_EQUALITY(castedDep2->getShowIf(), complexNumVisDep->getShowIf());
368 
369  RCP<const SimpleFunctionObject<T> > functionObject =
370  castedDep2->getFunctionObject();
371  TEST_ASSERT(functionObject != null);
372  RCP<const SubtractionFunction<T> > castedFunction =
373  rcp_dynamic_cast<const SubtractionFunction<T> >(functionObject);
374  TEST_ASSERT(castedFunction != null);
376  castedFunction->getModifiyingOperand(),
377  subFunction->getModifiyingOperand());
378 }
379 
380 #define NUMBER_VIS_TEST(T) \
381 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( \
382  Teuchos_Dependencies, NumberVisualDepSerialization, T)
383 
384 NUMBER_VIS_TEST(int)
385 NUMBER_VIS_TEST(double)
386 NUMBER_VIS_TEST(float)
388 
389 TEUCHOS_UNIT_TEST(Teuchos_Dependencies, ConditionVisualDepSerialization){
390  std::string dependee1 = "string param";
391  std::string dependee2 = "bool param";
392  std::string dependee3 = "int param";
393  std::string dependent1 = "dependent param1";
394  std::string dependent2 = "dependent param2";
395  std::string dependent3 = "dependent param3";
396  ParameterList myDepList("Condition Visual Dep List");
397  RCP<DependencySheet> myDepSheet = rcp(new DependencySheet);
398  myDepList.set(dependee1, "val1");
399  myDepList.set(dependee2, true);
400  myDepList.set(dependee3, 1);
401  myDepList.set(dependent1, 1.0);
402  myDepList.set(dependent2, 1.0);
403  myDepList.set(dependent3, (float)1.0);
404 
405  StringCondition::ValueList conditionVal1 =
406  tuple<std::string>("steve", "blah", "your face");
407  RCP<StringCondition> stringCon =
408  rcp(new StringCondition(
409  myDepList.getEntryRCP(dependee1), conditionVal1));
410 
411  RCP<BoolCondition> boolCon =
412  rcp(new BoolCondition(myDepList.getEntryRCP(dependee2)));
413 
414  RCP<NumberCondition<int> > numberCon =
415  rcp(new NumberCondition<int>(myDepList.getEntryRCP(dependee3)));
416 
418  tuple<RCP<const Condition> >(boolCon, numberCon);
419 
420  RCP<AndCondition> andCon = rcp(new AndCondition(conList));
421 
422  RCP<ConditionVisualDependency> simpleConVisDep = rcp(
424  stringCon,
425  myDepList.getEntryRCP(dependent1)));
426 
427  Dependency::ParameterEntryList dependentList;
428  dependentList.insert(myDepList.getEntryRCP(dependent2));
429  dependentList.insert(myDepList.getEntryRCP(dependent3));
430 
431  RCP<ConditionVisualDependency> complexConVisDep = rcp(
433  andCon,
434  dependentList,
435  false));
436 
437  myDepSheet->addDependency(simpleConVisDep);
438  myDepSheet->addDependency(complexConVisDep);
439 
440  RCP<DependencySheet> readInDepSheet = rcp(new DependencySheet);
441 
442  XMLParameterListWriter plWriter;
443  XMLObject xmlOut = plWriter.toXML(myDepList, myDepSheet);
444  out << xmlOut.toString();
445 
446  RCP<ParameterList> readInList =
447  writeThenReadPL(myDepList, myDepSheet, readInDepSheet);
448 
449  RCP<ParameterEntry> readinDependee1 = readInList->getEntryRCP(dependee1);
450  RCP<ParameterEntry> readinDependent1 = readInList->getEntryRCP(dependent1);
451  RCP<ParameterEntry> readinDependee2 = readInList->getEntryRCP(dependee2);
452  RCP<ParameterEntry> readinDependent2 = readInList->getEntryRCP(dependent2);
453  RCP<ParameterEntry> readinDependee3 = readInList->getEntryRCP(dependee3);
454  RCP<ParameterEntry> readinDependent3 = readInList->getEntryRCP(dependent3);
455 
456  RCP<Dependency> readinDep1 =
457  *(readInDepSheet->getDependenciesForParameter(readinDependee1)->begin());
458 
459  RCP<Dependency> readinDep2 =
460  *(readInDepSheet->getDependenciesForParameter(readinDependee2)->begin());
461 
462  RCP<Dependency> readinDep3 =
463  *(readInDepSheet->getDependenciesForParameter(readinDependee3)->begin());
464 
466  VERIFY_DEPENDEE(readinDep1, readinDependee1);
467  VERIFY_DEPENDENT(readinDep1, readinDependent1);
468 
469  TEST_ASSERT(readinDep2.get() == readinDep3.get());
470 
472  VERIFY_DEPENDEE(readinDep2, readinDependee2);
473  VERIFY_DEPENDEE(readinDep2, readinDependee3);
474  VERIFY_DEPENDENT(readinDep2, readinDependent2);
475  VERIFY_DEPENDENT(readinDep2, readinDependent3);
476 
477  RCP<ConditionVisualDependency> castedDep1 =
478  rcp_dynamic_cast<ConditionVisualDependency>(readinDep1, true);
479  RCP<ConditionVisualDependency> castedDep2 =
480  rcp_dynamic_cast<ConditionVisualDependency>(readinDep2, true);
481 
482  TEST_EQUALITY(castedDep1->getShowIf(), simpleConVisDep->getShowIf());
483  TEST_EQUALITY(castedDep2->getShowIf(), complexConVisDep->getShowIf());
484 
485  TEST_EQUALITY(castedDep1->getCondition()->getTypeAttributeValue(),
486  simpleConVisDep->getCondition()->getTypeAttributeValue());
487  TEST_EQUALITY(castedDep2->getCondition()->getTypeAttributeValue(),
488  complexConVisDep->getCondition()->getTypeAttributeValue());
489 }
490 
491 #define ArrayModifierTest(DEPENDENCYTYPE, ARRAY_TYPE) \
492 TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( \
493  Teuchos_Dependencies, \
494  DEPENDENCYTYPE##_serialization_tests, \
495  DependeeType, \
496  DependentType) \
497 { \
498  std::string dependee1 = "dependee param"; \
499  std::string dependee2 = "dependee param2"; \
500  std::string dependent1 = "dependent param1"; \
501  std::string dependent2 = "dependent param2"; \
502  ParameterList myDepList("Array modifier dep list"); \
503  RCP<DependencySheet> myDepSheet = rcp(new DependencySheet); \
504  myDepList.set(dependee1, ScalarTraits<DependeeType>::one()); \
505  myDepList.set(dependee2, ScalarTraits<DependeeType>::one()); \
506  myDepList.set(dependent1, ARRAY_TYPE<DependentType>()); \
507  myDepList.set(dependent2, ARRAY_TYPE<DependentType>()); \
508  \
509  \
510  RCP<DEPENDENCYTYPE<DependeeType, DependentType> > basicArrayDep = \
511  rcp(new DEPENDENCYTYPE<DependeeType, DependentType>( \
512  myDepList.getEntryRCP(dependee1), \
513  myDepList.getEntryRCP(dependent1))); \
514  \
515  DependeeType one = ScalarTraits< DependeeType >::one(); \
516  RCP<AdditionFunction< DependeeType > > functionTester = \
517  rcp(new AdditionFunction<DependeeType>(one)); \
518  \
519  RCP<DEPENDENCYTYPE<DependeeType, DependentType> > funcArrayDep = \
520  rcp(new DEPENDENCYTYPE<DependeeType, DependentType>( \
521  myDepList.getEntryRCP(dependee2), \
522  myDepList.getEntryRCP(dependent2), \
523  functionTester)); \
524  \
525  \
526  myDepSheet->addDependency(basicArrayDep); \
527  myDepSheet->addDependency(funcArrayDep); \
528  \
529  RCP<DependencySheet> readInDepSheet = rcp(new DependencySheet); \
530  \
531  XMLParameterListWriter plWriter; \
532  XMLObject xmlOut = plWriter.toXML(myDepList, myDepSheet); \
533  out << xmlOut.toString(); \
534  \
535  RCP<ParameterList> readInList = \
536  writeThenReadPL(myDepList, myDepSheet, readInDepSheet); \
537  \
538  RCP<ParameterEntry> readinDependee1 = readInList->getEntryRCP(dependee1); \
539  RCP<ParameterEntry> readinDependent1 = readInList->getEntryRCP(dependent1); \
540  RCP<ParameterEntry> readinDependee2 = readInList->getEntryRCP(dependee2); \
541  RCP<ParameterEntry> readinDependent2 = readInList->getEntryRCP(dependent2); \
542  \
543  RCP<Dependency> readinDep1 = \
544  *(readInDepSheet->getDependenciesForParameter(readinDependee1)->begin()); \
545  RCP<Dependency> readinDep2 = \
546  *(readInDepSheet->getDependenciesForParameter(readinDependee2)->begin()); \
547  \
548  typedef DEPENDENCYTYPE<DependeeType, DependentType> deptype; \
549  BASIC_DEPENDENCY_TEST(readinDep1, deptype, 1, 1); \
550  VERIFY_DEPENDEE(readinDep1, readinDependee1); \
551  VERIFY_DEPENDENT(readinDep1, readinDependent1); \
552  \
553  BASIC_DEPENDENCY_TEST(readinDep2, deptype, 1, 1); \
554  VERIFY_DEPENDEE(readinDep2, readinDependee2); \
555  VERIFY_DEPENDENT(readinDep2, readinDependent2); \
556  \
557  RCP<DEPENDENCYTYPE<DependeeType, DependentType> > castedDep1 = \
558  rcp_dynamic_cast<DEPENDENCYTYPE<DependeeType, DependentType> >( \
559  readinDep1); \
560  TEST_ASSERT(castedDep1 != null); \
561  \
562  RCP<DEPENDENCYTYPE<DependeeType, DependentType> > castedDep2 = \
563  rcp_dynamic_cast<DEPENDENCYTYPE<DependeeType, DependentType> >( \
564  readinDep2); \
565  TEST_ASSERT(castedDep2 != null); \
566  \
567  RCP<const SimpleFunctionObject< DependeeType > > readInFunc = \
568  castedDep2->getFunctionObject(); \
569  TEST_ASSERT(readInFunc != null); \
570  \
571  RCP<const AdditionFunction< DependeeType > > castedFunc = \
572  rcp_dynamic_cast<const AdditionFunction< DependeeType > >(readInFunc); \
573  TEST_ASSERT(castedFunc != null); \
574  TEST_EQUALITY( \
575  castedFunc->getModifiyingOperand(), \
576  functionTester->getModifiyingOperand()); \
577 }
578 
579 ArrayModifierTest(NumberArrayLengthDependency, Array)
580 
581 #define NUM_ARRAY_LENGTH_TEST(DependeeType, DependentType) \
582 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
583  Teuchos_Dependencies, \
584  NumberArrayLengthDependency_serialization_tests, \
585  DependeeType, \
586  DependentType)
587 
588 // Need to fix array serialization so we can test this with
589 // a dependent type of strings. Right now an array of emptyr strings does not
590 // seralize correctly
591 // KLN 09.17/2010
592 #define NUM_ARRAY_LENGTH_TEST_GROUP(DependeeType) \
593  NUM_ARRAY_LENGTH_TEST(DependeeType, int) \
594  NUM_ARRAY_LENGTH_TEST(DependeeType, float) \
595  NUM_ARRAY_LENGTH_TEST(DependeeType, double) \
596  NUM_ARRAY_LENGTH_TEST(DependeeType, llint)
597 
600 
601 ArrayModifierTest(TwoDRowDependency, TwoDArray)
602 
603 #define TWODROW_TEST(DependeeType, DependentType) \
604 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
605  Teuchos_Dependencies, \
606  TwoDRowDependency_serialization_tests, \
607  DependeeType, \
608  DependentType)
609 
610 // Need to fix array serialization so we can test this with
611 // a dependent type of strings. Right now an array of empty strings does not
612 // seralize correctly
613 // KLN 09.17/2010
614 #define TWODROW_TEST_GROUP(DependeeType) \
615  TWODROW_TEST(DependeeType, int) \
616  TWODROW_TEST(DependeeType, float) \
617  TWODROW_TEST(DependeeType, double) \
618  TWODROW_TEST(DependeeType, llint)
619 
622 
623 ArrayModifierTest(TwoDColDependency, TwoDArray)
624 
625 #define TWODCOL_TEST(DependeeType, DependentType) \
626 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
627  Teuchos_Dependencies, \
628  TwoDColDependency_serialization_tests, \
629  DependeeType, \
630  DependentType)
631 
632 // Need to fix array serialization so we can test this with
633 // a dependent type of strings. Right now an array of emptyr strings does not
634 // seralize correctly
635 // KLN 09.17/2010
636 #define TWODCOL_TEST_GROUP(DependeeType) \
637  TWODCOL_TEST(DependeeType, int) \
638  TWODCOL_TEST(DependeeType, float) \
639  TWODCOL_TEST(DependeeType, double) \
640  TWODCOL_TEST(DependeeType, llint)
641 
644 
645 TEUCHOS_UNIT_TEST(Teuchos_Dependencies, StringValidatorDepSerialization){
646  std::string dependee1 = "string param";
647  std::string dependee2 = "string param2";
648  std::string dependent1 = "dependent param1";
649  std::string dependent2 = "dependent param2";
650  ParameterList myDepList("String Vali Dep List");
651  RCP<DependencySheet> myDepSheet = rcp(new DependencySheet);
652  myDepList.set(dependee1, "val1");
653  myDepList.set(dependee2, "val2");
654  myDepList.set(dependent1, 2.0);
655  myDepList.set(dependent2, 3.0);
656 
659 
662 
665 
667  valuesAndValidators["val1"] = double1Vali;
668  valuesAndValidators["val2"] = double2Vali;
669 
670  RCP<StringValidatorDependency> basicStringValiDep = rcp(
672  myDepList.getEntryRCP(dependee1),
673  myDepList.getEntryRCP(dependent1),
674  valuesAndValidators));
675 
676  Dependency::ParameterEntryList dependentList;
677  dependentList.insert(myDepList.getEntryRCP(dependent1));
678  dependentList.insert(myDepList.getEntryRCP(dependent2));
679 
680  RCP<StringValidatorDependency> complexStringValiDep = rcp(
682  myDepList.getEntryRCP(dependee2),
683  dependentList,
684  valuesAndValidators,
685  defaultVali));
686 
687  myDepSheet->addDependency(basicStringValiDep);
688  myDepSheet->addDependency(complexStringValiDep);
689 
690  RCP<DependencySheet> readInDepSheet = rcp(new DependencySheet);
691 
692  XMLParameterListWriter plWriter;
693  XMLObject xmlOut = plWriter.toXML(myDepList, myDepSheet);
694  out << xmlOut.toString();
695 
696  RCP<ParameterList> readInList =
697  writeThenReadPL(myDepList, myDepSheet, readInDepSheet);
698 
699  RCP<ParameterEntry> readinDependee1 = readInList->getEntryRCP(dependee1);
700  RCP<ParameterEntry> readinDependent1 = readInList->getEntryRCP(dependent1);
701  RCP<ParameterEntry> readinDependee2 = readInList->getEntryRCP(dependee2);
702  RCP<ParameterEntry> readinDependent2 = readInList->getEntryRCP(dependent2);
703 
704  RCP<Dependency> readinDep1 =
705  *(readInDepSheet->getDependenciesForParameter(readinDependee1)->begin());
706 
707  RCP<Dependency> readinDep2 =
708  *(readInDepSheet->getDependenciesForParameter(readinDependee2)->begin());
709 
711  VERIFY_DEPENDEE(readinDep1, readinDependee1);
712  VERIFY_DEPENDENT(readinDep1, readinDependent1);
713 
715  VERIFY_DEPENDEE(readinDep2, readinDependee2);
716  VERIFY_DEPENDENT(readinDep2, readinDependent1);
717  VERIFY_DEPENDENT(readinDep2, readinDependent2);
718 
719 
720  RCP<StringValidatorDependency> castedDep1 =
721  rcp_dynamic_cast<StringValidatorDependency>(readinDep1, true);
722  RCP<StringValidatorDependency> castedDep2 =
723  rcp_dynamic_cast<StringValidatorDependency>(readinDep2, true);
724 
725  TEST_ASSERT(castedDep1->getValuesAndValidators().size() == 2);
726  TEST_ASSERT(castedDep2->getValuesAndValidators().size() == 2);
727  TEST_ASSERT(castedDep1->getDefaultValidator().is_null());
728  TEST_ASSERT(nonnull(castedDep2->getDefaultValidator()));
729 
731  rcp_dynamic_cast<const EnhancedNumberValidator<double> >(
732  castedDep1->getValuesAndValidators().find("val1")->second, true)->getMax(),
733  double1Vali->getMax());
735  rcp_dynamic_cast<const EnhancedNumberValidator<double> >(
736  castedDep2->getValuesAndValidators().find("val1")->second, true)->getMax(),
737  double1Vali->getMax());
738 
740  rcp_dynamic_cast<const EnhancedNumberValidator<double> >(
741  castedDep1->getValuesAndValidators().find("val2")->second, true)->getMax(),
742  double2Vali->getMax());
744  rcp_dynamic_cast<const EnhancedNumberValidator<double> >(
745  castedDep2->getValuesAndValidators().find("val2")->second, true)->getMax(),
746  double2Vali->getMax());
747 
749  rcp_dynamic_cast<const EnhancedNumberValidator<double> >(
750  castedDep2->getDefaultValidator(), true)->getMax(),
751  defaultVali->getMax());
752 
753 }
754 
755 TEUCHOS_UNIT_TEST(Teuchos_Dependencies, BoolValidatorDepSerialization){
756  std::string dependee1 = "bool param";
757  std::string dependee2 = "bool param2";
758  std::string dependent1 = "dependent param1";
759  std::string dependent2 = "dependent param2";
760  ParameterList myDepList("Bool Vali Dep List");
761  RCP<DependencySheet> myDepSheet = rcp(new DependencySheet);
762  myDepList.set(dependee1, true);
763  myDepList.set(dependee2, false);
764  myDepList.set(dependent1, 2.0);
765  myDepList.set(dependent2, 3.0);
766 
769 
772 
775 
776 
777  RCP<BoolValidatorDependency> simpleBoolValiDep = rcp(
779  myDepList.getEntryRCP(dependee1),
780  myDepList.getEntryRCP(dependent1),
781  true1Vali,
782  false1Vali));
783 
784  Dependency::ParameterEntryList dependentList;
785  dependentList.insert(myDepList.getEntryRCP(dependent1));
786  dependentList.insert(myDepList.getEntryRCP(dependent2));
787 
788  RCP<BoolValidatorDependency> complexBoolValiDep = rcp(
790  myDepList.getEntryRCP(dependee2),
791  dependentList,
792  true2Vali));
793 
794  myDepSheet->addDependency(simpleBoolValiDep);
795  myDepSheet->addDependency(complexBoolValiDep);
796 
797  RCP<DependencySheet> readInDepSheet = rcp(new DependencySheet);
798 
799  XMLParameterListWriter plWriter;
800  XMLObject xmlOut = plWriter.toXML(myDepList, myDepSheet);
801  out << xmlOut.toString();
802 
803  RCP<ParameterList> readInList =
804  writeThenReadPL(myDepList, myDepSheet, readInDepSheet);
805 
806  RCP<ParameterEntry> readinDependee1 = readInList->getEntryRCP(dependee1);
807  RCP<ParameterEntry> readinDependent1 = readInList->getEntryRCP(dependent1);
808  RCP<ParameterEntry> readinDependee2 = readInList->getEntryRCP(dependee2);
809  RCP<ParameterEntry> readinDependent2 = readInList->getEntryRCP(dependent2);
810 
811  RCP<Dependency> readinDep1 =
812  *(readInDepSheet->getDependenciesForParameter(readinDependee1)->begin());
813 
814  RCP<Dependency> readinDep2 =
815  *(readInDepSheet->getDependenciesForParameter(readinDependee2)->begin());
816 
818  VERIFY_DEPENDEE(readinDep1, readinDependee1);
819  VERIFY_DEPENDENT(readinDep1, readinDependent1);
820 
822  VERIFY_DEPENDEE(readinDep2, readinDependee2);
823  VERIFY_DEPENDENT(readinDep2, readinDependent1);
824  VERIFY_DEPENDENT(readinDep2, readinDependent2);
825 
826 
827  RCP<BoolValidatorDependency> castedDep1 =
828  rcp_dynamic_cast<BoolValidatorDependency>(readinDep1, true);
829  RCP<BoolValidatorDependency> castedDep2 =
830  rcp_dynamic_cast<BoolValidatorDependency>(readinDep2, true);
831 
832  TEST_ASSERT(nonnull(castedDep1->getTrueValidator()));
833  TEST_ASSERT(nonnull(castedDep1->getFalseValidator()));
834  TEST_ASSERT(nonnull(castedDep2->getTrueValidator()));
835  TEST_ASSERT(castedDep2->getFalseValidator().is_null());
837  rcp_dynamic_cast<const EnhancedNumberValidator<double> >(
838  castedDep1->getTrueValidator(), true)->getMax(),
839  true1Vali->getMax());
841  rcp_dynamic_cast<const EnhancedNumberValidator<double> >(
842  castedDep1->getFalseValidator(), true)->getMax(),
843  false1Vali->getMax());
845  rcp_dynamic_cast<const EnhancedNumberValidator<double> >(
846  castedDep2->getTrueValidator(), true)->getMax(),
847  true2Vali->getMax());
848 
849 }
850 
851 
853  Teuchos_Dependencies, RangeValidatorDepSerialization, T)
854 {
855  std::string dependee1 = "dependee param";
856  std::string dependee2 = "dependee param2";
857  std::string dependent1 = "dependent param1";
858  std::string dependent2 = "dependent param2";
859  ParameterList myDepList("Range Vali Dep List");
860  RCP<DependencySheet> myDepSheet = rcp(new DependencySheet);
861  myDepList.set(dependee1, ScalarTraits<T>::one());
862  myDepList.set(dependee2, ScalarTraits<T>::one());
863  myDepList.set(dependent1, 2.0);
864  myDepList.set(dependent2, 3.0);
865 
868 
871 
872  RCP<EnhancedNumberValidator<double> > defaultValidator =
874 
875  typename RangeValidatorDependency<T>::Range range1(0,10);
876  typename RangeValidatorDependency<T>::Range range2(11,50);
877 
879  rangeValiMap[range1] = double1Vali;
880  rangeValiMap[range2] = double2Vali;
881 
882  RCP<RangeValidatorDependency<T> > simpleRangeValiDep = rcp(
884  myDepList.getEntryRCP(dependee1),
885  myDepList.getEntryRCP(dependent1),
886  rangeValiMap));
887 
888  Dependency::ParameterEntryList dependentList;
889  dependentList.insert(myDepList.getEntryRCP(dependent1));
890  dependentList.insert(myDepList.getEntryRCP(dependent2));
891 
892  RCP<RangeValidatorDependency<T> > complexRangeValiDep = rcp(
894  myDepList.getEntryRCP(dependee2),
895  dependentList,
896  rangeValiMap,
897  defaultValidator));
898 
899  myDepSheet->addDependency(simpleRangeValiDep);
900  myDepSheet->addDependency(complexRangeValiDep);
901 
902  RCP<DependencySheet> readInDepSheet = rcp(new DependencySheet);
903 
904  XMLParameterListWriter plWriter;
905  XMLObject xmlOut = plWriter.toXML(myDepList, myDepSheet);
906  out << xmlOut.toString();
907 
908  RCP<ParameterList> readInList =
909  writeThenReadPL(myDepList, myDepSheet, readInDepSheet);
910 
911  RCP<ParameterEntry> readinDependee1 = readInList->getEntryRCP(dependee1);
912  RCP<ParameterEntry> readinDependent1 = readInList->getEntryRCP(dependent1);
913  RCP<ParameterEntry> readinDependee2 = readInList->getEntryRCP(dependee2);
914  RCP<ParameterEntry> readinDependent2 = readInList->getEntryRCP(dependent2);
915 
916  RCP<Dependency> readinDep1 =
917  *(readInDepSheet->getDependenciesForParameter(readinDependee1)->begin());
918 
919  RCP<Dependency> readinDep2 =
920  *(readInDepSheet->getDependenciesForParameter(readinDependee2)->begin());
921 
923  VERIFY_DEPENDEE(readinDep1, readinDependee1);
924  VERIFY_DEPENDENT(readinDep1, readinDependent1);
925 
927  VERIFY_DEPENDEE(readinDep2, readinDependee2);
928  VERIFY_DEPENDENT(readinDep2, readinDependent1);
929  VERIFY_DEPENDENT(readinDep2, readinDependent2);
930 
931 
932  RCP<RangeValidatorDependency<T> > castedDep1 =
933  rcp_dynamic_cast<RangeValidatorDependency<T> >(readinDep1, true);
934  RCP<RangeValidatorDependency<T> > castedDep2 =
935  rcp_dynamic_cast<RangeValidatorDependency<T> >(readinDep2, true);
936 
938  castedDep1->getRangeToValidatorMap();
939  TEST_EQUALITY(readinMap1.size(), 2);
941  readinMap1.begin();
942  TEST_EQUALITY(it->first.first, 0);
943  TEST_EQUALITY(it->first.second, 10);
944  it++;
945  TEST_EQUALITY(it->first.first, 11);
946  TEST_EQUALITY(it->first.second, 50);
947 
948 
950  readinMap1.find(range1)->second;
952  readinMap1.find(range2)->second;
954  rcp_dynamic_cast<const EnhancedNumberValidator<double> >(
955  range1Vali, true)->getMax(),
956  double1Vali->getMax());
958  rcp_dynamic_cast<const EnhancedNumberValidator<double> >(
959  range2Vali, true)->getMax(),
960  double2Vali->getMax());
961 
963  castedDep2->getRangeToValidatorMap();
964  it = readinMap2.begin();
965  TEST_EQUALITY(it->first.first, 0);
966  TEST_EQUALITY(it->first.second, 10);
967  it++;
968  TEST_EQUALITY(it->first.first, 11);
969  TEST_EQUALITY(it->first.second, 50);
970 
972  rcp_dynamic_cast<const EnhancedNumberValidator<double> >(
973  readinMap2.find(range1)->second, true)->getMax(),
974  double1Vali->getMax());
976  rcp_dynamic_cast<const EnhancedNumberValidator<double> >(
977  readinMap2.find(range2)->second, true)->getMax(),
978  double2Vali->getMax());
979 
980  RCP<const EnhancedNumberValidator<double> > defaultReadInVali =
981  rcp_dynamic_cast<const EnhancedNumberValidator<double> >(
982  castedDep2->getDefaultValidator());
983  TEST_EQUALITY( defaultReadInVali->getMax(), defaultValidator->getMax());
984  TEST_EQUALITY( defaultReadInVali->getMin(), defaultValidator->getMin());
985 }
986 
987 
988 #define RANGE_VALIDATOR_TEST(T) \
989 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( \
990  Teuchos_Dependencies, RangeValidatorDepSerialization, T)
991 
993 RANGE_VALIDATOR_TEST(double)
996 
997 /* General Testing*/
998 TEUCHOS_UNIT_TEST(Teuchos_Dependencies, DependencySerializationExceptions){
999 
1000  RCP<DependencySheet> depSheet = rcp(new DependencySheet);
1001 
1002  TEST_THROW(RCP<ParameterList> missingDependeeList =
1003  getParametersFromXmlFile("MissingDependeeTag.xml", depSheet),
1005  TEST_THROW(RCP<ParameterList> missingDependentsList =
1006  getParametersFromXmlFile("MissingDependentTag.xml", depSheet),
1008  TEST_THROW(RCP<ParameterList> missingDependeeList =
1009  getParametersFromXmlFile("MissingDependee.xml", depSheet),
1011  TEST_THROW(RCP<ParameterList> missingDependentList =
1012  getParametersFromXmlFile("MissingDependent.xml", depSheet),
1014 
1015  RCP<ParameterEntry> dependeeParam = rcp(new ParameterEntry(true));
1016  RCP<ParameterEntry> dependentParam = rcp(new ParameterEntry("blah"));
1017  RCP<BoolVisualDependency> boolVisDep =
1018  rcp(new BoolVisualDependency(dependeeParam, dependentParam));
1019 
1021  entryIDsMap[dependentParam] = 1;
1022  ValidatortoIDMap validatorIDsMap;
1023  BoolVisualDependencyXMLConverter boolVisConverter;
1024  TEST_THROW(
1025  boolVisConverter.fromDependencytoXML(
1026  boolVisDep, entryIDsMap, validatorIDsMap),
1028  entryIDsMap.erase(dependentParam);
1029  entryIDsMap[dependeeParam] = 3;
1030  TEST_THROW(
1031  boolVisConverter.fromDependencytoXML(
1032  boolVisDep, entryIDsMap, validatorIDsMap),
1034 }
1035 
1036 /* Testing serialization exceptions for NumberVisualDependencies */
1037 
1038 TEUCHOS_UNIT_TEST(Teuchos_Dependencies, NumberVisualDepSerializationExceptions){
1039 
1040  EXCEPTION_TEST_BOILERPLATE(4, "blah");
1041  RCP<Dependency> numVisDep =
1042  rcp(new NumberVisualDependency<int>(dependeeParam1, dependentParam1));
1043  CONVERT_DEP_TO_XML(numVisDep);
1044  TOO_MANY_DEPENDEE_TEST(numVisDep);
1045 
1046 }
1047 
1048 TEUCHOS_UNIT_TEST(Teuchos_Dependencies, BoolVisualDepSerializationExceptions){
1049  EXCEPTION_TEST_BOILERPLATE(true, "blah");
1050  RCP<Dependency> boolVisDep =
1051  rcp(new BoolVisualDependency(dependeeParam1, dependentParam1));
1052  CONVERT_DEP_TO_XML(boolVisDep);
1053  TOO_MANY_DEPENDEE_TEST(boolVisDep);
1054 }
1055 
1056 TEUCHOS_UNIT_TEST(Teuchos_Dependencies, StringVisualDepSerializationExceptions)
1057 {
1058  EXCEPTION_TEST_BOILERPLATE(std::string("balh"), 4);
1059  RCP<Dependency> stringVisDep =
1060  rcp(new StringVisualDependency(dependeeParam1, dependentParam1, "steve"));
1061  CONVERT_DEP_TO_XML(stringVisDep);
1062  TOO_MANY_DEPENDEE_TEST(stringVisDep);
1063 
1065  stringVisDepXML,
1067  missingValuesXML);
1068 
1069  TEST_THROW(
1071  missingValuesXML, readerEntryMap, readerValiMap),
1073 
1074 }
1075 
1077  Teuchos_Dependencies, ConditionVisualDepSerializationExceptions)
1078 {
1079  EXCEPTION_TEST_BOILERPLATE(true, 4);
1080  RCP<Condition> boolCon = rcp(new BoolCondition(dependeeParam1));
1081  RCP<Dependency> conVisDep =
1082  rcp(new ConditionVisualDependency(boolCon, dependentParam1));
1083  CONVERT_DEP_TO_XML(conVisDep);
1085  conVisDepXML,
1087  missingConXML);
1088 
1089  TEST_THROW(
1091  missingConXML, readerEntryMap, readerValiMap),
1093 }
1094 
1096  Teuchos_Dependencies, BoolValidatorDepSerializationExceptions)
1097 {
1098  EXCEPTION_TEST_BOILERPLATE(true, 7);
1101  RCP<EnhancedNumberValidator<int> > falseVali =
1103  INSERT_VALIDATOR_TO_MAPS(trueVali);
1104  INSERT_VALIDATOR_TO_MAPS(falseVali);
1105  RCP<Dependency> boolValiDep =
1107  dependeeParam1,
1108  dependentParam1,
1109  trueVali,
1110  falseVali));
1111  CONVERT_DEP_TO_XML(boolValiDep);
1112  TOO_MANY_DEPENDEE_TEST(boolValiDep);
1113 
1114  readerValiMap.erase(writerValiMap.find(trueVali)->second);
1115 
1116  TEST_THROW(
1118  boolValiDepXML, readerEntryMap, readerValiMap),
1120 
1121  readerValiMap.insert( IDtoValidatorMap::IDValidatorPair(
1122  writerValiMap.find(trueVali)->second, trueVali));
1123  readerValiMap.erase(writerValiMap.find(falseVali)->second);
1124 
1125  TEST_THROW(
1127  boolValiDepXML, readerEntryMap, readerValiMap),
1129 
1130 }
1131 
1133  Teuchos_Dependencies, StringValidatorDepSerializationExceptions)
1134 {
1135  EXCEPTION_TEST_BOILERPLATE(std::string("blah"), 4);
1136  RCP<FileNameValidator> scrapVali =
1138  RCP<FileNameValidator> scrapVali2 =
1141  valiMap["blah"] = scrapVali;
1142  INSERT_VALIDATOR_TO_MAPS(scrapVali);
1143  INSERT_VALIDATOR_TO_MAPS(scrapVali2);
1144 
1145  RCP<Dependency> stringValiDep =
1147  dependeeParam1, dependentParam1, valiMap, scrapVali2));
1148  CONVERT_DEP_TO_XML(stringValiDep);
1149 
1150  TOO_MANY_DEPENDEE_TEST(stringValiDep);
1151 
1153  stringValiDepXML,
1155  missingValuesXML);
1156 
1157  TEST_THROW(
1159  missingValuesXML, readerEntryMap, readerValiMap),
1161 
1162  readerValiMap.erase(writerValiMap.find(scrapVali)->second);
1163 
1164  TEST_THROW(
1166  stringValiDepXML, readerEntryMap, readerValiMap),
1168 
1169  readerValiMap.insert( IDtoValidatorMap::IDValidatorPair(
1170  writerValiMap.find(scrapVali)->second,scrapVali));
1171  readerValiMap.erase(writerValiMap.find(scrapVali2)->second);
1172 
1173  TEST_THROW(
1175  stringValiDepXML, readerEntryMap, readerValiMap),
1177 }
1178 
1180  Teuchos_Dependencies, RangeValidatorDepSerializationExceptions)
1181 {
1182  EXCEPTION_TEST_BOILERPLATE(3, "blah");
1183 
1184  RCP<FileNameValidator> scrapVali =
1186  RCP<FileNameValidator> otherScrapVali =
1188  RCP<FileNameValidator> defaultScrapVali =
1192  RangeValidatorDependency<int>::Range scrapRange(2,5);
1193  valiMap[scrapRange] = scrapVali;
1194  secondvaliMap[scrapRange] = otherScrapVali;
1195  writerValiMap.insert(scrapVali);
1196  writerValiMap.insert(otherScrapVali);
1197  writerValiMap.insert(defaultScrapVali);
1198  readerValiMap.insert(
1200  writerValiMap.find(scrapVali)->second,scrapVali));
1201  readerValiMap.insert(
1203  writerValiMap.find(otherScrapVali)->second,otherScrapVali));
1204  readerValiMap.insert(
1206  writerValiMap.find(defaultScrapVali)->second,defaultScrapVali));
1207 
1208  RCP<Dependency> rangeDep =
1210  dependeeParam1, dependentParam1, valiMap));
1211 
1212  RCP<Dependency> rangeDefaultDep =
1214  dependeeParam1, dependentParam1, secondvaliMap, defaultScrapVali));
1215 
1216  CONVERT_DEP_TO_XML(rangeDep);
1217  CONVERT_DEP_TO_XML(rangeDefaultDep);
1218 
1219  TOO_MANY_DEPENDEE_TEST(rangeDep);
1220 
1222  rangeDepXML,
1224  missingRangesXML
1225  )
1226 
1227  TEST_THROW(
1229  missingRangesXML, readerEntryMap, readerValiMap),
1231 
1232  readerValiMap.erase(writerValiMap.find(scrapVali)->second);
1233 
1234  TEST_THROW(
1236  rangeDepXML, readerEntryMap, readerValiMap),
1238 
1239  readerValiMap.erase(writerValiMap.find(defaultScrapVali)->second);
1240  TEST_THROW(
1242  rangeDefaultDepXML, readerEntryMap, readerValiMap),
1244 
1245 }
1246 
1248  Teuchos_Dependencies, NumArrayLengthDepSerializationExceptions)
1249 {
1251  RCP<Dependency> numArrayLengthDep =
1253  dependeeParam1, dependentParam1));
1254  CONVERT_DEP_TO_XML(numArrayLengthDep);
1255  TOO_MANY_DEPENDEE_TEST(numArrayLengthDep);
1256 }
1257 
1260  Teuchos_Dependencies, DepSheetTests)
1261 {
1262  ParameterList myDepList("String Visual Dep List");
1263  std::string dependee1 = "dependee1";
1264  std::string dependent1 = "dependent1";
1265  RCP<DependencySheet> myDepSheet = rcp(new DependencySheet("My List"));
1266  myDepList.set(dependee1, "val1");
1267  myDepList.set(dependent1, 2.0);
1268  StringVisualDependency::ValueList valList1 = tuple<std::string>("val1");
1269  RCP<StringVisualDependency> basicStringVisDep = rcp(
1271  myDepList.getEntryRCP(dependee1),
1272  myDepList.getEntryRCP(dependent1),
1273  valList1));
1274  myDepSheet->addDependency(basicStringVisDep);
1275 
1276  RCP<DependencySheet> readInDepSheet = rcp(new DependencySheet);
1277 
1278  XMLParameterListWriter plWriter;
1279  XMLObject xmlOut = plWriter.toXML(myDepList, myDepSheet);
1280  out << xmlOut.toString();
1281 
1282  RCP<ParameterList> readInList =
1283  writeThenReadPL(myDepList, myDepSheet, readInDepSheet);
1284  TEST_EQUALITY(readInDepSheet->getName(), myDepSheet->getName());
1285 }
1286 
1287 
1288 } //namespace Teuchos
1289 
#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 dependency 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.
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)
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Templated set method.
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.