Commit 6d605449 authored by T.J. Corona's avatar T.J. Corona Committed by Kitware Robot

Merge topic 'extensible-attribute-copy-test'

b6fd4326 Fix a bug in StringItem/ValueItemTemplate::assign + extensible items.
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: John Tourtellott's avatarJohn Tourtellott <john.tourtellott@kitware.com>
Merge-request: !356
parents e61d486a b6fd4326
......@@ -375,6 +375,7 @@ bool FileSystemItem::assign(ConstItemPtr &sourceItem, unsigned int options)
return false; // Source is not a directory item!
}
this->setNumberOfValues(sourceDirItem->numberOfValues());
for (std::size_t i=0; i<sourceDirItem->numberOfValues(); ++i)
{
if (sourceDirItem->isSet(i))
......
......@@ -143,7 +143,7 @@ smtk::attribute::AttributePtr System::createAttribute(const std::string &typeNam
{
return smtk::attribute::AttributePtr();
}
smtk::attribute::AttributePtr att =
this->createAttribute(this->createUniqueName(def->rootName()), def);
return att;
......@@ -760,7 +760,7 @@ System::copyAttribute(const smtk::attribute::AttributePtr sourceAtt,
//TODO Should make sure the definition we found matches the structure of the definition
// used by the Source Attribute if they don't then error out
}
std::string name = sourceAtt->name();
if (this->findAttribute(name))
{
......
......@@ -576,6 +576,7 @@ namespace smtk
return false; // Source is not the right type of item
}
// Update values
this->setNumberOfValues(sourceValueItemTemplate->numberOfValues());
for (std::size_t i=0; i<sourceValueItemTemplate->numberOfValues(); ++i)
{
if (sourceValueItemTemplate->isSet(i) &&
......
......@@ -10,6 +10,7 @@ set(attributeTests
discreteStringsWithDefaultTest
expressionTest
expressionTest2
extensibleAttributeCopyTest
attributeAssociationTest
attributeAutoNamingTest
attributeReferencingTest
......
//=========================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//=========================================================================
#include "smtk/attribute/System.h"
#include "smtk/attribute/Definition.h"
#include "smtk/attribute/Attribute.h"
#include "smtk/io/AttributeReader.h"
#include "smtk/io/Logger.h"
#include "smtk/attribute/FileItem.h"
#include "smtk/attribute/StringItem.h"
#include <iostream>
namespace
{
const char* testInput =
"<?xml version=\"1.0\" encoding=\"utf-8\" ?> "
"<SMTK_AttributeSystem Version=\"2\"> "
" <Definitions> "
" <AttDef Type=\"att1\" BaseType=\"\"> "
" <ItemDefinitions> "
" <String Name=\"myStrings\" Extensible=\"1\" "
" NumberOfRequiredValues=\"1\"> "
" </String> "
" <File Name=\"myFiles\" Extensible=\"1\" ShouldExist=\"false\" "
" NumberOfRequiredValues=\"1\"> "
" </File> "
" </ItemDefinitions> "
" </AttDef> "
" </Definitions> "
" <Attributes> "
" <Att Name=\"att\" Type=\"att1\"/> "
" </Attributes> "
"</SMTK_AttributeSystem> "
;
}
int main()
{
smtk::attribute::System system;
smtk::io::Logger logger;
smtk::io::AttributeReader reader;
if (reader.readContents(system, testInput, logger))
{
std::cerr << "Encountered Errors while reading input data\n";
std::cerr << logger.convertToString();
return -2;
}
std::vector<smtk::attribute::AttributePtr> atts;
system.attributes(atts);
if (atts.size() != 1)
{
std::cerr << "Unexpected number of attributes: "<<atts.size()<<"\n";
std::cerr << logger.convertToString();
return -2;
}
smtk::attribute::AttributePtr att = atts[0];
smtk::attribute::StringItemPtr myStrings = att->findString("myStrings");
myStrings->setNumberOfValues(2);
myStrings->setValue(0, "string0");
myStrings->setValue(1, "string1");
smtk::attribute::FileItemPtr myFiles = att->findFile("myFiles");
myFiles->setNumberOfValues(2);
myFiles->setValue(0, "/path/to/file0");
myFiles->setValue(1, "/path/to/file1");
{
std::vector<smtk::attribute::AttributePtr> copiedAtts;
system.attributes(copiedAtts);
if (copiedAtts.size() != 1)
{
std::cerr << "Unexpected number of attributes: "<<copiedAtts.size()<<"\n";
std::cerr << logger.convertToString();
return -2;
}
smtk::attribute::AttributePtr copiedAtt = copiedAtts[0];
smtk::attribute::StringItemPtr myCopiedStrings =
copiedAtt->findString("myStrings");
smtk::attribute::ItemPtr myStringsAsItems =
std::static_pointer_cast<smtk::attribute::Item>(myStrings);
smtk::attribute::ConstItemPtr myStringsAsConstItems =
std::const_pointer_cast<smtk::attribute::Item>(myStringsAsItems);
myCopiedStrings->assign(myStringsAsConstItems);
if (myCopiedStrings->numberOfValues() != myStrings->numberOfValues())
{
std::cerr << "Unexpected number of string values: "<<myCopiedStrings->numberOfValues()<<" vs "<<myStrings->numberOfValues()<<"\n";
std::cerr << logger.convertToString();
return -2;
}
smtk::attribute::FileItemPtr myCopiedFiles = copiedAtt->findFile("myFiles");
smtk::attribute::ItemPtr myFilesAsItems =
std::static_pointer_cast<smtk::attribute::Item>(myFiles);
smtk::attribute::ConstItemPtr myFilesAsConstItems =
std::const_pointer_cast<smtk::attribute::Item>(myFilesAsItems);
myCopiedFiles->assign(myFilesAsConstItems);
if (myCopiedFiles->numberOfValues() != myFiles->numberOfValues())
{
std::cerr << "Unexpected number of file values: "<<myCopiedFiles->numberOfValues()<<" vs "<<myFiles->numberOfValues()<<"\n";
std::cerr << logger.convertToString();
return -2;
}
}
{
smtk::attribute::AttributePtr copiedAtt = system.copyAttribute(att);
if (!copiedAtt)
{
std::cerr << "Failed to copy attribute" << "\n";
std::cerr << logger.convertToString();
return -2;
}
if (!copiedAtt->isValid())
{
std::cerr << "Copied attribute is invalid" << "\n";
std::cerr << logger.convertToString();
return -2;
}
if (copiedAtt->numberOfItems() != 2)
{
std::cerr << "Copy attribute produced unexpected results" << "\n";
std::cerr << logger.convertToString();
return -2;
}
smtk::attribute::StringItemPtr myCopiedStrings =
copiedAtt->findString("myStrings");
if (myCopiedStrings->numberOfValues() != myStrings->numberOfValues())
{
std::cerr << "Unexpected number of string values: "<<myCopiedStrings->numberOfValues()<<" vs "<<myStrings->numberOfValues()<<"\n";
std::cerr << logger.convertToString();
return -2;
}
smtk::attribute::FileItemPtr myCopiedFiles = copiedAtt->findFile("myFiles");
if (myCopiedFiles->numberOfValues() != myFiles->numberOfValues())
{
std::cerr << "Unexpected number of file values: "<<myCopiedFiles->numberOfValues()<<" vs "<<myFiles->numberOfValues()<<"\n";
std::cerr << logger.convertToString();
return -2;
}
}
return 0;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment