Пример #1
0
// Testing get/set functions
void tst_QAbstractSocket::getSetCheck()
{
    MyAbstractSocket obj1;
    // qint64 QAbstractSocket::readBufferSize()
    // void QAbstractSocket::setReadBufferSize(qint64)
    obj1.setReadBufferSize(qint64(0));
    QCOMPARE(qint64(0), obj1.readBufferSize());
    obj1.setReadBufferSize((Q_INT64_C(-9223372036854775807) - 1));
    QCOMPARE((Q_INT64_C(-9223372036854775807) - 1), obj1.readBufferSize());
    obj1.setReadBufferSize(Q_INT64_C(9223372036854775807));
    QCOMPARE(Q_INT64_C(9223372036854775807), obj1.readBufferSize());

    // quint16 QAbstractSocket::localPort()
    // void QAbstractSocket::setLocalPort(quint16)
    obj1.setLocalPort(quint16(0));
    QCOMPARE(quint16(0), obj1.localPort());
    obj1.setLocalPort(quint16(0xffff));
    QCOMPARE(quint16(0xffff), obj1.localPort());

    // quint16 QAbstractSocket::peerPort()
    // void QAbstractSocket::setPeerPort(quint16)
    obj1.setPeerPort(quint16(0));
    QCOMPARE(quint16(0), obj1.peerPort());
    obj1.setPeerPort(quint16(0xffff));
    QCOMPARE(quint16(0xffff), obj1.peerPort());
}
Пример #2
0
bool QMutexPrivate::wait(int timeout)
{
    struct timespec ts, *pts = 0;
    QElapsedTimer timer;
    if (timeout >= 0) {
        ts.tv_nsec = ((timeout % 1000) * 1000) * 1000;
        ts.tv_sec = (timeout / 1000);
        pts = &ts;
        timer.start();
    }
    while (contenders.fetchAndStoreAcquire(2) > 0) {
        int r = _q_futex(&contenders._q_value, FUTEX_WAIT, 2, pts, 0, 0);
        if (r != 0 && errno == ETIMEDOUT)
            return false;

        if (pts) {
            // recalculate the timeout
            qint64 xtimeout = timeout * 1000 * 1000;
            xtimeout -= timer.nsecsElapsed();
            if (xtimeout < 0) {
                // timer expired after we returned
                return false;
            }

            ts.tv_sec = xtimeout / Q_INT64_C(1000) / 1000 / 1000;
            ts.tv_nsec = xtimeout % (Q_INT64_C(1000) * 1000 * 1000);
        }
    }
    return true;
}
void MWToolsOrientation::shortAction()
{
    ++m_currentstate;

    switch (m_currentstate)
    {
    case 1:
        m_value = "top";
        m_timestamp = Q_INT64_C(-1);
        setIcon(1);
        break;
    case 2:
        m_value = "left";
        m_timestamp = Q_INT64_C(-1);
        setIcon(2);
        break;
    case 3:
        m_value = "auto";
        m_timestamp = 0;
        m_currentstate=0;
        setIcon(0);
        break;
    }

    emit ValueChanged(QVariantList() << m_value, m_timestamp);
}
Пример #4
0
int QHexEdit::addressWidth()
{
    qint64 size = _chunks->size();
    int n = 1;
    if (size > Q_INT64_C(0x100000000)) {
        n += 8;
        size /= Q_INT64_C(0x100000000);
    }
    if (size > 0x10000) {
        n += 4;
        size /= 0x10000;
    }
    if (size > 0x100) {
        n += 2;
        size /= 0x100;
    }
    if (size > 0x10) {
        n += 1;
        size /= 0x10;
    }

    if (n > _addressWidth)
        return n;
    else
        return _addressWidth;
}
QGitHubReleaseAPIPrivate::QGitHubReleaseAPIPrivate(const QUrl &apiUrl, bool multi,
												   QGitHubReleaseAPI::TYPE type, QObject *p) :
	QObject(p), m_apiDownloader(new FileDownloader(apiUrl, m_userAgent)), m_jsonData(), m_vdata(),
	m_errorString(), m_rateLimit(0), m_rateLimitRemaining(0), m_singleEntryRequested(!multi),
	m_rateLimitReset(), m_avatars(), m_eTag(QString::null), m_dlOutputFile(0L),
	m_readBytes(Q_INT64_C(-1)), m_readReply(0L), m_bytesAvail(Q_INT64_C(-1)), m_type(type) {
	init();
}
Пример #6
0
static void testCopyTo( KArchive* archive )
{
    const KArchiveDirectory* dir = archive->directory();
    KTempDir tmpDir;
    const QString dirName = tmpDir.name();

    dir->copyTo( dirName );

    QVERIFY(QFile::exists(dirName+"dir"));
    QVERIFY(QFileInfo(dirName+"dir").isDir());

    QFileInfo fileInfo1(dirName+"dir/subdir/mediumfile2");
    QVERIFY(fileInfo1.exists());
    QVERIFY(fileInfo1.isFile());
    QCOMPARE(fileInfo1.size(), Q_INT64_C(100));

    QFileInfo fileInfo2(dirName+"hugefile");
    QVERIFY(fileInfo2.exists());
    QVERIFY(fileInfo2.isFile());
    QCOMPARE(fileInfo2.size(), Q_INT64_C(20000));

    QFileInfo fileInfo3(dirName+"mediumfile");
    QVERIFY(fileInfo3.exists());
    QVERIFY(fileInfo3.isFile());
    QCOMPARE(fileInfo3.size(), Q_INT64_C(100));

    QFileInfo fileInfo4(dirName+"my/dir/test3");
    QVERIFY(fileInfo4.exists());
    QVERIFY(fileInfo4.isFile());
    QCOMPARE(fileInfo4.size(), Q_INT64_C(29));

#ifndef Q_OS_WIN
    const QString fileName = dirName+"z/test3_symlink";
    const QFileInfo fileInfo5(fileName);
    QVERIFY(fileInfo5.exists());
    QVERIFY(fileInfo5.isFile());
    // Do not use fileInfo.readLink() for unix symlinks
    // It returns the -full- path to the target, while we want the target string "as is".
    QString symLinkTarget;
    const QByteArray encodedFileName = QFile::encodeName(fileName);
    QByteArray s;
#if defined(PATH_MAX)
    s.resize(PATH_MAX+1);
#else
    int path_max = pathconf(encodedFileName.data(), _PC_PATH_MAX);
    if (path_max <= 0) {
        path_max = 4096;
    }
    s.resize(path_max);
#endif
    int len = readlink(encodedFileName.data(), s.data(), s.size() - 1);
    if ( len >= 0 ) {
        s[len] = '\0';
        symLinkTarget = QFile::decodeName(s);
    }
    QCOMPARE(symLinkTarget, QString("test3"));
#endif
}
Пример #7
0
void QNetworkReplyImplPrivate::_q_copyReadyRead()
{
    Q_Q(QNetworkReplyImpl);
    if (state != Working)
        return;
    if (!copyDevice || !q->isOpen())
        return;

    // FIXME Optimize to use download buffer if it is a QBuffer.
    // Needs to be done where sendCacheContents() (?) of HTTP is emitting
    // metaDataChanged ?

    forever {
        qint64 bytesToRead = nextDownstreamBlockSize();
        if (bytesToRead == 0)
            // we'll be called again, eventually
            break;

        bytesToRead = qBound<qint64>(1, bytesToRead, copyDevice->bytesAvailable());
        QByteArray byteData;
        byteData.resize(bytesToRead);
        qint64 bytesActuallyRead = copyDevice->read(byteData.data(), byteData.size());
        if (bytesActuallyRead == -1) {
            byteData.clear();
            backendNotify(NotifyCopyFinished);
            break;
        }

        byteData.resize(bytesActuallyRead);
        readBuffer.append(byteData);

        if (!copyDevice->isSequential() && copyDevice->atEnd()) {
            backendNotify(NotifyCopyFinished);
            bytesDownloaded += bytesActuallyRead;
            break;
        }

        bytesDownloaded += bytesActuallyRead;
    }

    if (bytesDownloaded == lastBytesDownloaded) {
        // we didn't read anything
        return;
    }

    lastBytesDownloaded = bytesDownloaded;
    QVariant totalSize = cookedHeaders.value(QNetworkRequest::ContentLengthHeader);
    if (preMigrationDownloaded != Q_INT64_C(-1))
        totalSize = totalSize.toLongLong() + preMigrationDownloaded;
    pauseNotificationHandling();
    // emit readyRead before downloadProgress incase this will cause events to be
    // processed and we get into a recursive call (as in QProgressDialog).
    emit q->readyRead();
    emit q->downloadProgress(bytesDownloaded,
                             totalSize.isNull() ? Q_INT64_C(-1) : totalSize.toLongLong());
    resumeNotificationHandling();
}
Пример #8
0
qint64 BitcoinUnits::maxAmount(int unit)
{
    switch(unit)
    {
    case BTC:  return Q_INT64_C(2500000000000);
    case mBTC: return Q_INT64_C(2500000000000000);
    default:   return 0;
    }
}
qint64 CarboncoinUnits::maxAmount(int unit)
{
    switch(unit)
    {
    case CARBON:  return Q_INT64_C(21000000);
    case KCARBON: return Q_INT64_C(21000);
    case MCARBON: return Q_INT64_C(21);
    default:   return 0;
    }
}
Пример #10
0
qint64 BitmarkUnits::maxAmount(int unit)
{
    switch(unit)
    {
    case BTM:  return Q_INT64_C(21000000);
    case MARK: return Q_INT64_C(21000000000);
    case mb: return Q_INT64_C(21000000000000);
    default:   return 0;
    }
}
Пример #11
0
qint64 DarcoinUnits::maxAmount(int unit)
{
    switch(unit)
    {
    case DAR:  return Q_INT64_C(21000000);
    case mDAR: return Q_INT64_C(21000000000);
    case uDAR: return Q_INT64_C(21000000000000);
    default:   return 0;
    }
}
Пример #12
0
qint64 BitcoinUnits::maxAmount(int unit)
{
    switch(unit)
    {
    case LAT:  return Q_INT64_C(21000000);
    case mLAT: return Q_INT64_C(21000000000);
    case uLAT: return Q_INT64_C(21000000000000);
    default:   return 0;
    }
}
Пример #13
0
qint64 VirtaCoinUnits::maxAmount(int unit)
{
    switch(unit)
    {
    case VTA:  return Q_INT64_C(21000000000);
    case mVTA: return Q_INT64_C(21000000000000);
    case uVTA: return Q_INT64_C(21000000000000000);
    default:   return 0;
    }
}
Пример #14
0
qint8 readSignedByte(QIODevice &device)
{
    qint8 result = 0;
    if (device.read(reinterpret_cast<char *> (&result),
            Q_INT64_C(1)) != Q_INT64_C(1))
    {
        throw std::runtime_error("Unable to read file");
    }
    return result;
}
qint64 NautiluscoinUnits::maxAmount(int unit)
{
    switch(unit)
    {
    case NAUT:  return Q_INT64_C(21000000);
    case mNAUT: return Q_INT64_C(21000000000);
    case uNAUT: return Q_INT64_C(21000000000000);
    default:   return 0;
    }
}
Пример #16
0
qint64 iQcoinUnits::maxAmount(int unit)
{
    switch(unit)
    {
    case IQC:  return Q_INT64_C(21000000);
    case mIQC: return Q_INT64_C(21000000000);
    case uIQC: return Q_INT64_C(21000000000000);
    default:   return 0;
    }
}
Пример #17
0
qint64 BitcoinUnits::factor(int unit)
{
    switch(unit)
    {
    case MBTCH: return Q_INT64_C(100000000000000);
    case kBTCH: return Q_INT64_C(100000000000);
    case BTCH:  return Q_INT64_C(100000000);
    case C**t: return Q_INT64_C(1);
    default:    return Q_INT64_C(100000000);
    }
}
Пример #18
0
qint64 BitcoinUnits::maxAmount(int unit)
{
    switch(unit)
    {
    case DASH:  return Q_INT64_C(21000000);
    case mDASH: return Q_INT64_C(21000000000);
    case uDASH: return Q_INT64_C(21000000000000);
    case duffs: return Q_INT64_C(2100000000000000);
    default:   return 0;
    }
}
Пример #19
0
qint64 BitcoinUnits::factor(int unit)
{
    switch(unit)
    {
    case MVPRC: return Q_INT64_C(100000000000000);
    case kVPRC: return Q_INT64_C(100000000000);
    case VPRC:  return Q_INT64_C(100000000);
    case Koinu: return Q_INT64_C(1);
    default:    return Q_INT64_C(100000000);
    }
}
Пример #20
0
qint64 BitcoinUnits::maxAmount(int unit)
{
    switch(unit)
    {
    case MVPRC: return Q_INT64_C(900000);
    case kVPRC: return Q_INT64_C(900000000);
    case VPRC:  return Q_INT64_C(900000000000);    //less than the coin supply until the year 2170
    case Koinu: return Q_INT64_C(9000000000000000000); // Slightly under max value for int64
    default:   return 0;
    }
}
Пример #21
0
qint32 readSignedDWord(QIODevice &device)
{
    qint32 result = 0;
    if (device.read(reinterpret_cast<char *> (&result),
            Q_INT64_C(4)) != Q_INT64_C(4))
    {
        throw std::runtime_error("Unable to read file");
    }
    result = qFromLittleEndian(result);
    return result;
}
QGitHubReleaseAPIPrivate::QGitHubReleaseAPIPrivate(const QString &user, const QString &repo,
												   bool latest, QGitHubReleaseAPI::TYPE type,
												   QObject *p) : QObject(p),
	m_apiDownloader(new FileDownloader(QUrl(QString("https://api.github.com/repos/%1/%2/releases%3")
											.arg(QString(QUrl::toPercentEncoding(user)))
											.arg(QString(QUrl::toPercentEncoding(repo)))
											.arg(latest ? "/latest" : "")), m_userAgent)),
	m_jsonData(), m_vdata(), m_errorString(), m_rateLimit(0), m_rateLimitRemaining(0),
	m_singleEntryRequested(latest), m_rateLimitReset(), m_avatars(), m_eTag(QString::null),
	m_dlOutputFile(0L), m_readBytes(Q_INT64_C(-1)), m_readReply(0L), m_bytesAvail(Q_INT64_C(-1)),
	m_type(type) {
	init();
}
Пример #23
0
void QNetworkReplyImplPrivate::_q_copyReadyRead()
{
    Q_Q(QNetworkReplyImpl);
    if (state != Working)
        return;
    if (!copyDevice || !q->isOpen())
        return;

    forever {
        qint64 bytesToRead = nextDownstreamBlockSize();
        if (bytesToRead == 0)
            // we'll be called again, eventually
            break;

        bytesToRead = qBound<qint64>(1, bytesToRead, copyDevice->bytesAvailable());
        QByteArray byteData;
        byteData.resize(bytesToRead);
        qint64 bytesActuallyRead = copyDevice->read(byteData.data(), byteData.size());
        if (bytesActuallyRead == -1) {
            byteData.clear();
            backendNotify(NotifyCopyFinished);
            break;
        }

        byteData.resize(bytesActuallyRead);
        readBuffer.append(byteData);

        if (!copyDevice->isSequential() && copyDevice->atEnd()) {
            backendNotify(NotifyCopyFinished);
            bytesDownloaded += bytesActuallyRead;
            break;
        }

        bytesDownloaded += bytesActuallyRead;
    }

    if (bytesDownloaded == lastBytesDownloaded) {
        // we didn't read anything
        return;
    }

    lastBytesDownloaded = bytesDownloaded;
    QVariant totalSize = cookedHeaders.value(QNetworkRequest::ContentLengthHeader);
    if (preMigrationDownloaded != Q_INT64_C(-1))
        totalSize = totalSize.toLongLong() + preMigrationDownloaded;
    pauseNotificationHandling();
    emit q->downloadProgress(bytesDownloaded,
                             totalSize.isNull() ? Q_INT64_C(-1) : totalSize.toLongLong());
    emit q->readyRead();
    resumeNotificationHandling();
}
//------------------------------------------------------------------------------
void MainWindow::rewriteFileStatus(QListWidget *listWidget, QLineEdit *labelFileStatus)
{
    int fileCount = 0;
    qint64 totalFileSize = 0;
    qint64 tera = Q_INT64_C(1099511627776);
    qint64 peta = Q_INT64_C(1125899906842624);

    for (int ii = 0; ii < listWidget->count(); ii++)
    {
        QString fpath = listWidget->item(ii)->text();
        QFile *file = new QFile(fpath);
        totalFileSize += file->size();
        fileCount++;
    }
    QString fileSizeString = "";
    if (totalFileSize == 0)
    {
        fileSizeString = "0";
    }
    else
    {
        fileSizeString = QString("%L2").arg(totalFileSize);
    }
    QString aboutFileSizeString = "";
    int aboutFileSize;
    if(totalFileSize < 1024){
        aboutFileSizeString = "";
    }
    else if(totalFileSize < 1024 * 1024){
        aboutFileSize = (int)(totalFileSize / 1024);
        aboutFileSizeString = " (" + tr("about") + QString("%1").arg(aboutFileSize) + tr("Kbyte") + ")";
    }
    else if (totalFileSize < 1073741824) // �P�M�K 1024 * 1024 * 1024
    {
        aboutFileSize = (int)(totalFileSize / (1024 * 1024));
        aboutFileSizeString = " (" + tr("about") + QString("%1").arg(aboutFileSize) + tr("Mbyte") + ")";
    }
    else if (totalFileSize < tera) // �P�e�� 1024 * 1024 * 1024 * 1024
    {
        aboutFileSize = (int)(totalFileSize / (1073741824));
        aboutFileSizeString = " (" + tr("about") + QString("%1").arg(aboutFileSize) + tr("Gbyte") + ")";
    }
    else if (totalFileSize < peta) // �P�y�^ 1024 * 1024 * 1024 * 1024 * 1024
    {
        aboutFileSize = (int)(totalFileSize / (tera));
        aboutFileSizeString = " (" + tr("about") + QString("%1").arg(aboutFileSize) + tr("Tbyte") + ")";
    }

    labelFileStatus->setText(tr("Selected File Count : ") + QString("%1").arg(fileCount) + "  " + tr("Total File Size : ") + fileSizeString + aboutFileSizeString);
}
Пример #25
0
void tst_QByteArray::number()
{
    QCOMPARE(QString(QByteArray::number((quint64) 0)),
	    QString(QByteArray("0")));
    QCOMPARE(QString(QByteArray::number(Q_UINT64_C(0xFFFFFFFFFFFFFFFF))),
	    QString(QByteArray("18446744073709551615")));
    QCOMPARE(QString(QByteArray::number(Q_INT64_C(0xFFFFFFFFFFFFFFFF))),
	    QString(QByteArray("-1")));
    QCOMPARE(QString(QByteArray::number(qint64(0))),
	    QString(QByteArray("0")));
    QCOMPARE(QString(QByteArray::number(Q_INT64_C(0x7FFFFFFFFFFFFFFF))),
	    QString(QByteArray("9223372036854775807")));
    QCOMPARE(QString(QByteArray::number(Q_INT64_C(0x8000000000000000))),
	    QString(QByteArray("-9223372036854775808")));
}
void QtQuickSampleApplicationTest::RobotStateHistoryVisualizeTest()
{
    // model init
    RobotStateHistoryTest model;
    RobotState state;
    auto it=0;

    // array feltöltése
    int arr[] = { 0,1 };
    QVector<int> v(2);
    qCopy(arr, arr+2, v.begin());

    // stream init
    QByteArray buffer;
    QDataStream stream(&buffer, QIODevice::ReadWrite);

    // stream mintaadatokkal való feltöltése
    stream << (qint32) 3;
    stream << Q_INT64_C(123243);
    stream << 1.4;
    stream << 1.0;
    stream << 1.0;
    stream << v;
    stream << (qint8) 1;
    stream << QString::fromUtf8("nincs hiba");

    // state feltöltése a mintaadatokkal
    state.ReadFrom(stream);

    int actual;
    actual = model.visualizeTest(state);

    // qtest
    QVERIFY2(actual==1 , "Nem futott le a historyHasChanged függvény");
}
Пример #27
0
bool QtlMovieCleanupSubtitles::start()
{
    // Do not start twice.
    if (!QtlMovieAction::start()) {
        return false;
    }

    debug(tr("Starting subtitle file cleanup"));
    debug(tr("Input file: %1").arg(_inputFile.fileName()));
    debug(tr("Output file: %1").arg(_outputFile.fileName()));

    // Open the input file.
    if (!_inputFile.open(QFile::ReadOnly)) {
        emitCompleted(false, tr("Error opening %1").arg(_inputFile.fileName()));
        return true; // true = started (and completed as well in that case).
    }

    // Create the output file.
    if (!_outputFile.open(QFile::WriteOnly)) {
        _inputFile.close();
        emitCompleted(false, tr("Error creating %1").arg(_outputFile.fileName()));
        return true; // true = started (and completed as well in that case).
    }

    // Start immediate timer, a way to read continuously packets but return periodically to the event loop.
    _timerId = startTimer(0);

    // Do not report progress more often that every 1% of the file size or 1 kB.
    _totalSize = _inputFile.size();
    _reportInterval = qMax(Q_INT64_C(1024), _totalSize / 100);
    _nextReport = _reportInterval;

    // Will read packets later.
    return true;
}
Пример #28
0
void LogfileReader::updateView()
{
    // get maximum size of logfile to display
    qint64 pos = Q_INT64_C(1024) * sizeSpin->value();
    getTextView()->clear();

    QFile file(fileName);

    if(file.open(QIODevice::ReadOnly))
    {
        QTextStream stream(&file);
        stream.setCodec(QTextCodec::codecForName("UTF-8"));
        stream.setAutoDetectUnicode(true);

        // Set file pointer to <pos> bytes from the end
        if(stream.device()->size() > pos)
        {
            stream.device()->seek(stream.device()->size() - pos);
        }
        // Skip first line, since it may be incomplete
        // NOTE: we always skip the first line(in the log), but the
        //       first line is just a '\n', so it's ok
        stream.readLine();
        QString str;

        while(!stream.atEnd())
        {
            str = stream.readLine().toHtmlEscaped();
            getTextView()->appendLog(str);
        }

        stream.setDevice(0);
        file.close();
    }
}
Пример #29
0
qint64 PerformanceTimer::difference(PerformanceTimer* timer)
{
    qint64 sec, frac;
    sec = t1 - timer->t1;
    frac = t2 - timer->t2;
    return sec * Q_INT64_C(1000000000) + frac;
}
/*!
  Parses the multipart data and writes the one content to a file.
  Returns the file name.
 */
QString TMultipartFormData::writeContent(QIODevice *dev) const
{
    if (!dev->isOpen()) {
        return QString();
    }

    TTemporaryFile &out = Tf::currentContext()->createTemporaryFile();
    if (!out.open()) {
        return QString();
    }

    while (!dev->atEnd()) {
        QByteArray line = dev->readLine();
        if (line.startsWith(dataBoundary)) {
            qint64 size = qMax(out.size() - 2, Q_INT64_C(0));
            out.resize(size);  // Truncates the CR+LF
            break;
        }

        if (out.write(line) < 0) {
            return QString();
        }
    }
    out.close();
    return out.absoluteFilePath();
}