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_srcvl2.c (4285B)


      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   struct srcvl_receiver receiver;
     28   FILE* stream;
     29   int seek;
     30   (void)argc, (void)argv;
     31 
     32   CHK(mem_init_proxy_allocator(&allocator, &mem_default_allocator) == RES_OK);
     33   srcvl_create(&allocator, &srcvl);
     34 
     35   stream = tmpfile();
     36   CHK(stream != NULL);
     37   fprintf(stream, "- { name: entity0 }\n");
     38   fprintf(stream, "- { name: \"entity1\" }\n");
     39   fprintf(stream, "- { name: entity2, side: FRONT }\n");
     40   fprintf(stream, "- { name: entity3, side: BACK }\n");
     41   fprintf(stream, "- name: entity4\n");
     42   fprintf(stream, "  side: FRONT_AND_BACK\n");
     43   fprintf(stream, "- { name: entity5, side: BACK, per_primitive: INCOMING }\n");
     44   fprintf(stream, "- { name: entity6, side: BACK, per_primitive: ABSORBED }\n");
     45   fprintf(stream, "- { name: entity7, side: BACK, per_primitive: INCOMING_AND_ABSORBED }\n");
     46   fprintf(stream, "- { name: entity8, per_primitive: NONE, side: FRONT }\n");
     47   rewind(stream);
     48 
     49   CHK(srcvl_setup_stream(srcvl, NULL, stream) == RES_OK);
     50   CHK(srcvl_load(srcvl) == RES_OK);
     51   CHK(srcvl_count(srcvl) == 9);
     52 
     53   srcvl_get(srcvl, 0, &receiver);
     54   CHK(strcmp(receiver.name, "entity0") == 0);
     55   CHK(receiver.side == SRCVL_FRONT_AND_BACK);
     56   CHK(receiver.per_primitive_output == SRCVL_PP_NONE);
     57 
     58   srcvl_get(srcvl, 1, &receiver);
     59   CHK(strcmp(receiver.name, "entity1") == 0);
     60   CHK(receiver.side == SRCVL_FRONT_AND_BACK);
     61   CHK(receiver.per_primitive_output == SRCVL_PP_NONE);
     62 
     63   srcvl_get(srcvl, 2, &receiver);
     64   CHK(strcmp(receiver.name, "entity2") == 0);
     65   CHK(receiver.side == SRCVL_FRONT);
     66   CHK(receiver.per_primitive_output == SRCVL_PP_NONE);
     67 
     68   srcvl_get(srcvl, 3, &receiver);
     69   CHK(strcmp(receiver.name, "entity3") == 0);
     70   CHK(receiver.side == SRCVL_BACK);
     71   CHK(receiver.per_primitive_output == SRCVL_PP_NONE);
     72 
     73   srcvl_get(srcvl, 4, &receiver);
     74   CHK(strcmp(receiver.name, "entity4") == 0);
     75   CHK(receiver.side == SRCVL_FRONT_AND_BACK);
     76   CHK(receiver.per_primitive_output == SRCVL_PP_NONE);
     77 
     78   srcvl_get(srcvl, 5, &receiver);
     79   CHK(strcmp(receiver.name, "entity5") == 0);
     80   CHK(receiver.side == SRCVL_BACK);
     81   CHK(receiver.per_primitive_output == SRCVL_PP_INCOMING);
     82 
     83   srcvl_get(srcvl, 6, &receiver);
     84   CHK(strcmp(receiver.name, "entity6") == 0);
     85   CHK(receiver.side == SRCVL_BACK);
     86   CHK(receiver.per_primitive_output == SRCVL_PP_ABSORBED);
     87 
     88   srcvl_get(srcvl, 7, &receiver);
     89   CHK(strcmp(receiver.name, "entity7") == 0);
     90   CHK(receiver.side == SRCVL_BACK);
     91   CHK(receiver.per_primitive_output == SRCVL_PP_INCOMING_AND_ABSORBED);
     92 
     93   srcvl_get(srcvl, 8, &receiver);
     94   CHK(strcmp(receiver.name, "entity8") == 0);
     95   CHK(receiver.side == SRCVL_FRONT);
     96   CHK(receiver.per_primitive_output == SRCVL_PP_NONE);
     97 
     98   CHK(srcvl_load(srcvl) == RES_BAD_OP);
     99 
    100   seek = (int)ftell(stream);
    101   fprintf(stream, "---\n");
    102   fprintf(stream, "[{name: test 0, side: FRONT}, {name: test 1, side: BACK}]\n");
    103   fseek(stream, seek, SEEK_SET);
    104 
    105   CHK(srcvl_setup_stream(srcvl, NULL, stream) == RES_OK);
    106   CHK(srcvl_load(srcvl) == RES_OK);
    107   CHK(srcvl_count(srcvl) == 2);
    108 
    109   srcvl_get(srcvl, 0, &receiver);
    110   CHK(strcmp(receiver.name, "test 0") == 0);
    111   CHK(receiver.side == SRCVL_FRONT);
    112 
    113   srcvl_get(srcvl, 1, &receiver);
    114   CHK(strcmp(receiver.name, "test 1") == 0);
    115   CHK(receiver.side == SRCVL_BACK);
    116 
    117   fclose(stream);
    118   srcvl_ref_put(srcvl);
    119 
    120   check_memory_allocator(&allocator);
    121   mem_shutdown_proxy_allocator(&allocator);
    122   CHK(mem_allocated_size() == 0);
    123   return 0;
    124 }