void AutoTestUnitTests::testCodeParserGTest() { if (qgetenv("GOOGLETEST_DIR").isEmpty()) QSKIP("This test needs googletest - set GOOGLETEST_DIR (point to googletest repository)"); QFETCH(QString, projectFilePath); CppTools::Tests::ProjectOpenerAndCloser projectManager; CppTools::ProjectInfo projectInfo = projectManager.open(projectFilePath, true); QVERIFY(projectInfo.isValid()); QSignalSpy parserSpy(m_model->parser(), SIGNAL(parsingFinished())); QSignalSpy modelUpdateSpy(m_model, SIGNAL(sweepingDone())); QVERIFY(parserSpy.wait(20000)); QVERIFY(modelUpdateSpy.wait()); QCOMPARE(m_model->gtestNamesCount(), 7); QMultiMap<QString, int> expectedNamesAndSets; expectedNamesAndSets.insert(QStringLiteral("FactorialTest"), 3); expectedNamesAndSets.insert(QStringLiteral("FactorialTest_Iterative"), 2); expectedNamesAndSets.insert(QStringLiteral("Sum"), 2); expectedNamesAndSets.insert(QStringLiteral("QueueTest"), 2); expectedNamesAndSets.insert(QStringLiteral("DummyTest"), 1); // used as parameterized test expectedNamesAndSets.insert(QStringLiteral("DummyTest"), 1); // used as 'normal' test expectedNamesAndSets.insert(QStringLiteral("NamespaceTest"), 1); QMultiMap<QString, int> foundNamesAndSets = m_model->gtestNamesAndSets(); QCOMPARE(expectedNamesAndSets.size(), foundNamesAndSets.size()); foreach (const QString &name, expectedNamesAndSets.keys()) QCOMPARE(expectedNamesAndSets.values(name), foundNamesAndSets.values(name)); // check also that no Qt related tests have been found QCOMPARE(m_model->autoTestsCount(), 0); QCOMPARE(m_model->namedQuickTestsCount(), 0); QCOMPARE(m_model->unnamedQuickTestsCount(), 0); QCOMPARE(m_model->dataTagsCount(), 0); }
void AutoTestUnitTests::testCodeParserGTest() { if (qgetenv("GOOGLETEST_DIR").isEmpty()) QSKIP("This test needs googletest - set GOOGLETEST_DIR (point to googletest repository)"); NavigationWidget *navigation = NavigationWidget::instance(); navigation->activateSubWidget(Constants::AUTOTEST_ID); CppTools::Tests::ProjectOpenerAndCloser projectManager; CppTools::ProjectInfo projectInfo = projectManager.open( QString(m_tmpDir->path() + QLatin1String("/simple_gt/simple_gt.pro")), true); QVERIFY(projectInfo.isValid()); QSignalSpy parserSpy(m_model->parser(), SIGNAL(parsingFinished())); QVERIFY(parserSpy.wait(20000)); QCOMPARE(m_model->gtestNamesCount(), 6); QMultiMap<QString, int> expectedNamesAndSets; expectedNamesAndSets.insert(QStringLiteral("FactorialTest"), 3); expectedNamesAndSets.insert(QStringLiteral("FactorialTest_Iterative"), 2); expectedNamesAndSets.insert(QStringLiteral("Sum"), 2); expectedNamesAndSets.insert(QStringLiteral("QueueTest"), 2); expectedNamesAndSets.insert(QStringLiteral("DummyTest"), 1); // used as parameterized test expectedNamesAndSets.insert(QStringLiteral("DummyTest"), 1); // used as 'normal' test QMultiMap<QString, int> foundNamesAndSets = m_model->gtestNamesAndSets(); QCOMPARE(expectedNamesAndSets.size(), foundNamesAndSets.size()); foreach (const QString &name, expectedNamesAndSets.keys()) QCOMPARE(expectedNamesAndSets.values(name), foundNamesAndSets.values(name)); // check also that no Qt related tests have been found QCOMPARE(m_model->autoTestsCount(), 0); QCOMPARE(m_model->namedQuickTestsCount(), 0); QCOMPARE(m_model->unnamedQuickTestsCount(), 0); QCOMPARE(m_model->dataTagsCount(), 0); }
bool AbstractRuleBinder::parseRuleReferences(QString& strRule) { QMultiMap<size_t, QMap<size_t,size_t> > mapLookups; if (!ruleCheckerPtr->parseRule(strRule,mapLookups)) return false; if (mapLookups.size()>0){ QMultiMap<size_t, QMap<size_t,size_t> >::iterator j = mapLookups.begin(); while (j != mapLookups.end()) { QString strResult; size_t field=j.value().begin().value(); size_t mapper=j.value().begin().key(); QVariant var=getVal(field,mapper); if (var.type()==QVariant::Invalid) return false; if (var.type()==QVariant::String) strResult=tr("'") + var.toString() + tr("'"); else strResult=var.toString(); QString searchStr=StrRulePtr + tr("(") + QVariant(j.key()).toString() + tr(")"); strRule=strRule.replace(searchStr, strResult); ++j; } } //search for references to the current sample QMap<QString, QString> mapSample; if (!parseSample(strRule,mapSample)) return false; QMap<QString, QString>::iterator j = mapSample.begin(); while (j != mapSample.end()) { QString searchStr=StrRuleSample + tr("(") + QVariant(j.key()).toString() + tr(")"); strRule=strRule.replace(searchStr, j.value()); //qDebug() << strRule << endl; ++j; } return true; }
void multipleCheckDialog::writeToGui() { QMultiMap<QString,contactWidgetFastBook*> fastList; QString filter = ui->lineEdit->text(); for (libJackSMS::dataTypes::phoneBookType::const_iterator i = rubrica.begin(); i != rubrica.end(); ++i) { //Controllo che non sia giĆ presente nella lista destinatari if (!padre->isInRecipients(i.value().getPhone())) { if (i->getName().contains(filter, Qt::CaseInsensitive)) { QIcon ico; libJackSMS::dataTypes::configuredServicesType::const_iterator x = elencoServiziConfigurati.find(i->getAccount()); if (x == elencoServiziConfigurati.end()) { ico = QIcon(":/resource/ico_contact.png"); } else { QString serv = x.value().getService(); libJackSMS::dataTypes::servicesType::const_iterator tmp = elencoServizi.find(serv); ico = tmp->getIcon(); } contactWidgetFastBook *ww = new contactWidgetFastBook(i.value(), ico.pixmap(16,16), true); fastList.insert(i->getName().toUpper(), ww); } } } if (fastList.size() > 0) { for (QMultiMap<QString,contactWidgetFastBook*>::ConstIterator xx = fastList.begin(); xx != fastList.end(); ++xx) { QListWidgetItem *item = new QListWidgetItem; item->setSizeHint(xx.value()->size()); ui->listWidget->addItem(item); ui->listWidget->setItemWidget(item, xx.value()); } } }
QByteArray huffman(QByteArray data, MainWindow *mainWindow) { // count int count[tableSize]; qFill(&count[0], &count[tableSize - 1], 0); for (int i = 0; i < data.size(); ++i) ++count[static_cast<quint8>(data[i])]; QMultiMap<int, QList<QPair<quint8, QBitArray> > > p; // <count, <symbol, code> > for (int i = 0; i < tableSize; ++i) { if (count[i] == 0) continue; QList<QPair<quint8, QBitArray> > list; list.append(qMakePair(static_cast<quint8>(i), QBitArray())); p.insert(count[i], list); } // caculate codes from bottom to top while (p.size() > 1) { const int count0 = p.begin().key(); QList<QPair<quint8, QBitArray> > list0 = p.begin().value(); p.erase(p.begin()); const int count1 = p.begin().key(); QList<QPair<quint8, QBitArray> > list1 = p.begin().value(); p.erase(p.begin()); for (QList<QPair<quint8, QBitArray> >::Iterator iter = list0.begin(); iter != list0.end(); ++iter) { iter->second.resize(iter->second.size() + 1); iter->second.setBit(iter->second.size() - 1, false); } for (QList<QPair<quint8, QBitArray> >::Iterator iter = list1.begin(); iter != list1.end(); ++iter) { iter->second.resize(iter->second.size() + 1); iter->second.setBit(iter->second.size() - 1, true); } p.insert(count0 + count1, list0 + list1); } // extract codes QHash<quint8, QBitArray> codes; for (QList<QPair<quint8, QBitArray> >::ConstIterator iter = p.begin().value().constBegin(); iter != p.begin().value().constEnd(); ++iter) { QBitArray code; code.resize(iter->second.size()); for (int j = 0; j < code.size(); ++j) if (iter->second[code.size() - j - 1]) code.setBit(j); codes[iter->first] = code; } // encode QBitArray bits; for (int i = 0; i < data.size(); ++i) { mainWindow->setProgress(qRound(static_cast<qreal>(100 * i) / data.size())); const QBitArray &code = codes[static_cast<quint8>(data[i])]; const int oldSize = bits.size(); bits.resize(oldSize + code.size()); for (int i = 0; i < code.size(); ++i) if (code[i]) bits.setBit(oldSize + i); } QByteArray result; { QDataStream stream(&result, QIODevice::WriteOnly); stream << codes << static_cast<qint32>(data.size()) << bits; } return result; }