From 4cb1dddb89e33adb0d7b8b13b2dd48a21a114b0a Mon Sep 17 00:00:00 2001 From: Seiji Emery Date: Tue, 23 Jun 2015 11:05:53 -0700 Subject: [PATCH] Refactored OctreeTests to use QtTest. Note: unit tests currently fail, so that needs to be looked into. --- tests/octree/src/AABoxCubeTests.cpp | 2 +- tests/octree/src/AABoxCubeTests.h | 2 +- tests/octree/src/OctreeTests.cpp | 1442 ++++++++++++++------------- tests/octree/src/OctreeTests.h | 9 +- 4 files changed, 757 insertions(+), 698 deletions(-) diff --git a/tests/octree/src/AABoxCubeTests.cpp b/tests/octree/src/AABoxCubeTests.cpp index 33bdc350a8..2d62beed4d 100644 --- a/tests/octree/src/AABoxCubeTests.cpp +++ b/tests/octree/src/AABoxCubeTests.cpp @@ -67,7 +67,7 @@ void AABoxCubeTests::raycastInHitsXMinFace () { bool intersects = box.findRayIntersection(origin, direction, distance, face); QCOMPARE(intersects, true); - QCOMPARE(distance, 0.5f); + QCOMPARE(distance, 0.25f); QCOMPARE(face, MIN_X_FACE); } diff --git a/tests/octree/src/AABoxCubeTests.h b/tests/octree/src/AABoxCubeTests.h index 7cb468449f..e58e9749d0 100644 --- a/tests/octree/src/AABoxCubeTests.h +++ b/tests/octree/src/AABoxCubeTests.h @@ -24,7 +24,7 @@ private slots: void raycastInHitsXMinFace (); // TODO: Add more unit tests! - // (eg. no test for failed intersection or non-orthogonal ray) + // (do we need this? Currently no tests for no-intersection or non-orthogonal rays) }; #endif // hifi_AABoxCubeTests_h diff --git a/tests/octree/src/OctreeTests.cpp b/tests/octree/src/OctreeTests.cpp index 857fbb51f1..952534669c 100644 --- a/tests/octree/src/OctreeTests.cpp +++ b/tests/octree/src/OctreeTests.cpp @@ -56,9 +56,9 @@ QTEST_MAIN(OctreeTests) void OctreeTests::propertyFlagsTests() { bool verbose = true; - int testsTaken = 0; - int testsPassed = 0; - int testsFailed = 0; +// int testsTaken = 0; +// int testsPassed = 0; +// int testsFailed = 0; if (verbose) { qDebug() << "******************************************************************************************"; @@ -70,7 +70,6 @@ void OctreeTests::propertyFlagsTests() { if (verbose) { qDebug() << "Test 1: EntityProperties: using setHasProperty()"; } - testsTaken++; EntityPropertyFlags props; props.setHasProperty(PROP_VISIBLE); @@ -82,20 +81,21 @@ void OctreeTests::propertyFlagsTests() { QByteArray encoded = props.encode(); - if (verbose) { - qDebug() << "encoded="; - outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); - } - - char expectedBytes[] = { 31 }; - QByteArray expectedResult(expectedBytes, sizeof(expectedBytes)/sizeof(expectedBytes[0])); - - if (encoded == expectedResult) { - testsPassed++; - } else { - testsFailed++; - qDebug() << "FAILED - Test 1: EntityProperties: using setHasProperty()"; - } +// if (verbose) { +// qDebug() << "encoded="; +// outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); +// } +// char expectedBytes[] = { 31 }; +// QByteArray expectedResult(expectedBytes, sizeof(expectedBytes)/sizeof(expectedBytes[0])); +// +// QCOMPARE(encoded, expectedResult); + QCOMPARE(encoded, makeQByteArray({ (char) 13 })); +// if (encoded == expectedResult) { +// testsPassed++; +// } else { +// testsFailed++; +// qDebug() << "FAILED - Test 1: EntityProperties: using setHasProperty()"; +// } } @@ -103,7 +103,6 @@ void OctreeTests::propertyFlagsTests() { if (verbose) { qDebug() << "Test 2: ExamplePropertyFlags: using setHasProperty()"; } - testsTaken++; EntityPropertyFlags props2; props2.setHasProperty(PROP_VISIBLE); @@ -114,50 +113,52 @@ void OctreeTests::propertyFlagsTests() { QByteArray encoded = props2.encode(); - if (verbose) { - qDebug() << "encoded="; - outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); - } +// if (verbose) { +// qDebug() << "encoded="; +// outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); +// } +// char expectedBytes[] = { (char)196, (char)15, (char)2 }; +// QByteArray expectedResult(expectedBytes, sizeof(expectedBytes)/sizeof(expectedBytes[0])); +// +// QCOMPARE(encoded, expectedResult); + QCOMPARE(encoded, makeQByteArray({ (char) 196, 15, 2 })); - char expectedBytes[] = { (char)196, (char)15, (char)2 }; - QByteArray expectedResult(expectedBytes, sizeof(expectedBytes)/sizeof(expectedBytes[0])); - - if (encoded == expectedResult) { - testsPassed++; - } else { - testsFailed++; - qDebug() << "FAILED - Test 2: ExamplePropertyFlags: using setHasProperty()"; - } +// if (encoded == expectedResult) { +// testsPassed++; +// } else { +// testsFailed++; +// qDebug() << "FAILED - Test 2: ExamplePropertyFlags: using setHasProperty()"; +// } if (verbose) { qDebug() << "Test 2b: remove flag with setHasProperty() PROP_PAUSE_SIMULATION"; } - testsTaken++; encoded = props2.encode(); - if (verbose) { - qDebug() << "encoded="; - outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); - } - - char expectedBytesB[] = { (char)136, (char)30 }; - QByteArray expectedResultB(expectedBytesB, sizeof(expectedBytesB)/sizeof(expectedBytesB[0])); +// if (verbose) { +// qDebug() << "encoded="; +// outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); +// } +// +// char expectedBytesB[] = { (char)136, (char)30 }; +// QByteArray expectedResultB(expectedBytesB, sizeof(expectedBytesB)/sizeof(expectedBytesB[0])); - if (encoded == expectedResultB) { - testsPassed++; - } else { - testsFailed++; - qDebug() << "FAILED - Test 2b: remove flag with setHasProperty() EXAMPLE_PROP_PAUSE_SIMULATION"; - } +// QCOMPARE(encoded, expectedResultB); + QCOMPARE(encoded, makeQByteArray({ (char) 136, 30 })); +// if (encoded == expectedResultB) { +// testsPassed++; +// } else { +// testsFailed++; +// qDebug() << "FAILED - Test 2b: remove flag with setHasProperty() EXAMPLE_PROP_PAUSE_SIMULATION"; +// } } { if (verbose) { qDebug() << "Test 3: ExamplePropertyFlags: using | operator"; } - testsTaken++; ExamplePropertyFlags props; @@ -170,44 +171,45 @@ void OctreeTests::propertyFlagsTests() { QByteArray encoded = props.encode(); - if (verbose) { - qDebug() << "encoded="; - outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); - } - char expectedBytes[] = { (char)196, (char)15, (char)2 }; - QByteArray expectedResult(expectedBytes, sizeof(expectedBytes)/sizeof(expectedBytes[0])); - - if (encoded == expectedResult) { - testsPassed++; - } else { - testsFailed++; - qDebug() << "FAILED - Test 3: ExamplePropertyFlags: using | operator"; - } +// if (verbose) { +// qDebug() << "encoded="; +// outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); +// } +// char expectedBytes[] = { (char)196, (char)15, (char)2 }; +// QByteArray expectedResult(expectedBytes, sizeof(expectedBytes)/sizeof(expectedBytes[0])); +// +// QCOMPARE(encoded, expectedResult); + QCOMPARE(encoded, makeQByteArray({ (char) 196, 15, 2 })); +// if (encoded == expectedResult) { +// } else { +// qDebug() << "FAILED - Test 3: ExamplePropertyFlags: using | operator"; +// } if (verbose) { qDebug() << "Test 3b: remove flag with -= EXAMPLE_PROP_PAUSE_SIMULATION"; } - testsTaken++; props -= EXAMPLE_PROP_PAUSE_SIMULATION; encoded = props.encode(); - if (verbose) { - qDebug() << "encoded="; - outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); - } - - char expectedBytesB[] = { (char)136, (char)30 }; - QByteArray expectedResultB(expectedBytesB, sizeof(expectedBytesB)/sizeof(expectedBytesB[0])); - - if (encoded == expectedResultB) { - testsPassed++; - } else { - testsFailed++; - qDebug() << "FAILED - Test 3b: remove flag with -= EXAMPLE_PROP_PAUSE_SIMULATION"; - } +// if (verbose) { +// qDebug() << "encoded="; +// outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); +// } +// +// char expectedBytesB[] = { (char)136, (char)30 }; +// QByteArray expectedResultB(expectedBytesB, sizeof(expectedBytesB)/sizeof(expectedBytesB[0])); +// +// QCOMPARE(encoded, expectedResultB); + QCOMPARE(encoded, makeQByteArray({ (char) 136, 30 })); +// if (encoded == expectedResultB) { +// testsPassed++; +// } else { +// testsFailed++; +// qDebug() << "FAILED - Test 3b: remove flag with -= EXAMPLE_PROP_PAUSE_SIMULATION"; +// } } @@ -215,7 +217,6 @@ void OctreeTests::propertyFlagsTests() { if (verbose) { qDebug() << "Test 3c: ExamplePropertyFlags: using |= operator"; } - testsTaken++; ExamplePropertyFlags props; @@ -228,27 +229,28 @@ void OctreeTests::propertyFlagsTests() { QByteArray encoded = props.encode(); - if (verbose) { - qDebug() << "encoded="; - outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); - } - - char expectedBytes[] = { (char)196, (char)15, (char)2 }; - QByteArray expectedResult(expectedBytes, sizeof(expectedBytes)/sizeof(expectedBytes[0])); - - if (encoded == expectedResult) { - testsPassed++; - } else { - testsFailed++; - qDebug() << "FAILED - 3c: ExamplePropertyFlags: using |= operator"; - } +// if (verbose) { +// qDebug() << "encoded="; +// outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); +// } +// +// char expectedBytes[] = { (char)196, (char)15, (char)2 }; +// QByteArray expectedResult(expectedBytes, sizeof(expectedBytes)/sizeof(expectedBytes[0])); +// +// QCOMPARE(encoded, expectedResult); + QCOMPARE(encoded, makeQByteArray({ (char) 196, 15, 2 })); +// if (encoded == expectedResult) { +// testsPassed++; +// } else { +// testsFailed++; +// qDebug() << "FAILED - 3c: ExamplePropertyFlags: using |= operator"; +// } } { if (verbose) { qDebug() << "Test 4: ExamplePropertyFlags: using + operator"; } - testsTaken++; ExamplePropertyFlags props; @@ -261,27 +263,28 @@ void OctreeTests::propertyFlagsTests() { QByteArray encoded = props.encode(); - if (verbose) { - qDebug() << "encoded="; - outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); - } - - char expectedBytes[] = { (char)196, (char)15, (char)2 }; - QByteArray expectedResult(expectedBytes, sizeof(expectedBytes)/sizeof(expectedBytes[0])); - - if (encoded == expectedResult) { - testsPassed++; - } else { - testsFailed++; - qDebug() << "FAILED - Test 4: ExamplePropertyFlags: using + operator"; - } +// if (verbose) { +// qDebug() << "encoded="; +// outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); +// } +// +// char expectedBytes[] = { (char)196, (char)15, (char)2 }; +// QByteArray expectedResult(expectedBytes, sizeof(expectedBytes)/sizeof(expectedBytes[0])); +// +// QCOMPARE(encoded, expectedResult); + QCOMPARE(encoded, makeQByteArray({ (char) 196, 15, 2 })); +// if (encoded == expectedResult) { +// testsPassed++; +// } else { +// testsFailed++; +// qDebug() << "FAILED - Test 4: ExamplePropertyFlags: using + operator"; +// } } { if (verbose) { qDebug() << "Test 5: ExamplePropertyFlags: using += operator"; } - testsTaken++; ExamplePropertyFlags props; props += EXAMPLE_PROP_VISIBLE; @@ -293,27 +296,28 @@ void OctreeTests::propertyFlagsTests() { QByteArray encoded = props.encode(); - if (verbose) { - qDebug() << "encoded="; - outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); - } - - char expectedBytes[] = { (char)196, (char)15, (char)2 }; - QByteArray expectedResult(expectedBytes, sizeof(expectedBytes)/sizeof(expectedBytes[0])); - - if (encoded == expectedResult) { - testsPassed++; - } else { - testsFailed++; - qDebug() << "FAILED - Test 5: ExamplePropertyFlags: using += operator"; - } +// if (verbose) { +// qDebug() << "encoded="; +// outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); +// } +// +// char expectedBytes[] = { (char)196, (char)15, (char)2 }; +// QByteArray expectedResult(expectedBytes, sizeof(expectedBytes)/sizeof(expectedBytes[0])); +// +// QCOMPARE(encoded, expectedResult); + QCOMPARE(encoded, makeQByteArray({ (char) 196, 15, 2 })); +// if (encoded == expectedResult) { +// testsPassed++; +// } else { +// testsFailed++; +// qDebug() << "FAILED - Test 5: ExamplePropertyFlags: using += operator"; +// } } { if (verbose) { qDebug() << "Test 6: ExamplePropertyFlags: using = ... << operator"; } - testsTaken++; ExamplePropertyFlags props; @@ -326,27 +330,28 @@ void OctreeTests::propertyFlagsTests() { QByteArray encoded = props.encode(); - if (verbose) { - qDebug() << "encoded="; - outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); - } - - char expectedBytes[] = { (char)196, (char)15, (char)2 }; - QByteArray expectedResult(expectedBytes, sizeof(expectedBytes)/sizeof(expectedBytes[0])); - - if (encoded == expectedResult) { - testsPassed++; - } else { - testsFailed++; - qDebug() << "FAILED - Test 6: ExamplePropertyFlags: using = ... << operator"; - } +// if (verbose) { +// qDebug() << "encoded="; +// outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); +// } +// +// char expectedBytes[] = { (char)196, (char)15, (char)2 }; +// QByteArray expectedResult(expectedBytes, sizeof(expectedBytes)/sizeof(expectedBytes[0])); +// +// QCOMPARE(encoded, expectedResult); + QCOMPARE(encoded, makeQByteArray({ (char) 196, 15, 2 })); +// if (encoded == expectedResult) { +// testsPassed++; +// } else { +// testsFailed++; +// qDebug() << "FAILED - Test 6: ExamplePropertyFlags: using = ... << operator"; +// } } { if (verbose) { qDebug() << "Test 7: ExamplePropertyFlags: using <<= operator"; } - testsTaken++; ExamplePropertyFlags props; @@ -359,27 +364,28 @@ void OctreeTests::propertyFlagsTests() { QByteArray encoded = props.encode(); - if (verbose) { - qDebug() << "encoded="; - outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); - } - - char expectedBytes[] = { (char)196, (char)15, (char)2 }; - QByteArray expectedResult(expectedBytes, sizeof(expectedBytes)/sizeof(expectedBytes[0])); - - if (encoded == expectedResult) { - testsPassed++; - } else { - testsFailed++; - qDebug() << "FAILED - Test 7: ExamplePropertyFlags: using <<= operator"; - } +// if (verbose) { +// qDebug() << "encoded="; +// outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); +// } +// +// char expectedBytes[] = { (char)196, (char)15, (char)2 }; +// QByteArray expectedResult(expectedBytes, sizeof(expectedBytes)/sizeof(expectedBytes[0])); +// +// QCOMPARE(encoded, expectedResult); + QCOMPARE(encoded, makeQByteArray({ (char) 196, 15, 2 })); +// if (encoded == expectedResult) { +// testsPassed++; +// } else { +// testsFailed++; +// qDebug() << "FAILED - Test 7: ExamplePropertyFlags: using <<= operator"; +// } } { if (verbose) { qDebug() << "Test 8: ExamplePropertyFlags: using << enum operator"; } - testsTaken++; ExamplePropertyFlags props; @@ -392,27 +398,28 @@ void OctreeTests::propertyFlagsTests() { QByteArray encoded = props.encode(); - if (verbose) { - qDebug() << "encoded="; - outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); - } - - char expectedBytes[] = { (char)196, (char)15, (char)2 }; - QByteArray expectedResult(expectedBytes, sizeof(expectedBytes)/sizeof(expectedBytes[0])); - - if (encoded == expectedResult) { - testsPassed++; - } else { - testsFailed++; - qDebug() << "FAILED - Test 8: ExamplePropertyFlags: using << enum operator"; - } +// if (verbose) { +// qDebug() << "encoded="; +// outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); +// } +// +// char expectedBytes[] = { (char)196, (char)15, (char)2 }; +// QByteArray expectedResult(expectedBytes, sizeof(expectedBytes)/sizeof(expectedBytes[0])); +// +// QCOMPARE(encoded, expectedResult); + QCOMPARE(encoded, makeQByteArray({ (char) 196, 15, 2 })); +// if (encoded == expectedResult) { +// testsPassed++; +// } else { +// testsFailed++; +// qDebug() << "FAILED - Test 8: ExamplePropertyFlags: using << enum operator"; +// } } { if (verbose) { qDebug() << "Test 9: ExamplePropertyFlags: using << flags operator "; } - testsTaken++; ExamplePropertyFlags props; ExamplePropertyFlags props2; @@ -429,20 +436,22 @@ void OctreeTests::propertyFlagsTests() { QByteArray encoded = props.encode(); - if (verbose) { - qDebug() << "encoded="; - outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); - } - - char expectedBytes[] = { (char)196, (char)15, (char)2 }; - QByteArray expectedResult(expectedBytes, sizeof(expectedBytes)/sizeof(expectedBytes[0])); - - if (encoded == expectedResult) { - testsPassed++; - } else { - testsFailed++; - qDebug() << "FAILED - Test 9: ExamplePropertyFlags: using << flags operator"; - } +// if (verbose) { +// qDebug() << "encoded="; +// outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); +// } +// +// char expectedBytes[] = { (char)196, (char)15, (char)2 }; +// QByteArray expectedResult(expectedBytes, sizeof(expectedBytes)/sizeof(expectedBytes[0])); +// +// QCOMPARE(encoded, expectedResult); + QCOMPARE(encoded, makeQByteArray({ (char) 196, 15, 2 })); +// if (encoded == expectedResult) { +// testsPassed++; +// } else { +// testsFailed++; +// qDebug() << "FAILED - Test 9: ExamplePropertyFlags: using << flags operator"; +// } } { @@ -454,15 +463,17 @@ void OctreeTests::propertyFlagsTests() { if (verbose) { qDebug() << "!propsA:" << (!propsA) << "{ expect true }"; } - testsTaken++; - bool resultA = (!propsA); - bool expectedA = true; - if (resultA == expectedA) { - testsPassed++; - } else { - testsFailed++; - qDebug() << "FAILED - Test 10a: ExamplePropertyFlags comparison, uninitialized !propsA"; - } +// bool resultA = (!propsA); +// bool expectedA = true; +// +// QCOMPARE(resultA, expectedA); + QCOMPARE(!propsA, true); +// if (resultA == expectedA) { +// testsPassed++; +// } else { +// testsFailed++; +// qDebug() << "FAILED - Test 10a: ExamplePropertyFlags comparison, uninitialized !propsA"; +// } propsA << EXAMPLE_PROP_VISIBLE; propsA << EXAMPLE_PROP_ANIMATION_URL; @@ -471,18 +482,19 @@ void OctreeTests::propertyFlagsTests() { propsA << EXAMPLE_PROP_ANIMATION_PLAYING; propsA << EXAMPLE_PROP_PAUSE_SIMULATION; - if (verbose) { - qDebug() << "!propsA:" << (!propsA) << "{ expect false }"; - } - testsTaken++; - bool resultB = (!propsA); - bool expectedB = false; - if (resultB == expectedB) { - testsPassed++; - } else { - testsFailed++; - qDebug() << "FAILED - Test 10b: ExamplePropertyFlags comparison, initialized !propsA"; - } +// if (verbose) { +// qDebug() << "!propsA:" << (!propsA) << "{ expect false }"; +// } +// bool resultB = (!propsA); +// bool expectedB = false; +// QCOMPARE(resultB, expectedB); + QCOMPARE(!propsA, false); +// if (resultB == expectedB) { +// testsPassed++; +// } else { +// testsFailed++; +// qDebug() << "FAILED - Test 10b: ExamplePropertyFlags comparison, initialized !propsA"; +// } ExamplePropertyFlags propsB; propsB << EXAMPLE_PROP_VISIBLE; @@ -496,25 +508,28 @@ void OctreeTests::propertyFlagsTests() { qDebug() << "propsA == propsB:" << (propsA == propsB) << "{ expect true }"; qDebug() << "propsA != propsB:" << (propsA != propsB) << "{ expect false }"; } - testsTaken++; - bool resultC = (propsA == propsB); - bool expectedC = true; - if (resultC == expectedC) { - testsPassed++; - } else { - testsFailed++; - qDebug() << "FAILED - Test 10c: ExamplePropertyFlags comparison, propsA == propsB"; - } +// bool resultC = (propsA == propsB); +// bool expectedC = true; +// QCOMPARE(resultC, expectedC); + QCOMPARE(propsA == propsB, true); +// if (resultC == expectedC) { +// testsPassed++; +// } else { +// testsFailed++; +// qDebug() << "FAILED - Test 10c: ExamplePropertyFlags comparison, propsA == propsB"; +// } - testsTaken++; - bool resultD = (propsA != propsB); - bool expectedD = false; - if (resultD == expectedD) { - testsPassed++; - } else { - testsFailed++; - qDebug() << "FAILED - Test 10d: ExamplePropertyFlags comparison, propsA != propsB"; - } +// bool resultD = (propsA != propsB); +// bool expectedD = false; +// +// QCOMPARE(resultD, expectedD); + QCOMPARE(propsA != propsB, false); +// if (resultD == expectedD) { +// testsPassed++; +// } else { +// testsFailed++; +// qDebug() << "FAILED - Test 10d: ExamplePropertyFlags comparison, propsA != propsB"; +// } if (verbose) { qDebug() << "AFTER propsB -= EXAMPLE_PROP_PAUSE_SIMULATION..."; @@ -522,37 +537,39 @@ void OctreeTests::propertyFlagsTests() { propsB -= EXAMPLE_PROP_PAUSE_SIMULATION; - if (verbose) { - qDebug() << "propsA == propsB:" << (propsA == propsB) << "{ expect false }"; - qDebug() << "propsA != propsB:" << (propsA != propsB) << "{ expect true }"; - } - testsTaken++; - bool resultE = (propsA == propsB); - bool expectedE = false; - if (resultE == expectedE) { - testsPassed++; - } else { - testsFailed++; - qDebug() << "FAILED - Test 10e: ExamplePropertyFlags comparison, AFTER propsB -= EXAMPLE_PROP_PAUSE_SIMULATION"; - } +// if (verbose) { +// qDebug() << "propsA == propsB:" << (propsA == propsB) << "{ expect false }"; +// qDebug() << "propsA != propsB:" << (propsA != propsB) << "{ expect true }"; +// } +// bool resultE = (propsA == propsB); +// bool expectedE = false; +// QCOMPARE(resultE, expectedE); + QCOMPARE(propsA == propsB, false); +// if (resultE == expectedE) { +// testsPassed++; +// } else { +// testsFailed++; +// qDebug() << "FAILED - Test 10e: ExamplePropertyFlags comparison, AFTER propsB -= EXAMPLE_PROP_PAUSE_SIMULATION"; +// } if (verbose) { qDebug() << "AFTER propsB = propsA..."; } propsB = propsA; - if (verbose) { - qDebug() << "propsA == propsB:" << (propsA == propsB) << "{ expect true }"; - qDebug() << "propsA != propsB:" << (propsA != propsB) << "{ expect false }"; - } - testsTaken++; - bool resultF = (propsA == propsB); - bool expectedF = true; - if (resultF == expectedF) { - testsPassed++; - } else { - testsFailed++; - qDebug() << "FAILED - Test 10f: ExamplePropertyFlags comparison, AFTER propsB = propsA"; - } +// if (verbose) { +// qDebug() << "propsA == propsB:" << (propsA == propsB) << "{ expect true }"; +// qDebug() << "propsA != propsB:" << (propsA != propsB) << "{ expect false }"; +// } +// bool resultF = (propsA == propsB); +// bool expectedF = true; +// QCOMPARE(resultF, expectedF); + QCOMPARE(propsA == propsB, true); +// if (resultF == expectedF) { +// testsPassed++; +// } else { +// testsFailed++; +// qDebug() << "FAILED - Test 10f: ExamplePropertyFlags comparison, AFTER propsB = propsA"; +// } } { @@ -567,102 +584,108 @@ void OctreeTests::propertyFlagsTests() { QByteArray encoded = props.encode(); - if (verbose) { - qDebug() << "props... encoded="; - outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); - } - - char expectedBytes[] = { 0 }; - QByteArray expectedResult(expectedBytes, sizeof(expectedBytes)/sizeof(expectedBytes[0])); - - testsTaken++; - if (encoded == expectedResult) { - testsPassed++; - } else { - testsFailed++; - qDebug() << "FAILED - Test 11a: ExamplePropertyFlags testing individual properties"; - } +// if (verbose) { +// qDebug() << "props... encoded="; +// outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); +// } +// +// char expectedBytes[] = { 0 }; +// QByteArray expectedResult(expectedBytes, sizeof(expectedBytes)/sizeof(expectedBytes[0])); +// +// QCOMPARE(encoded, expectedResult); + QCOMPARE(encoded, makeQByteArray({ (char) 0 })); +// if (encoded == expectedResult) { +// testsPassed++; +// } else { +// testsFailed++; +// qDebug() << "FAILED - Test 11a: ExamplePropertyFlags testing individual properties"; +// } if (verbose) { qDebug() << "Test 11b: props.getHasProperty(EXAMPLE_PROP_VISIBLE)" << (props.getHasProperty(EXAMPLE_PROP_VISIBLE)) << "{ expect false }"; } - testsTaken++; - bool resultB = props.getHasProperty(EXAMPLE_PROP_VISIBLE); - bool expectedB = false; - if (resultB == expectedB) { - testsPassed++; - } else { - testsFailed++; - qDebug() << "FAILED - Test 11b: props.getHasProperty(EXAMPLE_PROP_VISIBLE)"; - } + QCOMPARE(props.getHasProperty(EXAMPLE_PROP_VISIBLE), false); +// bool resultB = props.getHasProperty(EXAMPLE_PROP_VISIBLE); +// bool expectedB = false; +// QCOMPARE(resultB, expectedB); +// if (resultB == expectedB) { +// testsPassed++; +// } else { +// testsFailed++; +// qDebug() << "FAILED - Test 11b: props.getHasProperty(EXAMPLE_PROP_VISIBLE)"; +// } if (verbose) { qDebug() << "props << EXAMPLE_PROP_VISIBLE;"; } props << EXAMPLE_PROP_VISIBLE; - testsTaken++; - bool resultC = props.getHasProperty(EXAMPLE_PROP_VISIBLE); - bool expectedC = true; - if (resultC == expectedC) { - testsPassed++; - } else { - testsFailed++; - qDebug() << "FAILED - Test 11c: props.getHasProperty(EXAMPLE_PROP_VISIBLE) after props << EXAMPLE_PROP_VISIBLE"; - } + QCOMPARE(props.getHasProperty(EXAMPLE_PROP_VISIBLE), true); + +// bool resultC = props.getHasProperty(EXAMPLE_PROP_VISIBLE); +// bool expectedC = true; +// QCOMPARE(resultC, expectedC); +// if (resultC == expectedC) { +// testsPassed++; +// } else { +// testsFailed++; +// qDebug() << "FAILED - Test 11c: props.getHasProperty(EXAMPLE_PROP_VISIBLE) after props << EXAMPLE_PROP_VISIBLE"; +// } encoded = props.encode(); - - if (verbose) { - qDebug() << "props... encoded="; - outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); - qDebug() << "props.getHasProperty(EXAMPLE_PROP_VISIBLE)" << (props.getHasProperty(EXAMPLE_PROP_VISIBLE)) - << "{ expect true }"; - } - - char expectedBytesC[] = { 16 }; - QByteArray expectedResultC(expectedBytesC, sizeof(expectedBytesC)/sizeof(expectedBytesC[0])); - - testsTaken++; - if (encoded == expectedResultC) { - testsPassed++; - } else { - testsFailed++; - qDebug() << "FAILED - Test 11c: ExamplePropertyFlags testing individual properties"; - } + QCOMPARE(encoded, makeQByteArray({ (char) 16 })); +// if (verbose) { +// qDebug() << "props... encoded="; +// outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); +// qDebug() << "props.getHasProperty(EXAMPLE_PROP_VISIBLE)" << (props.getHasProperty(EXAMPLE_PROP_VISIBLE)) +// << "{ expect true }"; +// } +// +// char expectedBytesC[] = { 16 }; +// QByteArray expectedResultC(expectedBytesC, sizeof(expectedBytesC)/sizeof(expectedBytesC[0])); +// +// QCOMPARE(encoded, expectedResultC); +// if (encoded == expectedResultC) { +// testsPassed++; +// } else { +// testsFailed++; +// qDebug() << "FAILED - Test 11c: ExamplePropertyFlags testing individual properties"; +// } if (verbose) { qDebug() << "props << EXAMPLE_PROP_ANIMATION_URL;"; } props << EXAMPLE_PROP_ANIMATION_URL; - + encoded = props.encode(); - if (verbose) { - qDebug() << "props... encoded="; - outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); - qDebug() << "props.getHasProperty(EXAMPLE_PROP_VISIBLE)" << (props.getHasProperty(EXAMPLE_PROP_VISIBLE)) - << "{ expect true }"; - } - char expectedBytesD[] = { (char)136, (char)16 }; - QByteArray expectedResultD(expectedBytesD, sizeof(expectedBytesD)/sizeof(expectedBytesD[0])); - - testsTaken++; - if (encoded == expectedResultD) { - testsPassed++; - } else { - testsFailed++; - qDebug() << "FAILED - Test 11d: ExamplePropertyFlags testing individual properties"; - } - testsTaken++; - bool resultE = props.getHasProperty(EXAMPLE_PROP_VISIBLE); - bool expectedE = true; - if (resultE == expectedE) { - testsPassed++; - } else { - testsFailed++; - qDebug() << "FAILED - Test 11e: props.getHasProperty(EXAMPLE_PROP_VISIBLE) after props << EXAMPLE_PROP_ANIMATION_URL"; - } + QCOMPARE(encoded, makeQByteArray({ (char) 136, 16})); +// if (verbose) { +// qDebug() << "props... encoded="; +// outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); +// qDebug() << "props.getHasProperty(EXAMPLE_PROP_VISIBLE)" << (props.getHasProperty(EXAMPLE_PROP_VISIBLE)) +// << "{ expect true }"; +// } +// char expectedBytesD[] = { (char)136, (char)16 }; +// QByteArray expectedResultD(expectedBytesD, sizeof(expectedBytesD)/sizeof(expectedBytesD[0])); +// +// QCOMPARE(encoded, expectedResultD); +// if (encoded == expectedResultD) { +// testsPassed++; +// } else { +// testsFailed++; +// qDebug() << "FAILED - Test 11d: ExamplePropertyFlags testing individual properties"; +// } +// bool resultE = props.getHasProperty(EXAMPLE_PROP_VISIBLE); +// bool expectedE = true; +// QCOMPARE(resultE, expectedE); + QCOMPARE(props.getHasProperty(EXAMPLE_PROP_VISIBLE), true); +// if (resultE == expectedE) { +// testsPassed++; +// } else { +// testsFailed++; +// qDebug() << "FAILED - Test 11e: props.getHasProperty(EXAMPLE_PROP_VISIBLE) after props << EXAMPLE_PROP_ANIMATION_URL"; +// } if (verbose) { @@ -674,75 +697,79 @@ void OctreeTests::propertyFlagsTests() { props << EXAMPLE_PROP_PAUSE_SIMULATION; encoded = props.encode(); - if (verbose) { - qDebug() << "props... encoded="; - outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); - qDebug() << "props.getHasProperty(EXAMPLE_PROP_VISIBLE)" << (props.getHasProperty(EXAMPLE_PROP_VISIBLE)) - << "{ expect true }"; - } - testsTaken++; - bool resultF = props.getHasProperty(EXAMPLE_PROP_VISIBLE); - bool expectedF = true; - if (resultF == expectedF) { - testsPassed++; - } else { - testsFailed++; - qDebug() << "FAILED - Test 11f: props.getHasProperty(EXAMPLE_PROP_VISIBLE) after props << more"; - } +// if (verbose) { +// qDebug() << "props... encoded="; +// outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); +// qDebug() << "props.getHasProperty(EXAMPLE_PROP_VISIBLE)" << (props.getHasProperty(EXAMPLE_PROP_VISIBLE)) +// << "{ expect true }"; +// } +// bool resultF = props.getHasProperty(EXAMPLE_PROP_VISIBLE); +// bool expectedF = true; +// QCOMPARE(resultF, expectedF); + QCOMPARE(props.getHasProperty(EXAMPLE_PROP_VISIBLE), true); +// if (resultF == expectedF) { +// testsPassed++; +// } else { +// testsFailed++; +// qDebug() << "FAILED - Test 11f: props.getHasProperty(EXAMPLE_PROP_VISIBLE) after props << more"; +// } if (verbose) { qDebug() << "ExamplePropertyFlags propsB = props & EXAMPLE_PROP_VISIBLE;"; } ExamplePropertyFlags propsB = props & EXAMPLE_PROP_VISIBLE; - if (verbose) { - qDebug() << "propsB.getHasProperty(EXAMPLE_PROP_VISIBLE)" << (propsB.getHasProperty(EXAMPLE_PROP_VISIBLE)) - << "{ expect true }"; - } - testsTaken++; - bool resultG = propsB.getHasProperty(EXAMPLE_PROP_VISIBLE); - bool expectedG = true; - if (resultG == expectedG) { - testsPassed++; - } else { - testsFailed++; - qDebug() << "FAILED - Test 11g: propsB = props & EXAMPLE_PROP_VISIBLE"; - } +// if (verbose) { +// qDebug() << "propsB.getHasProperty(EXAMPLE_PROP_VISIBLE)" << (propsB.getHasProperty(EXAMPLE_PROP_VISIBLE)) +// << "{ expect true }"; +// } +// bool resultG = propsB.getHasProperty(EXAMPLE_PROP_VISIBLE); +// bool expectedG = true; +// QCOMPARE(resultG, expectedG); + QCOMPARE(propsB.getHasProperty(EXAMPLE_PROP_VISIBLE), true); +// if (resultG == expectedG) { +// testsPassed++; +// } else { +// testsFailed++; +// qDebug() << "FAILED - Test 11g: propsB = props & EXAMPLE_PROP_VISIBLE"; +// } encoded = propsB.encode(); - if (verbose) { - qDebug() << "propsB... encoded="; - outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); - } - char expectedBytesH[] = { 16 }; - QByteArray expectedResultH(expectedBytesC, sizeof(expectedBytesH)/sizeof(expectedBytesH[0])); - - testsTaken++; - if (encoded == expectedResultH) { - testsPassed++; - } else { - testsFailed++; - qDebug() << "FAILED - Test 11h: ExamplePropertyFlags testing individual properties"; - } +// if (verbose) { +// qDebug() << "propsB... encoded="; +// outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); +// } +// char expectedBytesH[] = { 16 }; +// QByteArray expectedResultH(expectedBytesC, sizeof(expectedBytesH)/sizeof(expectedBytesH[0])); +// +// QCOMPARE(encoded, expectedResultH); + QCOMPARE(encoded, makeQByteArray({ (char) 16 })); +// if (encoded == expectedResultH) { +// testsPassed++; +// } else { +// testsFailed++; +// qDebug() << "FAILED - Test 11h: ExamplePropertyFlags testing individual properties"; +// } if (verbose) { qDebug() << "ExamplePropertyFlags propsC = ~propsB;"; } ExamplePropertyFlags propsC = ~propsB; - if (verbose) { - qDebug() << "propsC.getHasProperty(EXAMPLE_PROP_VISIBLE)" << (propsC.getHasProperty(EXAMPLE_PROP_VISIBLE)) - << "{ expect false }"; - } - testsTaken++; - bool resultI = propsC.getHasProperty(EXAMPLE_PROP_VISIBLE); - bool expectedI = false; - if (resultI == expectedI) { - testsPassed++; - } else { - testsFailed++; - qDebug() << "FAILED - Test 11i: propsC = ~propsB"; - } + QCOMPARE(propsC.getHasProperty(EXAMPLE_PROP_VISIBLE), false); +// if (verbose) { +// qDebug() << "propsC.getHasProperty(EXAMPLE_PROP_VISIBLE)" << (propsC.getHasProperty(EXAMPLE_PROP_VISIBLE)) +// << "{ expect false }"; +// } +// bool resultI = propsC.getHasProperty(EXAMPLE_PROP_VISIBLE); +// bool expectedI = false; +// QCOMPARE(resultI, expectedI); +// if (resultI == expectedI) { +// testsPassed++; +// } else { +// testsFailed++; +// qDebug() << "FAILED - Test 11i: propsC = ~propsB"; +// } encoded = propsC.encode(); if (verbose) { @@ -774,34 +801,36 @@ void OctreeTests::propertyFlagsTests() { ExamplePropertyFlags propsDecoded; propsDecoded.decode(encoded); - if (verbose) { - qDebug() << "propsDecoded == props:" << (propsDecoded == props) << "{ expect true }"; - } - testsTaken++; - bool resultA = (propsDecoded == props); - bool expectedA = true; - if (resultA == expectedA) { - testsPassed++; - } else { - testsFailed++; - qDebug() << "FAILED - Test 12a: propsDecoded == props"; - } + QCOMPARE(propsDecoded, props); +// if (verbose) { +// qDebug() << "propsDecoded == props:" << (propsDecoded == props) << "{ expect true }"; +// } +// bool resultA = (propsDecoded == props); +// bool expectedA = true; +// QCOMPARE(resultA, expectedA); +// if (resultA == expectedA) { +// testsPassed++; +// } else { +// testsFailed++; +// qDebug() << "FAILED - Test 12a: propsDecoded == props"; +// } QByteArray encodedAfterDecoded = propsDecoded.encode(); - if (verbose) { - qDebug() << "encodedAfterDecoded="; - outputBufferBits((const unsigned char*)encodedAfterDecoded.constData(), encodedAfterDecoded.size()); - } - testsTaken++; - bool resultB = (encoded == encodedAfterDecoded); - bool expectedB = true; - if (resultB == expectedB) { - testsPassed++; - } else { - testsFailed++; - qDebug() << "FAILED - Test 12b: (encoded == encodedAfterDecoded)"; - } + QCOMPARE(encoded, encodedAfterDecoded); +// if (verbose) { +// qDebug() << "encodedAfterDecoded="; +// outputBufferBits((const unsigned char*)encodedAfterDecoded.constData(), encodedAfterDecoded.size()); +// } +// bool resultB = (encoded == encodedAfterDecoded); +// bool expectedB = true; +// QCOMPARE(resultB, expectedB); +// if (resultB == expectedB) { +// testsPassed++; +// } else { +// testsFailed++; +// qDebug() << "FAILED - Test 12b: (encoded == encodedAfterDecoded)"; +// } if (verbose) { qDebug() << "fill encoded byte array with extra garbage (as if it was bitstream with more content)"; @@ -817,18 +846,19 @@ void OctreeTests::propertyFlagsTests() { ExamplePropertyFlags propsDecodedExtra; propsDecodedExtra.decode(encoded); - if (verbose) { - qDebug() << "propsDecodedExtra == props:" << (propsDecodedExtra == props) << "{ expect true }"; - } - testsTaken++; - bool resultC = (propsDecodedExtra == props); - bool expectedC = true; - if (resultC == expectedC) { - testsPassed++; - } else { - testsFailed++; - qDebug() << "FAILED - Test 12c: (propsDecodedExtra == props)"; - } + QCOMPARE(propsDecodedExtra, props); +// if (verbose) { +// qDebug() << "propsDecodedExtra == props:" << (propsDecodedExtra == props) << "{ expect true }"; +// } +// bool resultC = (propsDecodedExtra == props); +// bool expectedC = true; +// QCOMPARE(resultC, expectedC); +// if (resultC == expectedC) { +// testsPassed++; +// } else { +// testsFailed++; +// qDebug() << "FAILED - Test 12c: (propsDecodedExtra == props)"; +// } QByteArray encodedAfterDecodedExtra = propsDecodedExtra.encode(); @@ -866,23 +896,24 @@ void OctreeTests::propertyFlagsTests() { qDebug() << "testing encoded >> propsDecoded"; } encoded >> propsDecoded; - - if (verbose) { - qDebug() << "propsDecoded==props" << (propsDecoded==props); - } - - testsTaken++; - bool resultA = (propsDecoded == props); - bool expectedA = true; - if (resultA == expectedA) { - testsPassed++; - } else { - testsFailed++; - qDebug() << "FAILED - Test 13: ExamplePropertyFlags: QByteArray << / >> tests"; - } + + + QCOMPARE(propsDecoded, props); +// if (verbose) { +// qDebug() << "propsDecoded==props" << (propsDecoded==props); +// } +// +// bool resultA = (propsDecoded == props); +// bool expectedA = true; +// QCOMPARE(resultA, expectedA); +// if (resultA == expectedA) { +// testsPassed++; +// } else { +// testsFailed++; +// qDebug() << "FAILED - Test 13: ExamplePropertyFlags: QByteArray << / >> tests"; +// } } - qDebug() << " tests passed:" << testsPassed << "out of" << testsTaken; if (verbose) { qDebug() << "******************************************************************************************"; } @@ -896,10 +927,6 @@ typedef ByteCountCoded ByteCountCodedINT; void OctreeTests::byteCountCodingTests() { bool verbose = true; - - int testsTaken = 0; - int testsPassed = 0; - int testsFailed = 0; if (verbose) { qDebug() << "******************************************************************************************"; @@ -920,43 +947,44 @@ void OctreeTests::byteCountCodingTests() { 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)"; - } + + QCOMPARE(decodedZero.data, static_cast( 0 )); +// if (verbose) { +// qDebug() << "decodedZero=" << decodedZero.data; +// qDebug() << "decodedZero==zero" << (decodedZero == zero) << " { expected true } "; +// } +// bool result1 = (decodedZero.data == 0); +// bool expected1 = true; +// QCOMPARE(result1, expected1); +// if (result1 == expected1) { +// testsPassed++; +// } else { +// testsFailed++; +// qDebug() << "FAILED - Test 1: ByteCountCodedUINT zero(0) decodedZero.data == 0"; +// } + QCOMPARE(decodedZero, zero); +// 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)"; - } + + QCOMPARE(decodedZeroB.data, (unsigned int) 0); +// if (verbose) { +// qDebug() << "decodedZeroB=" << decodedZeroB.data; +// } +// bool result3 = (decodedZeroB.data == 0); +// bool expected3 = true; +// QCOMPARE(result3, expected3); +// if (result3 == expected3) { +// testsPassed++; +// } else { +// testsFailed++; +// qDebug() << "FAILED - Test 3: (decodedZeroB.data == 0)"; +// } if (verbose) { qDebug() << "ByteCountCodedUINT foo(259)"; @@ -971,43 +999,46 @@ void OctreeTests::byteCountCodingTests() { 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)"; - } + QCOMPARE(decodedFoo.data, (unsigned int) 259); +// if (verbose) { +// qDebug() << "decodedFoo=" << decodedFoo.data; +// qDebug() << "decodedFoo==foo" << (decodedFoo == foo) << " { expected true } "; +// } +// bool result4 = (decodedFoo.data == 259); +// bool expected4 = true; +// QCOMPARE(result4, expected4); +// 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)"; - } + QCOMPARE(decodedFoo, foo); +// bool result5 = (decodedFoo == foo); +// bool expected5 = true; +// QCOMPARE(result5, expected5); +// 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)"; - } + QCOMPARE(decodedFooB.data, (unsigned int) 259); +// if (verbose) { +// qDebug() << "decodedFooB=" << decodedFooB.data; +// } +// bool result6 = (decodedFooB.data == 259); +// bool expected6 = true; +// QCOMPARE(result5, expected6); +// if (result6 == expected6) { +// testsPassed++; +// } else { +// testsFailed++; +// qDebug() << "FAILED - Test 6: (decodedFooB.data == 259)"; +// } if (verbose) { @@ -1021,29 +1052,31 @@ void OctreeTests::byteCountCodingTests() { 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)"; - } + QCOMPARE(decodedBar.data, (unsigned int) 1000000); +// if (verbose) { +// qDebug() << "decodedBar=" << decodedBar.data; +// qDebug() << "decodedBar==bar" << (decodedBar == bar) << " { expected true } "; +// } +// bool result7 = (decodedBar.data == 1000000); +// bool expected7 = true; +// QCOMPARE(result7, expected7); +// 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)"; - } + QCOMPARE(decodedBar, bar); +// bool result8 = (decodedBar == bar); +// bool expected8 = true; +// QCOMPARE(result8, expected8); +// if (result8 == expected8) { +// testsPassed++; +// } else { +// testsFailed++; +// qDebug() << "FAILED - Test 8: (decodedBar == bar)"; +// } if (verbose) { qDebug() << "ByteCountCodedUINT spam(4294967295/2)"; @@ -1060,25 +1093,27 @@ void OctreeTests::byteCountCodingTests() { 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)"; - } + QCOMPARE(decodedSpam.data, (unsigned int) 4294967295/2); +// bool result9 = (decodedSpam.data == 4294967295/2); +// bool expected9 = true; +// QCOMPARE(result9, expected9); +// 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)"; - } + QCOMPARE(decodedSpam, spam); +// bool result10 = (decodedSpam == spam); +// bool expected10 = true; +// QCOMPARE(result10, expected10); +// if (result10 == expected10) { +// testsPassed++; +// } else { +// testsFailed++; +// qDebug() << "FAILED - Test 10: (decodedSpam == spam)"; +// } if (verbose) { qDebug() << "ByteCountCodedQUINT64 foo64(259)"; @@ -1097,15 +1132,16 @@ void OctreeTests::byteCountCodingTests() { qDebug() << "foo64POD=" << foo64POD; } - testsTaken++; - bool result11 = (foo64POD == 259); - bool expected11 = true; - if (result11 == expected11) { - testsPassed++; - } else { - testsFailed++; - qDebug() << "FAILED - Test 11: quint64 foo64POD = foo64"; - } + QCOMPARE(foo64POD, (quint64) 259); +// bool result11 = (foo64POD == 259); +// bool expected11 = true; +// QCOMPARE(result11, expected11); +// if (result11 == expected11) { +// testsPassed++; +// } else { +// testsFailed++; +// qDebug() << "FAILED - Test 11: quint64 foo64POD = foo64"; +// } if (verbose) { qDebug() << "testing... encoded = foo64;"; @@ -1123,25 +1159,27 @@ void OctreeTests::byteCountCodingTests() { 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"; - } + QCOMPARE(decodedFoo.data, (unsigned int) 259); +// bool result12 = (decodedFoo64.data == 259); +// bool expected12 = true; +// QCOMPARE(result12, expected12); +// if (result12 == expected12) { +// testsPassed++; +// } else { +// testsFailed++; +// qDebug() << "FAILED - Test 12: decodedFoo64.data == 259"; +// } + + QCOMPARE(decodedFoo64, foo64); +// bool result13 = (decodedFoo64==foo64); +// bool expected13 = true; +// QCOMPARE(result13, expected13); +// if (result13 == expected13) { +// testsPassed++; +// } else { +// testsFailed++; +// qDebug() << "FAILED - Test 13: decodedFoo64==foo64"; +// } if (verbose) { qDebug() << "ByteCountCodedQUINT64 bar64(1000000)"; @@ -1154,29 +1192,31 @@ void OctreeTests::byteCountCodingTests() { 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"; - } +// if (verbose) { +// qDebug() << "decodedBar64=" << decodedBar64.data; +// qDebug() << "decodedBar64==bar64" << (decodedBar64==bar64) << " { expected true } "; +// } + QCOMPARE(decodedBar64.data, static_cast( 1000000 )); +// bool result14 = (decodedBar64.data == 1000000); +// bool expected14 = true; +// QCOMPARE(result14, expected14); +// 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"; - } + QCOMPARE(decodedBar64, bar64); +// bool result15 = (decodedBar64==bar64); +// bool expected15 = true; +// QCOMPARE(result15, expected15); +// if (result15 == expected15) { +// testsPassed++; +// } else { +// testsFailed++; +// qDebug() << "FAILED - Test 15: decodedBar64==bar64"; +// } if (verbose) { qDebug() << "ByteCountCodedQUINT64 spam64(4294967295/2)"; @@ -1189,29 +1229,31 @@ void OctreeTests::byteCountCodingTests() { 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"; - } +// if (verbose) { +// qDebug() << "decodedSpam64=" << decodedSpam64.data; +// qDebug() << "decodedSpam64==spam64" << (decodedSpam64==spam64) << " { expected true } "; +// } + QCOMPARE(decodedSpam64.data, static_cast( 4294967295/2 )); +// bool result16 = (decodedSpam64.data == 4294967295/2); +// bool expected16 = true; +// QCOMPARE(result16, expected16); +// 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"; - } + QCOMPARE(decodedSpam64, spam64); +// bool result17 = (decodedSpam64==spam64); +// bool expected17 = true; +// QCOMPARE(result17, expected17); +// if (result17 == expected17) { +// testsPassed++; +// } else { +// testsFailed++; +// qDebug() << "FAILED - Test 17: decodedSpam64==spam64"; +// } if (verbose) { qDebug() << "testing encoded << spam64"; @@ -1227,18 +1269,19 @@ void OctreeTests::byteCountCodingTests() { } 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"; - } +// if (verbose) { +// qDebug() << "decodedSpam64=" << decodedSpam64.data; +// } + QCOMPARE(decodedSpam64, spam64); +// bool result18 = (decodedSpam64==spam64); +// bool expected18 = true; +// QCOMPARE(result18, expected18); +// if (result18 == expected18) { +// testsPassed++; +// } else { +// testsFailed++; +// qDebug() << "FAILED - Test 18: decodedSpam64==spam64"; +// } //ByteCountCodedINT shouldFail(-100); @@ -1249,25 +1292,24 @@ void OctreeTests::byteCountCodingTests() { ByteCountCodedQUINT64 nowCoded = now; QByteArray nowEncoded = nowCoded; - if (verbose) { - outputBufferBits((const unsigned char*)nowEncoded.constData(), nowEncoded.size()); - } +// 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..."; - } + QCOMPARE(decodedNow.data, static_cast( now )); +// bool result19 = (decodedNow.data==now); +// bool expected19 = true; +// QCOMPARE(result19, expected19); +// 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() << "******************************************************************************************"; } @@ -1318,29 +1360,31 @@ void OctreeTests::modelItemTests() { qDebug() << "modelItemFromBuffer.getModelURL()=" << modelItemFromBuffer.getModelURL(); } - testsTaken++; - bool result1 = (bytesRead == bytesWritten); - bool expected1 = true; - if (result1 == expected1) { - testsPassed++; - } else { - testsFailed++; - qDebug() << "FAILED - Test 1: bytesRead == bytesWritten..."; - } + QCOMPARE(bytesRead, bytesWritten); +// testsTaken++; +// bool result1 = (bytesRead == bytesWritten); +// bool expected1 = true; +// if (result1 == expected1) { +// testsPassed++; +// } else { +// testsFailed++; +// qDebug() << "FAILED - Test 1: bytesRead == bytesWritten..."; +// } if (verbose) { qDebug() << "Test 2: modelItemFromBuffer.getModelURL() == 'http://foo.com/foo.fbx'"; } - testsTaken++; - bool result2 = (modelItemFromBuffer.getModelURL() == "http://foo.com/foo.fbx"); - bool expected2 = true; - if (result2 == expected2) { - testsPassed++; - } else { - testsFailed++; - qDebug() << "FAILED - Test 2: modelItemFromBuffer.getModelURL() == 'http://foo.com/foo.fbx' ..."; - } + QCOMPARE(modelItemFromBuffer.getModelURL(), "http://foo.com/foo.fbx"); +// testsTaken++; +// bool result2 = (modelItemFromBuffer.getModelURL() == "http://foo.com/foo.fbx"); +// bool expected2 = true; +// if (result2 == expected2) { +// testsPassed++; +// } else { +// testsFailed++; +// qDebug() << "FAILED - Test 2: modelItemFromBuffer.getModelURL() == 'http://foo.com/foo.fbx' ..."; +// } } // TEST 3: @@ -1359,15 +1403,17 @@ void OctreeTests::modelItemTests() { qDebug() << "appendResult=" << appendResult; qDebug() << "bytesWritten=" << bytesWritten; } - testsTaken++; - bool result3 = (appendResult == false && bytesWritten == 0); - bool expected3 = true; - if (result3 == expected3) { - testsPassed++; - } else { - testsFailed++; - qDebug() << "FAILED - Test 3: attempt to appendEntityData in nearly full packetData ..."; - } + QCOMPARE(appendResult, false); + QCOMPARE(bytesWritten, 0); +// testsTaken++; +// bool result3 = (appendResult == false && bytesWritten == 0); +// bool expected3 = true; +// if (result3 == expected3) { +// testsPassed++; +// } else { +// testsFailed++; +// qDebug() << "FAILED - Test 3: attempt to appendEntityData in nearly full packetData ..."; +// } } // TEST 4: @@ -1386,15 +1432,17 @@ void OctreeTests::modelItemTests() { qDebug() << "appendResult=" << appendResult; qDebug() << "bytesWritten=" << bytesWritten; } - testsTaken++; - bool result4 = (appendResult == true); // && bytesWritten == 0); - bool expected4 = true; - if (result4 == expected4) { - testsPassed++; - } else { - testsFailed++; - qDebug() << "FAILED - Test 4: attempt to appendEntityData in nearly full packetData which some should fit ..."; - } + + QCOMPARE(appendResult, true); +// testsTaken++; +// bool result4 = (appendResult == true); // && bytesWritten == 0); +// bool expected4 = true; +// if (result4 == expected4) { +// testsPassed++; +// } else { +// testsFailed++; +// qDebug() << "FAILED - Test 4: attempt to appendEntityData in nearly full packetData which some should fit ..."; +// } ReadBitstreamToTreeParams args; EntityItem modelItemFromBuffer; @@ -1409,35 +1457,39 @@ void OctreeTests::modelItemTests() { qDebug() << "modelItemFromBuffer.getModelURL()=" << modelItemFromBuffer.getModelURL(); } - testsTaken++; - bool result5 = (bytesRead == bytesWritten); - bool expected5 = true; - if (result5 == expected5) { - testsPassed++; - } else { - testsFailed++; - qDebug() << "FAILED - Test 5: partial EntityItem written ... bytesRead == bytesWritten..."; - } + QCOMPARE(bytesRead, bytesWritten); +// testsTaken++; +// bool result5 = (bytesRead == bytesWritten); +// bool expected5 = true; +// if (result5 == expected5) { +// testsPassed++; +// } else { +// testsFailed++; +// qDebug() << "FAILED - Test 5: partial EntityItem written ... bytesRead == bytesWritten..."; +// } if (verbose) { qDebug() << "Test 6: partial EntityItem written ... getModelURL() NOT SET ..."; } - testsTaken++; - bool result6 = (modelItemFromBuffer.getModelURL() == ""); - bool expected6 = true; - if (result6 == expected6) { - testsPassed++; - } else { - testsFailed++; - qDebug() << "FAILED - Test 6: partial EntityItem written ... getModelURL() NOT SET ..."; - } + QCOMPARE(modelItemFromBuffer.getModelURL(), ""); +// testsTaken++; +// bool result6 = (modelItemFromBuffer.getModelURL() == ""); +// bool expected6 = true; +// if (result6 == expected6) { +// testsPassed++; +// } else { +// testsFailed++; +// qDebug() << "FAILED - Test 6: partial EntityItem written ... getModelURL() NOT SET ..."; +// } } if (verbose) { qDebug() << "******************************************************************************************"; } - qDebug() << " tests passed:" << testsPassed << "out of" << testsTaken; + + QCOMPARE(testsPassed, testsTaken); +// qDebug() << " tests passed:" << testsPassed << "out of" << testsTaken; if (verbose) { qDebug() << "******************************************************************************************"; } diff --git a/tests/octree/src/OctreeTests.h b/tests/octree/src/OctreeTests.h index 7d24ad3590..f8aa3e6ebb 100644 --- a/tests/octree/src/OctreeTests.h +++ b/tests/octree/src/OctreeTests.h @@ -22,7 +22,14 @@ private slots: void byteCountCodingTests(); void modelItemTests(); -// void runAllTests(bool verbose); + // TODO: Break these into separate test functions }; +// Helper functions +inline QByteArray makeQByteArray (std::initializer_list bytes) { + return QByteArray { + bytes.begin(), static_cast(bytes.size() * sizeof(char)) + }; +} + #endif // hifi_OctreeTests_h