am-freescan/integrations/freescan-service/tests/calibration_recovery_test.cpp
Codex a16f16e19a feat(scanner): show native calibration window and SDK progress
Use the existing successful calibration-enter workflow to display the same SDK manufacturer's window and actual callback progress in the task UI. Bind metadata, JPEG and MJPEG to the execution, SDK session, calibration ID and trusted process/window identity; closing the monitor only stops viewing.

Include source-only FreeScanCpp integration, WGC capture lifecycle fixes and immediate ENTER acknowledgement cache synchronization. Preserve original scanner project guards, regression sources and third-party licensing; exclude private runtime configuration and generated artifacts.

Validated platform Java compilation/regressions, frontend type checks and standalone build, native compilation/offline and HTTP regressions, immediate calibration identity checks and ten synthetic window close/reopen cycles. Production installation/restart and real scanner calibration remain pending.
2026-11-21 19:52:07 +08:00

67 lines
3.0 KiB
C++

#include "../src/calibration_recovery.hpp"
#include <iostream>
using freescan::Json;
namespace {
int passed = 0;
void check(bool value, const char *message) {
if (!value)
throw std::runtime_error(message);
++passed;
}
const std::string reviewed = "0123456789abcdef0123456789abcdef";
Json idle() {
return {{"sessionId", reviewed}, {"projectReady", false}, {"scanning", false},
{"calibrationSession", true}, {"busy", false}, {"restartRequired", false}};
}
void rejected(const Json &info, const std::string &session, bool force, const char *code) {
bool denied = false;
try { freescan::detail::validate_calibration_recovery(info, session, force); }
catch (const freescan::ApiError &error) {
denied = error.code == code;
}
check(denied, code);
}
} // namespace
int main() {
try {
auto info = idle();
freescan::detail::validate_calibration_recovery(info, reviewed, false);
check(true, "Idle calibration is eligible for normal release.");
info["busy"] = true;
rejected(info, reviewed, false, "recovery_requires_force");
freescan::detail::validate_calibration_recovery(info, reviewed, true);
check(true, "Explicit force admits busy calibration.");
info["restartRequired"] = true;
freescan::detail::validate_calibration_recovery(info, reviewed, true);
check(true, "Timeout latch does not trap the recovery path.");
rejected(info, "ffffffffffffffffffffffffffffffff", true, "session_changed");
info["projectReady"] = true;
rejected(info, reviewed, true, "project_protected");
info = idle(); info["scanning"] = true;
rejected(info, reviewed, true, "project_protected");
info = idle(); info["calibrationSession"] = false;
rejected(info, reviewed, true, "calibration_not_active");
info = idle(); info.erase("projectReady");
rejected(info, reviewed, true, "project_protected");
info = idle(); info.erase("scanning");
rejected(info, reviewed, true, "project_protected");
info = idle(); info.erase("calibrationSession");
rejected(info, reviewed, true, "calibration_not_active");
info = idle(); info.erase("busy");
rejected(info, reviewed, false, "recovery_requires_force");
info = idle(); info["sessionId"] = nullptr;
rejected(info, reviewed, true, "session_changed");
rejected(Json::object(), reviewed, true, "session_changed");
rejected(Json::array(), reviewed, true, "session_changed");
check(GetModuleHandleW(L"SDKCWrapper.dll") == nullptr &&
GetModuleHandleW(L"FreeScanNativeBridge.dll") == nullptr,
"Safety tests never load the SDK or bridge.");
std::cout << "Calibration recovery safety checks passed: " << passed << "\n";
return 0;
} catch (const std::exception &error) {
std::cerr << "Calibration recovery safety test failed: " << error.what() << "\n";
return 1;
}
}