htcp

Properties of water suspended in clouds
git clone git://git.meso-star.fr/htcp.git
Log | Files | Refs | README | LICENSE

test_htcp.c (2247B)


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