37 lines
2.0 KiB
C
37 lines
2.0 KiB
C
#include "sim_interpreter.h"
|
|
|
|
#include <assert.h>
|
|
#include <math.h>
|
|
#include <string.h>
|
|
|
|
int main(void) {
|
|
sim_interpreter interpreter = {0};
|
|
sim_interpreter_state state = {0};
|
|
sim_interpreter_state second = {0};
|
|
char canonical[SIM_INTERPRETER_CANONICAL_CAPACITY] = {0};
|
|
uint32_t required;
|
|
|
|
assert(sim_interpreter_init(&interpreter) == SIM_INTERP_OK);
|
|
assert(sim_interpreter_execute(&interpreter, "G21 G90 G1 X10 Y2 F120", (uint32_t)(sizeof("G21 G90 G1 X10 Y2 F120") - 1)) == SIM_INTERP_OK);
|
|
assert(sim_interpreter_read_state(&interpreter, &state) == SIM_INTERP_OK);
|
|
assert(state.x == 10.0 && state.y == 2.0 && state.feed == 120.0);
|
|
required = sim_interpreter_canonical(&interpreter, canonical, sizeof(canonical));
|
|
assert(required > 1 && canonical[required - 1] == '\0');
|
|
assert(sim_interpreter_state_hash(&interpreter) != 0);
|
|
assert(sim_interpreter_execute(&interpreter, "G91 X1 (increment)", (uint32_t)(sizeof("G91 X1 (increment)") - 1)) == SIM_INTERP_OK);
|
|
assert(sim_interpreter_read_state(&interpreter, &second) == SIM_INTERP_OK);
|
|
assert(second.x == 11.0 && second.line == state.line + 1);
|
|
assert(sim_interpreter_execute(&interpreter, "G20 X1", 6) == SIM_INTERP_OK);
|
|
assert(fabs(interpreter.state.x - 36.4) < 1e-12);
|
|
assert(sim_interpreter_execute(&interpreter, "X1 G90 G21", (uint32_t)(sizeof("X1 G90 G21") - 1)) == SIM_INTERP_OK);
|
|
assert(interpreter.state.x == 1.0);
|
|
assert(sim_interpreter_execute(&interpreter, "G1 G0 X1", 8) == SIM_INTERP_ERR_STATE);
|
|
assert(sim_interpreter_execute(&interpreter, "G999", 4) == SIM_INTERP_ERR_UNKNOWN_CODE);
|
|
assert(sim_interpreter_execute(&interpreter, "Xnan", 4) == SIM_INTERP_ERR_SYNTAX);
|
|
assert(sim_interpreter_execute(&interpreter, "G1 X1 X2", 8) == SIM_INTERP_ERR_STATE);
|
|
assert(sim_interpreter_execute(&interpreter, "M2", 2) == SIM_INTERP_OK);
|
|
assert(interpreter.state.program_end == 1);
|
|
assert(sim_interpreter_execute(&interpreter, "G1 X0", (uint32_t)(sizeof("G1 X0") - 1)) == SIM_INTERP_ERR_STATE);
|
|
return 0;
|
|
}
|