LCOV - code coverage report
Current view: top level - tests - find_uid-tests.c (source / functions) Hit Total Coverage
Test: .coverage.total Lines: 46 46 100.0 %
Date: 2015-10-19 Functions: 5 5 100.0 %

          Line data    Source code
       1             : /*
       2             :     SSSD
       3             : 
       4             :     find_uid - Utilities tests
       5             : 
       6             :     Authors:
       7             :         Sumit Bose <sbose@redhat.com>
       8             : 
       9             :     Copyright (C) 2009 Red Hat
      10             : 
      11             :     This program is free software; you can redistribute it and/or modify
      12             :     it under the terms of the GNU General Public License as published by
      13             :     the Free Software Foundation; either version 3 of the License, or
      14             :     (at your option) any later version.
      15             : 
      16             :     This program is distributed in the hope that it will be useful,
      17             :     but WITHOUT ANY WARRANTY; without even the implied warranty of
      18             :     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19             :     GNU General Public License for more details.
      20             : 
      21             :     You should have received a copy of the GNU General Public License
      22             :     along with this program.  If not, see <http://www.gnu.org/licenses/>.
      23             : */
      24             : 
      25             : #include <stdlib.h>
      26             : #include <unistd.h>
      27             : #include <sys/types.h>
      28             : 
      29             : #include <check.h>
      30             : 
      31             : #include "util/find_uid.h"
      32             : #include "tests/common.h"
      33             : 
      34             : 
      35           1 : START_TEST(test_check_if_uid_is_active_success)
      36             : {
      37             :     uid_t uid;
      38             :     bool result;
      39             :     int ret;
      40             : 
      41           1 :     uid = getuid();
      42             : 
      43           1 :     ret = check_if_uid_is_active(uid, &result);
      44           1 :     fail_unless(ret == EOK, "check_if_uid_is_active failed.");
      45           1 :     fail_unless(result, "check_if_uid_is_active did not found my uid [%d]",
      46             :                 uid);
      47             : }
      48           1 : END_TEST
      49             : 
      50           1 : START_TEST(test_check_if_uid_is_active_fail)
      51             : {
      52             :     uid_t uid;
      53             :     bool result;
      54             :     int ret;
      55             : 
      56           1 :     uid = (uid_t) -4;
      57             : 
      58           1 :     ret = check_if_uid_is_active(uid, &result);
      59           1 :     fail_unless(ret == EOK, "check_if_uid_is_active failed.");
      60           1 :     fail_unless(!result, "check_if_uid_is_active found (hopefully not active) "
      61             :                          "uid [%d]", uid);
      62             : }
      63           1 : END_TEST
      64             : 
      65           1 : START_TEST(test_get_uid_table)
      66             : {
      67             :     uid_t uid;
      68             :     int ret;
      69             :     TALLOC_CTX *tmp_ctx;
      70             :     hash_table_t *table;
      71             :     hash_key_t key;
      72             :     hash_value_t value;
      73             : 
      74           1 :     tmp_ctx = talloc_new(NULL);
      75           1 :     fail_unless(tmp_ctx != NULL, "talloc_new failed.");
      76             : 
      77           1 :     ret = get_uid_table(tmp_ctx, &table);
      78           1 :     fail_unless(ret == EOK, "get_uid_table failed.");
      79             : 
      80           1 :     uid = getuid();
      81           1 :     key.type = HASH_KEY_ULONG;
      82           1 :     key.ul = (unsigned long) uid;
      83             : 
      84           1 :     ret = hash_lookup(table, &key, &value);
      85             : 
      86           1 :     fail_unless(ret == HASH_SUCCESS, "Cannot find my uid [%d] in the table", uid);
      87             : 
      88           1 :     uid = (uid_t) -4;
      89           1 :     key.type = HASH_KEY_ULONG;
      90           1 :     key.ul = (unsigned long) uid;
      91             : 
      92           1 :     ret = hash_lookup(table, &key, &value);
      93             : 
      94           1 :     fail_unless(ret == HASH_ERROR_KEY_NOT_FOUND, "Found (hopefully not active) "
      95             :                                                  "uid [%d] in the table", uid);
      96             : 
      97           1 :     talloc_free(tmp_ctx);
      98             : }
      99           1 : END_TEST
     100             : 
     101           1 : Suite *find_uid_suite (void)
     102             : {
     103           1 :     Suite *s = suite_create ("find_uid");
     104             : 
     105           1 :     TCase *tc_find_uid = tcase_create ("find_uid");
     106             : 
     107           1 :     tcase_add_test (tc_find_uid, test_check_if_uid_is_active_success);
     108           1 :     tcase_add_test (tc_find_uid, test_check_if_uid_is_active_fail);
     109           1 :     tcase_add_test (tc_find_uid, test_get_uid_table);
     110           1 :     suite_add_tcase (s, tc_find_uid);
     111             : 
     112           1 :     return s;
     113             : }
     114             : 
     115           1 : int main(void)
     116             : {
     117           1 :     debug_level = SSSDBG_MASK_ALL;
     118             :     int number_failed;
     119             : 
     120           1 :     tests_set_cwd();
     121             : 
     122           1 :     Suite *s = find_uid_suite ();
     123           1 :     SRunner *sr = srunner_create (s);
     124             :     /* If CK_VERBOSITY is set, use that, otherwise it defaults to CK_NORMAL */
     125           1 :     srunner_run_all(sr, CK_ENV);
     126           1 :     number_failed = srunner_ntests_failed (sr);
     127           1 :     srunner_free (sr);
     128           1 :     return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
     129             : }

Generated by: LCOV version 1.10