From 83fb3f14d8e750ac104fce975b5e96add86794fe Mon Sep 17 00:00:00 2001 From: = Date: Fri, 4 Apr 2025 20:40:12 -0400 Subject: [PATCH] Add and update autotests. --- tests/360/autotest_cod10_360.cpp | 125 +++++++++++++++++++++++++++++ tests/360/autotest_cod11_360.cpp | 125 +++++++++++++++++++++++++++++ tests/360/autotest_cod12_360.cpp | 125 +++++++++++++++++++++++++++++ tests/360/autotest_cod2_360.cpp | 120 +++++++++++++++++++++++++++ tests/360/autotest_cod4_360.cpp | 119 +++++++++++++++++++++++++++ tests/360/autotest_cod5_360.cpp | 125 +++++++++++++++++++++++++++++ tests/360/autotest_cod6_360.cpp | 125 +++++++++++++++++++++++++++++ tests/360/autotest_cod7_360.cpp | 125 +++++++++++++++++++++++++++++ tests/360/autotest_cod8_360.cpp | 125 +++++++++++++++++++++++++++++ tests/360/autotest_cod9_360.cpp | 125 +++++++++++++++++++++++++++++ tests/PC/autotest_cod10_pc.cpp | 124 ++++++++++++++++++++++++++++ tests/PC/autotest_cod11_pc.cpp | 124 ++++++++++++++++++++++++++++ tests/PC/autotest_cod12_pc.cpp | 124 ++++++++++++++++++++++++++++ tests/PC/autotest_cod4_pc.cpp | 120 +++++++++++++++++++++++++++ tests/PC/autotest_cod5_pc.cpp | 124 ++++++++++++++++++++++++++++ tests/PC/autotest_cod6_pc.cpp | 116 ++++++++++++++++++++++++++ tests/PC/autotest_cod7_pc.cpp | 123 ++++++++++++++++++++++++++++ tests/PC/autotest_cod8_pc.cpp | 124 ++++++++++++++++++++++++++++ tests/PC/autotest_cod9_pc.cpp | 124 ++++++++++++++++++++++++++++ tests/PS3/autotest_cod10_ps3.cpp | 125 +++++++++++++++++++++++++++++ tests/PS3/autotest_cod11_ps3.cpp | 125 +++++++++++++++++++++++++++++ tests/PS3/autotest_cod12_ps3.cpp | 125 +++++++++++++++++++++++++++++ tests/PS3/autotest_cod4_ps3.cpp | 124 ++++++++++++++++++++++++++++ tests/PS3/autotest_cod5_ps3.cpp | 125 +++++++++++++++++++++++++++++ tests/PS3/autotest_cod6_ps3.cpp | 125 +++++++++++++++++++++++++++++ tests/PS3/autotest_cod7_ps3.cpp | 125 +++++++++++++++++++++++++++++ tests/PS3/autotest_cod8_ps3.cpp | 125 +++++++++++++++++++++++++++++ tests/PS3/autotest_cod9_ps3.cpp | 125 +++++++++++++++++++++++++++++ tests/Wii/autotest_cod7_wii.cpp | 125 +++++++++++++++++++++++++++++ tests/WiiU/autotest_cod10_wiiu.cpp | 125 +++++++++++++++++++++++++++++ tests/WiiU/autotest_cod9_wiiu.cpp | 125 +++++++++++++++++++++++++++++ tests/autotest_cod.h | 64 ++++++++++++++- tests/autotest_cod5_pc.cpp | 40 --------- 33 files changed, 3902 insertions(+), 43 deletions(-) create mode 100644 tests/360/autotest_cod10_360.cpp create mode 100644 tests/360/autotest_cod11_360.cpp create mode 100644 tests/360/autotest_cod12_360.cpp create mode 100644 tests/360/autotest_cod2_360.cpp create mode 100644 tests/360/autotest_cod4_360.cpp create mode 100644 tests/360/autotest_cod5_360.cpp create mode 100644 tests/360/autotest_cod6_360.cpp create mode 100644 tests/360/autotest_cod7_360.cpp create mode 100644 tests/360/autotest_cod8_360.cpp create mode 100644 tests/360/autotest_cod9_360.cpp create mode 100644 tests/PC/autotest_cod10_pc.cpp create mode 100644 tests/PC/autotest_cod11_pc.cpp create mode 100644 tests/PC/autotest_cod12_pc.cpp create mode 100644 tests/PC/autotest_cod4_pc.cpp create mode 100644 tests/PC/autotest_cod5_pc.cpp create mode 100644 tests/PC/autotest_cod6_pc.cpp create mode 100644 tests/PC/autotest_cod7_pc.cpp create mode 100644 tests/PC/autotest_cod8_pc.cpp create mode 100644 tests/PC/autotest_cod9_pc.cpp create mode 100644 tests/PS3/autotest_cod10_ps3.cpp create mode 100644 tests/PS3/autotest_cod11_ps3.cpp create mode 100644 tests/PS3/autotest_cod12_ps3.cpp create mode 100644 tests/PS3/autotest_cod4_ps3.cpp create mode 100644 tests/PS3/autotest_cod5_ps3.cpp create mode 100644 tests/PS3/autotest_cod6_ps3.cpp create mode 100644 tests/PS3/autotest_cod7_ps3.cpp create mode 100644 tests/PS3/autotest_cod8_ps3.cpp create mode 100644 tests/PS3/autotest_cod9_ps3.cpp create mode 100644 tests/Wii/autotest_cod7_wii.cpp create mode 100644 tests/WiiU/autotest_cod10_wiiu.cpp create mode 100644 tests/WiiU/autotest_cod9_wiiu.cpp delete mode 100644 tests/autotest_cod5_pc.cpp diff --git a/tests/360/autotest_cod10_360.cpp b/tests/360/autotest_cod10_360.cpp new file mode 100644 index 0000000..a69ad7b --- /dev/null +++ b/tests/360/autotest_cod10_360.cpp @@ -0,0 +1,125 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD10_360 : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod10/360"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD10_360::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD10_360::testDecompression_data() { + QTest::addColumn("fastFilePath_cod10_360"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD10_360::testDecompression() { + QFETCH(QString, fastFilePath_cod10_360); + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod10_360); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod10_360)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + QVERIFY2(zoneSize + 44 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod10_360)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod10_360); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD10_360::testCompression_data() { + QTest::addColumn("zoneFilePath_cod10_360"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD10_360::testCompression() { + QFETCH(QString, zoneFilePath_cod10_360); + + QFile zoneFile(zoneFilePath_cod10_360); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod10_360)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod10_360); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + + QByteArray newCompressedData;// = Compressor::CompressZLIB(decompressedData, Z_BEST_COMPRESSION); + newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_COMPRESSION, MAX_WBITS, 8, Z_DEFAULT_STRATEGY, {}); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD10_360::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod10_360.moc" diff --git a/tests/360/autotest_cod11_360.cpp b/tests/360/autotest_cod11_360.cpp new file mode 100644 index 0000000..cb91e7e --- /dev/null +++ b/tests/360/autotest_cod11_360.cpp @@ -0,0 +1,125 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD11_360 : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod11/360"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD11_360::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD11_360::testDecompression_data() { + QTest::addColumn("fastFilePath_cod11_360"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD11_360::testDecompression() { + QFETCH(QString, fastFilePath_cod11_360); + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod11_360); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod11_360)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + QVERIFY2(zoneSize + 44 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod11_360)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod11_360); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD11_360::testCompression_data() { + QTest::addColumn("zoneFilePath_cod11_360"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD11_360::testCompression() { + QFETCH(QString, zoneFilePath_cod11_360); + + QFile zoneFile(zoneFilePath_cod11_360); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod11_360)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod11_360); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + + QByteArray newCompressedData;// = Compressor::CompressZLIB(decompressedData, Z_BEST_COMPRESSION); + newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_COMPRESSION, MAX_WBITS, 8, Z_DEFAULT_STRATEGY, {}); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD11_360::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod11_360.moc" diff --git a/tests/360/autotest_cod12_360.cpp b/tests/360/autotest_cod12_360.cpp new file mode 100644 index 0000000..926c0a5 --- /dev/null +++ b/tests/360/autotest_cod12_360.cpp @@ -0,0 +1,125 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD12_360 : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod12/360"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD12_360::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD12_360::testDecompression_data() { + QTest::addColumn("fastFilePath_cod12_360"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD12_360::testDecompression() { + QFETCH(QString, fastFilePath_cod12_360); + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod12_360); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod12_360)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + QVERIFY2(zoneSize + 44 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod12_360)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod12_360); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD12_360::testCompression_data() { + QTest::addColumn("zoneFilePath_cod12_360"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD12_360::testCompression() { + QFETCH(QString, zoneFilePath_cod12_360); + + QFile zoneFile(zoneFilePath_cod12_360); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod12_360)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod12_360); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + + QByteArray newCompressedData;// = Compressor::CompressZLIB(decompressedData, Z_BEST_COMPRESSION); + newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_COMPRESSION, MAX_WBITS, 8, Z_DEFAULT_STRATEGY, {}); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD12_360::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod12_360.moc" diff --git a/tests/360/autotest_cod2_360.cpp b/tests/360/autotest_cod2_360.cpp new file mode 100644 index 0000000..9ecadec --- /dev/null +++ b/tests/360/autotest_cod2_360.cpp @@ -0,0 +1,120 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD2_360 : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod2/360"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD2_360::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD2_360::testDecompression_data() { + QTest::addColumn("fastFilePath_cod2_360"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD2_360::testDecompression() { + QFETCH(QString, fastFilePath_cod2_360); + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod2_360); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod2_360)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(20); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + // TODO: Find new way to verify as cod2 doesn't store size in zone file + //QVERIFY2(zoneSize + 44 == testZoneData.size(), + // qPrintable("Decompression validation failed for: " + fastFilePath_cod2_360)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod2_360); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD2_360::testCompression_data() { + QTest::addColumn("zoneFilePath_cod2_360"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD2_360::testCompression() { + QFETCH(QString, zoneFilePath_cod2_360); + + QFile zoneFile(zoneFilePath_cod2_360); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod2_360)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod2_360); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(20); + + QByteArray newCompressedData;// = Compressor::CompressZLIB(decompressedData, Z_BEST_COMPRESSION); + newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_COMPRESSION, MAX_WBITS, 8, Z_DEFAULT_STRATEGY, {}); + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD2_360::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod2_360.moc" diff --git a/tests/360/autotest_cod4_360.cpp b/tests/360/autotest_cod4_360.cpp new file mode 100644 index 0000000..39e2a6a --- /dev/null +++ b/tests/360/autotest_cod4_360.cpp @@ -0,0 +1,119 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD4_360 : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod4/360"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD4_360::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD4_360::testDecompression_data() { + QTest::addColumn("fastFilePath_cod4_360"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD4_360::testDecompression() { + QFETCH(QString, fastFilePath_cod4_360); + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod4_360); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod4_360)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::BigEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + QVERIFY2(zoneSize + 36 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod4_360)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod4_360); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD4_360::testCompression_data() { + QTest::addColumn("zoneFilePath_cod4_360"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD4_360::testCompression() { + QFETCH(QString, zoneFilePath_cod4_360); + + QFile zoneFile(zoneFilePath_cod4_360); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod4_360)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod4_360); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + + QByteArray newCompressedData;// = Compressor::CompressZLIB(decompressedData, Z_BEST_COMPRESSION); + newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_COMPRESSION, MAX_WBITS, 8, Z_DEFAULT_STRATEGY, {}); + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD4_360::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod4_360.moc" diff --git a/tests/360/autotest_cod5_360.cpp b/tests/360/autotest_cod5_360.cpp new file mode 100644 index 0000000..bc78cc7 --- /dev/null +++ b/tests/360/autotest_cod5_360.cpp @@ -0,0 +1,125 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD5_360 : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod5/360"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD5_360::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD5_360::testDecompression_data() { + QTest::addColumn("fastFilePath_cod5_360"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD5_360::testDecompression() { + QFETCH(QString, fastFilePath_cod5_360); + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod5_360); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod5_360)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + QVERIFY2(zoneSize + 44 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod5_360)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod5_360); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD5_360::testCompression_data() { + QTest::addColumn("zoneFilePath_cod5_360"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD5_360::testCompression() { + QFETCH(QString, zoneFilePath_cod5_360); + + QFile zoneFile(zoneFilePath_cod5_360); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod5_360)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod5_360); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + + QByteArray newCompressedData;// = Compressor::CompressZLIB(decompressedData, Z_BEST_COMPRESSION); + newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_COMPRESSION, MAX_WBITS, 8, Z_DEFAULT_STRATEGY, {}); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD5_360::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod5_360.moc" diff --git a/tests/360/autotest_cod6_360.cpp b/tests/360/autotest_cod6_360.cpp new file mode 100644 index 0000000..994446d --- /dev/null +++ b/tests/360/autotest_cod6_360.cpp @@ -0,0 +1,125 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD6_360 : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod6/360"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD6_360::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD6_360::testDecompression_data() { + QTest::addColumn("fastFilePath_cod6_360"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD6_360::testDecompression() { + QFETCH(QString, fastFilePath_cod6_360); + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod6_360); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod6_360)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + QVERIFY2(zoneSize + 44 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod6_360)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod6_360); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD6_360::testCompression_data() { + QTest::addColumn("zoneFilePath_cod6_360"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD6_360::testCompression() { + QFETCH(QString, zoneFilePath_cod6_360); + + QFile zoneFile(zoneFilePath_cod6_360); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod6_360)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod6_360); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + + QByteArray newCompressedData;// = Compressor::CompressZLIB(decompressedData, Z_BEST_COMPRESSION); + newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_COMPRESSION, MAX_WBITS, 8, Z_DEFAULT_STRATEGY, {}); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD6_360::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod6_360.moc" diff --git a/tests/360/autotest_cod7_360.cpp b/tests/360/autotest_cod7_360.cpp new file mode 100644 index 0000000..a1bdb9a --- /dev/null +++ b/tests/360/autotest_cod7_360.cpp @@ -0,0 +1,125 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD7_360 : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod7/360"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD7_360::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD7_360::testDecompression_data() { + QTest::addColumn("fastFilePath_cod7_360"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD7_360::testDecompression() { + QFETCH(QString, fastFilePath_cod7_360); + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod7_360); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod7_360)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + QVERIFY2(zoneSize + 44 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod7_360)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod7_360); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD7_360::testCompression_data() { + QTest::addColumn("zoneFilePath_cod7_360"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD7_360::testCompression() { + QFETCH(QString, zoneFilePath_cod7_360); + + QFile zoneFile(zoneFilePath_cod7_360); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod7_360)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod7_360); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + + QByteArray newCompressedData;// = Compressor::CompressZLIB(decompressedData, Z_BEST_COMPRESSION); + newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_COMPRESSION, MAX_WBITS, 8, Z_DEFAULT_STRATEGY, {}); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD7_360::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod7_360.moc" diff --git a/tests/360/autotest_cod8_360.cpp b/tests/360/autotest_cod8_360.cpp new file mode 100644 index 0000000..99b4251 --- /dev/null +++ b/tests/360/autotest_cod8_360.cpp @@ -0,0 +1,125 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD8_360 : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod8/360"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD8_360::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD8_360::testDecompression_data() { + QTest::addColumn("fastFilePath_cod8_360"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD8_360::testDecompression() { + QFETCH(QString, fastFilePath_cod8_360); + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod8_360); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod8_360)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + QVERIFY2(zoneSize + 44 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod8_360)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod8_360); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD8_360::testCompression_data() { + QTest::addColumn("zoneFilePath_cod8_360"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD8_360::testCompression() { + QFETCH(QString, zoneFilePath_cod8_360); + + QFile zoneFile(zoneFilePath_cod8_360); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod8_360)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod8_360); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + + QByteArray newCompressedData;// = Compressor::CompressZLIB(decompressedData, Z_BEST_COMPRESSION); + newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_COMPRESSION, MAX_WBITS, 8, Z_DEFAULT_STRATEGY, {}); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD8_360::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod8_360.moc" diff --git a/tests/360/autotest_cod9_360.cpp b/tests/360/autotest_cod9_360.cpp new file mode 100644 index 0000000..386901d --- /dev/null +++ b/tests/360/autotest_cod9_360.cpp @@ -0,0 +1,125 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD9_360 : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod9/360"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD9_360::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD9_360::testDecompression_data() { + QTest::addColumn("fastFilePath_cod9_360"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD9_360::testDecompression() { + QFETCH(QString, fastFilePath_cod9_360); + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod9_360); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod9_360)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + QVERIFY2(zoneSize + 44 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod9_360)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod9_360); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD9_360::testCompression_data() { + QTest::addColumn("zoneFilePath_cod9_360"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD9_360::testCompression() { + QFETCH(QString, zoneFilePath_cod9_360); + + QFile zoneFile(zoneFilePath_cod9_360); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod9_360)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod9_360); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + + QByteArray newCompressedData;// = Compressor::CompressZLIB(decompressedData, Z_BEST_COMPRESSION); + newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_COMPRESSION, MAX_WBITS, 8, Z_DEFAULT_STRATEGY, {}); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD9_360::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod9_360.moc" diff --git a/tests/PC/autotest_cod10_pc.cpp b/tests/PC/autotest_cod10_pc.cpp new file mode 100644 index 0000000..ad2a304 --- /dev/null +++ b/tests/PC/autotest_cod10_pc.cpp @@ -0,0 +1,124 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD10_PC : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod8/pc"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD10_PC::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD10_PC::testDecompression_data() { + QTest::addColumn("fastFilePath_cod10_pc"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + + +void AutoTest_COD10_PC::testDecompression() { + QFETCH(QString, fastFilePath_cod10_pc); + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod10_pc); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod10_pc)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + QVERIFY2(zoneSize + 36 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod10_pc)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod10_pc); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD10_PC::testCompression_data() { + QTest::addColumn("zoneFilePath_cod10_pc"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD10_PC::testCompression() { + QFETCH(QString, zoneFilePath_cod10_pc); + + QFile zoneFile(zoneFilePath_cod10_pc); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod10_pc)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod10_pc); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + QByteArray newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_SPEED); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD10_PC::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod10_pc.moc" diff --git a/tests/PC/autotest_cod11_pc.cpp b/tests/PC/autotest_cod11_pc.cpp new file mode 100644 index 0000000..999a038 --- /dev/null +++ b/tests/PC/autotest_cod11_pc.cpp @@ -0,0 +1,124 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD11_PC : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod11/pc"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD11_PC::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD11_PC::testDecompression_data() { + QTest::addColumn("fastFilePath_cod11_pc"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + + +void AutoTest_COD11_PC::testDecompression() { + QFETCH(QString, fastFilePath_cod11_pc); + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod11_pc); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod11_pc)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + QVERIFY2(zoneSize + 36 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod11_pc)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod11_pc); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD11_PC::testCompression_data() { + QTest::addColumn("zoneFilePath_cod11_pc"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD11_PC::testCompression() { + QFETCH(QString, zoneFilePath_cod11_pc); + + QFile zoneFile(zoneFilePath_cod11_pc); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod11_pc)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod11_pc); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + QByteArray newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_SPEED); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD11_PC::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod11_pc.moc" diff --git a/tests/PC/autotest_cod12_pc.cpp b/tests/PC/autotest_cod12_pc.cpp new file mode 100644 index 0000000..ef8b276 --- /dev/null +++ b/tests/PC/autotest_cod12_pc.cpp @@ -0,0 +1,124 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD12_PC : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod12/pc"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD12_PC::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD12_PC::testDecompression_data() { + QTest::addColumn("fastFilePath_cod12_pc"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + + +void AutoTest_COD12_PC::testDecompression() { + QFETCH(QString, fastFilePath_cod12_pc); + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod12_pc); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod12_pc)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + QVERIFY2(zoneSize + 36 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod12_pc)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod12_pc); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD12_PC::testCompression_data() { + QTest::addColumn("zoneFilePath_cod12_pc"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD12_PC::testCompression() { + QFETCH(QString, zoneFilePath_cod12_pc); + + QFile zoneFile(zoneFilePath_cod12_pc); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod12_pc)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod12_pc); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + QByteArray newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_SPEED); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD12_PC::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod12_pc.moc" diff --git a/tests/PC/autotest_cod4_pc.cpp b/tests/PC/autotest_cod4_pc.cpp new file mode 100644 index 0000000..b89ae4f --- /dev/null +++ b/tests/PC/autotest_cod4_pc.cpp @@ -0,0 +1,120 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + + +class AutoTest_COD4_PC : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod4/pc"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD4_PC::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD4_PC::testDecompression_data() { + QTest::addColumn("fastFilePath_cod4_pc"); + + QStringList fastFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : fastFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD4_PC::testDecompression() { + QFETCH(QString, fastFilePath_cod4_pc); + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod4_pc); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod4_pc)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + QVERIFY2(zoneSize + 44 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod4_pc)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod4_pc); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD4_PC::testCompression_data() { + QTest::addColumn("zoneFilePath_cod4_pc"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD4_PC::testCompression() { + QFETCH(QString, zoneFilePath_cod4_pc); + + QFile zoneFile(zoneFilePath_cod4_pc); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod4_pc)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod4_pc); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + + QByteArray newCompressedData;// = Compressor::CompressZLIB(decompressedData, Z_BEST_COMPRESSION); + newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_COMPRESSION, MAX_WBITS, 8, Z_DEFAULT_STRATEGY, {}); + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD4_PC::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod4_pc.moc" diff --git a/tests/PC/autotest_cod5_pc.cpp b/tests/PC/autotest_cod5_pc.cpp new file mode 100644 index 0000000..57f0d78 --- /dev/null +++ b/tests/PC/autotest_cod5_pc.cpp @@ -0,0 +1,124 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD5_PC : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod5/pc"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD5_PC::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD5_PC::testDecompression_data() { + QTest::addColumn("fastFilePath_cod5_pc"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD5_PC::testDecompression() { + QFETCH(QString, fastFilePath_cod5_pc); + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod5_pc); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod5_pc)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + QVERIFY2(zoneSize + 36 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod5_pc)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod5_pc); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD5_PC::testCompression_data() { + QTest::addColumn("zoneFilePath_cod5_pc"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD5_PC::testCompression() { + QFETCH(QString, zoneFilePath_cod5_pc); + + QFile zoneFile(zoneFilePath_cod5_pc); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod5_pc)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod5_pc); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + + QByteArray newCompressedData = Compression::CompressZLIB(decompressedData); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD5_PC::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod5_pc.moc" diff --git a/tests/PC/autotest_cod6_pc.cpp b/tests/PC/autotest_cod6_pc.cpp new file mode 100644 index 0000000..33d0f48 --- /dev/null +++ b/tests/PC/autotest_cod6_pc.cpp @@ -0,0 +1,116 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD6_PC : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod6/pc"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD6_PC::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD6_PC::testDecompression_data() { + QTest::addColumn("fastFilePath_cod6_pc"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD6_PC::testDecompression() { + QFETCH(QString, fastFilePath_cod6_pc); + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod6_pc); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod6_pc)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(21); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + QVERIFY2(zoneSize + 40 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod6_pc)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod6_pc); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD6_PC::testCompression_data() { + QTest::addColumn("zoneFilePath_cod6_pc"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD6_PC::testCompression() { + QFETCH(QString, zoneFilePath_cod6_pc); + + QFile zoneFile(zoneFilePath_cod6_pc); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod6_pc)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod6_pc); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(21); + QByteArray newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_COMPRESSION); + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD6_PC::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod6_pc.moc" diff --git a/tests/PC/autotest_cod7_pc.cpp b/tests/PC/autotest_cod7_pc.cpp new file mode 100644 index 0000000..3d26478 --- /dev/null +++ b/tests/PC/autotest_cod7_pc.cpp @@ -0,0 +1,123 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD7_PC : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod7/pc"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD7_PC::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD7_PC::testDecompression_data() { + QTest::addColumn("fastFilePath_cod7_pc"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD7_PC::testDecompression() { + QFETCH(QString, fastFilePath_cod7_pc); + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod7_pc); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod7_pc)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + QVERIFY2(zoneSize + 36 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod7_pc)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod7_pc); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD7_PC::testCompression_data() { + QTest::addColumn("zoneFilePath_cod7_pc"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD7_PC::testCompression() { + QFETCH(QString, zoneFilePath_cod7_pc); + + QFile zoneFile(zoneFilePath_cod7_pc); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod7_pc)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod7_pc); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + QByteArray newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_SPEED); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD7_PC::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod7_pc.moc" diff --git a/tests/PC/autotest_cod8_pc.cpp b/tests/PC/autotest_cod8_pc.cpp new file mode 100644 index 0000000..decf3b3 --- /dev/null +++ b/tests/PC/autotest_cod8_pc.cpp @@ -0,0 +1,124 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD8_PC : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod8/pc"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD8_PC::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD8_PC::testDecompression_data() { + QTest::addColumn("fastFilePath_cod8_pc"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + + +void AutoTest_COD8_PC::testDecompression() { + QFETCH(QString, fastFilePath_cod8_pc); + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod8_pc); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod8_pc)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + QVERIFY2(zoneSize + 36 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod8_pc)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod8_pc); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD8_PC::testCompression_data() { + QTest::addColumn("zoneFilePath_cod8_pc"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD8_PC::testCompression() { + QFETCH(QString, zoneFilePath_cod8_pc); + + QFile zoneFile(zoneFilePath_cod8_pc); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod8_pc)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod8_pc); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + QByteArray newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_SPEED); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD8_PC::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod8_pc.moc" diff --git a/tests/PC/autotest_cod9_pc.cpp b/tests/PC/autotest_cod9_pc.cpp new file mode 100644 index 0000000..f8a1e64 --- /dev/null +++ b/tests/PC/autotest_cod9_pc.cpp @@ -0,0 +1,124 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD9_PC : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod9/pc"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD9_PC::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD9_PC::testDecompression_data() { + QTest::addColumn("fastFilePath_cod9_pc"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + + +void AutoTest_COD9_PC::testDecompression() { + QFETCH(QString, fastFilePath_cod9_pc); + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod9_pc); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod9_pc)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + QVERIFY2(zoneSize + 36 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod9_pc)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod9_pc); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD9_PC::testCompression_data() { + QTest::addColumn("zoneFilePath_cod9_pc"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD9_PC::testCompression() { + QFETCH(QString, zoneFilePath_cod9_pc); + + QFile zoneFile(zoneFilePath_cod9_pc); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod9_pc)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod9_pc); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + QByteArray newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_SPEED); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD9_PC::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod9_pc.moc" diff --git a/tests/PS3/autotest_cod10_ps3.cpp b/tests/PS3/autotest_cod10_ps3.cpp new file mode 100644 index 0000000..6432d3b --- /dev/null +++ b/tests/PS3/autotest_cod10_ps3.cpp @@ -0,0 +1,125 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD10_PS3 : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod10/PS3"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD10_PS3::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD10_PS3::testDecompression_data() { + QTest::addColumn("fastFilePath_cod10_ps3"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD10_PS3::testDecompression() { + QFETCH(QString, fastFilePath_cod10_ps3); + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod10_ps3); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod10_ps3)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + QVERIFY2(zoneSize + 44 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod10_ps3)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod10_ps3); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD10_PS3::testCompression_data() { + QTest::addColumn("zoneFilePath_cod10_ps3"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD10_PS3::testCompression() { + QFETCH(QString, zoneFilePath_cod10_ps3); + + QFile zoneFile(zoneFilePath_cod10_ps3); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod10_ps3)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod10_ps3); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + + QByteArray newCompressedData;// = Compressor::CompressZLIB(decompressedData, Z_BEST_COMPRESSION); + newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_COMPRESSION, MAX_WBITS, 8, Z_DEFAULT_STRATEGY, {}); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD10_PS3::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod10_ps3.moc" diff --git a/tests/PS3/autotest_cod11_ps3.cpp b/tests/PS3/autotest_cod11_ps3.cpp new file mode 100644 index 0000000..e20a48b --- /dev/null +++ b/tests/PS3/autotest_cod11_ps3.cpp @@ -0,0 +1,125 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD11_PS3 : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod11/PS3"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD11_PS3::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD11_PS3::testDecompression_data() { + QTest::addColumn("fastFilePath_cod11_ps3"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD11_PS3::testDecompression() { + QFETCH(QString, fastFilePath_cod11_ps3); + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod11_ps3); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod11_ps3)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + QVERIFY2(zoneSize + 44 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod11_ps3)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod11_ps3); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD11_PS3::testCompression_data() { + QTest::addColumn("zoneFilePath_cod11_ps3"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD11_PS3::testCompression() { + QFETCH(QString, zoneFilePath_cod11_ps3); + + QFile zoneFile(zoneFilePath_cod11_ps3); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod11_ps3)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod11_ps3); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + + QByteArray newCompressedData;// = Compressor::CompressZLIB(decompressedData, Z_BEST_COMPRESSION); + newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_COMPRESSION, MAX_WBITS, 8, Z_DEFAULT_STRATEGY, {}); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD11_PS3::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod11_ps3.moc" diff --git a/tests/PS3/autotest_cod12_ps3.cpp b/tests/PS3/autotest_cod12_ps3.cpp new file mode 100644 index 0000000..8a23cd2 --- /dev/null +++ b/tests/PS3/autotest_cod12_ps3.cpp @@ -0,0 +1,125 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD12_PS3 : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod12/PS3"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD12_PS3::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD12_PS3::testDecompression_data() { + QTest::addColumn("fastFilePath_cod12_ps3"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD12_PS3::testDecompression() { + QFETCH(QString, fastFilePath_cod12_ps3); + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod12_ps3); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod12_ps3)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + QVERIFY2(zoneSize + 44 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod12_ps3)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod12_ps3); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD12_PS3::testCompression_data() { + QTest::addColumn("zoneFilePath_cod12_ps3"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD12_PS3::testCompression() { + QFETCH(QString, zoneFilePath_cod12_ps3); + + QFile zoneFile(zoneFilePath_cod12_ps3); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod12_ps3)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod12_ps3); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + + QByteArray newCompressedData;// = Compressor::CompressZLIB(decompressedData, Z_BEST_COMPRESSION); + newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_COMPRESSION, MAX_WBITS, 8, Z_DEFAULT_STRATEGY, {}); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD12_PS3::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod12_ps3.moc" diff --git a/tests/PS3/autotest_cod4_ps3.cpp b/tests/PS3/autotest_cod4_ps3.cpp new file mode 100644 index 0000000..8ca2dc2 --- /dev/null +++ b/tests/PS3/autotest_cod4_ps3.cpp @@ -0,0 +1,124 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD4_PS3 : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod4/PS3"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD4_PS3::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD4_PS3::testDecompression_data() { + QTest::addColumn("fastFilePath_cod4_ps3"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD4_PS3::testDecompression() { + QFETCH(QString, fastFilePath_cod4_ps3); + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod4_ps3); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod4_ps3)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressDeflate(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + //QVERIFY2(zoneSize + 44 == testZoneData.size(), + // qPrintable("Decompression validation failed for: " + fastFilePath_cod4_ps3)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod4_ps3); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD4_PS3::testCompression_data() { + QTest::addColumn("zoneFilePath_cod4_ps3"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD4_PS3::testCompression() { + QFETCH(QString, zoneFilePath_cod4_ps3); + + QFile zoneFile(zoneFilePath_cod4_ps3); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod4_ps3)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod4_ps3); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + + QByteArray newCompressedData = Compression::CompressDeflateWithSettings(decompressedData, Z_BEST_COMPRESSION); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD4_PS3::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod4_ps3.moc" diff --git a/tests/PS3/autotest_cod5_ps3.cpp b/tests/PS3/autotest_cod5_ps3.cpp new file mode 100644 index 0000000..a04c1d2 --- /dev/null +++ b/tests/PS3/autotest_cod5_ps3.cpp @@ -0,0 +1,125 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD5_PS3 : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod5/PS3"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD5_PS3::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD5_PS3::testDecompression_data() { + QTest::addColumn("fastFilePath_cod5_ps3"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD5_PS3::testDecompression() { + QFETCH(QString, fastFilePath_cod5_ps3); + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod5_ps3); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod5_ps3)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + QVERIFY2(zoneSize + 44 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod5_ps3)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod5_ps3); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD5_PS3::testCompression_data() { + QTest::addColumn("zoneFilePath_cod5_ps3"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD5_PS3::testCompression() { + QFETCH(QString, zoneFilePath_cod5_ps3); + + QFile zoneFile(zoneFilePath_cod5_ps3); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod5_ps3)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod5_ps3); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + + QByteArray newCompressedData;// = Compressor::CompressZLIB(decompressedData, Z_BEST_COMPRESSION); + newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_COMPRESSION, MAX_WBITS, 8, Z_DEFAULT_STRATEGY, {}); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD5_PS3::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod5_ps3.moc" diff --git a/tests/PS3/autotest_cod6_ps3.cpp b/tests/PS3/autotest_cod6_ps3.cpp new file mode 100644 index 0000000..b5b5234 --- /dev/null +++ b/tests/PS3/autotest_cod6_ps3.cpp @@ -0,0 +1,125 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD6_PS3 : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod6/PS3"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD6_PS3::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD6_PS3::testDecompression_data() { + QTest::addColumn("fastFilePath_cod6_ps3"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD6_PS3::testDecompression() { + QFETCH(QString, fastFilePath_cod6_ps3); + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod6_ps3); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod6_ps3)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + QVERIFY2(zoneSize + 44 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod6_ps3)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod6_ps3); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD6_PS3::testCompression_data() { + QTest::addColumn("zoneFilePath_cod6_ps3"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD6_PS3::testCompression() { + QFETCH(QString, zoneFilePath_cod6_ps3); + + QFile zoneFile(zoneFilePath_cod6_ps3); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod6_ps3)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod6_ps3); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + + QByteArray newCompressedData;// = Compressor::CompressZLIB(decompressedData, Z_BEST_COMPRESSION); + newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_COMPRESSION, MAX_WBITS, 8, Z_DEFAULT_STRATEGY, {}); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD6_PS3::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod6_ps3.moc" diff --git a/tests/PS3/autotest_cod7_ps3.cpp b/tests/PS3/autotest_cod7_ps3.cpp new file mode 100644 index 0000000..a49fa55 --- /dev/null +++ b/tests/PS3/autotest_cod7_ps3.cpp @@ -0,0 +1,125 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD7_PS3 : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod7/PS3"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD7_PS3::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD7_PS3::testDecompression_data() { + QTest::addColumn("fastFilePath_cod7_ps3"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD7_PS3::testDecompression() { + QFETCH(QString, fastFilePath_cod7_ps3); + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod7_ps3); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod7_ps3)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + QVERIFY2(zoneSize + 44 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod7_ps3)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod7_ps3); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD7_PS3::testCompression_data() { + QTest::addColumn("zoneFilePath_cod7_ps3"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD7_PS3::testCompression() { + QFETCH(QString, zoneFilePath_cod7_ps3); + + QFile zoneFile(zoneFilePath_cod7_ps3); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod7_ps3)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod7_ps3); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + + QByteArray newCompressedData;// = Compressor::CompressZLIB(decompressedData, Z_BEST_COMPRESSION); + newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_COMPRESSION, MAX_WBITS, 8, Z_DEFAULT_STRATEGY, {}); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD7_PS3::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod7_ps3.moc" diff --git a/tests/PS3/autotest_cod8_ps3.cpp b/tests/PS3/autotest_cod8_ps3.cpp new file mode 100644 index 0000000..fdae339 --- /dev/null +++ b/tests/PS3/autotest_cod8_ps3.cpp @@ -0,0 +1,125 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD8_PS3 : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod8/PS3"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD8_PS3::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD8_PS3::testDecompression_data() { + QTest::addColumn("fastFilePath_cod8_ps3"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD8_PS3::testDecompression() { + QFETCH(QString, fastFilePath_cod8_ps3); + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod8_ps3); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod8_ps3)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + QVERIFY2(zoneSize + 44 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod8_ps3)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod8_ps3); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD8_PS3::testCompression_data() { + QTest::addColumn("zoneFilePath_cod8_ps3"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD8_PS3::testCompression() { + QFETCH(QString, zoneFilePath_cod8_ps3); + + QFile zoneFile(zoneFilePath_cod8_ps3); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod8_ps3)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod8_ps3); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + + QByteArray newCompressedData;// = Compressor::CompressZLIB(decompressedData, Z_BEST_COMPRESSION); + newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_COMPRESSION, MAX_WBITS, 8, Z_DEFAULT_STRATEGY, {}); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD8_PS3::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod8_ps3.moc" diff --git a/tests/PS3/autotest_cod9_ps3.cpp b/tests/PS3/autotest_cod9_ps3.cpp new file mode 100644 index 0000000..660f16b --- /dev/null +++ b/tests/PS3/autotest_cod9_ps3.cpp @@ -0,0 +1,125 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD9_PS3 : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod9/PS3"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD9_PS3::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD9_PS3::testDecompression_data() { + QTest::addColumn("fastFilePath_cod9_ps3"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD9_PS3::testDecompression() { + QFETCH(QString, fastFilePath_cod9_ps3); + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod9_ps3); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod9_ps3)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + QVERIFY2(zoneSize + 44 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod9_ps3)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod9_ps3); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD9_PS3::testCompression_data() { + QTest::addColumn("zoneFilePath_cod9_ps3"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD9_PS3::testCompression() { + QFETCH(QString, zoneFilePath_cod9_ps3); + + QFile zoneFile(zoneFilePath_cod9_ps3); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod9_ps3)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod9_ps3); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + + QByteArray newCompressedData;// = Compressor::CompressZLIB(decompressedData, Z_BEST_COMPRESSION); + newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_COMPRESSION, MAX_WBITS, 8, Z_DEFAULT_STRATEGY, {}); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD9_PS3::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod9_ps3.moc" diff --git a/tests/Wii/autotest_cod7_wii.cpp b/tests/Wii/autotest_cod7_wii.cpp new file mode 100644 index 0000000..69948a5 --- /dev/null +++ b/tests/Wii/autotest_cod7_wii.cpp @@ -0,0 +1,125 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD7_Wii : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod7/Wii"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD7_Wii::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD7_Wii::testDecompression_data() { + QTest::addColumn("fastFilePath_cod7_wii"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD7_Wii::testDecompression() { + QFETCH(QString, fastFilePath_cod7_wii); + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod7_wii); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod7_wii)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + QVERIFY2(zoneSize + 44 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod7_wii)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod7_wii); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD7_Wii::testCompression_data() { + QTest::addColumn("zoneFilePath_cod7_wii"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD7_Wii::testCompression() { + QFETCH(QString, zoneFilePath_cod2_360); + + QFile zoneFile(zoneFilePath_cod2_360); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod2_360)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod2_360); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + + QByteArray newCompressedData;// = Compressor::CompressZLIB(decompressedData, Z_BEST_COMPRESSION); + newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_COMPRESSION, MAX_WBITS, 8, Z_DEFAULT_STRATEGY, {}); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD7_Wii::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod7_wii.moc" diff --git a/tests/WiiU/autotest_cod10_wiiu.cpp b/tests/WiiU/autotest_cod10_wiiu.cpp new file mode 100644 index 0000000..ec487f4 --- /dev/null +++ b/tests/WiiU/autotest_cod10_wiiu.cpp @@ -0,0 +1,125 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD10_WiiU : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod10/WiiU"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD10_WiiU::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD10_WiiU::testDecompression_data() { + QTest::addColumn("fastFilePath_cod10_wiiu"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD10_WiiU::testDecompression() { + QFETCH(QString, fastFilePath_cod10_wiiu); + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod10_wiiu); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod10_wiiu)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + QVERIFY2(zoneSize + 44 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod10_wiiu)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod10_wiiu); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD10_WiiU::testCompression_data() { + QTest::addColumn("zoneFilePath_cod10_wiiu"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD10_WiiU::testCompression() { + QFETCH(QString, zoneFilePath_cod10_wiiu); + + QFile zoneFile(zoneFilePath_cod10_wiiu); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod10_wiiu)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod10_wiiu); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + + QByteArray newCompressedData;// = Compressor::CompressZLIB(decompressedData, Z_BEST_COMPRESSION); + newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_COMPRESSION, MAX_WBITS, 8, Z_DEFAULT_STRATEGY, {}); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD10_WiiU::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod10_wiiu.moc" diff --git a/tests/WiiU/autotest_cod9_wiiu.cpp b/tests/WiiU/autotest_cod9_wiiu.cpp new file mode 100644 index 0000000..819f170 --- /dev/null +++ b/tests/WiiU/autotest_cod9_wiiu.cpp @@ -0,0 +1,125 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD9_WiiU : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod9/WiiU"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD9_WiiU::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD9_WiiU::testDecompression_data() { + QTest::addColumn("fastFilePath_cod9_wiiu"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD9_WiiU::testDecompression() { + QFETCH(QString, fastFilePath_cod9_wiiu); + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod9_wiiu); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod9_wiiu)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + QVERIFY2(zoneSize + 44 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod9_wiiu)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod9_wiiu); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD9_WiiU::testCompression_data() { + QTest::addColumn("zoneFilePath_cod9_wiiu"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD9_WiiU::testCompression() { + QFETCH(QString, zoneFilePath_cod9_wiiu); + + QFile zoneFile(zoneFilePath_cod9_wiiu); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod9_wiiu)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod9_wiiu); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + + QByteArray newCompressedData;// = Compressor::CompressZLIB(decompressedData, Z_BEST_COMPRESSION); + newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_COMPRESSION, MAX_WBITS, 8, Z_DEFAULT_STRATEGY, {}); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD9_WiiU::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod9_wiiu.moc" diff --git a/tests/autotest_cod.h b/tests/autotest_cod.h index 89019f0..4c4b2e3 100644 --- a/tests/autotest_cod.h +++ b/tests/autotest_cod.h @@ -1,11 +1,69 @@ +#ifndef AUTOTEST_COD_CPP +#define AUTOTEST_COD_CPP + #include class AutoTest_COD : public QObject { Q_OBJECT -private slots: +public: + void setFastFileDirectory(const QString aFastFileDir) { + mFastFileDirectory = aFastFileDir; + } + QString getFastFileDirectory() { + return mFastFileDirectory; + } + + void setZoneFileDirectory(const QString aZoneFileDir) { + mZoneFileDirectory = aZoneFileDir; + } + QString getZoneFileDirectory() { + return mZoneFileDirectory; + } + + void createDirectory(const QString aDir) { + QDir newDir(aDir); + if (!newDir.exists()) { + newDir.mkpath(aDir); + } + } + QStringList findFastFiles(const QString &aBaseDir, int aMaxIter = MAX_ITER) { + QStringList fastFiles; + + QDirIterator it(aBaseDir, QStringList() << "*.ff", QDir::Files, QDirIterator::Subdirectories); + + int i = 0; + while (it.hasNext() && i < aMaxIter) { + fastFiles << it.next(); + ++i; + } + + return fastFiles; + } + QStringList findZoneFiles(const QString &aBaseDir, int aMaxIter = MAX_ITER) { + QStringList zoneFiles; + + QDirIterator it(aBaseDir, QStringList() << "*.zone", QDir::Files, QDirIterator::Subdirectories); + + int i = 0; + while (it.hasNext() && i < aMaxIter) { + zoneFiles << it.next(); + ++i; + } + + return zoneFiles; + } + virtual void initTestCase() = 0; + virtual void testDecompression_data() = 0; virtual void testDecompression() = 0; + virtual void testCompression_data() = 0; + virtual void testCompression() = 0; + virtual void cleanupTestCase() = 0; + +private: + static const int MAX_ITER = -1; + QString mFastFileDirectory; + QString mZoneFileDirectory; }; -// Don't generate a main() function -#include "autotest_cod.moc" +#endif // AUTOTEST_COD_CPP diff --git a/tests/autotest_cod5_pc.cpp b/tests/autotest_cod5_pc.cpp deleted file mode 100644 index f605f03..0000000 --- a/tests/autotest_cod5_pc.cpp +++ /dev/null @@ -1,40 +0,0 @@ -#include - -#include "autotest_cod.cpp" -#include "compressor.h" - -class AutoTest_COD5 : public AutoTest_COD { - Q_OBJECT - -private slots: - void testDecompression(); - -private: - //void testDecompression(); -}; - -void AutoTest_COD5::testDecompression() { - qDebug() << "Available folders:" << QDir("qrc:/").entryList(); - - const QString testStem = "ber1"; - const QString testFFPath = QString(":/cod5/fastfile/%1.ff").arg(testStem); - QFile testFastFile(testFFPath); - if (!testFastFile.open(QIODevice::ReadOnly)) { - qDebug() << "Failed to open test fastfile: " << testFFPath; - } - - const QByteArray testFFData(testFastFile.readAll()); - const QByteArray testZoneData = Compressor::DecompressZLIB(testFFData.mid(12)); - - const QString testZonePath = QString(":/cod5/zonefile/%1.zone").arg(testStem); - QFile testZoneFile(testZonePath); - if (!testZoneFile.open(QIODevice::ReadOnly)) { - qDebug() << "Failed to open true zonefile: " << testZonePath; - } - const QByteArray trueZoneData(testZoneFile.readAll()); - - QCOMPARE(testZoneData, trueZoneData); -} - -// Don't generate a main() function -#include "autotest_cod5.moc"