LCOV - code coverage report
Current view: top level - test - test-uid-range.c (source / functions) Hit Total Coverage
Test: systemd_full.info Lines: 53 53 100.0 %
Date: 2019-08-23 13:36:53 Functions: 1 1 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 47 94 50.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: LGPL-2.1+ */
       2                 :            : 
       3                 :            : #include <stddef.h>
       4                 :            : 
       5                 :            : #include "alloc-util.h"
       6                 :            : #include "uid-range.h"
       7                 :            : #include "user-util.h"
       8                 :            : #include "util.h"
       9                 :            : 
      10                 :          4 : int main(int argc, char *argv[]) {
      11                 :          8 :         _cleanup_free_ UidRange *p = NULL;
      12                 :          4 :         unsigned n = 0;
      13                 :            :         uid_t search;
      14                 :            : 
      15         [ -  + ]:          4 :         assert_se(uid_range_add_str(&p, &n, "500-999") >= 0);
      16         [ -  + ]:          4 :         assert_se(n == 1);
      17         [ -  + ]:          4 :         assert_se(p[0].start == 500);
      18         [ -  + ]:          4 :         assert_se(p[0].nr == 500);
      19                 :            : 
      20         [ -  + ]:          4 :         assert_se(!uid_range_contains(p, n, 499));
      21         [ -  + ]:          4 :         assert_se(uid_range_contains(p, n, 500));
      22         [ -  + ]:          4 :         assert_se(uid_range_contains(p, n, 999));
      23         [ -  + ]:          4 :         assert_se(!uid_range_contains(p, n, 1000));
      24                 :            : 
      25                 :          4 :         search = UID_INVALID;
      26         [ -  + ]:          4 :         assert_se(uid_range_next_lower(p, n, &search));
      27         [ -  + ]:          4 :         assert_se(search == 999);
      28         [ -  + ]:          4 :         assert_se(uid_range_next_lower(p, n, &search));
      29         [ -  + ]:          4 :         assert_se(search == 998);
      30                 :          4 :         search = 501;
      31         [ -  + ]:          4 :         assert_se(uid_range_next_lower(p, n, &search));
      32         [ -  + ]:          4 :         assert_se(search == 500);
      33         [ -  + ]:          4 :         assert_se(uid_range_next_lower(p, n, &search) == -EBUSY);
      34                 :            : 
      35         [ -  + ]:          4 :         assert_se(uid_range_add_str(&p, &n, "1000") >= 0);
      36         [ -  + ]:          4 :         assert_se(n == 1);
      37         [ -  + ]:          4 :         assert_se(p[0].start == 500);
      38         [ -  + ]:          4 :         assert_se(p[0].nr == 501);
      39                 :            : 
      40         [ -  + ]:          4 :         assert_se(uid_range_add_str(&p, &n, "30-40") >= 0);
      41         [ -  + ]:          4 :         assert_se(n == 2);
      42         [ -  + ]:          4 :         assert_se(p[0].start == 30);
      43         [ -  + ]:          4 :         assert_se(p[0].nr == 11);
      44         [ -  + ]:          4 :         assert_se(p[1].start == 500);
      45         [ -  + ]:          4 :         assert_se(p[1].nr == 501);
      46                 :            : 
      47         [ -  + ]:          4 :         assert_se(uid_range_add_str(&p, &n, "60-70") >= 0);
      48         [ -  + ]:          4 :         assert_se(n == 3);
      49         [ -  + ]:          4 :         assert_se(p[0].start == 30);
      50         [ -  + ]:          4 :         assert_se(p[0].nr == 11);
      51         [ -  + ]:          4 :         assert_se(p[1].start == 60);
      52         [ -  + ]:          4 :         assert_se(p[1].nr == 11);
      53         [ -  + ]:          4 :         assert_se(p[2].start == 500);
      54         [ -  + ]:          4 :         assert_se(p[2].nr == 501);
      55                 :            : 
      56         [ -  + ]:          4 :         assert_se(uid_range_add_str(&p, &n, "20-2000") >= 0);
      57         [ -  + ]:          4 :         assert_se(n == 1);
      58         [ -  + ]:          4 :         assert_se(p[0].start == 20);
      59         [ -  + ]:          4 :         assert_se(p[0].nr == 1981);
      60                 :            : 
      61         [ -  + ]:          4 :         assert_se(uid_range_add_str(&p, &n, "2002") >= 0);
      62         [ -  + ]:          4 :         assert_se(n == 2);
      63         [ -  + ]:          4 :         assert_se(p[0].start == 20);
      64         [ -  + ]:          4 :         assert_se(p[0].nr == 1981);
      65         [ -  + ]:          4 :         assert_se(p[1].start == 2002);
      66         [ -  + ]:          4 :         assert_se(p[1].nr == 1);
      67                 :            : 
      68         [ -  + ]:          4 :         assert_se(uid_range_add_str(&p, &n, "2001") >= 0);
      69         [ -  + ]:          4 :         assert_se(n == 1);
      70         [ -  + ]:          4 :         assert_se(p[0].start == 20);
      71         [ -  + ]:          4 :         assert_se(p[0].nr == 1983);
      72                 :            : 
      73                 :          4 :         return 0;
      74                 :            : }

Generated by: LCOV version 1.14