#include "infrastructure/runtime_project_bundle.h" #include "support/test_support.h" #include #include #include #include namespace { using TestSupport::require; void writeFile(const QString &path, const QByteArray &bytes) { QFile file(path); require(file.open(QIODevice::WriteOnly), "test file must open for writing"); require(file.write(bytes) == bytes.size(), "test file must be written fully"); } void testBundleRoundTripAndValidation() { QTemporaryDir directory; require(directory.isValid(), "temporary directory must be available"); const QString template_path = directory.filePath(QStringLiteral("template.exe")); const QString project_path = directory.filePath(QStringLiteral("project.json")); const QString bundle_path = directory.filePath(QStringLiteral("motor.exe")); const QByteArray template_bytes("MZ-template-binary"); const QByteArray project_bytes( "{\"formatVersion\":\"1.0\",\"name\":\"motor\"}"); writeFile(template_path, template_bytes); writeFile(project_path, project_bytes); const RuntimeProjectBundleWriteResult write_result = RuntimeProjectBundleService::write( template_path, project_path, bundle_path); require(write_result.succeeded, "runtime bundle must be written"); const RuntimeProjectBundleLoadResult loaded = RuntimeProjectBundleService::load(bundle_path); require(loaded.status == RuntimeProjectBundleStatus::Loaded, "runtime bundle must be recognized"); require(loaded.project_data == project_bytes, "runtime bundle must preserve project bytes"); const RuntimeProjectBundleLoadResult ordinary = RuntimeProjectBundleService::load(template_path); require(ordinary.status == RuntimeProjectBundleStatus::NotFound, "ordinary executable must not be treated as a runtime bundle"); QFile corrupted(bundle_path); require(corrupted.open(QIODevice::ReadWrite), "bundle must open for corruption regression"); require(corrupted.seek(corrupted.size() - 1), "bundle footer must be seekable"); const char invalid_byte = static_cast(0xff); require(corrupted.write(&invalid_byte, 1) == 1, "bundle corruption must be writable"); corrupted.close(); const RuntimeProjectBundleLoadResult invalid = RuntimeProjectBundleService::load(bundle_path); require(invalid.status == RuntimeProjectBundleStatus::Invalid, "corrupted runtime bundle must be rejected"); } } // namespace int main() { try { testBundleRoundTripAndValidation(); } catch (const std::exception &error) { std::cerr << "runtime project bundle tests failed: " << error.what() << '\n'; return 1; } std::cout << "runtime project bundle tests passed\n"; return 0; }