test_svx_device.c (2232B)
1 /* Copyright (C) 2018, 2020-2025 |Méso|Star> (contact@meso-star.com) 2 * Copyright (C) 2018 Université Paul Sabatier 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. */ 16 17 #include "svx.h" 18 #include "test_svx_utils.h" 19 20 #include <rsys/logger.h> 21 22 static void 23 log_stream(const char* msg, void* ctx) 24 { 25 ASSERT(msg); 26 (void)msg, (void)ctx; 27 printf("%s\n", msg); 28 } 29 30 int 31 main(int argc, char** argv) 32 { 33 struct mem_allocator allocator; 34 struct logger logger; 35 struct svx_device* svx; 36 (void)argc, (void)argv; 37 38 CHK(svx_device_create(NULL, NULL, 0, NULL) == RES_BAD_ARG); 39 CHK(svx_device_create(NULL, NULL, 0, &svx) == RES_OK); 40 41 CHK(svx_device_ref_get(NULL) == RES_BAD_ARG); 42 CHK(svx_device_ref_get(svx) == RES_OK); 43 CHK(svx_device_ref_put(NULL) == RES_BAD_ARG); 44 CHK(svx_device_ref_put(svx) == RES_OK); 45 CHK(svx_device_ref_put(svx) == RES_OK); 46 47 CHK(mem_init_proxy_allocator(&allocator, &mem_default_allocator) == RES_OK); 48 CHK(svx_device_create(NULL, &allocator, 1, &svx) == RES_OK); 49 CHK(svx_device_ref_put(svx) == RES_OK); 50 51 CHK(logger_init(&allocator, &logger) == RES_OK); 52 logger_set_stream(&logger, LOG_OUTPUT, log_stream, NULL); 53 logger_set_stream(&logger, LOG_ERROR, log_stream, NULL); 54 logger_set_stream(&logger, LOG_WARNING, log_stream, NULL); 55 56 CHK(svx_device_create(&logger, &allocator, 0, &svx) == RES_OK); 57 CHK(svx_device_ref_put(svx) == RES_OK); 58 CHK(svx_device_create(&logger, NULL, 0, &svx) == RES_OK); 59 CHK(svx_device_ref_put(svx) == RES_OK); 60 61 logger_release(&logger); 62 check_memory_allocator(&allocator); 63 mem_shutdown_proxy_allocator(&allocator); 64 CHK(mem_allocated_size() == 0); 65 return 0; 66 }