Ejemplo n.º 1
0
void OctreeTests::byteCountCodingTests() {
    bool verbose = true;
    
    qDebug() << "FIXME: this test is broken and needs to be fixed.";
    qDebug() << "We're disabling this so that ALL_BUILD works";
    return;

    if (verbose) {
        qDebug() << "******************************************************************************************";
    }
    
    qDebug() << "OctreeTests::byteCountCodingTests()";
    
    QByteArray encoded;
    
    if (verbose) {
        qDebug() << "ByteCountCodedUINT zero(0)";
    }
    ByteCountCodedUINT zero(0);
    encoded = zero.encode();
    if (verbose) {
        outputBufferBits((const unsigned char*)encoded.constData(), encoded.size());
    }

    ByteCountCodedUINT decodedZero;
    decodedZero.decode(encoded);
    
    QCOMPARE(decodedZero.data, static_cast<decltype(decodedZero.data)>( 0 ));
    QCOMPARE(decodedZero, zero);

    ByteCountCodedUINT decodedZeroB(encoded);
    
    QCOMPARE(decodedZeroB.data, (unsigned int) 0);

    if (verbose) {
        qDebug() << "ByteCountCodedUINT foo(259)";
    }
    ByteCountCodedUINT foo(259);
    encoded = foo.encode();

    if (verbose) {
        outputBufferBits((const unsigned char*)encoded.constData(), encoded.size());
    }

    ByteCountCodedUINT decodedFoo;
    decodedFoo.decode(encoded);

    QCOMPARE(decodedFoo.data, (unsigned int) 259);

    QCOMPARE(decodedFoo, foo);

    ByteCountCodedUINT decodedFooB(encoded);
    QCOMPARE(decodedFooB.data, (unsigned int) 259);

    if (verbose) {
        qDebug() << "ByteCountCodedUINT bar(1000000)";
    }
    ByteCountCodedUINT bar(1000000);
    encoded = bar.encode();
    if (verbose) {
        outputBufferBits((const unsigned char*)encoded.constData(), encoded.size());
    }

    ByteCountCodedUINT decodedBar;
    decodedBar.decode(encoded);
    QCOMPARE(decodedBar.data, (unsigned int) 1000000);

    QCOMPARE(decodedBar, bar);

    if (verbose) {
        qDebug() << "ByteCountCodedUINT spam(4294967295/2)";
    }
    ByteCountCodedUINT spam(4294967295/2);
    encoded = spam.encode();
    if (verbose) {
        outputBufferBits((const unsigned char*)encoded.constData(), encoded.size());
    }

    ByteCountCodedUINT decodedSpam;
    decodedSpam.decode(encoded);
    if (verbose) {
        qDebug() << "decodedSpam=" << decodedSpam.data;
        qDebug() << "decodedSpam==spam" << (decodedSpam==spam) << " { expected true } ";
    }
    QCOMPARE(decodedSpam.data, (unsigned int) 4294967295/2);

    QCOMPARE(decodedSpam, spam);

    if (verbose) {
        qDebug() << "ByteCountCodedQUINT64 foo64(259)";
    }
    ByteCountCodedQUINT64 foo64(259);
    encoded = foo64.encode();
    if (verbose) {
        outputBufferBits((const unsigned char*)encoded.constData(), encoded.size());
    }
    
    if (verbose) {
        qDebug() << "testing... quint64 foo64POD = foo64;";
    }
    quint64 foo64POD = foo64;
    if (verbose) {
        qDebug() << "foo64POD=" << foo64POD;
    }

    QCOMPARE(foo64POD, (quint64) 259);
    if (verbose) {
        qDebug() << "testing... encoded = foo64;";
    }
    encoded = foo64;

    if (verbose) {
        outputBufferBits((const unsigned char*)encoded.constData(), encoded.size());
    }

    ByteCountCodedQUINT64 decodedFoo64;
    decodedFoo64 = encoded;

    if (verbose) {
        qDebug() << "decodedFoo64=" << decodedFoo64.data;
        qDebug() << "decodedFoo64==foo64" << (decodedFoo64==foo64) << " { expected true } ";
    }
    QCOMPARE(decodedFoo.data, (unsigned int) 259);
    
    QCOMPARE(decodedFoo64, foo64);

    if (verbose) {
        qDebug() << "ByteCountCodedQUINT64 bar64(1000000)";
    }
    ByteCountCodedQUINT64 bar64(1000000);
    encoded = bar64.encode();
    if (verbose) {
        outputBufferBits((const unsigned char*)encoded.constData(), encoded.size());
    }

    ByteCountCodedQUINT64 decodedBar64;
    decodedBar64.decode(encoded);
    QCOMPARE(decodedBar64.data, static_cast<decltype(decodedBar.data)>( 1000000 ));

    QCOMPARE(decodedBar64, bar64);

    if (verbose) {
        qDebug() << "ByteCountCodedQUINT64 spam64(4294967295/2)";
    }
    ByteCountCodedQUINT64 spam64(4294967295/2);
    encoded = spam64.encode();
    if (verbose) {
        outputBufferBits((const unsigned char*)encoded.constData(), encoded.size());
    }

    ByteCountCodedQUINT64 decodedSpam64;
    decodedSpam64.decode(encoded);
    QCOMPARE(decodedSpam64.data, static_cast<decltype(decodedSpam64.data)>( 4294967295/2 ));

    QCOMPARE(decodedSpam64, spam64);
    if (verbose) {
        qDebug() << "testing encoded << spam64";
    }
    encoded.clear();
    encoded << spam64;
    if (verbose) {
        outputBufferBits((const unsigned char*)encoded.constData(), encoded.size());
    }

    if (verbose) {
        qDebug() << "testing encoded >> decodedSpam64";
    }
    encoded >> decodedSpam64;

    QCOMPARE(decodedSpam64, spam64);
    
    if (verbose) {
        qDebug() << "NOW...";
    }
    quint64 now = usecTimestampNow();
    ByteCountCodedQUINT64 nowCoded = now;
    QByteArray nowEncoded = nowCoded;

    ByteCountCodedQUINT64 decodedNow = nowEncoded;
    QCOMPARE(decodedNow.data, static_cast<decltype(decodedNow.data)>( now ));
    
    if (verbose) {
        qDebug() << "******************************************************************************************";
    }
    if (verbose) {
        qDebug() << "******************************************************************************************";
    }
}
Ejemplo n.º 2
0
void OctreeTests::byteCountCodingTests(bool verbose) {
    int testsTaken = 0;
    int testsPassed = 0;
    int testsFailed = 0;

    if (verbose) {
        qDebug() << "******************************************************************************************";
    }
    
    qDebug() << "OctreeTests::byteCountCodingTests()";
    
    QByteArray encoded;
    
    if (verbose) {
        qDebug() << "ByteCountCodedUINT zero(0)";
    }
    ByteCountCodedUINT zero(0);
    encoded = zero.encode();
    if (verbose) {
        outputBufferBits((const unsigned char*)encoded.constData(), encoded.size());
    }

    ByteCountCodedUINT decodedZero;
    decodedZero.decode(encoded);
    if (verbose) {
        qDebug() << "decodedZero=" << decodedZero.data;
        qDebug() << "decodedZero==zero" << (decodedZero == zero) << " { expected true } ";
    }
    testsTaken++;
    bool result1 = (decodedZero.data == 0);
    bool expected1 = true;
    if (result1 == expected1) {
        testsPassed++;
    } else {
        testsFailed++;
        qDebug() << "FAILED - Test 1: ByteCountCodedUINT zero(0) decodedZero.data == 0";
    }

    testsTaken++;
    bool result2 = (decodedZero == zero);
    bool expected2 = true;
    if (result2 == expected2) {
        testsPassed++;
    } else {
        testsFailed++;
        qDebug() << "FAILED - Test 2: ByteCountCodedUINT zero(0) (decodedZero == zero)";
    }

    ByteCountCodedUINT decodedZeroB(encoded);
    if (verbose) {
        qDebug() << "decodedZeroB=" << decodedZeroB.data;
    }
    testsTaken++;
    bool result3 = (decodedZeroB.data == 0);
    bool expected3 = true;
    if (result3 == expected3) {
        testsPassed++;
    } else {
        testsFailed++;
        qDebug() << "FAILED - Test 3: (decodedZeroB.data == 0)";
    }

    if (verbose) {
        qDebug() << "ByteCountCodedUINT foo(259)";
    }
    ByteCountCodedUINT foo(259);
    encoded = foo.encode();

    if (verbose) {
        outputBufferBits((const unsigned char*)encoded.constData(), encoded.size());
    }

    ByteCountCodedUINT decodedFoo;
    decodedFoo.decode(encoded);

    if (verbose) {
        qDebug() << "decodedFoo=" << decodedFoo.data;
        qDebug() << "decodedFoo==foo" << (decodedFoo == foo) << " { expected true } ";
    }
    testsTaken++;
    bool result4 = (decodedFoo.data == 259);
    bool expected4 = true;
    if (result4 == expected4) {
        testsPassed++;
    } else {
        testsFailed++;
        qDebug() << "FAILED - Test 4: ByteCountCodedUINT zero(0) (decodedFoo.data == 259)";
    }

    testsTaken++;
    bool result5 = (decodedFoo == foo);
    bool expected5 = true;
    if (result5 == expected5) {
        testsPassed++;
    } else {
        testsFailed++;
        qDebug() << "FAILED - Test 5: (decodedFoo == foo)";
    }

    ByteCountCodedUINT decodedFooB(encoded);
    if (verbose) {
        qDebug() << "decodedFooB=" << decodedFooB.data;
    }
    testsTaken++;
    bool result6 = (decodedFooB.data == 259);
    bool expected6 = true;
    if (result6 == expected6) {
        testsPassed++;
    } else {
        testsFailed++;
        qDebug() << "FAILED - Test 6: (decodedFooB.data == 259)";
    }


    if (verbose) {
        qDebug() << "ByteCountCodedUINT bar(1000000)";
    }
    ByteCountCodedUINT bar(1000000);
    encoded = bar.encode();
    if (verbose) {
        outputBufferBits((const unsigned char*)encoded.constData(), encoded.size());
    }

    ByteCountCodedUINT decodedBar;
    decodedBar.decode(encoded);
    if (verbose) {
        qDebug() << "decodedBar=" << decodedBar.data;
        qDebug() << "decodedBar==bar" << (decodedBar == bar) << " { expected true } ";
    }
    testsTaken++;
    bool result7 = (decodedBar.data == 1000000);
    bool expected7 = true;
    if (result7 == expected7) {
        testsPassed++;
    } else {
        testsFailed++;
        qDebug() << "FAILED - Test 7: ByteCountCodedUINT zero(0) (decodedBar.data == 1000000)";
    }

    testsTaken++;
    bool result8 = (decodedBar == bar);
    bool expected8 = true;
    if (result8 == expected8) {
        testsPassed++;
    } else {
        testsFailed++;
        qDebug() << "FAILED - Test 8: (decodedBar == bar)";
    }

    if (verbose) {
        qDebug() << "ByteCountCodedUINT spam(4294967295/2)";
    }
    ByteCountCodedUINT spam(4294967295/2);
    encoded = spam.encode();
    if (verbose) {
        outputBufferBits((const unsigned char*)encoded.constData(), encoded.size());
    }

    ByteCountCodedUINT decodedSpam;
    decodedSpam.decode(encoded);
    if (verbose) {
        qDebug() << "decodedSpam=" << decodedSpam.data;
        qDebug() << "decodedSpam==spam" << (decodedSpam==spam) << " { expected true } ";
    }
    testsTaken++;
    bool result9 = (decodedSpam.data == 4294967295/2);
    bool expected9 = true;
    if (result9 == expected9) {
        testsPassed++;
    } else {
        testsFailed++;
        qDebug() << "FAILED - Test 9: (decodedSpam.data == 4294967295/2)";
    }

    testsTaken++;
    bool result10 = (decodedSpam == spam);
    bool expected10 = true;
    if (result10 == expected10) {
        testsPassed++;
    } else {
        testsFailed++;
        qDebug() << "FAILED - Test 10: (decodedSpam == spam)";
    }

    if (verbose) {
        qDebug() << "ByteCountCodedQUINT64 foo64(259)";
    }
    ByteCountCodedQUINT64 foo64(259);
    encoded = foo64.encode();
    if (verbose) {
        outputBufferBits((const unsigned char*)encoded.constData(), encoded.size());
    }
    
    if (verbose) {
        qDebug() << "testing... quint64 foo64POD = foo64;";
    }
    quint64 foo64POD = foo64;
    if (verbose) {
        qDebug() << "foo64POD=" << foo64POD;
    }

    testsTaken++;
    bool result11 = (foo64POD == 259);
    bool expected11 = true;
    if (result11 == expected11) {
        testsPassed++;
    } else {
        testsFailed++;
        qDebug() << "FAILED - Test 11: quint64 foo64POD = foo64";
    }

    if (verbose) {
        qDebug() << "testing... encoded = foo64;";
    }
    encoded = foo64;

    if (verbose) {
        outputBufferBits((const unsigned char*)encoded.constData(), encoded.size());
    }

    ByteCountCodedQUINT64 decodedFoo64;
    decodedFoo64 = encoded;

    if (verbose) {
        qDebug() << "decodedFoo64=" << decodedFoo64.data;
        qDebug() << "decodedFoo64==foo64" << (decodedFoo64==foo64) << " { expected true } ";
    }
    testsTaken++;
    bool result12 = (decodedFoo64.data == 259);
    bool expected12 = true;
    if (result12 == expected12) {
        testsPassed++;
    } else {
        testsFailed++;
        qDebug() << "FAILED - Test 12: decodedFoo64.data == 259";
    }

    testsTaken++;
    bool result13 = (decodedFoo64==foo64);
    bool expected13 = true;
    if (result13 == expected13) {
        testsPassed++;
    } else {
        testsFailed++;
        qDebug() << "FAILED - Test 13: decodedFoo64==foo64";
    }

    if (verbose) {
        qDebug() << "ByteCountCodedQUINT64 bar64(1000000)";
    }
    ByteCountCodedQUINT64 bar64(1000000);
    encoded = bar64.encode();
    if (verbose) {
        outputBufferBits((const unsigned char*)encoded.constData(), encoded.size());
    }

    ByteCountCodedQUINT64 decodedBar64;
    decodedBar64.decode(encoded);
    if (verbose) {
        qDebug() << "decodedBar64=" << decodedBar64.data;
        qDebug() << "decodedBar64==bar64" << (decodedBar64==bar64) << " { expected true } ";
    }
    testsTaken++;
    bool result14 = (decodedBar64.data == 1000000);
    bool expected14 = true;
    if (result14 == expected14) {
        testsPassed++;
    } else {
        testsFailed++;
        qDebug() << "FAILED - Test 14: decodedBar64.data == 1000000";
    }

    testsTaken++;
    bool result15 = (decodedBar64==bar64);
    bool expected15 = true;
    if (result15 == expected15) {
        testsPassed++;
    } else {
        testsFailed++;
        qDebug() << "FAILED - Test 15: decodedBar64==bar64";
    }

    if (verbose) {
        qDebug() << "ByteCountCodedQUINT64 spam64(4294967295/2)";
    }
    ByteCountCodedQUINT64 spam64(4294967295/2);
    encoded = spam64.encode();
    if (verbose) {
        outputBufferBits((const unsigned char*)encoded.constData(), encoded.size());
    }

    ByteCountCodedQUINT64 decodedSpam64;
    decodedSpam64.decode(encoded);
    if (verbose) {
        qDebug() << "decodedSpam64=" << decodedSpam64.data;
        qDebug() << "decodedSpam64==spam64" << (decodedSpam64==spam64) << " { expected true } ";
    }
    testsTaken++;
    bool result16 = (decodedSpam64.data == 4294967295/2);
    bool expected16 = true;
    if (result16 == expected16) {
        testsPassed++;
    } else {
        testsFailed++;
        qDebug() << "FAILED - Test 16: decodedSpam64.data == 4294967295/2";
    }

    testsTaken++;
    bool result17 = (decodedSpam64==spam64);
    bool expected17 = true;
    if (result17 == expected17) {
        testsPassed++;
    } else {
        testsFailed++;
        qDebug() << "FAILED - Test 17: decodedSpam64==spam64";
    }

    if (verbose) {
        qDebug() << "testing encoded << spam64";
    }
    encoded.clear();
    encoded << spam64;
    if (verbose) {
        outputBufferBits((const unsigned char*)encoded.constData(), encoded.size());
    }

    if (verbose) {
        qDebug() << "testing encoded >> decodedSpam64";
    }
    encoded >> decodedSpam64;

    if (verbose) {
        qDebug() << "decodedSpam64=" << decodedSpam64.data;
    }
    testsTaken++;
    bool result18 = (decodedSpam64==spam64);
    bool expected18 = true;
    if (result18 == expected18) {
        testsPassed++;
    } else {
        testsFailed++;
        qDebug() << "FAILED - Test 18: decodedSpam64==spam64";
    }

    //ByteCountCodedINT shouldFail(-100);
    
    if (verbose) {
        qDebug() << "NOW...";
    }
    quint64 now = usecTimestampNow();
    ByteCountCodedQUINT64 nowCoded = now;
    QByteArray nowEncoded = nowCoded;

    if (verbose) {
        outputBufferBits((const unsigned char*)nowEncoded.constData(), nowEncoded.size());
    }
    ByteCountCodedQUINT64 decodedNow = nowEncoded;

    testsTaken++;
    bool result19 = (decodedNow.data==now);
    bool expected19 = true;
    if (result19 == expected19) {
        testsPassed++;
    } else {
        testsFailed++;
        qDebug() << "FAILED - Test 19: now test...";
    }
    
    if (verbose) {
        qDebug() << "******************************************************************************************";
    }
    qDebug() << "   tests passed:" << testsPassed << "out of" << testsTaken;
    if (verbose) {
        qDebug() << "******************************************************************************************";
    }
}