feat: add rack mode, colon commands, and client command parser
This commit is contained in:
committed by
Loic Coenen (aider)
parent
c7df02d37c
commit
9fda1b2669
@@ -14,6 +14,16 @@ static int tests_failed = 0;
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#define ASSERT_TRUE(expr, msg) do { \
|
||||
if (!(expr)) { \
|
||||
fprintf(stderr, "FAIL: %s\n", msg); \
|
||||
tests_failed++; \
|
||||
} else { \
|
||||
printf("PASS: %s\n", msg); \
|
||||
tests_passed++; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
static void test_carla_load_null_binary(void)
|
||||
{
|
||||
int id = -999;
|
||||
@@ -33,13 +43,50 @@ static void test_carla_connect_invalid_id(void)
|
||||
ASSERT_EQ(-1, ret, "carla_connect(-1, ...) returns -1");
|
||||
}
|
||||
|
||||
static void test_carla_get_handle_before_init(void)
|
||||
{
|
||||
CarlaHostHandle h = carla_get_handle();
|
||||
ASSERT_TRUE(h == NULL, "carla_get_handle() returns NULL before init");
|
||||
}
|
||||
|
||||
static void test_carla_set_bypass_invalid_id(void)
|
||||
{
|
||||
carla_set_bypass(-1, true);
|
||||
printf("PASS: carla_set_bypass(-1, true) did not crash\n");
|
||||
tests_passed++;
|
||||
}
|
||||
|
||||
static void test_carla_disconnect_no_jack(void)
|
||||
{
|
||||
int ret = carla_disconnect("from", "to");
|
||||
ASSERT_EQ(0, ret, "carla_disconnect('from','to') returns 0 when no JACK client");
|
||||
}
|
||||
|
||||
static void test_carla_set_bypass_valid_id_no_handle(void)
|
||||
{
|
||||
carla_set_bypass(0, true);
|
||||
printf("PASS: carla_set_bypass(0, true) did not crash (no handle)\n");
|
||||
tests_passed++;
|
||||
}
|
||||
|
||||
static void test_carla_unload_valid_id_no_handle(void)
|
||||
{
|
||||
int ret = carla_unload(0);
|
||||
ASSERT_EQ(-1, ret, "carla_unload(0) returns -1 when no handle");
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
printf("=== Carla host stub unit tests ===\n");
|
||||
printf("=== Carla host unit tests ===\n");
|
||||
|
||||
test_carla_load_null_binary();
|
||||
test_carla_unload_invalid_id();
|
||||
test_carla_connect_invalid_id();
|
||||
test_carla_get_handle_before_init();
|
||||
test_carla_set_bypass_invalid_id();
|
||||
test_carla_disconnect_no_jack();
|
||||
test_carla_set_bypass_valid_id_no_handle();
|
||||
test_carla_unload_valid_id_no_handle();
|
||||
|
||||
printf("\nResults: %d passed, %d failed\n", tests_passed, tests_failed);
|
||||
return tests_failed > 0 ? 1 : 0;
|
||||
|
||||
111
client/tests/test_client_cmd.c
Normal file
111
client/tests/test_client_cmd.c
Normal file
@@ -0,0 +1,111 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "client_cmd.h"
|
||||
#include "plugins.h"
|
||||
|
||||
static int tests_passed = 0;
|
||||
static int tests_failed = 0;
|
||||
|
||||
#define ASSERT_EQ(expected, actual, msg) do { \
|
||||
if ((expected) != (actual)) { \
|
||||
fprintf(stderr, "FAIL: %s (expected %d, got %d)\n", msg, (int)(expected), (int)(actual)); \
|
||||
tests_failed++; \
|
||||
} else { \
|
||||
printf("PASS: %s\n", msg); \
|
||||
tests_passed++; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#define ASSERT_STR_EQ(expected, actual, msg) do { \
|
||||
if (strcmp((expected), (actual)) != 0) { \
|
||||
fprintf(stderr, "FAIL: %s (expected \"%s\", got \"%s\")\n", msg, (expected), (actual)); \
|
||||
tests_failed++; \
|
||||
} else { \
|
||||
printf("PASS: %s\n", msg); \
|
||||
tests_passed++; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
/* Test invalid commands */
|
||||
static void test_unknown_command(void)
|
||||
{
|
||||
int id = -1;
|
||||
int ret = handle_client_command("unknown_command", &id);
|
||||
ASSERT_EQ(-1, ret, "handle_client_command('unknown_command', ...) returns -1");
|
||||
}
|
||||
|
||||
static void test_empty_input(void)
|
||||
{
|
||||
int id = -1;
|
||||
int ret = handle_client_command("", &id);
|
||||
ASSERT_EQ(-1, ret, "handle_client_command('', ...) returns -1");
|
||||
}
|
||||
|
||||
static void test_null_input(void)
|
||||
{
|
||||
int id = -1;
|
||||
int ret = handle_client_command(NULL, &id);
|
||||
ASSERT_EQ(-1, ret, "handle_client_command(NULL, ...) returns -1");
|
||||
}
|
||||
|
||||
/* Test addplugin command */
|
||||
static void test_addplugin_no_path(void)
|
||||
{
|
||||
int id = -1;
|
||||
int ret = handle_client_command("addplugin", &id);
|
||||
ASSERT_EQ(-1, ret, "handle_client_command('addplugin', ...) returns -1 (no path)");
|
||||
}
|
||||
|
||||
static void test_addplugin_empty_path(void)
|
||||
{
|
||||
int id = -1;
|
||||
int ret = handle_client_command("addplugin ", &id);
|
||||
ASSERT_EQ(-1, ret, "handle_client_command('addplugin ', ...) returns -1 (empty path)");
|
||||
}
|
||||
|
||||
static void test_addplugin_valid(void)
|
||||
{
|
||||
int id = -1;
|
||||
int ret = handle_client_command("addplugin /does/not/exist.so", &id);
|
||||
ASSERT_EQ(-1, ret, "handle_client_command('addplugin /does/not/exist.so', ...) returns -1 (no such file)");
|
||||
}
|
||||
|
||||
/* Test connect command */
|
||||
static void test_connect_no_args(void)
|
||||
{
|
||||
int id = -1;
|
||||
int ret = handle_client_command("connect", &id);
|
||||
ASSERT_EQ(-1, ret, "handle_client_command('connect', ...) returns -1 (no args)");
|
||||
}
|
||||
|
||||
static void test_connect_missing_to(void)
|
||||
{
|
||||
int id = -1;
|
||||
int ret = handle_client_command("connect plugin:out_1", &id);
|
||||
ASSERT_EQ(-1, ret, "handle_client_command('connect plugin:out_1', ...) returns -1 (missing 'to')");
|
||||
}
|
||||
|
||||
static void test_connect_invalid_id(void)
|
||||
{
|
||||
int id = -1;
|
||||
int ret = handle_client_command("connect plugin:out looper:in", &id);
|
||||
ASSERT_EQ(-1, ret, "handle_client_command('connect plugin:out looper:in', ...) returns -1 (stub)");
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
printf("=== Client command parser unit tests ===\n");
|
||||
|
||||
test_unknown_command();
|
||||
test_empty_input();
|
||||
test_null_input();
|
||||
test_addplugin_no_path();
|
||||
test_addplugin_empty_path();
|
||||
test_addplugin_valid();
|
||||
test_connect_no_args();
|
||||
test_connect_missing_to();
|
||||
test_connect_invalid_id();
|
||||
|
||||
printf("\nResults: %d passed, %d failed\n", tests_passed, tests_failed);
|
||||
return tests_failed > 0 ? 1 : 0;
|
||||
}
|
||||
@@ -14,56 +14,72 @@ static int tests_failed = 0;
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
static void test_plugin_load_null_binary(void)
|
||||
#define ASSERT_TRUE(expr, msg) do { \
|
||||
if (!(expr)) { \
|
||||
fprintf(stderr, "FAIL: %s\n", msg); \
|
||||
tests_failed++; \
|
||||
} else { \
|
||||
printf("PASS: %s\n", msg); \
|
||||
tests_passed++; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
static void test_plugin_load_null(void)
|
||||
{
|
||||
int id = -999;
|
||||
int ret = plugin_load(NULL, "someplugin", &id);
|
||||
ASSERT_EQ(-1, ret, "plugin_load(NULL, ...) returns -1");
|
||||
int ret = plugin_load(NULL, NULL, &id);
|
||||
ASSERT_EQ(-1, ret, "plugin_load(NULL, NULL, ...) returns -1");
|
||||
}
|
||||
|
||||
static void test_plugin_load_nonnull_binary(void)
|
||||
{
|
||||
int id = -999;
|
||||
int ret = plugin_load("/path/to/plugin.so", NULL, &id);
|
||||
ASSERT_EQ(-1, ret, "plugin_load(non‑NULL binary, ...) returns -1");
|
||||
}
|
||||
|
||||
static void test_plugin_unload_invalid_id(void)
|
||||
static void test_plugin_unload_invalid(void)
|
||||
{
|
||||
int ret = plugin_unload(-1);
|
||||
ASSERT_EQ(-1, ret, "plugin_unload(-1) returns -1");
|
||||
}
|
||||
|
||||
static void test_plugin_connect_invalid_id(void)
|
||||
static void test_plugin_connect_invalid(void)
|
||||
{
|
||||
int ret = plugin_connect(-1, "out", "looper:in");
|
||||
ASSERT_EQ(-1, ret, "plugin_connect(-1, ...) returns -1");
|
||||
}
|
||||
|
||||
static void test_plugin_disconnect(void)
|
||||
static void test_plugin_disconnect_no_jack(void)
|
||||
{
|
||||
int ret = plugin_disconnect("from_port", "to_port");
|
||||
ASSERT_EQ(0, ret, "plugin_disconnect(...) returns 0");
|
||||
int ret = plugin_disconnect("from", "to");
|
||||
ASSERT_EQ(0, ret, "plugin_disconnect('from','to') returns 0 (safe stub)");
|
||||
}
|
||||
|
||||
static void test_plugin_set_bypass_invalid(void)
|
||||
static void test_plugin_set_bypass_invalid_id(void)
|
||||
{
|
||||
/* set_bypass returns void; just make sure it doesn't crash */
|
||||
plugin_set_bypass(-1, true);
|
||||
printf("PASS: plugin_set_bypass(-1, true) did not crash\n");
|
||||
tests_passed++;
|
||||
}
|
||||
|
||||
static void test_plugin_set_bypass_valid_id(void)
|
||||
{
|
||||
plugin_set_bypass(0, true);
|
||||
printf("PASS: plugin_set_bypass(0, true) did not crash\n");
|
||||
tests_passed++;
|
||||
}
|
||||
|
||||
static void test_plugin_connect_valid_id(void)
|
||||
{
|
||||
int ret = plugin_connect(0, "out", "looper:in");
|
||||
ASSERT_EQ(-1, ret, "plugin_connect(0, ...) returns -1 (no plugin loaded)");
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
printf("=== Plugin stub unit tests ===\n");
|
||||
|
||||
test_plugin_load_null_binary();
|
||||
test_plugin_load_nonnull_binary();
|
||||
test_plugin_unload_invalid_id();
|
||||
test_plugin_connect_invalid_id();
|
||||
test_plugin_disconnect();
|
||||
test_plugin_set_bypass_invalid();
|
||||
test_plugin_load_null();
|
||||
test_plugin_unload_invalid();
|
||||
test_plugin_connect_invalid();
|
||||
test_plugin_disconnect_no_jack();
|
||||
test_plugin_set_bypass_invalid_id();
|
||||
test_plugin_set_bypass_valid_id();
|
||||
test_plugin_connect_valid_id();
|
||||
|
||||
printf("\nResults: %d passed, %d failed\n", tests_passed, tests_failed);
|
||||
return tests_failed > 0 ? 1 : 0;
|
||||
|
||||
Reference in New Issue
Block a user