solstice

Compute collected power and efficiencies of a solar plant
git clone git://git.meso-star.com/solstice.git
Log | Files | Refs | README | LICENSE

test_srcvl.c (2442B)


      1 /* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com)
      2  * Copyright (C) 2016-2018 CNRS
      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 "srcvl.h"
     18 #include "test_solstice_utils.h"
     19 
     20 #include <string.h>
     21 
     22 int
     23 main(int argc, char** argv)
     24 {
     25   struct mem_allocator allocator;
     26   struct srcvl* srcvl;
     27   int ifile = 1;
     28   int i;
     29   res_T load_res = RES_OK;
     30   (void)argc, (void)argv;
     31 
     32   if(argc > 1) {
     33     if(!strcmp(argv[1], "-e")) {
     34       load_res = RES_BAD_ARG;
     35       ifile = 2;
     36     } else if(!strcmp(argv[1], "-h")) {
     37       printf("Usage: %s [OPTIONS] [FILE ... ]\n", argv[0]);
     38       printf(
     39 "Check the receiver API and that the submitted FILEs are valid. Use the `-e'\n"
     40 "option to check that the FILEs are invalid.\n\n");
     41       printf("OPTIONS:\n");
     42       printf("  -h print this help and exit.\n");
     43       printf("  -e check that the submitted FILEs have errors.\n");
     44       return 0;
     45     }
     46   }
     47 
     48   CHK(mem_init_proxy_allocator(&allocator, &mem_default_allocator) == RES_OK);
     49   srcvl_create(&allocator, &srcvl);
     50 
     51   CHK(srcvl_setup_stream(srcvl, NULL, tmpfile()) == RES_OK);
     52   CHK(srcvl_setup_stream(srcvl, "yop", tmpfile()) == RES_OK);
     53   CHK(srcvl_load(srcvl) == RES_BAD_OP); /* Empty stream */
     54 
     55   FOR_EACH(i, ifile, argc) {
     56     FILE* file = fopen(argv[i], "rb");
     57     int count = 0;
     58     CHK(file != NULL);
     59     CHK(srcvl_setup_stream(srcvl, argv[i], file) == RES_OK);
     60     for(;;) {
     61       const res_T res = srcvl_load(srcvl);
     62       if(count == 0 && load_res == RES_OK) {
     63         CHK(res == RES_OK);
     64       } else if(res == RES_BAD_OP) {
     65         break;
     66       }
     67       CHK(res == load_res);
     68       ++count;
     69     }
     70     fclose(file);
     71   }
     72   srcvl_ref_get(srcvl);
     73   srcvl_ref_put(srcvl);
     74   srcvl_ref_put(srcvl);
     75 
     76   check_memory_allocator(&allocator);
     77   mem_shutdown_proxy_allocator(&allocator);
     78   CHK(mem_allocated_size() == 0);
     79   return 0;
     80 }
     81