chore: checkpoint app work before firmware sync
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
#include "voice_protocol.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static void test_endpoint_validation(void) {
|
||||
PvEndpoint endpoint;
|
||||
assert(pv_parse_endpoint("ws://192.168.68.102:8644/api/esp32/voice/ws", &endpoint));
|
||||
assert(strcmp(endpoint.host, "192.168.68.102") == 0);
|
||||
assert(endpoint.port == 8644);
|
||||
assert(strcmp(endpoint.path, "/api/esp32/voice/ws") == 0);
|
||||
assert(!pv_parse_endpoint("ws://127.0.0.1:8642/api", &endpoint));
|
||||
assert(!pv_parse_endpoint("ws://localhost:8642/api", &endpoint));
|
||||
assert(!pv_parse_endpoint("wss://192.168.68.102/api", &endpoint));
|
||||
assert(!pv_parse_endpoint("ws://192.168.68.102:0/api", &endpoint));
|
||||
}
|
||||
|
||||
static void test_start_and_pcm_boundaries(void) {
|
||||
char json[256];
|
||||
assert(pv_make_start_json(json, sizeof(json), "session-01", "tactility-14c19d1a790"));
|
||||
assert(strstr(json, "\"v\":1") != NULL);
|
||||
assert(strstr(json, "\"pcm_s16le\"") != NULL);
|
||||
assert(!pv_make_start_json(json, sizeof(json), "bad session", "device"));
|
||||
assert(pv_valid_pcm_chunk(2));
|
||||
assert(pv_valid_pcm_chunk(PV_PCM_CHUNK_MAX));
|
||||
assert(!pv_valid_pcm_chunk(0));
|
||||
assert(!pv_valid_pcm_chunk(3));
|
||||
assert(!pv_valid_pcm_chunk(PV_PCM_CHUNK_MAX + 2));
|
||||
assert(pv_valid_downstream_audio("pcm_s16le", 24000, 1, 2, 48000));
|
||||
assert(!pv_valid_downstream_audio("wav", 24000, 1, 2, 48000));
|
||||
assert(!pv_valid_downstream_audio("pcm_s16le", 24000, 2, 2, 48000));
|
||||
assert(!pv_valid_downstream_audio("pcm_s16le", 24000, 1, 2, PV_DOWNSTREAM_MAX + 2));
|
||||
assert(pv_binary_matches_metadata(48000, 48000));
|
||||
assert(!pv_binary_matches_metadata(48000, 47998));
|
||||
}
|
||||
|
||||
static void test_retry_and_state(void) {
|
||||
const uint32_t expected[] = {1, 2, 4, 8, 16, 30, 30};
|
||||
for (unsigned i = 0; i < sizeof(expected) / sizeof(expected[0]); ++i) assert(pv_retry_delay_seconds(i) == expected[i]);
|
||||
assert(pv_disconnect_state(true) == PV_RECONNECTING);
|
||||
assert(pv_disconnect_state(false) == PV_FAILED);
|
||||
assert(strcmp(pv_state_label(PV_STREAMING), "STREAMING") == 0);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
test_endpoint_validation();
|
||||
test_start_and_pcm_boundaries();
|
||||
test_retry_and_state();
|
||||
puts("voice_protocol tests passed");
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user