112 lines
3.3 KiB
C
112 lines
3.3 KiB
C
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
#include <assert.h>
|
|
#include <stdbool.h>
|
|
#include "engine.h"
|
|
#include "cli.h"
|
|
#include "dispatcher.h"
|
|
|
|
// Global state for the dispatch function
|
|
static AppState g_state;
|
|
|
|
static void test_dispatch(Action action) {
|
|
reducer(&g_state, action);
|
|
}
|
|
|
|
static void test_cli_parse(void) {
|
|
printf("Test CLI parse... ");
|
|
|
|
// Initialize global state
|
|
memset(&g_state, 0, sizeof(AppState));
|
|
|
|
// Initialize clips
|
|
for (int i = 0; i < MAX_CLIPS; i++) {
|
|
g_state.clips[i].state = CLIP_EMPTY;
|
|
g_state.clips[i].buffer = NULL; // not needed for parsing
|
|
g_state.clips[i].buffer_size = 0;
|
|
g_state.clips[i].write_position = 0;
|
|
g_state.clips[i].read_position = 0;
|
|
}
|
|
|
|
// Initialize transport
|
|
g_state.transport_state = TRANSPORT_STOPPED;
|
|
g_state.clock_source = CLOCK_SOURCE_INTERNAL;
|
|
g_state.bpm = 120.0;
|
|
g_state.samples_per_beat = (48000 * 60.0) / 120.0;
|
|
g_state.clock_count = 0;
|
|
g_state.beat_position = 0;
|
|
g_state.bar_position = 0;
|
|
g_state.sample_position = 0;
|
|
g_state.sample_accumulator = 0.0;
|
|
|
|
// Initialize quantize
|
|
g_state.quantize_mode = QUANTIZE_OFF;
|
|
g_state.quantize_threshold = 0;
|
|
|
|
// Initialize undo
|
|
g_state.undo.undo_index = 0;
|
|
g_state.undo.redo_index = 0;
|
|
g_state.undo.count = 0;
|
|
for (int i = 0; i < MAX_UNDO_HISTORY; i++) {
|
|
g_state.undo.prev_clip_indices[i] = -1;
|
|
}
|
|
|
|
// JACK info
|
|
g_state.sample_rate = 48000;
|
|
g_state.running = true;
|
|
|
|
// Create engine with dispatch function
|
|
Engine engine;
|
|
memset(&engine, 0, sizeof(Engine));
|
|
engine.dispatch = test_dispatch;
|
|
engine.sample_rate = 48000;
|
|
|
|
// Test valid commands
|
|
assert(cli_process_line(&engine, "help") == 1);
|
|
assert(cli_process_line(&engine, "trigger clip 0") == 1);
|
|
assert(g_state.clips[0].state == CLIP_RECORDING);
|
|
|
|
assert(cli_process_line(&engine, "trigger scene 1") == 1);
|
|
for (int ch = 0; ch < MAX_CHANNELS; ch++) {
|
|
assert(g_state.clips[CLIP_INDEX(1, ch)].state == CLIP_RECORDING);
|
|
}
|
|
|
|
assert(cli_process_line(&engine, "reset clip 2") == 1);
|
|
assert(g_state.clips[2].state == CLIP_EMPTY);
|
|
|
|
assert(cli_process_line(&engine, "reset transport") == 1);
|
|
assert(g_state.transport_state == TRANSPORT_STOPPED);
|
|
|
|
assert(cli_process_line(&engine, "quantize beat") == 1);
|
|
assert(g_state.quantize_mode == QUANTIZE_BEAT);
|
|
|
|
assert(cli_process_line(&engine, "threshold 1000") == 1);
|
|
assert(g_state.quantize_threshold == 1000);
|
|
|
|
assert(cli_process_line(&engine, "quit") == 0);
|
|
|
|
// Test invalid commands (should not crash)
|
|
assert(cli_process_line(&engine, "") == 1);
|
|
assert(cli_process_line(&engine, "unknown") == 1);
|
|
assert(cli_process_line(&engine, "trigger") == 1);
|
|
assert(cli_process_line(&engine, "reset") == 1);
|
|
assert(cli_process_line(&engine, "quantize") == 1);
|
|
assert(cli_process_line(&engine, "threshold") == 1);
|
|
|
|
// Cleanup
|
|
for (int i = 0; i < MAX_CLIPS; i++) {
|
|
free(g_state.clips[i].buffer);
|
|
g_state.clips[i].buffer = NULL;
|
|
}
|
|
|
|
printf("PASSED\n");
|
|
}
|
|
|
|
int main(void) {
|
|
printf("Running CLI tests...\n\n");
|
|
test_cli_parse();
|
|
printf("\nAll CLI tests passed!\n");
|
|
return 0;
|
|
}
|