diff --git a/core/tests/cnc_sim_api_linuxcnc_rs274_smoke.cpp b/core/tests/cnc_sim_api_linuxcnc_rs274_smoke.cpp index a1e89d8..cacc225 100644 --- a/core/tests/cnc_sim_api_linuxcnc_rs274_smoke.cpp +++ b/core/tests/cnc_sim_api_linuxcnc_rs274_smoke.cpp @@ -303,6 +303,45 @@ int main() { } } + { + std::vector percent_events; + CncSimHandle *percent_sim = cnc_sim_create(); + cnc_sim_set_event_callback(percent_sim, collect_event, &percent_events); + ScopedEnv file_mode_env("CNC_SIM_RS274_FILE_MODE", "1"); + const char percent_program[] = + "%\n" + "G21 G90\n" + "F100\n" + "G1 X1\n" + "%\n" + "G1 X99\n"; + bool percent_ok = true; + percent_ok &= expect(cnc_sim_parse_program(percent_sim, + percent_program, + sizeof(percent_program) - 1) == 0, + cnc_sim_last_error(percent_sim)); + std::vector feed_lines; + std::vector feed_x; + for (const auto &event : percent_events) { + if (event.type == CNC_SIM_EVENT_LINEAR_FEED) { + feed_lines.push_back(event.line); + feed_x.push_back(event.end.x); + } + } + // LinuxCNC source basis: rs274ngc_pre.cc open() enables percent-file + // mode when the first nonblank line is '%'; interp_read.cc read_text() + // stops at the matching '%', so later program text is ignored. + percent_ok &= expect(feed_lines.size() == 1 && + feed_lines[0] == 4 && + feed_x.size() == 1 && + near(feed_x[0], 1.0), + "expected LinuxCNC percent-file mode to ignore trailing text"); + cnc_sim_destroy(percent_sim); + if (!percent_ok) { + return 1; + } + } + const char config[] = "{\"backend\":\"linuxcnc-rs274\",\"rtcp\":{\"enabled\":true,\"toolLength\":100,\"toolLengths\":{\"7\":125}}}"; const char program[] =