Esempio n. 1
0
TEUCHOS_UNIT_TEST(Teuchos_ParameterList, parameterEntryXMLConverters)
{
    ParameterList myList;
    ADD_TYPE_AND_ARRAY_TYPE_PARAMETER(int, 2);
    ADD_TYPE_AND_ARRAY_TYPE_PARAMETER(unsigned int, 3);
    ADD_TYPE_AND_ARRAY_TYPE_PARAMETER(short int, 4);
    ADD_TYPE_AND_ARRAY_TYPE_PARAMETER(unsigned short int, 5);
    ADD_TYPE_AND_ARRAY_TYPE_PARAMETER(long int, 6);
    ADD_TYPE_AND_ARRAY_TYPE_PARAMETER(unsigned long int, 7);
#ifdef HAVE_TEUCHOS_LONG_LONG_INT
    ADD_TYPE_AND_ARRAY_TYPE_PARAMETER(long long int, 8);
    ADD_TYPE_AND_ARRAY_TYPE_PARAMETER(unsigned long long int, 9);
#endif //HAVE_TEUCHOS_LONG_LONG_INT
    ADD_TYPE_AND_ARRAY_TYPE_PARAMETER(double, 10.0);
    ADD_TYPE_AND_ARRAY_TYPE_PARAMETER(float, 11.0);

    ADD_TYPE_AND_ARRAY_TYPE_PARAMETER(std::string, "hello");

    ADD_TYPE_PARAMETER(char, 'a');
    ADD_TYPE_PARAMETER(bool, true);

    RCP<ParameterList> readInPL = writeThenReadPL(myList);

    out << "\nmyList:\n";
    myList.print(out);
    out << "\n*readInPL:\n";
    readInPL->print(out);

    TEST_ASSERT(haveSameValues(myList, *readInPL));
}
bool Teuchos::haveSameValues( const ParameterList& list1, const ParameterList& list2 )
{
  // Check that the top-level names of the two parameter lists are the same
  //const std::string &paramListName1 = list1.name();
  //const std::string &paramListName2 = list2.name();
  //if ( paramListName1 != paramListName2 ) {
  //  return false;
  //}
  ParameterList::ConstIterator itr1, itr2;
  for(
    itr1 = list1.begin(), itr2 = list2.begin();
    itr1 != list1.end() && itr2 != list2.end();
    ++itr1, ++itr2
    )
  {
    const std::string    &entryName1   = list1.name(itr1);
    const std::string    &entryName2   = list2.name(itr2);
    const ParameterEntry &entry1       = list1.entry(itr1);
    const ParameterEntry &entry2       = list2.entry(itr2);
    if( entryName1 != entryName2 ) {
      return false;
    }
    if( entry1.isList() && entry2.isList() ) {
      if (
        !haveSameValues(
          getValue<ParameterList>(entry1),
          getValue<ParameterList>(entry2))
        )
      {
        // Note: Above we cast to a non-const ParameterList even through we
        // only need a const ParameterList.  We have to do this since a
        // non-const ParameterList is always added initially which determines
        // the value.
        return false;
      }
    }
    else {
      if( entry1.getAny() != entry2.getAny() ) {
        return false;
      }
    }
  }
  // Check that the two parameter lists are the same length:
  if ((itr1 != list1.end()) || (itr2 != list2.end())) {
    return false;
  }
  return true;
}