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