Add and update autotests.
This commit is contained in:
parent
b192f6ee16
commit
83fb3f14d8
125
tests/360/autotest_cod10_360.cpp
Normal file
125
tests/360/autotest_cod10_360.cpp
Normal file
@ -0,0 +1,125 @@
|
||||
#include <QtTest/QtTest>
|
||||
#include <QDirIterator>
|
||||
#include <QFileInfo>
|
||||
|
||||
#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<QString>("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<QString>("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"
|
||||
125
tests/360/autotest_cod11_360.cpp
Normal file
125
tests/360/autotest_cod11_360.cpp
Normal file
@ -0,0 +1,125 @@
|
||||
#include <QtTest/QtTest>
|
||||
#include <QDirIterator>
|
||||
#include <QFileInfo>
|
||||
|
||||
#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<QString>("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<QString>("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"
|
||||
125
tests/360/autotest_cod12_360.cpp
Normal file
125
tests/360/autotest_cod12_360.cpp
Normal file
@ -0,0 +1,125 @@
|
||||
#include <QtTest/QtTest>
|
||||
#include <QDirIterator>
|
||||
#include <QFileInfo>
|
||||
|
||||
#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<QString>("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<QString>("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"
|
||||
120
tests/360/autotest_cod2_360.cpp
Normal file
120
tests/360/autotest_cod2_360.cpp
Normal file
@ -0,0 +1,120 @@
|
||||
#include <QtTest/QtTest>
|
||||
#include <QDirIterator>
|
||||
#include <QFileInfo>
|
||||
|
||||
#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<QString>("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<QString>("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"
|
||||
119
tests/360/autotest_cod4_360.cpp
Normal file
119
tests/360/autotest_cod4_360.cpp
Normal file
@ -0,0 +1,119 @@
|
||||
#include <QtTest/QtTest>
|
||||
#include <QDirIterator>
|
||||
#include <QFileInfo>
|
||||
|
||||
#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<QString>("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<QString>("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"
|
||||
125
tests/360/autotest_cod5_360.cpp
Normal file
125
tests/360/autotest_cod5_360.cpp
Normal file
@ -0,0 +1,125 @@
|
||||
#include <QtTest/QtTest>
|
||||
#include <QDirIterator>
|
||||
#include <QFileInfo>
|
||||
|
||||
#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<QString>("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<QString>("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"
|
||||
125
tests/360/autotest_cod6_360.cpp
Normal file
125
tests/360/autotest_cod6_360.cpp
Normal file
@ -0,0 +1,125 @@
|
||||
#include <QtTest/QtTest>
|
||||
#include <QDirIterator>
|
||||
#include <QFileInfo>
|
||||
|
||||
#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<QString>("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<QString>("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"
|
||||
125
tests/360/autotest_cod7_360.cpp
Normal file
125
tests/360/autotest_cod7_360.cpp
Normal file
@ -0,0 +1,125 @@
|
||||
#include <QtTest/QtTest>
|
||||
#include <QDirIterator>
|
||||
#include <QFileInfo>
|
||||
|
||||
#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<QString>("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<QString>("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"
|
||||
125
tests/360/autotest_cod8_360.cpp
Normal file
125
tests/360/autotest_cod8_360.cpp
Normal file
@ -0,0 +1,125 @@
|
||||
#include <QtTest/QtTest>
|
||||
#include <QDirIterator>
|
||||
#include <QFileInfo>
|
||||
|
||||
#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<QString>("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<QString>("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"
|
||||
125
tests/360/autotest_cod9_360.cpp
Normal file
125
tests/360/autotest_cod9_360.cpp
Normal file
@ -0,0 +1,125 @@
|
||||
#include <QtTest/QtTest>
|
||||
#include <QDirIterator>
|
||||
#include <QFileInfo>
|
||||
|
||||
#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<QString>("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<QString>("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"
|
||||
124
tests/PC/autotest_cod10_pc.cpp
Normal file
124
tests/PC/autotest_cod10_pc.cpp
Normal file
@ -0,0 +1,124 @@
|
||||
#include <QtTest/QtTest>
|
||||
#include <QDirIterator>
|
||||
#include <QFileInfo>
|
||||
|
||||
#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<QString>("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<QString>("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"
|
||||
124
tests/PC/autotest_cod11_pc.cpp
Normal file
124
tests/PC/autotest_cod11_pc.cpp
Normal file
@ -0,0 +1,124 @@
|
||||
#include <QtTest/QtTest>
|
||||
#include <QDirIterator>
|
||||
#include <QFileInfo>
|
||||
|
||||
#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<QString>("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<QString>("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"
|
||||
124
tests/PC/autotest_cod12_pc.cpp
Normal file
124
tests/PC/autotest_cod12_pc.cpp
Normal file
@ -0,0 +1,124 @@
|
||||
#include <QtTest/QtTest>
|
||||
#include <QDirIterator>
|
||||
#include <QFileInfo>
|
||||
|
||||
#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<QString>("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<QString>("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"
|
||||
120
tests/PC/autotest_cod4_pc.cpp
Normal file
120
tests/PC/autotest_cod4_pc.cpp
Normal file
@ -0,0 +1,120 @@
|
||||
#include <QtTest/QtTest>
|
||||
#include <QDirIterator>
|
||||
#include <QFileInfo>
|
||||
|
||||
#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<QString>("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<QString>("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"
|
||||
124
tests/PC/autotest_cod5_pc.cpp
Normal file
124
tests/PC/autotest_cod5_pc.cpp
Normal file
@ -0,0 +1,124 @@
|
||||
#include <QtTest/QtTest>
|
||||
#include <QDirIterator>
|
||||
#include <QFileInfo>
|
||||
|
||||
#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<QString>("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<QString>("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"
|
||||
116
tests/PC/autotest_cod6_pc.cpp
Normal file
116
tests/PC/autotest_cod6_pc.cpp
Normal file
@ -0,0 +1,116 @@
|
||||
#include <QtTest/QtTest>
|
||||
#include <QDirIterator>
|
||||
#include <QFileInfo>
|
||||
|
||||
#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<QString>("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<QString>("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"
|
||||
123
tests/PC/autotest_cod7_pc.cpp
Normal file
123
tests/PC/autotest_cod7_pc.cpp
Normal file
@ -0,0 +1,123 @@
|
||||
#include <QtTest/QtTest>
|
||||
#include <QDirIterator>
|
||||
#include <QFileInfo>
|
||||
|
||||
#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<QString>("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<QString>("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"
|
||||
124
tests/PC/autotest_cod8_pc.cpp
Normal file
124
tests/PC/autotest_cod8_pc.cpp
Normal file
@ -0,0 +1,124 @@
|
||||
#include <QtTest/QtTest>
|
||||
#include <QDirIterator>
|
||||
#include <QFileInfo>
|
||||
|
||||
#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<QString>("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<QString>("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"
|
||||
124
tests/PC/autotest_cod9_pc.cpp
Normal file
124
tests/PC/autotest_cod9_pc.cpp
Normal file
@ -0,0 +1,124 @@
|
||||
#include <QtTest/QtTest>
|
||||
#include <QDirIterator>
|
||||
#include <QFileInfo>
|
||||
|
||||
#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<QString>("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<QString>("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"
|
||||
125
tests/PS3/autotest_cod10_ps3.cpp
Normal file
125
tests/PS3/autotest_cod10_ps3.cpp
Normal file
@ -0,0 +1,125 @@
|
||||
#include <QtTest/QtTest>
|
||||
#include <QDirIterator>
|
||||
#include <QFileInfo>
|
||||
|
||||
#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<QString>("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<QString>("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"
|
||||
125
tests/PS3/autotest_cod11_ps3.cpp
Normal file
125
tests/PS3/autotest_cod11_ps3.cpp
Normal file
@ -0,0 +1,125 @@
|
||||
#include <QtTest/QtTest>
|
||||
#include <QDirIterator>
|
||||
#include <QFileInfo>
|
||||
|
||||
#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<QString>("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<QString>("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"
|
||||
125
tests/PS3/autotest_cod12_ps3.cpp
Normal file
125
tests/PS3/autotest_cod12_ps3.cpp
Normal file
@ -0,0 +1,125 @@
|
||||
#include <QtTest/QtTest>
|
||||
#include <QDirIterator>
|
||||
#include <QFileInfo>
|
||||
|
||||
#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<QString>("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<QString>("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"
|
||||
124
tests/PS3/autotest_cod4_ps3.cpp
Normal file
124
tests/PS3/autotest_cod4_ps3.cpp
Normal file
@ -0,0 +1,124 @@
|
||||
#include <QtTest/QtTest>
|
||||
#include <QDirIterator>
|
||||
#include <QFileInfo>
|
||||
|
||||
#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<QString>("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<QString>("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"
|
||||
125
tests/PS3/autotest_cod5_ps3.cpp
Normal file
125
tests/PS3/autotest_cod5_ps3.cpp
Normal file
@ -0,0 +1,125 @@
|
||||
#include <QtTest/QtTest>
|
||||
#include <QDirIterator>
|
||||
#include <QFileInfo>
|
||||
|
||||
#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<QString>("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<QString>("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"
|
||||
125
tests/PS3/autotest_cod6_ps3.cpp
Normal file
125
tests/PS3/autotest_cod6_ps3.cpp
Normal file
@ -0,0 +1,125 @@
|
||||
#include <QtTest/QtTest>
|
||||
#include <QDirIterator>
|
||||
#include <QFileInfo>
|
||||
|
||||
#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<QString>("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<QString>("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"
|
||||
125
tests/PS3/autotest_cod7_ps3.cpp
Normal file
125
tests/PS3/autotest_cod7_ps3.cpp
Normal file
@ -0,0 +1,125 @@
|
||||
#include <QtTest/QtTest>
|
||||
#include <QDirIterator>
|
||||
#include <QFileInfo>
|
||||
|
||||
#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<QString>("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<QString>("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"
|
||||
125
tests/PS3/autotest_cod8_ps3.cpp
Normal file
125
tests/PS3/autotest_cod8_ps3.cpp
Normal file
@ -0,0 +1,125 @@
|
||||
#include <QtTest/QtTest>
|
||||
#include <QDirIterator>
|
||||
#include <QFileInfo>
|
||||
|
||||
#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<QString>("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<QString>("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"
|
||||
125
tests/PS3/autotest_cod9_ps3.cpp
Normal file
125
tests/PS3/autotest_cod9_ps3.cpp
Normal file
@ -0,0 +1,125 @@
|
||||
#include <QtTest/QtTest>
|
||||
#include <QDirIterator>
|
||||
#include <QFileInfo>
|
||||
|
||||
#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<QString>("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<QString>("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"
|
||||
125
tests/Wii/autotest_cod7_wii.cpp
Normal file
125
tests/Wii/autotest_cod7_wii.cpp
Normal file
@ -0,0 +1,125 @@
|
||||
#include <QtTest/QtTest>
|
||||
#include <QDirIterator>
|
||||
#include <QFileInfo>
|
||||
|
||||
#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<QString>("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<QString>("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"
|
||||
125
tests/WiiU/autotest_cod10_wiiu.cpp
Normal file
125
tests/WiiU/autotest_cod10_wiiu.cpp
Normal file
@ -0,0 +1,125 @@
|
||||
#include <QtTest/QtTest>
|
||||
#include <QDirIterator>
|
||||
#include <QFileInfo>
|
||||
|
||||
#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<QString>("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<QString>("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"
|
||||
125
tests/WiiU/autotest_cod9_wiiu.cpp
Normal file
125
tests/WiiU/autotest_cod9_wiiu.cpp
Normal file
@ -0,0 +1,125 @@
|
||||
#include <QtTest/QtTest>
|
||||
#include <QDirIterator>
|
||||
#include <QFileInfo>
|
||||
|
||||
#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<QString>("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<QString>("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"
|
||||
@ -1,11 +1,69 @@
|
||||
#ifndef AUTOTEST_COD_CPP
|
||||
#define AUTOTEST_COD_CPP
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
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
|
||||
|
||||
@ -1,40 +0,0 @@
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
#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"
|
||||
Loading…
x
Reference in New Issue
Block a user