mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 16:27:11 +01:00
6aca6bc4f6
From the review of #531: - Load= and UnLoad= without the name of a load threw std::out_of_range as soon as ParseVehicleCommand() read them: extract_value() reads past the end of the text when nothing but spaces follows the =. Before this branch the same exception came later, in the RunCommand() of a vehicle standing at the ramp. ParseVehicleCommand() gives an empty name now, which loads and unloads nothing (AssignLoad("") and LoadingDone() with no name, as for an empty vehicle). extract_value() itself is left as it was: it has hundreds of callers and test_utilities.cpp records its exception at the end of the text. New checks in test_vehicle_command.cpp. - compression_at() is an inline function of physics/components/internal.h, as square() is, rather than a global function of external linkage defined in collisions.cpp; its body is the same - the comment of train_type::sn61 says what the AI does for it (the master controller up to a position with torque after setting the direction) rather than that nothing handles it - tests/unit/COVERAGE.md names the files as they are now (physics/components/, vehicle/dynamic/lifecycle.cpp) instead of physics/physics.cpp, a name the renaming script left there The naming of AGENTS.md, which the review asked about, stays as it is.
52 lines
2.3 KiB
C++
52 lines
2.3 KiB
C++
#include "stdafx.h"
|
|
#include "doctest.h"
|
|
|
|
#include <string>
|
|
|
|
#include "physics/vehiclecommand.h"
|
|
|
|
// the commands of the vehicles read from their text (events, scripts, the AI) and named for the log: every command
|
|
// has the name the scenery files have always used, and reads back as itself
|
|
|
|
TEST_CASE("vehicle commands read back from their names") {
|
|
using enum VehicleCommand;
|
|
for (auto command{static_cast<int>(mainController)}; command <= static_cast<int>(setDamage); ++command) {
|
|
auto const value{static_cast<VehicleCommand>(command)};
|
|
auto const name{std::string{VehicleCommandName(value)}};
|
|
CAPTURE(name);
|
|
REQUIRE_FALSE(name.empty());
|
|
if (value == load || value == unload) {
|
|
continue; // these carry the name of the load after the =
|
|
}
|
|
CHECK(ParseVehicleCommand(name).command == value);
|
|
CHECK(ParseVehicleCommand(name).argument.empty());
|
|
}
|
|
}
|
|
|
|
TEST_CASE("vehicle commands: the empty text, an unknown one, the load") {
|
|
CHECK(ParseVehicleCommand("").command == VehicleCommand::none);
|
|
CHECK(ParseVehicleCommand("SetVelocity").command == VehicleCommand::unknown); // the AI's, not a vehicle's
|
|
CHECK(ParseVehicleCommand("mainctrl").command == VehicleCommand::unknown); // the names are compared exactly
|
|
CHECK(ParseVehicleCommand("MainCtrl").command == VehicleCommand::mainController);
|
|
CHECK(ParseVehicleCommand("SpeedCtrlUnit.Parking").command == VehicleCommand::speedControlParking);
|
|
|
|
auto const load{ParseVehicleCommand("Load=Coal")};
|
|
CHECK(load.command == VehicleCommand::load);
|
|
CHECK(load.argument == "Coal");
|
|
auto const unload{ParseVehicleCommand("UnLoad=passengers")};
|
|
CHECK(unload.command == VehicleCommand::unload);
|
|
CHECK(unload.argument == "passengers");
|
|
|
|
// a load without a name is a load of no name, not an exception: the vehicle loads nothing for it
|
|
auto const noname{ParseVehicleCommand("Load=")};
|
|
CHECK(noname.command == VehicleCommand::load);
|
|
CHECK(noname.argument.empty());
|
|
CHECK(ParseVehicleCommand("UnLoad= ").argument.empty());
|
|
// a space after the = is skipped, as extract_value() does
|
|
CHECK(ParseVehicleCommand("Load= Coal").argument == "Coal");
|
|
|
|
CHECK(VehicleCommandName(VehicleCommand::none).empty());
|
|
CHECK(VehicleCommandName(VehicleCommand::unknown).empty());
|
|
CHECK(VehicleCommandName(VehicleCommand::integratedController) == "EIMIC");
|
|
}
|