Beispiel #1
0
void XmlWriter::writeObjectData( QXmlStreamWriter &stream, const Object *object )
{
    Q_ASSERT( object );

    // Flags
    const QSet<QByteArray> flags = object->flags();
    for( QSet<QByteArray>::const_iterator it = flags.constBegin(); it != flags.constEnd(); ++it ) {
        stream.writeTextElement( "flag", ( *it ) );
    }

    // Attributes
    const QHash<QByteArray, QVariant> attributes = object->attributes();
    for( QHash<QByteArray, QVariant>::const_iterator it = attributes.constBegin(); it != attributes.constEnd(); ++it ) {
        stream.writeStartElement( "attribute" );
        stream.writeTextElement( "key", it.key() );
        stream.writeStartElement( "value" );
        writeVariant( stream, it.value() );
        stream.writeEndElement(); // value
        stream.writeEndElement(); // attribute
    }

    // Attachments
    for( int i = 0; i < object->countAttachments(); ++i ) {
        writeAttachment( stream, object->attachment( i ) );
    }
}
Beispiel #2
0
static void writeAttachments(struct MHINFO *w)
{
	struct MHINFO *v;
	if (w->doAttach) {
		writeAttachment(w);
	} else {
		foreach(v, w->components)
		    writeAttachments(v);
	}
}				/* writeAttachments */
void AttachmentSeriesTest::attachmentTest()
{
    CPPUNIT_ASSERT(m_series);

    //Create Path
    const ::boost::filesystem::path path = ::fwTools::System::getTemporaryFolder() / "attachmenttest";
    ::boost::filesystem::create_directories(path);
    const std::string filename                     = "attach.ext";
    const ::boost::filesystem::path attachmentFile = path / filename;
    const std::string mediaType                    = "text";

    std::ofstream file;
    file.open(attachmentFile.string().c_str(), std::ofstream::out);
    file << "42";
    file.close();
    size_t fileSize = ::boost::filesystem::file_size(attachmentFile);

    //None
    CPPUNIT_ASSERT_EQUAL(::fwMedData::AttachmentSeries::NONE, m_series->getAttachmentAvailability());
    CPPUNIT_ASSERT(m_series->getBufferObject()->isEmpty());

    //Local
    m_series->setAttachmentPath(attachmentFile);
    m_series->setMediaType(mediaType);
    CPPUNIT_ASSERT_EQUAL(::fwMedData::AttachmentSeries::LOCAL, m_series->getAttachmentAvailability());
    CPPUNIT_ASSERT_EQUAL(attachmentFile, m_series->getAttachmentPath());
    CPPUNIT_ASSERT(!m_series->getBufferObject()->isEmpty());
    CPPUNIT_ASSERT_EQUAL(fileSize, m_series->getBufferObject()->getSize());
    CPPUNIT_ASSERT_EQUAL(mediaType, m_series->getMediaType());

    //Embedded
    const std::string jsonzFile = "AttachmentSeriesTest.jsonz";
    ::fwAtoms::Object::sptr atom1 = ::fwAtomConversion::convert(m_series);
    writeAttachment((path/jsonzFile), atom1);
    ::fwAtoms::Object::sptr atom2 = readAttachment(path/jsonzFile);

    ::fwData::Object::sptr object;
    ::fwMedData::AttachmentSeries::sptr attachmentSeries;

    object           = ::fwAtomConversion::convert(atom2, ::fwAtomConversion::AtomVisitor::ChangePolicy());
    attachmentSeries = ::fwMedData::AttachmentSeries::dynamicCast(object);

    CPPUNIT_ASSERT(attachmentSeries);
    CPPUNIT_ASSERT_EQUAL(::fwMedData::AttachmentSeries::EMBEDDED, attachmentSeries->getAttachmentAvailability());
    CPPUNIT_ASSERT_EQUAL(filename, attachmentSeries->getAttachmentPath().string());
    CPPUNIT_ASSERT_EQUAL(mediaType, attachmentSeries->getMediaType());

    ::fwMemory::BufferObject::sptr buff = attachmentSeries->getBufferObject();
    ::fwMemory::BufferObject::Lock lock = buff->lock();
    CPPUNIT_ASSERT_EQUAL(fileSize, buff->getSize());
    CPPUNIT_ASSERT( lock.getBuffer() != nullptr );
}