feat: add mock JACK test target and unit tests for carla host
This commit is contained in:
@@ -1,13 +1,38 @@
|
||||
#include <CarlaHost.h>
|
||||
#include <CarlaBackend.h>
|
||||
#include <jack/jack.h>
|
||||
#include <string.h>
|
||||
#include "carla_host.h"
|
||||
|
||||
#ifdef MOCK_JACK
|
||||
/* Mock JACK functions – always succeed */
|
||||
/* Provide a dummy type so we can have a non‑NULL pointer */
|
||||
typedef void jack_client_t;
|
||||
static int mock_jack_connect(const char *from, const char *to) {
|
||||
(void)from; (void)to;
|
||||
return 0;
|
||||
}
|
||||
static int mock_jack_disconnect(const char *from, const char *to) {
|
||||
(void)from; (void)to;
|
||||
return 0;
|
||||
}
|
||||
/* Provide a fake jack_client pointer that is non‑NULL */
|
||||
#define jack_client ((jack_client_t*)1)
|
||||
/* Real jack_connect/jack_disconnect take 3 arguments (client, a, b).
|
||||
We ignore the client and forward to the mock 2‑arg functions. */
|
||||
#define jack_connect(client, a, b) ((void)(client), mock_jack_connect(a, b))
|
||||
#define jack_disconnect(client, a, b) ((void)(client), mock_jack_disconnect(a, b))
|
||||
#else
|
||||
#include <jack/jack.h>
|
||||
#endif
|
||||
|
||||
#define MAX_PLUGINS 256
|
||||
|
||||
static CarlaHostHandle handle = NULL;
|
||||
#ifdef MOCK_JACK
|
||||
/* jack_client is defined via macro above (non‑NULL) */
|
||||
#else
|
||||
static jack_client_t *jack_client = NULL; // private JACK client for port connections
|
||||
#endif
|
||||
static int carla_pids[MAX_PLUGINS];
|
||||
static int plugin_count = 0;
|
||||
|
||||
@@ -25,16 +50,20 @@ static int conn_count = 0;
|
||||
int carla_init_jack(void) {
|
||||
if (handle != NULL) return 0;
|
||||
|
||||
#ifndef MOCK_JACK
|
||||
// 1) Open our own JACK client (for port connections)
|
||||
jack_status_t status;
|
||||
jack_client = jack_client_open("looper-connector", JackNoStartServer, &status);
|
||||
// It's okay if jack_client is NULL; we still try Carla
|
||||
#endif
|
||||
|
||||
// 2) Create the Carla host handle
|
||||
handle = carla_standalone_host_init();
|
||||
if (!handle) {
|
||||
#ifndef MOCK_JACK
|
||||
if (jack_client) jack_client_close(jack_client);
|
||||
jack_client = NULL;
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -42,8 +71,10 @@ int carla_init_jack(void) {
|
||||
if (!carla_engine_init(handle, "JACK", "looper-client")) {
|
||||
carla_engine_close(handle);
|
||||
handle = NULL;
|
||||
#ifndef MOCK_JACK
|
||||
if (jack_client) jack_client_close(jack_client);
|
||||
jack_client = NULL;
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
@@ -54,10 +85,12 @@ void carla_cleanup_jack(void) {
|
||||
carla_engine_close(handle);
|
||||
handle = NULL;
|
||||
}
|
||||
#ifndef MOCK_JACK
|
||||
if (jack_client) {
|
||||
jack_client_close(jack_client);
|
||||
jack_client = NULL;
|
||||
}
|
||||
#endif
|
||||
plugin_count = 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user