core: client API Majestic, modèles et CLI check
- libopenpu : validation VIN, modèles JSON (getAvailableUpdate, devices), classification ecuType -> type/guide, sélection des mises à jour - couche Transport abstraite + implémentation libcurl (proxy env, redirections, streaming, timeout d'inactivité) - tolérance au EOF TLS sans close_notify de la passerelle Majestic, limitée aux corps délimités par la fermeture (ni Content-Length ni chunked) - openpu-cli : check / raw-devices / raw-updates - tests doctest (VIN, parsing, classification, client API avec faux transport), fixtures dont une capture réelle anonymisée (NAC wave 2) - qualité : presets CMake (debug, asan, tidy), .clang-tidy, tools/check.sh (tests, ASan/UBSan, valgrind, clang-tidy, cppcheck) - validé contre l'API réelle sur 3 véhicules (NAC w4, RCC, NAC w2) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WDASLCiN764v685boRVYar
This commit is contained in:
1 parent
660a420a3e
commit
95704f9882
28 files changed
+1877
-2
No files matched your search
@@ -0,0 +1,16 @@
|
||||
find_package(doctest QUIET)
|
||||
|
||||
add_executable(openpu_tests
|
||||
main.cpp
|
||||
test_vin.cpp
|
||||
test_models.cpp
|
||||
test_http.cpp
|
||||
test_api_client.cpp
|
||||
)
|
||||
target_link_libraries(openpu_tests PRIVATE openpu_core openpu_warnings)
|
||||
if(TARGET doctest::doctest)
|
||||
target_link_libraries(openpu_tests PRIVATE doctest::doctest)
|
||||
endif()
|
||||
target_compile_definitions(openpu_tests PRIVATE OPENPU_FIXTURES_DIR="${CMAKE_CURRENT_SOURCE_DIR}/fixtures")
|
||||
|
||||
add_test(NAME openpu_tests COMMAND openpu_tests)
|
||||
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"vin": "VR3XXXXXXXXXXXXXX",
|
||||
"requestDate": "2026-11-28T17:00:00Z",
|
||||
"devices": [
|
||||
{ "ecuType": "BSI_X" },
|
||||
{ "ecuType": "RCC_EU_W3" }
|
||||
]
|
||||
}
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"devices": [
|
||||
{
|
||||
"ecuType": "NAC_EUR_WAVE2"
|
||||
}
|
||||
],
|
||||
"requestDate": "2026-11-28T18:43:48+0100",
|
||||
"vin": "VF3XXXXXXXXXXXXXX"
|
||||
}
|
||||
Vendored
+37
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"installerURL": "https://majestic.mpsa.com/mjf00-web/rest/UpdateDownload?updateId=005000000000000001&uin=00000000000000000000&type=fw",
|
||||
"requestResult": "OK",
|
||||
"software": [
|
||||
{
|
||||
"currentSoftwareVersion": "4.0.2-r0",
|
||||
"softwareType": "map-eur",
|
||||
"update": [
|
||||
{
|
||||
"licenseURL": "",
|
||||
"updateDate": "2026-07-27 07:52:53.0",
|
||||
"updateId": "005000000000000002",
|
||||
"updateSize": "10475161600",
|
||||
"updateURL": "https://download-cde.tomtom.com/OEM/PSA/MAP/PSA_map-eur_31.0.0-r0-NAC_EUR_WAVE2.tar",
|
||||
"updateVersion": "31.0.0-r0"
|
||||
}
|
||||
],
|
||||
"updateRequestResult": "OK"
|
||||
},
|
||||
{
|
||||
"currentSoftwareVersion": "21.05.90.42_NAC-r0",
|
||||
"softwareType": "ovip-int-firmware-version",
|
||||
"update": [
|
||||
{
|
||||
"licenseURL": "https://majestic-web.mpsa.com/mjf00-web/rest/LicenseDownload?mediaVersion=005000000000000003&uin=00000000000000000000",
|
||||
"updateDate": "2026-06-30 12:48:06.0",
|
||||
"updateId": "005000000000000003",
|
||||
"updateSize": "2728908800",
|
||||
"updateURL": "https://majestic-web.mpsa.com/mjf00-web/rest/UpdateDownload?updateId=005000000000000003&uin=00000000000000000000&type=fw",
|
||||
"updateVersion": "21.08.90.52_NAC-r0"
|
||||
}
|
||||
],
|
||||
"updateRequestResult": "OK"
|
||||
}
|
||||
],
|
||||
"vin": "VF3XXXXXXXXXXXXXX"
|
||||
}
|
||||
Vendored
+28
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"requestResult": "OK",
|
||||
"installerURL": "https://example.invalid/installer",
|
||||
"vin": "VR3XXXXXXXXXXXXXX",
|
||||
"software": [
|
||||
{
|
||||
"softwareType": "rcc-firmware",
|
||||
"updateRequestResult": "OK",
|
||||
"currentSoftwareVersion": "22-1X00-0",
|
||||
"update": [
|
||||
{
|
||||
"updateId": "005000000000000001",
|
||||
"updateSize": "8390000000",
|
||||
"updateVersion": "23-2I44-1",
|
||||
"updateDate": "2024-03-12",
|
||||
"updateURL": "https://majestic-web.mpsa.com/mjf00-web/rest/UpdateDownload?updateId=005000000000000001&uin=00000000000000000000&type=fw",
|
||||
"licenseURL": "https://majestic-web.mpsa.com/mjf00-web/rest/LicenseDownload?mediaVersion=005000000000000001&uin=00000000000000000000"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"softwareType": "map-eur",
|
||||
"updateRequestResult": "KO",
|
||||
"currentSoftwareVersion": "",
|
||||
"update": []
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||
#include <doctest/doctest.h>
|
||||
@@ -0,0 +1,153 @@
|
||||
#include "openpu/api_client.hpp"
|
||||
|
||||
#include <deque>
|
||||
#include <doctest/doctest.h>
|
||||
|
||||
using namespace openpu;
|
||||
|
||||
namespace {
|
||||
|
||||
/// Replays canned responses and records the requests it received.
|
||||
class FakeTransport final : public Transport {
|
||||
public:
|
||||
std::deque<HttpResponse> responses;
|
||||
std::vector<HttpRequest> requests;
|
||||
bool failNetwork = false;
|
||||
|
||||
HttpResponse perform(const HttpRequest& request) override
|
||||
{
|
||||
requests.push_back(request);
|
||||
if (failNetwork)
|
||||
throw NetworkError("could not resolve host");
|
||||
REQUIRE_FALSE(responses.empty());
|
||||
HttpResponse r = responses.front();
|
||||
responses.pop_front();
|
||||
return r;
|
||||
}
|
||||
};
|
||||
|
||||
HttpResponse ok(std::string body)
|
||||
{
|
||||
HttpResponse r;
|
||||
r.status = 200;
|
||||
r.body = std::move(body);
|
||||
return r;
|
||||
}
|
||||
|
||||
HttpResponse status(long code)
|
||||
{
|
||||
HttpResponse r;
|
||||
r.status = code;
|
||||
return r;
|
||||
}
|
||||
|
||||
const char* const kVin = "VR3ABCDEFGH123456";
|
||||
|
||||
ApiConfig testConfig()
|
||||
{
|
||||
ApiConfig c;
|
||||
c.devicesUrl = "https://api.test/v1/devices/";
|
||||
c.updatesUrl = "https://api.test/v1/getAvailableUpdate";
|
||||
c.clientId = "cid";
|
||||
return c;
|
||||
}
|
||||
|
||||
const char* const kUpdates = R"({"requestResult":"OK","software":[
|
||||
{"softwareType":"rcc-firmware","updateRequestResult":"OK","update":[
|
||||
{"updateId":"1","updateSize":"100","updateVersion":"v2","updateDate":"2024-01-01",
|
||||
"updateURL":"https://dl.test/UpdateDownload?updateId=1","licenseURL":"https://dl.test/LicenseDownload?mediaVersion=1"}]},
|
||||
{"softwareType":"map-eur","updateRequestResult":"OK","update":[
|
||||
{"updateId":"2","updateSize":"50","updateVersion":"m9","updateURL":"https://dl.test/UpdateDownload?updateId=2"}]}]})";
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("checkVehicle issues devices then getAvailableUpdate with client_id")
|
||||
{
|
||||
FakeTransport t;
|
||||
t.responses.push_back(ok(R"({"devices":[{"ecuType":"RCC_EU_W3"}]})"));
|
||||
t.responses.push_back(ok(kUpdates));
|
||||
ApiClient api(t, testConfig());
|
||||
|
||||
const VehicleCheck c = api.checkVehicle(kVin);
|
||||
CHECK(c.exists);
|
||||
CHECK(c.type == HeadUnitType::Rcc);
|
||||
|
||||
REQUIRE(t.requests.size() == 2);
|
||||
CHECK(t.requests[0].method == HttpMethod::Get);
|
||||
CHECK(t.requests[0].url == std::string("https://api.test/v1/devices/") + kVin + "?client_id=cid");
|
||||
CHECK(t.requests[1].method == HttpMethod::Post);
|
||||
CHECK(t.requests[1].url == "https://api.test/v1/getAvailableUpdate?client_id=cid");
|
||||
CHECK(t.requests[1].body.find("\"crony2-map-western_europe\"") != std::string::npos); // all 7 types
|
||||
bool hasContentType = false;
|
||||
for (const auto& [k, v] : t.requests[1].headers)
|
||||
hasContentType |= (k == "Content-Type" && v == "application/json");
|
||||
CHECK(hasContentType);
|
||||
}
|
||||
|
||||
TEST_CASE("checkVehicle: 404 on devices means unknown VIN, no second call")
|
||||
{
|
||||
FakeTransport t;
|
||||
t.responses.push_back(status(404));
|
||||
ApiClient api(t, testConfig());
|
||||
CHECK_FALSE(api.checkVehicle(kVin).exists);
|
||||
CHECK(t.requests.size() == 1);
|
||||
}
|
||||
|
||||
TEST_CASE("errors are mapped to ApiError kinds")
|
||||
{
|
||||
FakeTransport t;
|
||||
ApiClient api(t, testConfig());
|
||||
|
||||
SUBCASE("server error")
|
||||
{
|
||||
t.responses.push_back(status(503));
|
||||
try {
|
||||
api.checkVehicle(kVin);
|
||||
FAIL("expected ApiError");
|
||||
} catch (const ApiError& e) {
|
||||
CHECK(e.kind() == ApiError::Kind::Server);
|
||||
CHECK(e.status() == 503);
|
||||
}
|
||||
}
|
||||
SUBCASE("network error")
|
||||
{
|
||||
t.failNetwork = true;
|
||||
try {
|
||||
api.getUpdates(kVin, HeadUnitType::Rcc);
|
||||
FAIL("expected ApiError");
|
||||
} catch (const ApiError& e) {
|
||||
CHECK(e.kind() == ApiError::Kind::Network);
|
||||
}
|
||||
}
|
||||
SUBCASE("bad body")
|
||||
{
|
||||
t.responses.push_back(ok("<html>maintenance</html>"));
|
||||
try {
|
||||
api.getUpdates(kVin, HeadUnitType::Rcc);
|
||||
FAIL("expected ApiError");
|
||||
} catch (const ApiError& e) {
|
||||
CHECK(e.kind() == ApiError::Kind::BadResponse);
|
||||
}
|
||||
}
|
||||
SUBCASE("invalid VIN never reaches the network")
|
||||
{
|
||||
CHECK_THROWS_AS(api.checkVehicle("VF3SHORT"), ApiError);
|
||||
CHECK(t.requests.empty());
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("getUpdates requests the pair of types of the head unit")
|
||||
{
|
||||
FakeTransport t;
|
||||
t.responses.push_back(ok(kUpdates));
|
||||
ApiClient api(t, testConfig());
|
||||
const AvailableUpdates u = api.getUpdates(kVin, HeadUnitType::Rcc);
|
||||
REQUIRE(u.firmware.has_value());
|
||||
CHECK(u.firmware->version == "v2");
|
||||
CHECK(u.firmware->size == 100);
|
||||
REQUIRE(u.map.has_value());
|
||||
CHECK(u.map->version == "m9");
|
||||
CHECK(t.requests[0].body ==
|
||||
std::string(R"({"softwareTypes":[{"softwareType":"rcc-firmware"},{"softwareType":"map-eur"}],"vin":")") +
|
||||
kVin + "\"}");
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#include "openpu/http.hpp"
|
||||
|
||||
#include <doctest/doctest.h>
|
||||
|
||||
using namespace openpu;
|
||||
|
||||
TEST_CASE("filename from Content-Disposition")
|
||||
{
|
||||
CHECK(filenameFromContentDisposition("attachment; filename=license_ABC.key") == "license_ABC.key");
|
||||
CHECK(filenameFromContentDisposition("attachment; filename=\"licenses_1_20240101.tar\"") ==
|
||||
"licenses_1_20240101.tar");
|
||||
CHECK(filenameFromContentDisposition("attachment;filename=a.key; size=3") == "a.key");
|
||||
CHECK(filenameFromContentDisposition("attachment; filename*=UTF-8''l%C3%A9.key; filename=x.key") == "l\xC3\xA9.key");
|
||||
CHECK(filenameFromContentDisposition("inline") == "");
|
||||
CHECK(filenameFromContentDisposition("attachment; filename=../../etc/passwd") == "passwd");
|
||||
CHECK(filenameFromContentDisposition("attachment; filename=\"..\"") == "");
|
||||
}
|
||||
|
||||
TEST_CASE("filename from URL")
|
||||
{
|
||||
CHECK(filenameFromUrl("https://ds4emloty3shq.cloudfront.net/BOSCH/RCC_EU/rcc-firmware/PSA_rcc.tar") == "PSA_rcc.tar");
|
||||
CHECK(filenameFromUrl("https://h/a/b.tar?sig=1&x=2#frag") == "b.tar");
|
||||
CHECK(filenameFromUrl("https://h/a/my%20file.tar") == "my file.tar");
|
||||
CHECK(filenameFromUrl("https://h") == "");
|
||||
CHECK(filenameFromUrl("https://h/") == "");
|
||||
}
|
||||
@@ -0,0 +1,230 @@
|
||||
#include "openpu/models.hpp"
|
||||
|
||||
#include <doctest/doctest.h>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
using namespace openpu;
|
||||
|
||||
namespace {
|
||||
|
||||
std::string fixture(const std::string& name)
|
||||
{
|
||||
std::ifstream in(std::string(OPENPU_FIXTURES_DIR) + "/" + name);
|
||||
REQUIRE_MESSAGE(in.good(), "missing fixture " << name);
|
||||
std::stringstream ss;
|
||||
ss << in.rdbuf();
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
DevicesResponse devices(std::initializer_list<const char*> ecus)
|
||||
{
|
||||
DevicesResponse d;
|
||||
for (const char* e : ecus)
|
||||
d.ecuTypes.emplace_back(e);
|
||||
return d;
|
||||
}
|
||||
|
||||
UpdateListResponse okList()
|
||||
{
|
||||
UpdateListResponse r;
|
||||
r.requestResult = "OK";
|
||||
return r;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("head unit type string round-trip matches vehicles.json values")
|
||||
{
|
||||
for (auto t : {HeadUnitType::Nac, HeadUnitType::Rcc, HeadUnitType::Aio, HeadUnitType::CronyNav,
|
||||
HeadUnitType::CronyNonav})
|
||||
CHECK(headUnitTypeFromString(headUnitTypeName(t)) == t);
|
||||
CHECK(headUnitTypeName(HeadUnitType::Nac) == "nac");
|
||||
CHECK(headUnitTypeName(HeadUnitType::CronyNonav) == "crony_nonav");
|
||||
CHECK(headUnitTypeFromString("bogus") == HeadUnitType::Unknown);
|
||||
}
|
||||
|
||||
TEST_CASE("ECU family is the prefix before the first underscore")
|
||||
{
|
||||
CHECK(ecuFamily("NAC_EU_WAVE4") == HeadUnitType::Nac);
|
||||
CHECK(ecuFamily("nac_eu_wave2") == HeadUnitType::Nac);
|
||||
CHECK(ecuFamily("RCC_EU") == HeadUnitType::Rcc);
|
||||
CHECK(ecuFamily("AIO") == HeadUnitType::Aio);
|
||||
CHECK(ecuFamily("CRONY2_EU_VAR1_WAVE1") == HeadUnitType::CronyNav);
|
||||
CHECK(ecuFamily("BSI_X") == HeadUnitType::Unknown);
|
||||
CHECK(ecuFamily("") == HeadUnitType::Unknown);
|
||||
}
|
||||
|
||||
TEST_CASE("vehicle classification")
|
||||
{
|
||||
SUBCASE("NAC waves map to guide keys")
|
||||
{
|
||||
CHECK(classifyVehicle(okList(), devices({"NAC_EU_WAVE1"})).guideKey == "path_guide_wave_1");
|
||||
CHECK(classifyVehicle(okList(), devices({"NAC_EU_WAVE4"})).guideKey == "path_guide_wave_4");
|
||||
const auto c = classifyVehicle(okList(), devices({"NAC_EU"}));
|
||||
CHECK(c.exists);
|
||||
CHECK(c.type == HeadUnitType::Nac);
|
||||
CHECK(c.guideKey == "path_guide_wave_default");
|
||||
}
|
||||
SUBCASE("RCC and AIO")
|
||||
{
|
||||
auto c = classifyVehicle(okList(), devices({"BSI", "RCC_EU_W3"}));
|
||||
CHECK(c.exists);
|
||||
CHECK(c.type == HeadUnitType::Rcc);
|
||||
CHECK(c.guideKey == "path_guide_rcc");
|
||||
c = classifyVehicle(okList(), devices({"AIO_X"}));
|
||||
CHECK(c.type == HeadUnitType::Aio);
|
||||
CHECK(c.guideKey == "path_guide_aio");
|
||||
}
|
||||
SUBCASE("Crony nav vs nonav depends on available software")
|
||||
{
|
||||
auto list = okList();
|
||||
CHECK(classifyVehicle(list, devices({"CRONY2_EU_VAR2_WAVE1"})).type == HeadUnitType::CronyNav);
|
||||
CHECK(classifyVehicle(list, devices({"CRONY2_EU_VAR2_WAVE1"})).guideKey == "path_guide_crony_2");
|
||||
|
||||
SoftwareEntry nonav;
|
||||
nonav.softwareType = std::string(software::CronyNonav);
|
||||
nonav.updates.push_back(UpdateInfo{});
|
||||
list.software.push_back(nonav);
|
||||
// An entry without updateId does not count.
|
||||
CHECK(classifyVehicle(list, devices({"CRONY2_EU_VAR2_WAVE1"})).type == HeadUnitType::CronyNav);
|
||||
list.software.back().updates.front().updateId = "1";
|
||||
CHECK(classifyVehicle(list, devices({"CRONY2_EU_VAR2_WAVE1"})).type == HeadUnitType::CronyNonav);
|
||||
}
|
||||
SUBCASE("unknown Crony variant: exists but no type")
|
||||
{
|
||||
const auto c = classifyVehicle(okList(), devices({"CRONY3_XX"}));
|
||||
CHECK(c.exists);
|
||||
CHECK(c.type == HeadUnitType::Unknown);
|
||||
}
|
||||
SUBCASE("several valid ECUs: exists but no type")
|
||||
{
|
||||
const auto c = classifyVehicle(okList(), devices({"NAC_EU_WAVE2", "RCC_EU"}));
|
||||
CHECK(c.exists);
|
||||
CHECK(c.type == HeadUnitType::Unknown);
|
||||
CHECK(c.guideKey.empty());
|
||||
}
|
||||
SUBCASE("no supported ECU or failed request: does not exist")
|
||||
{
|
||||
CHECK_FALSE(classifyVehicle(okList(), devices({"BSI"})).exists);
|
||||
CHECK_FALSE(classifyVehicle(okList(), devices({})).exists);
|
||||
UpdateListResponse ko;
|
||||
ko.requestResult = "KO";
|
||||
CHECK_FALSE(classifyVehicle(ko, devices({"RCC_EU"})).exists);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("software types requested per head unit")
|
||||
{
|
||||
CHECK(softwareTypesFor(HeadUnitType::Nac).firmware == software::FirmwareNac);
|
||||
CHECK(softwareTypesFor(HeadUnitType::Rcc).firmware == software::FirmwareRcc);
|
||||
CHECK(*softwareTypesFor(HeadUnitType::Rcc).map == software::MapEurope);
|
||||
CHECK(*softwareTypesFor(HeadUnitType::CronyNav).map == software::MapCrony);
|
||||
CHECK_FALSE(softwareTypesFor(HeadUnitType::CronyNonav).map.has_value());
|
||||
CHECK(softwareTypesFor(HeadUnitType::Unknown).firmware == software::FirmwareAio);
|
||||
}
|
||||
|
||||
TEST_CASE("request body")
|
||||
{
|
||||
CHECK(buildUpdateRequest("VF3ABCDEFGH123456", {"rcc-firmware", "map-eur"}) ==
|
||||
R"({"softwareTypes":[{"softwareType":"rcc-firmware"},{"softwareType":"map-eur"}],"vin":"VF3ABCDEFGH123456"})");
|
||||
}
|
||||
|
||||
TEST_CASE("parse getAvailableUpdate response (fixture)")
|
||||
{
|
||||
const auto r = parseUpdateList(fixture("updates_rcc.json"));
|
||||
CHECK(r.requestResult == "OK");
|
||||
REQUIRE(r.software.size() == 2);
|
||||
CHECK(r.software[0].softwareType == "rcc-firmware");
|
||||
REQUIRE(r.software[0].updates.size() == 1);
|
||||
const auto& u = r.software[0].updates[0];
|
||||
CHECK(u.updateId == "005000000000000001");
|
||||
CHECK(u.size == 8390000000ULL); // given as a string by the backend
|
||||
CHECK(u.url.rfind("https://majestic-web.mpsa.com/", 0) == 0);
|
||||
|
||||
const auto sel = selectUpdates(r, HeadUnitType::Rcc);
|
||||
REQUIRE(sel.firmware.has_value());
|
||||
CHECK(sel.firmware->version == "23-2I44-1");
|
||||
CHECK(sel.firmware->licenseUrl.find("LicenseDownload") != std::string::npos);
|
||||
CHECK_FALSE(sel.map.has_value()); // map-eur entry is not OK
|
||||
}
|
||||
|
||||
TEST_CASE("parse devices response (fixture)")
|
||||
{
|
||||
const auto d = parseDevices(fixture("devices_rcc.json"));
|
||||
REQUIRE(d.ecuTypes.size() == 2);
|
||||
CHECK(d.ecuTypes[1] == "RCC_EU_W3");
|
||||
}
|
||||
|
||||
TEST_CASE("parser robustness")
|
||||
{
|
||||
CHECK_THROWS_AS(parseUpdateList("not json"), ParseError);
|
||||
CHECK_THROWS_AS(parseUpdateList("[1,2]"), ParseError);
|
||||
CHECK_THROWS_AS(parseDevices(""), ParseError);
|
||||
const auto r = parseUpdateList(R"({"requestResult":"OK","software":[{"softwareType":"x","update":null},7]})");
|
||||
REQUIRE(r.software.size() == 1);
|
||||
CHECK(r.software[0].updates.empty());
|
||||
const auto n = parseUpdateList(
|
||||
R"({"requestResult":"OK","software":[{"softwareType":"x","updateRequestResult":"OK","update":[{"updateId":5,"updateSize":12}]}]})");
|
||||
CHECK(n.software[0].updates[0].updateId == "5");
|
||||
CHECK(n.software[0].updates[0].size == 12);
|
||||
}
|
||||
|
||||
TEST_CASE("update selection")
|
||||
{
|
||||
auto make = [](std::vector<std::pair<std::string, std::string>> dateUrl) {
|
||||
UpdateListResponse r = okList();
|
||||
SoftwareEntry e;
|
||||
e.softwareType = "rcc-firmware";
|
||||
e.requestResult = "OK";
|
||||
for (auto& [d, u] : dateUrl) {
|
||||
UpdateInfo i;
|
||||
i.date = d;
|
||||
i.url = u;
|
||||
i.version = d;
|
||||
e.updates.push_back(i);
|
||||
}
|
||||
r.software.push_back(e);
|
||||
return r;
|
||||
};
|
||||
SUBCASE("first entry when dates are not comparable (original behaviour)")
|
||||
{
|
||||
const auto r = make({{"", "https://a/x"}, {"2024-01-01", "https://a/y"}});
|
||||
CHECK(pickUpdate(r, "rcc-firmware")->url == "https://a/x");
|
||||
}
|
||||
SUBCASE("most recent ISO date wins")
|
||||
{
|
||||
const auto r = make({{"2023-05-01T00:00:00Z", "https://a/old"}, {"2024-02-01T00:00:00Z", "https://a/new"}});
|
||||
CHECK(pickUpdate(r, "rcc-firmware")->url == "https://a/new");
|
||||
}
|
||||
SUBCASE("invalid URL is rejected")
|
||||
{
|
||||
CHECK_FALSE(pickUpdate(make({{"", "not-an-url"}}), "rcc-firmware").has_value());
|
||||
CHECK_FALSE(pickUpdate(make({{"", "https://"}}), "rcc-firmware").has_value());
|
||||
}
|
||||
SUBCASE("unknown type")
|
||||
{
|
||||
CHECK_FALSE(pickUpdate(make({{"", "https://a/x"}}), "map-eur").has_value());
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("real NAC wave 2 response (anonymised capture, 2026-11-28)")
|
||||
{
|
||||
const auto list = parseUpdateList(fixture("real_nac_updates.json"));
|
||||
const auto dev = parseDevices(fixture("real_nac_devices.json"));
|
||||
|
||||
const VehicleCheck check = classifyVehicle(list, dev);
|
||||
CHECK(check.exists);
|
||||
CHECK(check.type == HeadUnitType::Nac);
|
||||
CHECK(check.guideKey == "path_guide_wave_2");
|
||||
|
||||
const AvailableUpdates sel = selectUpdates(list, HeadUnitType::Nac);
|
||||
REQUIRE(sel.firmware.has_value());
|
||||
CHECK(sel.firmware->version == "21.08.90.52_NAC-r0");
|
||||
CHECK(sel.firmware->size == 2728908800ULL);
|
||||
CHECK_FALSE(sel.firmware->licenseUrl.empty());
|
||||
REQUIRE(sel.map.has_value());
|
||||
CHECK(sel.map->version == "31.0.0-r0");
|
||||
CHECK(sel.map->licenseUrl.empty()); // maps come without a license
|
||||
CHECK(sel.map->url.rfind("https://download-cde.tomtom.com/", 0) == 0);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#include "openpu/vin.hpp"
|
||||
|
||||
#include <doctest/doctest.h>
|
||||
|
||||
using openpu::isValidVin;
|
||||
using openpu::normalizeVin;
|
||||
|
||||
TEST_CASE("VIN validation follows ^V[FR]3[A-Z0-9]{14}$")
|
||||
{
|
||||
CHECK(isValidVin("VF3ABCDEFGH123456"));
|
||||
CHECK(isValidVin("VR3UPHNKSKT000001"));
|
||||
CHECK_FALSE(isValidVin(""));
|
||||
CHECK_FALSE(isValidVin("VF3ABCDEFGH12345")); // 16 chars
|
||||
CHECK_FALSE(isValidVin("VF3ABCDEFGH1234567")); // 18 chars
|
||||
CHECK_FALSE(isValidVin("VX3ABCDEFGH123456")); // bad 2nd char
|
||||
CHECK_FALSE(isValidVin("VF1ABCDEFGH123456")); // Renault WMI
|
||||
CHECK_FALSE(isValidVin("WF3ABCDEFGH123456"));
|
||||
CHECK_FALSE(isValidVin("vf3abcdefgh123456")); // must be normalised first
|
||||
CHECK_FALSE(isValidVin("VF3ABCDEFGH12345-"));
|
||||
}
|
||||
|
||||
TEST_CASE("VIN normalisation upper-cases and strips blanks")
|
||||
{
|
||||
CHECK(normalizeVin(" vf3 abcd efgh 123456\n") == "VF3ABCDEFGH123456");
|
||||
CHECK(isValidVin(normalizeVin("vr3uphnksk t000001")));
|
||||
}
|
||||
Reference in new issue
Block a user