Commit 191a3336 authored by Nicolas Philipps's avatar Nicolas Philipps
Browse files

Fixed fwAtomsBoostIO issue when hiting a cache value stored in a Atoms::Map, added unit tests

--HG--
branch : fw4spl_0.9.1
extra : source : 4f26c0c48d723217d1f157a0b20f11f66c8b5470
parent a71bd7e1
......@@ -111,13 +111,14 @@ void cache(const std::string &ptpath, const AtomCacheType::mapped_type &atom)
BOOST_FOREACH( const ::boost::property_tree::ptree::value_type &val, pt.get_child("map") )
{
std::string subPath = ptpath + (ptpath.empty()?"":".") + "map." + val.first + ".value";
::boost::property_tree::ptree mapChild = val.second;
::boost::property_tree::ptree value = mapChild.get_child("value");
std::string key = mapChild.get<std::string>("key");
::fwAtoms::Base::sptr subAtom = this->visit(
value, ptpath + (ptpath.empty()?"":".")+ "map.item." + key );
::fwAtoms::Base::sptr subAtom = this->visit( value, subPath );
std::string key = mapChild.get<std::string>("key");
atom->insert( key, subAtom );
}
return atom;
......
#include <sstream>
#include <boost/foreach.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/xml_parser.hpp>
#include <boost/lexical_cast.hpp>
#include <fwTools/UUID.hpp>
#include <fwTools/IBufferManager.hpp>
......@@ -101,13 +101,15 @@ void cache(const PropTreeCacheType::key_type &atom, const std::string &ptpath)
::boost::property_tree::ptree map;
this->cache(atom, ptpath);
std::string path = ptpath + (ptpath.empty()?"":".") + "map";
unsigned long long count = 0;
BOOST_FOREACH(const ::fwAtoms::Map::MapType::value_type& elt, atom->getValue())
{
const std::string nodeName = "item_" + ::boost::lexical_cast< std::string >(count++);
::boost::property_tree::ptree mapChild;
mapChild.put("key", elt.first);
mapChild.add_child("value", this->visit(elt.second, path + "." + elt.first));
mapChild.add_child("value", this->visit(elt.second, path + "." + nodeName + ".value"));
map.add_child("item", mapChild);
map.add_child(nodeName, mapChild);
}
pt.add_child("map", map);
return pt;
......@@ -122,12 +124,11 @@ void cache(const PropTreeCacheType::key_type &atom, const std::string &ptpath)
this->cache(atom, ptpath);
std::string path = ptpath + (ptpath.empty()?"":".") + "sequence";
unsigned long long int i = 0;
unsigned long long count = 0;
BOOST_FOREACH( const ::fwAtoms::Sequence::SequenceType::value_type& elt, atom->getValue())
{
std::stringstream sstr;
sstr << i++;
seq.add_child(sstr.str(), this->visit(elt, path + "." + sstr.str()));
const std::string nodeName = ::boost::lexical_cast< std::string >(count++);
seq.add_child(nodeName, this->visit(elt, path + "." + nodeName));
}
pt.add_child("sequence", seq);
return pt;
......@@ -144,12 +145,14 @@ void cache(const PropTreeCacheType::key_type &atom, const std::string &ptpath)
const ::fwAtoms::Object::MetaInfosType& metaInfos = atom->getMetaInfos();
::boost::property_tree::ptree metaInfosPt;
unsigned long long count = 0;
BOOST_FOREACH(const ::fwAtoms::Object::MetaInfosType::value_type& info, metaInfos)
{
const std::string nodeName = "item_" + ::boost::lexical_cast< std::string >(count++);
::boost::property_tree::ptree item;
item.put("key", info.first);
item.put("value", info.second);
metaInfosPt.push_back(::boost::property_tree::ptree::value_type("item", item));
metaInfosPt.push_back(::boost::property_tree::ptree::value_type(nodeName, item));
}
object.add_child("meta_infos", metaInfosPt);
......
......@@ -60,7 +60,7 @@ struct SequenceGenerator
SequenceGenerator()
{
META_KEY_0 = "info.a<b>.c.0";
META_KEY_1 = "info.a<b>.c.1";
META_KEY_1 = "info.a<b>.c.{1:d}";
META_KEY_2 = "info.a<b>.c.2";
META_KEY_3 = "info.a<b>.c.3";
META_VALUE_0 = "A";
......@@ -121,6 +121,15 @@ struct SequenceGenerator
m_seq->push_back(num2);
m_seq->push_back(boolTrue);
// tests the case of a a cache path hiting an object stored in a map
::fwAtoms::Map::sptr map2 = ::fwAtoms::Map::New();
::fwAtoms::Object::sptr obj2 = ::fwAtoms::Object::New();
map2->insert("obj2 ref1", obj2);
map2->insert("obj2 ref2", obj2);
map->insert("sequence loop key", m_seq);
map->insert("object one more ref", obj);
map->insert("map2", map2);
map->insert("blob key", ::fwAtoms::Blob::New());
map->insert("object key", ::fwAtoms::Object::New());
map->insert("sequence key", ::fwAtoms::String::New("map-str"));
......@@ -155,9 +164,23 @@ struct SequenceGenerator
::fwAtoms::Numeric::sptr readNum2 = ::fwAtoms::Numeric::dynamicCast((*readSeq)[9]);
::fwAtoms::Boolean::sptr readBoolT = ::fwAtoms::Boolean::dynamicCast((*readSeq)[10]);
CPPUNIT_ASSERT( readObj0 );
CPPUNIT_ASSERT( readObj1 );
CPPUNIT_ASSERT( readBlob );
CPPUNIT_ASSERT( readMap );
CPPUNIT_ASSERT( readSeq2 );
CPPUNIT_ASSERT( readBoolF );
CPPUNIT_ASSERT( readNum );
CPPUNIT_ASSERT( readStr );
CPPUNIT_ASSERT( !readNull );
CPPUNIT_ASSERT( readNum2 );
CPPUNIT_ASSERT( readBoolT );
::fwTools::BufferObject::sptr bo = blob->getBufferObject();
::fwTools::BufferObject::sptr readBo = readBlob->getBufferObject();
CPPUNIT_ASSERT( readBo );
CPPUNIT_ASSERT_EQUAL( bo->getSize(), readBo->getSize() );
::fwTools::BufferObject::Lock lock(bo->lock());
......@@ -167,23 +190,13 @@ struct SequenceGenerator
void *readV = readLock.getBuffer();
char* buff = static_cast<char*>(v);
char* readBuff = static_cast<char*>(readV);
CPPUNIT_ASSERT(readBlob);
for (size_t i = 0; i < bo->getSize(); ++i)
{
CPPUNIT_ASSERT_EQUAL( buff[i], readBuff[i] );
}
CPPUNIT_ASSERT( readObj0 );
CPPUNIT_ASSERT( readObj1 );
CPPUNIT_ASSERT( readBlob );
CPPUNIT_ASSERT( readMap );
CPPUNIT_ASSERT( readSeq2 );
CPPUNIT_ASSERT( readBoolF );
CPPUNIT_ASSERT( readNum );
CPPUNIT_ASSERT( readStr );
CPPUNIT_ASSERT( !readNull );
CPPUNIT_ASSERT( readNum2 );
CPPUNIT_ASSERT( readBoolT );
CPPUNIT_ASSERT_EQUAL( readObj0, readObj1 );
CPPUNIT_ASSERT_EQUAL( readSeq, readSeq2 );
......
Supports Markdown
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