XPlor/tests/PC/autotest_cod6_pc.cpp

139 lines
4.5 KiB
C++
Raw Normal View History

2025-04-04 20:40:12 -04:00
#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();
2025-04-04 20:40:12 -04:00
void testDecompression_data();
void testDecompression();
2025-04-04 20:40:12 -04:00
void testCompression_data();
void testCompression();
void testFactory_data();
void testFactory();
2025-04-04 20:40:12 -04:00
void cleanupTestCase();
};
void AutoTest_COD6_PC::initTestCase() {
// Ensure the exports directory exists.
createDirectory(EXPORT_DIR);
}
void AutoTest_COD6_PC::testDecompression_data() {
AutoTest_COD::testDecompression_data();
2025-04-04 20:40:12 -04:00
}
void AutoTest_COD6_PC::testDecompression() {
QFETCH(QString, fastFilePath);
2025-04-04 20:40:12 -04:00
// Open the original .ff file.
QFile testFastFile(fastFilePath);
2025-04-04 20:40:12 -04:00
QVERIFY2(testFastFile.open(QIODevice::ReadOnly),
qPrintable("Failed to open test fastfile: " + fastFilePath));
2025-04-04 20:40:12 -04:00
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.
2025-09-10 21:58:26 -04:00
XDataStream zoneStream(testZoneData);
zoneStream.setByteOrder(XDataStream::LittleEndian);
2025-04-04 20:40:12 -04:00
quint32 zoneSize;
zoneStream >> zoneSize;
QVERIFY2(zoneSize + 40 == testZoneData.size(),
qPrintable("Decompression validation failed for: " + fastFilePath));
2025-04-04 20:40:12 -04:00
// Write the decompressed zone data to the exports folder with a .zone extension.
QFileInfo fi(fastFilePath);
2025-04-04 20:40:12 -04:00
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() {
AutoTest_COD::testCompression_data();
2025-04-04 20:40:12 -04:00
}
void AutoTest_COD6_PC::testCompression() {
QFETCH(QString, zoneFilePath);
2025-04-04 20:40:12 -04:00
QFile zoneFile(zoneFilePath);
QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath));
2025-04-04 20:40:12 -04:00
QByteArray decompressedData = zoneFile.readAll();
zoneFile.close();
QFileInfo fi(zoneFilePath);
2025-04-04 20:40:12 -04:00
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::testFactory_data() {
AutoTest_COD::testFactory_data();
}
void AutoTest_COD6_PC::testFactory() {
QFETCH(QString, fastFilePath);
const QString testName = "Factory ingest: " + fastFilePath;
2025-09-05 18:35:17 -04:00
FastFile* fastFile = FastFileFactory::Create(fastFilePath);
const QString game = fastFile->GetGame();
bool correctGame = game == "COD6";
if (!correctGame) {
recordResult(testName, false);
}
QVERIFY2(correctGame
, qPrintable("Factory parsed wrong game [" + game + "] for fastfile: " + fastFilePath));
const QString platform = fastFile->GetPlatform();
bool correctPlatform = platform == "PC";
if (!correctPlatform) {
recordResult(testName, false);
}
QVERIFY2(correctPlatform
, qPrintable("Factory parsed wrong platform [" + platform + "] for fastfile: " + fastFilePath));
recordResult(testName, true);
}
2025-04-04 20:40:12 -04:00
void AutoTest_COD6_PC::cleanupTestCase() {
// Any cleanup if necessary.
}
// Don't generate a main() function
#include "autotest_cod6_pc.moc"