429 lines
21 KiB
C++
429 lines
21 KiB
C++
|
|
#include "../src/contracts.hpp"
|
|||
|
|
#include <cmath>
|
|||
|
|
#include <iostream>
|
|||
|
|
#include <limits>
|
|||
|
|
|
|||
|
|
using freescan::ApiError;
|
|||
|
|
using freescan::Json;
|
|||
|
|
namespace api = freescan::contracts;
|
|||
|
|
namespace {
|
|||
|
|
size_t passed = 0;
|
|||
|
|
const std::string a = "11111111-1111-4111-8111-111111111111", b = "22222222-2222-4222-8222-222222222222";
|
|||
|
|
void check(bool condition, const std::string &label) {
|
|||
|
|
if (!condition)
|
|||
|
|
throw std::runtime_error(label);
|
|||
|
|
++passed;
|
|||
|
|
}
|
|||
|
|
void ok(const std::string &action, const Json &body, const std::string &label = "") {
|
|||
|
|
try {
|
|||
|
|
api::validate(action, body);
|
|||
|
|
++passed;
|
|||
|
|
} catch (const std::exception &error) {
|
|||
|
|
throw std::runtime_error("Unexpected rejection " + action + " " + label + ": " + error.what());
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
void bad(const std::string &action, const Json &body, int status = 400,
|
|||
|
|
const std::string &code = "invalid_parameter") {
|
|||
|
|
try {
|
|||
|
|
api::validate(action, body);
|
|||
|
|
} catch (const ApiError &error) {
|
|||
|
|
check(error.status == status && error.code == code, "Wrong error for " + action + ": " + error.code);
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
throw std::runtime_error("Unexpected acceptance " + action + " " + body.dump());
|
|||
|
|
}
|
|||
|
|
Json triplets(size_t count) {
|
|||
|
|
Json result = Json::array();
|
|||
|
|
for (size_t i = 0; i < count; ++i)
|
|||
|
|
result.push_back({0, 1, -1});
|
|||
|
|
return result;
|
|||
|
|
}
|
|||
|
|
Json identifiers(size_t count) {
|
|||
|
|
Json result = Json::array();
|
|||
|
|
for (size_t i = 0; i < count; ++i)
|
|||
|
|
result.push_back(static_cast<int64_t>(i));
|
|||
|
|
return result;
|
|||
|
|
}
|
|||
|
|
Json repeated(size_t count, const Json &value) {
|
|||
|
|
Json result = Json::array();
|
|||
|
|
for (size_t i = 0; i < count; ++i)
|
|||
|
|
result.push_back(value);
|
|||
|
|
return result;
|
|||
|
|
}
|
|||
|
|
Json alignment(const char *mode = "featureAuto") {
|
|||
|
|
return {{"action", "apply"}, {"mode", mode}, {"fixedProjectUuid", a}, {"movingProjectUuid", b}};
|
|||
|
|
}
|
|||
|
|
Json deletion() {
|
|||
|
|
return {{"projectUuid", a}, {"markerIds", Json::array({0})}, {"confirm", true}};
|
|||
|
|
}
|
|||
|
|
Json clip() {
|
|||
|
|
return {{"center", {0, 0, 0}}, {"normal", {0, 1, 0}}, {"confirm", true}};
|
|||
|
|
}
|
|||
|
|
void routes_and_all_actions() {
|
|||
|
|
check(api::routes().size() == 45, "All original routes plus independent calibration window metadata/image/stream must exist.");
|
|||
|
|
check(api::export_formats() == Json({"ASCW", "ASCS", "STL", "OBJ", "PLY", "P3", "3MF", "TXT", "CSV",
|
|||
|
|
"ASCG", "TGF", "STP", "IGS", "ASC"}),
|
|||
|
|
"The exact 14 vendor format names/order must remain stable.");
|
|||
|
|
std::map<std::string, Json> actions = {{"connect", Json::object()},
|
|||
|
|
{"createProject", Json::object()},
|
|||
|
|
{"startScan", Json::object()},
|
|||
|
|
{"stopScan", Json::object()},
|
|||
|
|
{"setScanType", {{"scanType", "mesh"}}},
|
|||
|
|
{"importFramework", {{"fileIds", {std::string(32, 'a')}}, {"confirm", true}}},
|
|||
|
|
{"optimizeFramework", Json::object()},
|
|||
|
|
{"disconnect", {{"confirm", true}}},
|
|||
|
|
{"reconnect", {{"confirm", true}}},
|
|||
|
|
{"startPreview", Json::object()},
|
|||
|
|
{"stopPreview", Json::object()},
|
|||
|
|
{"parameters", {{"viewLock", false}}},
|
|||
|
|
{"mesh", Json::object()},
|
|||
|
|
{"meshConfirm", Json::object()},
|
|||
|
|
{"meshUndo", Json::object()},
|
|||
|
|
{"align", {{"action", "enter"}}},
|
|||
|
|
{"edit", deletion()},
|
|||
|
|
{"clipPlane", clip()},
|
|||
|
|
{"export", {{"formats", {"STL"}}}},
|
|||
|
|
{"dataSnapshot", Json::object()},
|
|||
|
|
{"calibrationEnter", Json::object()},
|
|||
|
|
{"calibrationSetMode", {{"mode", 0}}},
|
|||
|
|
{"calibrationSetTrakType", {{"trakType", 3}, {"confirm", true}}},
|
|||
|
|
{"calibrationStart", {{"confirm", true}}},
|
|||
|
|
{"calibrationStartSystem", {{"confirm", true}}},
|
|||
|
|
{"calibrationSetFree", {{"enabled", false}, {"confirm", true}}},
|
|||
|
|
{"calibrationCapturePose", {{"confirm", true}}},
|
|||
|
|
{"calibrationCompute", {{"confirm", true}}},
|
|||
|
|
{"calibrationSetAdvanced", {{"enabled", true}, {"confirm", true}}},
|
|||
|
|
{"calibrationApplyLast", {{"mode", 3}, {"confirm", true}}},
|
|||
|
|
{"calibrationRecover", {{"confirm", true}, {"expectedSessionId", std::string(32, 'a')}}}};
|
|||
|
|
std::set<std::string> seen;
|
|||
|
|
for (const auto &route : api::routes()) {
|
|||
|
|
const auto line = route.get<std::string>();
|
|||
|
|
if (line.rfind("POST ", 0) != 0)
|
|||
|
|
continue;
|
|||
|
|
if (line == "POST /api/v1/framework/files")
|
|||
|
|
continue; // Synchronous upload is handled by the HTTP layer, not the SDK worker.
|
|||
|
|
const auto action = api::action_for_path(line.substr(5));
|
|||
|
|
check(!action.empty() && seen.insert(action).second,
|
|||
|
|
"POST routes must resolve to distinct registered actions.");
|
|||
|
|
ok(action, actions.at(action));
|
|||
|
|
auto unknown = actions.at(action);
|
|||
|
|
unknown["unknownField"] = true;
|
|||
|
|
bad(action, unknown, 400, "unknown_parameter");
|
|||
|
|
check(api::maximum_body_bytes(action) == (action == "align" || action == "edit" ? 1048576u : 16384u),
|
|||
|
|
"Payload limit mismatch.");
|
|||
|
|
}
|
|||
|
|
check(seen.size() == actions.size(), "Every declared action needs a working exact route.");
|
|||
|
|
for (const auto *route :
|
|||
|
|
{"/api/v1/device/Connect", "/api/v1/projects/", "/api/v1/align/anything",
|
|||
|
|
"/api/v1/calibration/invalid", "/api/v1/projects?name=test", "/api/v1/files/../../file"})
|
|||
|
|
check(api::action_for_path(route).empty(), "Unknown paths cannot acquire a mutation action.");
|
|||
|
|
bad("unknown", Json::object(), 404, "unknown_action");
|
|||
|
|
bad("calibrationUnknown", Json::object(), 404, "unknown_action");
|
|||
|
|
bad("mesh", nullptr);
|
|||
|
|
bad("mesh", Json::array());
|
|||
|
|
bad("mesh", true);
|
|||
|
|
bad("mesh", "text");
|
|||
|
|
}
|
|||
|
|
void primitive_types_and_names() {
|
|||
|
|
for (const Json value : {Json(true), Json(false), Json(3.0), Json("3"), Json(nullptr),
|
|||
|
|
Json(int64_t(2147483648)), Json(uint64_t(18446744073709551615ull))})
|
|||
|
|
bad("connect", {{"deviceType", value}});
|
|||
|
|
ok("connect", {{"deviceType", 3}});
|
|||
|
|
ok("connect", {{"deviceType", 4}});
|
|||
|
|
bad("connect", {{"deviceType", 2}});
|
|||
|
|
ok("createProject", {{"mode", "laser"}, {"name", u8"扫描_Αβ١2-项目"}});
|
|||
|
|
ok("createProject", {{"name", u8"DžȻ中文"}});
|
|||
|
|
std::string forty;
|
|||
|
|
for (size_t i = 0; i < 40; ++i)
|
|||
|
|
forty += u8"测";
|
|||
|
|
ok("createProject", {{"name", forty}});
|
|||
|
|
bad("createProject", {{"name", forty + u8"测"}});
|
|||
|
|
for (const auto *value :
|
|||
|
|
{"", "../scan", "scan/result", "scan\\result", "A B", "A\nB", u8"é", u8"Ⅷ", u8"𠀀", u8"📷",
|
|||
|
|
"a\xE2\x80\xAE"
|
|||
|
|
"b"})
|
|||
|
|
bad("createProject", {{"name", value}});
|
|||
|
|
bad("createProject", {{"name", std::string(1, static_cast<char>(0xFF))}});
|
|||
|
|
bad("createProject", {{"name", nullptr}});
|
|||
|
|
bad("createProject", {{"mode", "TRAK"}});
|
|||
|
|
bad("createProject", {{"mode", true}});
|
|||
|
|
bad("export", {{"name", "../out"}, {"formats", {"PLY"}}});
|
|||
|
|
bad("disconnect", Json::object(), 400, "confirmation_required");
|
|||
|
|
bad("disconnect", {{"confirm", false}}, 400, "confirmation_required");
|
|||
|
|
bad("disconnect", {{"confirm", 1}}, 400, "confirmation_required");
|
|||
|
|
ok("disconnect", {{"confirm", true},
|
|||
|
|
{"discardProject", false},
|
|||
|
|
{"expectedProjectId", nullptr},
|
|||
|
|
{"expectedSessionId", nullptr}});
|
|||
|
|
ok("reconnect", {{"confirm", true},
|
|||
|
|
{"discardProject", true},
|
|||
|
|
{"expectedProjectId", u8"工程_١"},
|
|||
|
|
{"expectedSessionId", std::string(32, 'A')},
|
|||
|
|
{"deviceType", 4}});
|
|||
|
|
bad("disconnect", {{"confirm", true}, {"discardProject", 0}});
|
|||
|
|
bad("disconnect", {{"confirm", true}, {"expectedProjectId", "../scan"}});
|
|||
|
|
bad("disconnect", {{"confirm", true}, {"expectedProjectId", std::string(161, 'a')}});
|
|||
|
|
bad("disconnect", {{"confirm", true}, {"expectedSessionId", a}});
|
|||
|
|
bad("disconnect", {{"confirm", true}, {"expectedSessionId", std::string(32, 'g')}});
|
|||
|
|
bad("reconnect", {{"confirm", true}, {"deviceType", 3.0}});
|
|||
|
|
ok("disconnect", {{"confirm", true}, {"expectedProjectId", std::string(160, 'a')}});
|
|||
|
|
}
|
|||
|
|
void parameters_mesh_and_exports() {
|
|||
|
|
ok("parameters", {{"pointDistance", 0.001},
|
|||
|
|
{"brightness", 0},
|
|||
|
|
{"lightSourceMode", 0},
|
|||
|
|
{"scanFrameRate", 1},
|
|||
|
|
{"highSpeedMode", false},
|
|||
|
|
{"addMarkerMode", true},
|
|||
|
|
{"viewLock", false},
|
|||
|
|
{"localEnlargedView", true},
|
|||
|
|
{"qualityColor", false},
|
|||
|
|
{"strongLight", true},
|
|||
|
|
{"preScanMode", false},
|
|||
|
|
{"markerDiameters", {1, 50}}});
|
|||
|
|
ok("parameters", {{"pointDistance", 10},
|
|||
|
|
{"brightness", 17},
|
|||
|
|
{"lightSourceMode", 2},
|
|||
|
|
{"scanFrameRate", 120},
|
|||
|
|
{"markerDiameters", repeated(16, 1)}});
|
|||
|
|
bad("parameters", Json::object());
|
|||
|
|
bad("parameters", {{"brightness", 1.0}});
|
|||
|
|
bad("parameters", {{"brightness", true}});
|
|||
|
|
bad("parameters", {{"brightness", 18}});
|
|||
|
|
bad("parameters", {{"lightSourceMode", 3}});
|
|||
|
|
bad("parameters", {{"scanFrameRate", 0}});
|
|||
|
|
bad("parameters", {{"scanFrameRate", 121}});
|
|||
|
|
bad("parameters", {{"pointDistance", 0.000999}});
|
|||
|
|
bad("parameters", {{"pointDistance", 10.001}});
|
|||
|
|
for (const double number :
|
|||
|
|
{std::numeric_limits<double>::infinity(), -std::numeric_limits<double>::infinity(),
|
|||
|
|
std::numeric_limits<double>::quiet_NaN()})
|
|||
|
|
bad("parameters", {{"pointDistance", number}});
|
|||
|
|
for (const auto *key : {"highSpeedMode", "addMarkerMode", "viewLock", "localEnlargedView", "qualityColor",
|
|||
|
|
"strongLight", "preScanMode"})
|
|||
|
|
bad("parameters", {{key, 0}});
|
|||
|
|
for (const auto *key :
|
|||
|
|
{"frameworkBrightness", "cloudShowMode", "scanAlignType", "workingDistance", "workingRange"})
|
|||
|
|
bad("parameters", {{key, 1}}, 422, "unsupported_for_trak");
|
|||
|
|
for (const Json values : {Json::array(), Json::array({0}), Json::array({51}), Json::array({1.0}),
|
|||
|
|
Json::array({true}), repeated(17, 1), Json(nullptr)})
|
|||
|
|
bad("parameters", {{"markerDiameters", values}});
|
|||
|
|
ok("mesh", {{"filterLevel", 0},
|
|||
|
|
{"smoothLevel", 3},
|
|||
|
|
{"removeSmallFloatingParts", 100000000},
|
|||
|
|
{"cutMeshEdgeOptimization", false},
|
|||
|
|
{"cutMeshEdgeValue", 1000},
|
|||
|
|
{"holeOptimization", true},
|
|||
|
|
{"boundaryOptimization", false},
|
|||
|
|
{"maxTriangles", nullptr},
|
|||
|
|
{"fillSmallHole", nullptr},
|
|||
|
|
{"removeSpikes", false},
|
|||
|
|
{"fillMarkerHoles", true},
|
|||
|
|
{"rememberChoice", false}});
|
|||
|
|
ok("mesh", {{"maxTriangles", 100000000}, {"fillSmallHole", 1000000}});
|
|||
|
|
for (const auto *key : {"meshType", "qualityType", "simplificationByCurvature", "deleteNeighborhoodAreas",
|
|||
|
|
"cornerOptimization"})
|
|||
|
|
bad("mesh", {{key, 0}}, 422, "unsupported_for_trak");
|
|||
|
|
bad("mesh", {{"filterLevel", 4}});
|
|||
|
|
bad("mesh", {{"smoothLevel", -1}});
|
|||
|
|
bad("mesh", {{"removeSmallFloatingParts", 100000001}});
|
|||
|
|
bad("mesh", {{"cutMeshEdgeValue", 1000.1}});
|
|||
|
|
bad("mesh", {{"maxTriangles", 0}});
|
|||
|
|
bad("mesh", {{"fillSmallHole", 1000001}});
|
|||
|
|
bad("mesh", {{"maxTriangles", 1.0}});
|
|||
|
|
bad("mesh", {{"removeSpikes", 1}});
|
|||
|
|
ok("export", {{"formats", api::export_formats()}});
|
|||
|
|
bad("export", Json::object());
|
|||
|
|
bad("export", {{"formats", Json::array()}});
|
|||
|
|
bad("export", {{"formats", {"STL", "STL"}}});
|
|||
|
|
bad("export", {{"formats", {"MAT"}}});
|
|||
|
|
bad("export", {{"formats", {"stl"}}});
|
|||
|
|
bad("export", {{"formats", {true}}});
|
|||
|
|
ok("dataSnapshot", {{"maxPoints", 1000000}, {"include", {"points", "markers", "meshes"}}});
|
|||
|
|
ok("dataSnapshot", {{"pauseAcquisition", true}});
|
|||
|
|
ok("dataSnapshot", {{"pauseAcquisition", false}});
|
|||
|
|
for (const Json value : {Json(0), Json(1), Json(1.0), Json("true"), Json("false"), Json(nullptr)})
|
|||
|
|
bad("dataSnapshot", {{"pauseAcquisition", value}});
|
|||
|
|
bad("dataSnapshot", {{"maxPoints", 0}});
|
|||
|
|
bad("dataSnapshot", {{"maxPoints", 1000001}});
|
|||
|
|
bad("dataSnapshot", {{"maxPoints", 1.0}});
|
|||
|
|
bad("dataSnapshot", {{"maxPoints", true}});
|
|||
|
|
for (const Json values : {Json::array(), Json::array({"points", "points"}), Json::array({"camera"}),
|
|||
|
|
Json(nullptr), Json("points")})
|
|||
|
|
bad("dataSnapshot", {{"include", values}});
|
|||
|
|
}
|
|||
|
|
void guid_alignment_edit_and_clip() {
|
|||
|
|
const std::vector<std::string> guids = {
|
|||
|
|
a,
|
|||
|
|
"11111111111141118111111111111111",
|
|||
|
|
"{11111111-1111-4111-8111-111111111111}",
|
|||
|
|
"(11111111-1111-4111-8111-111111111111)",
|
|||
|
|
"{0x11111111,0x1111,0x4111,{0x81,0x11,0x11,0x11,0x11,0x11,0x11,0x11}}",
|
|||
|
|
u8" 11111111-1111-4111-8111-111111111111 "};
|
|||
|
|
for (const auto &guid : guids) {
|
|||
|
|
check(api::normalize_guid(guid) == a, "SDK GUID normalization must match static alias comparison.");
|
|||
|
|
auto value = alignment();
|
|||
|
|
value["fixedProjectUuid"] = guid;
|
|||
|
|
ok("align", value);
|
|||
|
|
value["movingProjectUuid"] = a;
|
|||
|
|
bad("align", value);
|
|||
|
|
}
|
|||
|
|
check(api::normalize_guid("{0X1,0X2,0X3,{0X4,0X5,0X6,0X7,0X8,0X9,0XA,0XB}}") ==
|
|||
|
|
"00000001-0002-0003-0405-060708090a0b",
|
|||
|
|
"Short uppercase X components normalize like Guid.TryParse.");
|
|||
|
|
check(api::normalize_guid(u8"{0x1, 0x2,0x3,{0x4,0x5,0x6,0x7,0x8,0x9,0xa,0xb}}") ==
|
|||
|
|
"00000001-0002-0003-0405-060708090a0b",
|
|||
|
|
"X form accepts Unicode whitespace like Guid.TryParse.");
|
|||
|
|
auto overflow = alignment();
|
|||
|
|
overflow["fixedProjectUuid"] = "{0x100000000,0x2,0x3,{0x4,0x5,0x6,0x7,0x8,0x9,0xa,0xb}}";
|
|||
|
|
bad("align", overflow);
|
|||
|
|
for (const auto *guid :
|
|||
|
|
{"00000000-0000-0000-0000-000000000000", "00000000000000000000000000000000",
|
|||
|
|
"{00000000-0000-0000-0000-000000000000}", "{0x0,0x0,0x0,{0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0}}",
|
|||
|
|
"{11111111111141118111111111111111}", "not-a-guid"}) {
|
|||
|
|
auto value = alignment();
|
|||
|
|
value["fixedProjectUuid"] = guid;
|
|||
|
|
bad("align", value);
|
|||
|
|
}
|
|||
|
|
auto manual = alignment("featureManual");
|
|||
|
|
manual["fixedPoints"] = triplets(3);
|
|||
|
|
manual["movingPoints"] = triplets(3);
|
|||
|
|
ok("align", manual);
|
|||
|
|
manual["movingPoints"] = triplets(2);
|
|||
|
|
bad("align", manual);
|
|||
|
|
manual["movingPoints"] = triplets(257);
|
|||
|
|
bad("align", manual);
|
|||
|
|
manual["fixedPoints"] = triplets(256);
|
|||
|
|
manual["movingPoints"] = triplets(256);
|
|||
|
|
ok("align", manual);
|
|||
|
|
manual["fixedPoints"][0][0] = 100000001;
|
|||
|
|
bad("align", manual);
|
|||
|
|
manual["fixedPoints"][0][0] = true;
|
|||
|
|
bad("align", manual);
|
|||
|
|
manual = alignment("markerManual");
|
|||
|
|
manual["fixedMarkerIds"] = identifiers(3);
|
|||
|
|
manual["movingMarkerIds"] = identifiers(3);
|
|||
|
|
manual["fixedMarkerPoints"] = triplets(3);
|
|||
|
|
manual["movingMarkerPoints"] = triplets(3);
|
|||
|
|
ok("align", manual);
|
|||
|
|
manual["movingMarkerIds"][0] = 9223372036854775807ll;
|
|||
|
|
ok("align", manual);
|
|||
|
|
manual["movingMarkerIds"][0] = uint64_t(9223372036854775808ull);
|
|||
|
|
bad("align", manual);
|
|||
|
|
manual["movingMarkerIds"][0] = 1.0;
|
|||
|
|
bad("align", manual);
|
|||
|
|
manual["movingMarkerIds"][0] = true;
|
|||
|
|
bad("align", manual);
|
|||
|
|
manual["movingMarkerIds"][0] = -1;
|
|||
|
|
bad("align", manual);
|
|||
|
|
bad("align", {{"action", "exit"}}, 400, "confirmation_required");
|
|||
|
|
ok("align", {{"action", "exit"}, {"confirm", true}});
|
|||
|
|
ok("align", {{"action", "cancel"}, {"confirm", false}});
|
|||
|
|
bad("align", {{"action", "enter"}, {"mode", "featureAuto"}}, 400, "unknown_parameter");
|
|||
|
|
auto value = deletion();
|
|||
|
|
ok("edit", value);
|
|||
|
|
value.erase("markerIds");
|
|||
|
|
value["points"] = triplets(1);
|
|||
|
|
bad("edit", value);
|
|||
|
|
value["pointIds"] = identifiers(1);
|
|||
|
|
bad("edit", value);
|
|||
|
|
value["cloudUuid"] = b;
|
|||
|
|
ok("edit", value);
|
|||
|
|
value["normals"] = triplets(2);
|
|||
|
|
bad("edit", value);
|
|||
|
|
value["pointIds"] = identifiers(4096);
|
|||
|
|
value["points"] = triplets(4096);
|
|||
|
|
value["normals"] = triplets(4096);
|
|||
|
|
ok("edit", value);
|
|||
|
|
value["pointIds"] = identifiers(4097);
|
|||
|
|
bad("edit", value);
|
|||
|
|
value = deletion();
|
|||
|
|
value["markerIds"] = Json::array({uint64_t(9223372036854775808ull)});
|
|||
|
|
bad("edit", value);
|
|||
|
|
value = clip();
|
|||
|
|
ok("clipPlane", value);
|
|||
|
|
value["deleteBelowMarkers"] = false;
|
|||
|
|
ok("clipPlane", value);
|
|||
|
|
value["deleteBelowPoints"] = false;
|
|||
|
|
bad("clipPlane", value);
|
|||
|
|
value["deleteBelowMarkers"] = true;
|
|||
|
|
ok("clipPlane", value);
|
|||
|
|
value = clip();
|
|||
|
|
value["normal"] = {0, -0.0, 0};
|
|||
|
|
bad("clipPlane", value);
|
|||
|
|
value["normal"] = {0, 0};
|
|||
|
|
bad("clipPlane", value);
|
|||
|
|
value["normal"] = {true, 0, 0};
|
|||
|
|
bad("clipPlane", value);
|
|||
|
|
value["normal"] = {std::numeric_limits<double>::infinity(), 0, 0};
|
|||
|
|
bad("clipPlane", value);
|
|||
|
|
}
|
|||
|
|
void calibration_limits() {
|
|||
|
|
const Json recovery{{"confirm", true}, {"expectedSessionId", std::string(32, 'a')}};
|
|||
|
|
ok("calibrationRecover", recovery);
|
|||
|
|
auto request = recovery;
|
|||
|
|
request["force"] = true;
|
|||
|
|
ok("calibrationRecover", request);
|
|||
|
|
request["force"] = false;
|
|||
|
|
ok("calibrationRecover", request);
|
|||
|
|
request["force"] = "true";
|
|||
|
|
bad("calibrationRecover", request);
|
|||
|
|
request = recovery;
|
|||
|
|
request["confirm"] = false;
|
|||
|
|
bad("calibrationRecover", request, 400, "confirmation_required");
|
|||
|
|
request = recovery;
|
|||
|
|
request.erase("expectedSessionId");
|
|||
|
|
bad("calibrationRecover", request);
|
|||
|
|
for (const Json value : {Json(nullptr), Json(1), Json(""), Json("../worker"), Json(std::string(31, 'a')), Json(std::string(32, 'z'))}) {
|
|||
|
|
request = recovery;
|
|||
|
|
request["expectedSessionId"] = value;
|
|||
|
|
bad("calibrationRecover", request);
|
|||
|
|
}
|
|||
|
|
bad("calibrationEnter", {{"confirm", true}}, 400, "unknown_parameter");
|
|||
|
|
bad("calibrationSetMode", Json::object());
|
|||
|
|
for (const Json value : {Json(true), Json(1.0), Json(-1), Json(4), Json(nullptr), Json("1")})
|
|||
|
|
bad("calibrationSetMode", {{"mode", value}});
|
|||
|
|
bad("calibrationSetTrakType", {{"trakType", 3}}, 400, "confirmation_required");
|
|||
|
|
bad("calibrationSetFree", {{"confirm", true}});
|
|||
|
|
bad("calibrationSetAdvanced", {{"confirm", true}, {"enabled", 0}});
|
|||
|
|
bad("calibrationApplyLast", {{"confirm", true}, {"mode", 4}});
|
|||
|
|
bad("calibrationStartSystem", {{"confirm", false}}, 400, "confirmation_required");
|
|||
|
|
}
|
|||
|
|
void framework_limits() {
|
|||
|
|
ok("setScanType", {{"scanType", "photogrammetry"}, {"device", "tracker"}, {"confirm", true}});
|
|||
|
|
ok("setScanType", {{"scanType", "markers"}, {"device", "scanner"}, {"confirm", false}});
|
|||
|
|
bad("setScanType", Json::object());
|
|||
|
|
bad("setScanType", {{"scanType", "FRAME"}});
|
|||
|
|
bad("setScanType", {{"scanType", 0}});
|
|||
|
|
bad("setScanType", {{"scanType", "mesh"}, {"device", "TENOVA"}});
|
|||
|
|
bad("setScanType", {{"scanType", "mesh"}, {"confirm", 1}});
|
|||
|
|
const std::string id(32, 'a');
|
|||
|
|
ok("importFramework", {{"fileIds", {id}}, {"confirm", true}});
|
|||
|
|
bad("importFramework", {{"fileIds", {id}}}, 400, "confirmation_required");
|
|||
|
|
bad("importFramework", {{"fileIds", {id}}, {"confirm", false}}, 400, "confirmation_required");
|
|||
|
|
bad("importFramework", {{"fileIds", Json::array()}, {"confirm", true}});
|
|||
|
|
bad("importFramework", {{"fileIds", {id, id}}, {"confirm", true}});
|
|||
|
|
bad("importFramework", {{"fileIds", {std::string(32, 'A')}}, {"confirm", true}});
|
|||
|
|
bad("importFramework", {{"fileIds", {"../outside.p3"}}, {"confirm", true}});
|
|||
|
|
bad("importFramework", {{"fileIds", {true}}, {"confirm", true}});
|
|||
|
|
bad("importFramework", {{"fileIds", repeated(9, id)}, {"confirm", true}});
|
|||
|
|
bad("importFramework", {{"fileIds", {id}}, {"paths", {"C:/secret.p3"}}, {"confirm", true}},
|
|||
|
|
400, "unknown_parameter");
|
|||
|
|
}
|
|||
|
|
} // namespace
|
|||
|
|
int main() {
|
|||
|
|
try {
|
|||
|
|
routes_and_all_actions();
|
|||
|
|
primitive_types_and_names();
|
|||
|
|
parameters_mesh_and_exports();
|
|||
|
|
guid_alignment_edit_and_clip();
|
|||
|
|
calibration_limits();
|
|||
|
|
framework_limits();
|
|||
|
|
std::cout << "C++ contract tests passed: " << passed << "\n";
|
|||
|
|
return 0;
|
|||
|
|
} catch (const std::exception &error) {
|
|||
|
|
std::cerr << "FAIL: " << error.what() << "\n";
|
|||
|
|
return 1;
|
|||
|
|
}
|
|||
|
|
}
|