94 lines
2.5 KiB
C
94 lines
2.5 KiB
C
#include <stdio.h>
|
|
#include "carla_host.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_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;
|
|
int ret = carla_load(NULL, "someplugin", &id);
|
|
ASSERT_EQ(-1, ret, "carla_load(NULL, ...) returns -1");
|
|
}
|
|
|
|
static void test_carla_unload_invalid_id(void)
|
|
{
|
|
int ret = carla_unload(-1);
|
|
ASSERT_EQ(-1, ret, "carla_unload(-1) returns -1");
|
|
}
|
|
|
|
static void test_carla_connect_invalid_id(void)
|
|
{
|
|
int ret = carla_connect(-1, "out", "looper:in");
|
|
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 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;
|
|
}
|