LCOV - code coverage report
Current view: top level - tests/lib - deps_formula.c (source / functions) Hit Total Coverage
Test: rapport Lines: 43 43 100.0 %
Date: 2021-12-10 16:22:55 Functions: 8 8 100.0 %
Branches: 20 34 58.8 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright (c) 2015, Vsevolod Stakhov
       3                 :            :  * All rights reserved.
       4                 :            :  *
       5                 :            :  * Redistribution and use in source and binary forms, with or without
       6                 :            :  * modification, are permitted provided that the following conditions are met:
       7                 :            :  *       * Redistributions of source code must retain the above copyright
       8                 :            :  *         notice, this list of conditions and the following disclaimer.
       9                 :            :  *       * Redistributions in binary form must reproduce the above copyright
      10                 :            :  *         notice, this list of conditions and the following disclaimer in the
      11                 :            :  *         documentation and/or other materials provided with the distribution.
      12                 :            :  *
      13                 :            :  * THIS SOFTWARE IS PROVIDED BY AUTHOR ''AS IS'' AND ANY
      14                 :            :  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
      15                 :            :  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
      16                 :            :  * DISCLAIMED. IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY
      17                 :            :  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
      18                 :            :  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
      19                 :            :  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
      20                 :            :  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
      21                 :            :  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
      22                 :            :  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      23                 :            :  */
      24                 :            : 
      25                 :            : 
      26                 :            : #include <atf-c.h>
      27                 :            : #include <err.h>
      28                 :            : #include <unistd.h>
      29                 :            : #include <pkg.h>
      30                 :            : #include <private/pkg.h>
      31                 :            : #include <private/pkg_deps.h>
      32                 :            : 
      33                 :            : ATF_TC(check_parsing);
      34                 :            : ATF_TC(check_sql);
      35                 :            : ATF_TC(check_op_parsing);
      36                 :            : 
      37                 :         52 : ATF_TC_HEAD(check_parsing, tc)
      38                 :            : {
      39                 :         52 :         atf_tc_set_md_var(tc, "descr", "testing parsing of deps formula");
      40                 :         52 : }
      41                 :            : 
      42                 :         13 : ATF_TC_BODY(check_parsing, tc)
      43                 :            : {
      44                 :            :         struct pkg_dep_formula *f;
      45                 :         13 :         const char *cases[] = {
      46                 :            :                 "name",
      47                 :            :                 "name = 1.0",
      48                 :            :                 "name >= 1.0,1",
      49                 :            :                 "name1, name2",
      50                 :            :                 "name1 | name2, name3",
      51                 :            :                 "name1 = 1.0 | name2 != 1.0, name3 > 1.0 < 2.0 != 1.5",
      52                 :            :                 "name1 = 1.0 | name2 != 1.0, name3 > 1.0 < 2.0 != 1.5, name4 +opt1 -opt2"
      53                 :            :         };
      54                 :            :         char *r;
      55                 :            :         unsigned int i;
      56                 :            : 
      57         [ +  + ]:        104 :         for (i = 0; i < sizeof(cases) / sizeof(cases[0]); i ++) {
      58                 :         91 :                 f = pkg_deps_parse_formula(cases[i]);
      59         [ +  - ]:         91 :                 ATF_REQUIRE(f != NULL);
      60                 :         91 :                 r = pkg_deps_formula_tostring(f);
      61         [ +  - ]:         91 :                 ATF_REQUIRE_STREQ(r, cases[i]);
      62                 :         91 :                 free(r);
      63                 :         91 :                 pkg_deps_formula_free(f);
      64                 :         91 :         }
      65                 :         13 : }
      66                 :            : 
      67                 :         52 : ATF_TC_HEAD(check_sql, tc)
      68                 :            : {
      69                 :         52 :         atf_tc_set_md_var(tc, "descr", "testing creating sql queries from formulas");
      70                 :         52 : }
      71                 :            : 
      72                 :         13 : ATF_TC_BODY(check_sql, tc)
      73                 :            : {
      74                 :            :         struct pkg_dep_formula *f;
      75                 :         13 :         const char *cases[] = {
      76                 :            :                 "name", "(name='name')",
      77                 :            :                 "name = 1.0", "(name='name' AND vercmp('=',version,'1.0'))",
      78                 :            :                 "name >= 1.0,1", "(name='name' AND vercmp('>=',version,'1.0,1'))",
      79                 :            :                 "name1 | name2", "(name='name1') OR (name='name2')",
      80                 :            :                 "name1 = 1.0 | name2 != 1.0", "(name='name1' AND vercmp('=',version,'1.0')) OR (name='name2' AND vercmp('!=',version,'1.0'))"
      81                 :            :         };
      82                 :            :         char *r;
      83                 :            :         unsigned int i;
      84                 :            : 
      85         [ +  + ]:         78 :         for (i = 0; i < sizeof(cases) / sizeof(cases[0]) / 2; i ++) {
      86                 :         65 :                 f = pkg_deps_parse_formula(cases[i * 2]);
      87         [ +  - ]:         65 :                 ATF_REQUIRE(f != NULL);
      88                 :         65 :                 r = pkg_deps_formula_tosql(f->items);
      89         [ +  - ]:         65 :                 ATF_REQUIRE_STREQ(r, cases[i * 2 + 1]);
      90                 :         65 :                 free(r);
      91                 :         65 :                 pkg_deps_formula_free(f);
      92                 :         65 :         }
      93                 :         13 : }
      94                 :            : 
      95                 :         52 : ATF_TC_HEAD(check_op_parsing, tc)
      96                 :            : {
      97                 :         52 :         atf_tc_set_md_var(tc, "descr", "testing parsing operands");
      98                 :         52 : }
      99                 :         13 : ATF_TC_BODY(check_op_parsing, tc)
     100                 :            : {
     101                 :            :         struct cases {
     102                 :            :                 const char *val;
     103                 :            :                 int expect;
     104                 :         13 :         } cases[] = {
     105                 :            :                 { "=", VERSION_EQ },
     106                 :            :                 { "==", VERSION_EQ },
     107                 :            :                 { ">=", VERSION_GE },
     108                 :            :                 { ">", VERSION_GT },
     109                 :            :                 { "<=", VERSION_LE },
     110                 :            :                 { "<", VERSION_LT },
     111                 :            :                 { "!", VERSION_NOT },
     112                 :            :                 { "!=", VERSION_NOT },
     113                 :            :                 { "*", VERSION_ANY },
     114                 :            :                 { NULL, VERSION_ANY },
     115                 :            :                 { "=>", VERSION_ANY },
     116                 :            :         };
     117                 :            : 
     118         [ +  + ]:        156 :         for (unsigned int i = 0; i < sizeof(cases) / sizeof(cases[0]); i ++) {
     119         [ +  - ]:        143 :                 ATF_REQUIRE_EQ((int)pkg_deps_string_toop(cases[i].val), cases[i].expect);
     120                 :        143 :         }
     121                 :         13 : }
     122                 :            : 
     123                 :        104 : ATF_TP_ADD_TCS(tp)
     124                 :            : {
     125   [ +  -  -  +  :         52 :         ATF_TP_ADD_TC(tp, check_parsing);
                   -  + ]
     126   [ +  -  -  +  :         52 :         ATF_TP_ADD_TC(tp, check_sql);
                   -  + ]
     127   [ +  -  -  +  :         52 :         ATF_TP_ADD_TC(tp, check_op_parsing);
                   -  + ]
     128                 :         52 :         return (atf_no_error());
     129                 :         52 : }

Generated by: LCOV version 1.15