star-meteo

Time varying meteorological data
git clone git://git.meso-star.fr/star-meteo.git
Log | Files | Refs | README | LICENSE

test_smeteo.c (2269B)


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