QByteArray MediaManager::createMultipartFormData(const QMap< QString, QByteArray >& formdata, const QList< QMap< QString, QByteArray > >& mediaFiles) { QByteArray newLine("\r\n"); QString formHeader( newLine + "Content-Disposition: form-data; name=\"%1\"" ); QByteArray header(newLine + "--AaB03x"); QByteArray footer(newLine + "--AaB03x--"); QString fileHeader(newLine + "Content-Disposition: file; name=\"%1\"; filename=\"%2\""); QByteArray data; data.append(header); if ( !mediaFiles.isEmpty() ) { QList< QMap< QString, QByteArray > >::const_iterator it1 = mediaFiles.constBegin(); QList< QMap< QString, QByteArray > >::const_iterator endIt1 = mediaFiles.constEnd(); for(; it1!=endIt1; ++it1){ data.append( fileHeader.arg(it1->value("name").data()).arg(it1->value("filename").data()).toUtf8() ); data.append(newLine + "Content-Type: " + it1->value("mediumType")); data.append(newLine); data.append(newLine + it1->value("medium")); } } QMap< QString, QByteArray >::const_iterator it = formdata.constBegin(); QMap< QString, QByteArray >::const_iterator endIt = formdata.constEnd(); for(;it!=endIt; ++it){ data.append(header); data.append(formHeader.arg(it.key()).toLatin1()); data.append(newLine); data.append(newLine + it.value()); } data.append(footer); return data; }
//-***************************************************************************** Reader::Request Reader::component( const std::string &name, const std::string &ininterp, const ComponentInfo &info ) { std::string interp = ininterp; if ( fileHeader().version < 3 ) { interp = GTO_INTERPRET_DEFAULT; } if ( m_objects == NULL ) { GTC_THROW( "Reader reading without objects" ); } PropertyContainer *g = reinterpret_cast<PropertyContainer*>( info.object->objectData ); Component *c = g->component( name ); if ( !c ) { // adds it too. c = g->createComponent( name, info.flags & Gto::Matrix ); } return Request( true, c ); }
void TEST_cppwriter::test_writeClass() { CppWriterTest* cpp = new CppWriterTest(); UMLClassifier* c = new UMLClassifier("Customer", "12345678"); UMLAttribute* attr; attr = c->createAttribute("name_"); attr = c->createAttribute("address_"); UMLOperation* op; op = c->createOperation("getName"); op = c->createOperation("getAddress"); cpp->writeClass(c); // does the just created file exist? QFile fileHeader(temporaryPath() + cpp->findFileName(c, QLatin1String(".h"))); QFile fileCPP(temporaryPath() + cpp->findFileName(c, QLatin1String(".cpp"))); QCOMPARE(fileHeader.exists(), true); QCOMPARE(fileCPP.exists(), true); }
TEST(FileHeader, Roundtrip) { Version version(1, 1, 0); FileHeader fileHeader(version, "Hello World"); std::stringstream stream; fileHeader.Write(stream); FileHeader fileHeader2(stream); EXPECT_EQ(fileHeader2.GetVersion().VersionMajor(), fileHeader.GetVersion().VersionMajor()); EXPECT_EQ(fileHeader2.GetVersion().VersionMiddle(), fileHeader.GetVersion().VersionMiddle()); EXPECT_EQ(fileHeader2.GetVersion().VersionMinor(), fileHeader.GetVersion().VersionMinor()); EXPECT_EQ(fileHeader2.TimeStamp(), fileHeader.TimeStamp()); EXPECT_EQ(fileHeader2.UserData(), fileHeader.UserData()); std::stringstream stream2; fileHeader2.Write(stream2); EXPECT_EQ(stream.str(), stream2.str()); }
//-***************************************************************************** Reader::Request Reader::property( const std::string &name, const std::string &pre_ininterp, const PropertyInfo &info ) { // Fix interp for versions prior to 3. std::string ininterp = pre_ininterp; if ( fileHeader().version < 3 ) { ininterp = GTO_INTERPRET_DEFAULT; } if ( m_objects == NULL ) { GTC_THROW( "Reader reading without objects" ); } std::string interp; // In case you need the property container, here it is. // PropertyContainer *pc = // reinterpret_cast<PropertyContainer*>( // info.component->object->objectData ); Component *c = reinterpret_cast<Component*>( info.component->componentData ); Property *p = c->find( name ); Property *np = NULL; // Only use the part of the interpretation up to the first semicolon. size_t sq = ininterp.find( ';' ); if ( sq != std::string::npos ) { interp = ininterp.substr( 0, sq ); } else { interp = ininterp; } // If there's no interpretation, change the interpretation to // GTO_INTERPRET_DEFAULT if ( interp == "" ) { interp = GTO_INTERPRET_DEFAULT; } // If the property doesn't exist, try the virtual 'newProperty' function // which returns NULL by default. If it makes a property, awesome! Use // that. If not, continue below. if ( p == NULL ) { if ( (np = newProperty( name, info )) ) { c->add( np ); np->resize( info.size ); return Request( true, np ); } } // From the layout, width & interpretation, build us a new // property, OR, verify that the old property is the right upcastable // type. Layout layout = gtoTypeToLayout( ( Gto::DataType )( info.type ) ); const MetaProperty *metaProp = findMetaProperty( layout, info.width, interp ); if ( metaProp == NULL ) { std::cerr << "GtoContainer::Reader WARNING: " << "Ignoring property \"" << name << "\"" << std::endl; return Request( false ); } Property *newProp = NULL; if ( p != NULL ) { if ( !metaProp->validUpcast( p ) ) { throw TypeMismatchExc(); } newProp = p; } else { newProp = metaProp->create( name ); c->add( newProp ); } // If we get here, we've got a new property, ready to receive data. // Resize it and send out the Request. assert( newProp != NULL ); newProp->resize( info.size ); return Request( true, newProp ); }