|
| 1 | +/* |
| 2 | + * SVAR - tc-recorder.c |
| 3 | + * SPDX-FileCopyrightText: 2025 Arkadiusz Bokowy and contributors |
| 4 | + * SPDX-License-Identifier: MIT |
| 5 | + */ |
| 6 | + |
| 7 | +#if HAVE_CONFIG_H |
| 8 | +# include "config.h" |
| 9 | +#endif |
| 10 | + |
| 11 | +#include <check.h> |
| 12 | +#include <stdint.h> |
| 13 | + |
| 14 | +#include "recorder.h" |
| 15 | +#include "recorder-alsa.h" |
| 16 | +#include "recorder-pipewire.h" |
| 17 | +#include "recorder-portaudio.h" |
| 18 | + |
| 19 | +#if ENABLE_ALSA |
| 20 | +START_TEST(test_recorder_alsa) { |
| 21 | + |
| 22 | + struct recorder * rec; |
| 23 | + ck_assert_ptr_nonnull(rec = recorder_alsa_new(PCM_FORMAT_S16LE, 2, 44100)); |
| 24 | + ck_assert_uint_eq(rec->type, RECORDER_TYPE_ALSA); |
| 25 | + |
| 26 | + recorder_list_devices(rec); |
| 27 | + recorder_free(rec); |
| 28 | + |
| 29 | +} END_TEST |
| 30 | +#endif |
| 31 | + |
| 32 | +#if ENABLE_PIPEWIRE |
| 33 | +START_TEST(test_recorder_pipewire) { |
| 34 | + |
| 35 | + struct recorder * rec; |
| 36 | + ck_assert_ptr_nonnull(rec = recorder_pipewire_new(PCM_FORMAT_S16LE, 2, 44100)); |
| 37 | + ck_assert_uint_eq(rec->type, RECORDER_TYPE_PIPEWIRE); |
| 38 | + |
| 39 | + recorder_list_devices(rec); |
| 40 | + recorder_free(rec); |
| 41 | + |
| 42 | +} END_TEST |
| 43 | +#endif |
| 44 | + |
| 45 | +#if ENABLE_PORTAUDIO |
| 46 | +START_TEST(test_recorder_portaudio) { |
| 47 | + |
| 48 | + struct recorder * rec; |
| 49 | + ck_assert_ptr_nonnull(rec = recorder_pa_new(PCM_FORMAT_S16LE, 2, 44100)); |
| 50 | + ck_assert_uint_eq(rec->type, RECORDER_TYPE_PORTAUDIO); |
| 51 | + |
| 52 | + recorder_list_devices(rec); |
| 53 | + recorder_free(rec); |
| 54 | + |
| 55 | +} END_TEST |
| 56 | +#endif |
| 57 | + |
| 58 | +START_TEST(test_recorder_monitor) { |
| 59 | + |
| 60 | + struct recorder * rec; |
| 61 | + ck_assert_ptr_nonnull(rec = recorder_new(PCM_FORMAT_U8, 1, 44100)); |
| 62 | + rec->monitor = true; |
| 63 | + |
| 64 | + uint8_t pcm[] = { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120 }; |
| 65 | + ck_assert_int_eq(recorder_monitor(rec, pcm, sizeof(pcm)), -2); |
| 66 | + |
| 67 | + recorder_free(rec); |
| 68 | + |
| 69 | +} END_TEST |
| 70 | + |
| 71 | +START_TEST(test_recorder_process) { |
| 72 | + |
| 73 | + struct recorder * rec; |
| 74 | + ck_assert_ptr_nonnull(rec = recorder_new(PCM_FORMAT_U8, 1, 44100)); |
| 75 | + rec->activation_threshold_level_db = -42.0; |
| 76 | + |
| 77 | + uint8_t pcm[] = { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120 }; |
| 78 | + ck_assert_int_eq(recorder_process(rec, pcm, sizeof(pcm)), 0); |
| 79 | + ck_assert_uint_eq(rbuf_read_linear_capacity(&rec->rb), sizeof(pcm)); |
| 80 | + |
| 81 | + recorder_free(rec); |
| 82 | + |
| 83 | +} END_TEST |
| 84 | + |
| 85 | +START_TEST(test_recorder_type_to_string) { |
| 86 | +#if ENABLE_ALSA |
| 87 | + ck_assert_str_eq(recorder_type_to_string(RECORDER_TYPE_ALSA), "ALSA"); |
| 88 | +#endif |
| 89 | +#if ENABLE_PIPEWIRE |
| 90 | + ck_assert_str_eq(recorder_type_to_string(RECORDER_TYPE_PIPEWIRE), "PipeWire"); |
| 91 | +#endif |
| 92 | +#if ENABLE_PORTAUDIO |
| 93 | + ck_assert_str_eq(recorder_type_to_string(RECORDER_TYPE_PORTAUDIO), "PortAudio"); |
| 94 | +#endif |
| 95 | +} END_TEST |
| 96 | + |
| 97 | +int tcase_init(Suite * s) { |
| 98 | + |
| 99 | + TCase * tc = tcase_create(__FILE__); |
| 100 | + suite_add_tcase(s, tc); |
| 101 | + |
| 102 | +#if ENABLE_ALSA |
| 103 | + tcase_add_test(tc, test_recorder_alsa); |
| 104 | +#endif |
| 105 | + |
| 106 | +#if ENABLE_PIPEWIRE |
| 107 | + tcase_add_test(tc, test_recorder_pipewire); |
| 108 | +#endif |
| 109 | + |
| 110 | +#if ENABLE_PORTAUDIO |
| 111 | + tcase_add_test(tc, test_recorder_portaudio); |
| 112 | +#endif |
| 113 | + |
| 114 | + tcase_add_test(tc, test_recorder_monitor); |
| 115 | + tcase_add_test(tc, test_recorder_process); |
| 116 | + tcase_add_test(tc, test_recorder_type_to_string); |
| 117 | + |
| 118 | + return 0; |
| 119 | +} |
0 commit comments