LCOV - code coverage report
Current view: top level - tests/cwrap - test_usertools.c (source / functions) Hit Total Coverage
Test: .coverage.total Lines: 31 34 91.2 %
Date: 2015-10-19 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /*
       2             :     Authors:
       3             :         Jakub Hrozek <jhrozek@redhat.com>
       4             : 
       5             :     Copyright (C) 2014 Red Hat
       6             : 
       7             :     SSSD tests: User utilities
       8             : 
       9             :     This program is free software; you can redistribute it and/or modify
      10             :     it under the terms of the GNU General Public License as published by
      11             :     the Free Software Foundation; either version 3 of the License, or
      12             :     (at your option) any later version.
      13             : 
      14             :     This program is distributed in the hope that it will be useful,
      15             :     but WITHOUT ANY WARRANTY; without even the implied warranty of
      16             :     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      17             :     GNU General Public License for more details.
      18             : 
      19             :     You should have received a copy of the GNU General Public License
      20             :     along with this program.  If not, see <http://www.gnu.org/licenses/>.
      21             : */
      22             : 
      23             : #include <sys/types.h>
      24             : #include <sys/stat.h>
      25             : #include <fcntl.h>
      26             : 
      27             : #include <popt.h>
      28             : #include "util/util.h"
      29             : #include "tests/cmocka/common_mock.h"
      30             : 
      31           1 : void test_get_user_num(void **state)
      32             : {
      33             :     uid_t uid;
      34             :     gid_t gid;
      35             :     errno_t ret;
      36             : 
      37           1 :     ret = sss_user_by_name_or_uid("123", &uid, &gid);
      38           1 :     assert_int_equal(ret, EOK);
      39           1 :     assert_int_equal(uid, 123);
      40           1 :     assert_int_equal(gid, 456);
      41           1 : }
      42             : 
      43           1 : void test_get_user_str(void **state)
      44             : {
      45             :     uid_t uid;
      46             :     gid_t gid;
      47             :     errno_t ret;
      48             : 
      49           1 :     ret = sss_user_by_name_or_uid("sssd", &uid, &gid);
      50           1 :     assert_int_equal(ret, EOK);
      51           1 :     assert_int_equal(uid, 123);
      52           1 :     assert_int_equal(gid, 456);
      53           1 : }
      54             : 
      55           1 : void test_get_user_nullparm(void **state)
      56             : {
      57             :     uid_t uid;
      58             :     gid_t gid;
      59             :     errno_t ret;
      60             : 
      61           1 :     ret = sss_user_by_name_or_uid("sssd", &uid, NULL);
      62           1 :     assert_int_equal(ret, EOK);
      63           1 :     assert_int_equal(uid, 123);
      64             : 
      65           1 :     ret = sss_user_by_name_or_uid("sssd", NULL, &gid);
      66           1 :     assert_int_equal(ret, EOK);
      67           1 :     assert_int_equal(gid, 456);
      68           1 : }
      69             : 
      70           1 : int main(int argc, const char *argv[])
      71             : {
      72             :     poptContext pc;
      73             :     int opt;
      74           6 :     struct poptOption long_options[] = {
      75             :         POPT_AUTOHELP
      76           5 :         SSSD_DEBUG_OPTS
      77             :         POPT_TABLEEND
      78             :     };
      79             : 
      80           1 :     const struct CMUnitTest tests[] = {
      81             :         cmocka_unit_test(test_get_user_num),
      82             :         cmocka_unit_test(test_get_user_str),
      83             :         cmocka_unit_test(test_get_user_nullparm),
      84             :     };
      85             : 
      86             :     /* Set debug level to invalid value so we can deside if -d 0 was used. */
      87           1 :     debug_level = SSSDBG_INVALID;
      88             : 
      89           1 :     pc = poptGetContext(argv[0], argc, argv, long_options, 0);
      90           1 :     while((opt = poptGetNextOpt(pc)) != -1) {
      91             :         switch(opt) {
      92             :         default:
      93           0 :             fprintf(stderr, "\nInvalid option %s: %s\n\n",
      94             :                     poptBadOption(pc, 0), poptStrerror(opt));
      95           0 :             poptPrintUsage(pc, stderr, 0);
      96           0 :             return 1;
      97             :         }
      98             :     }
      99           1 :     poptFreeContext(pc);
     100             : 
     101           1 :     DEBUG_CLI_INIT(debug_level);
     102             : 
     103           1 :     tests_set_cwd();
     104             : 
     105           1 :     return cmocka_run_group_tests(tests, NULL, NULL);
     106             : }

Generated by: LCOV version 1.10