void check_test_group(char const* name) { std::string grpname(name); if (grpname.empty()) throw std::runtime_error("missing test group name"); tut::groupnames gl = runner.get().list_groups(); tut::groupnames::const_iterator found = std::find(gl.begin(), gl.end(), grpname); if (found == gl.end()) throw std::runtime_error("test group " + grpname + " not found"); }
/** * Method to get the result for a network request. * @param aOperation The type of operation to be requested * @param aTransportResult The result of transport operation * @param aResponse The QByteArray instance containing the network response. * The plugins should delete this instance once they have read the * data from it. * @param aResult [out] An output parameter to the plugin manager.If the * return value is SmfSendRequestAgain, QVariant will be of type * SmfPluginRequestData. * For SmfGalleryPlugin: If last operation was pictures(), aResult will * be of type QList<SmfPicture>. If last operation was description(), * aResult will be of type QString. If last operation was upload() or * postComment(), aResult will be of type bool. * @param aRetType [out] SmfPluginRetType * @param aPageResult [out] The SmfResultPage structure variable */ SmfPluginError FlickrContactFetcherPlugin::responseAvailable( const SmfRequestTypeID aOperation, const SmfTransportResult &aTransportResult, QByteArray *aResponse, QVariant* aResult, SmfPluginRetType &aRetType, SmfResultPage &aPageResult ) { Q_UNUSED(aPageResult) qDebug()<<"Inside FlickrContactFetcherPlugin::responseAvailable()"; SmfPluginError error = SmfPluginErrNetworkError; if( !aResponse || (0 == aResponse->size()) ) { qDebug()<<"Response is NULL or empty"; aRetType = SmfRequestError; return error; } QByteArray response(*aResponse); delete aResponse; QFile respFile("c://data//SmfPluginFlickrContactResponse.txt"); if(!respFile.open(QIODevice::WriteOnly)) { qDebug()<<"File to write the response could not be opened, so writing to this file"; qDebug()<<"Flickr response = "<<QString(response); } else { respFile.write(response); respFile.close(); qDebug()<<"Writing FB response to a file named 'SmfPluginFlickrContactResponse.txt'"; } qDebug()<<"FB response size = "<<response.size(); if(SmfTransportOpNoError == aTransportResult) { qDebug()<<"No transport error"; #ifndef TESTINGTHISFUNCTION if(SmfContactGetFriends == aOperation) #else if(SmfContactGetFriends == aOperation ||aOperation == SmfContactGetFollowers||aOperation== SmfContactSearch ||aOperation ==SmfContactSearchNear||aOperation ==SmfContactSearchInGroup) #endif { qDebug()<<"For getting friends response"; QList<SmfContact> list; #ifdef SMF_XMLPARSING // Xml parsing // For getting contacts from xml response QXmlStreamReader xml(response); while (!xml.atEnd()) { xml.readNext(); if (xml.tokenType() == QXmlStreamReader::StartElement) { // If the tag is contact if (xml.name() == "contact") { qDebug()<<"Contact tag found"; SmfContact contact; QStringRef str; QContactName contactname; QString username = xml.attributes().value("username").toString(); qDebug()<<"Username = "******"Name",namevar1); list.append(contact); } } } #else // To remove the "jsonFlickrApi(" and also remove the last ")" from the response, // as these gives a Json parsing error response.remove(0, 14); response.chop(1); // For getting contacts from json response bool ok; SmfPluginUtil util; QVariantMap result = util.parse(response, &ok).toMap(); if (!ok) { qDebug()<<"An error occurred during json parsing"; aResult->setValue(list); aRetType = SmfRequestError; return SmfPluginErrParsingFailed; } QVariantMap map1 = result["contacts"].toMap(); qDebug()<<"page = "<<map1["page"].toString(); qDebug()<<"pages = "<<map1["pages"].toString(); qDebug()<<"per_page = "<<map1["per_page"].toString(); qDebug()<<"perpage = "<<map1["perpage"].toString(); qDebug()<<"total = "<<map1["perpage"].toString(); QList<QVariant> list1 = map1["contact"].toList(); QListIterator<QVariant> i(list1); while(i.hasNext()) { SmfContact contact; QVariantMap map2 = i.next().toMap(); qDebug()<<"nsid = "<<map2["nsid"].toString(); qDebug()<<"username = "******"username"].toString(); qDebug()<<"iconserver = "<<map2["iconserver"].toString(); qDebug()<<"iconfarm = "<<map2["iconfarm"].toString(); qDebug()<<"ignored = "<<map2["ignored"].toString(); qDebug()<<"realname = "<<map2["realname"].toString(); qDebug()<<"friend = "<<map2["friend"].toString(); qDebug()<<"family = "<<map2["family"].toString(); qDebug()<<"path_alias = "<<map2["path_alias"].toString(); qDebug()<<"location = "<<map2["location"].toString(); // Contact Name QContactName contactname; QString username = map2["username"].toString(); qDebug()<<"Username = "******"Name",nameVar); // Contact's Flickr Specific ID to QContactGuid QContactGuid guid; guid.setGuid(map2["nsid"].toString()); QVariant guidVar = QVariant::fromValue(guid); contact.setValue("Guid",guidVar); // Contact's profile image url QUrl url; if((0 == map2["iconfarm"].toInt()) && (0 == map2["iconserver"].toInt())) url = QString("http://www.flickr.com/images/buddyicon.jpg"); else { QString str("http://farm"); str.append(map2["iconfarm"].toString()); str.append(".static.flickr.com/"); str.append(map2["iconserver"].toString()); str.append("/buddyicons/"); str.append(map2["nsid"].toString()); str.append(".jpg"); url = str; } QContactAvatar avatar; qDebug()<<"Profile image URL = "<<url.toString(); avatar.setImageUrl(url); QVariant avatarVar = QVariant::fromValue(avatar); contact.setValue("Avatar",avatarVar); list.append(contact); } #endif qDebug()<<"list count = "<<list.count(); aResult->setValue(list); aRetType = SmfRequestComplete; error = SmfPluginErrNone; } else if(aOperation==SmfContactGetGroups) { response.remove(0, 14); response.chop(1); bool ok; qDebug()<<"Before Parser--"; SmfPluginUtil util; QVariant result = util.parse(response, &ok); if (!ok) { qDebug()<<"An error occurred during json parsing"; aRetType = SmfRequestError; return SmfPluginErrParsingFailed; //return 0; } QVariantMap map1 = result.toMap(); QList<SmfGroup> list; QVariantMap map2 = map1["groups"].toMap(); int page = map2["page"].toInt(&ok); qDebug()<<"PAGE = "<<map2["page"].toString(); QList<QVariant> list1 = map2["group"].toList(); QListIterator<QVariant> iter(list1); //Getting the group list from QJson Parser while(iter.hasNext()) { QVariantMap map2 = iter.next().toMap(); qDebug()<<"name = "<<map2["name"].toString(); qDebug()<<"id = "<<map2["id"].toString(); SmfGroup group; QString id(map2["id"].toString()); group.setId(id); QString grpname(map2["name"].toString()); group.setName(grpname); list.append(group); }//end While qDebug()<<"list count = "<<QString::number(list.count(),10); aResult->setValue(list); } else { qDebug()<<"Service unsupported, currently only SmfContactGetFriends !!!"; aRetType = SmfRequestError; error = SmfPluginErrServiceNotSupported; } } else if(SmfTransportOpOperationCanceledError == aTransportResult) { qDebug()<<"Operation Cancelled !!!"; error = SmfPluginErrCancelComplete; aRetType = SmfRequestComplete; } else { qDebug()<<"Transport Error !!!"; error = SmfPluginErrNetworkError; aRetType = SmfRequestError; } return error; }