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

          Line data    Source code
       1             : /*
       2             :     SSSD
       3             : 
       4             :     find_uid - Utilities tests
       5             : 
       6             :     Authors:
       7             :         Abhishek Singh <abhishekkumarsingh.cse@gmail.com>
       8             : 
       9             :     Copyright (C) 2013 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 <stdarg.h>
      26             : #include <stdlib.h>
      27             : #include <stddef.h>
      28             : #include <setjmp.h>
      29             : #include <unistd.h>
      30             : #include <sys/types.h>
      31             : #include <cmocka.h>
      32             : #include <dhash.h>
      33             : 
      34             : #include "util/find_uid.h"
      35             : #include "tests/common.h"
      36             : 
      37           1 : void test_check_if_uid_is_active_success(void **state)
      38             : {
      39             :     int ret;
      40             :     uid_t uid;
      41             :     bool result;
      42             : 
      43           1 :     uid = getuid();
      44             : 
      45           1 :     ret = check_if_uid_is_active(uid, &result);
      46           1 :     assert_true(ret == EOK);
      47           1 :     assert_true(result);
      48           1 : }
      49             : 
      50           1 : void test_check_if_uid_is_active_fail(void **state)
      51             : {
      52             :     int ret;
      53             :     uid_t uid;
      54             :     bool result;
      55             : 
      56           1 :     uid = (uid_t) -7;
      57             : 
      58           1 :     ret = check_if_uid_is_active(uid, &result);
      59           1 :     assert_true(ret == EOK);
      60           1 :     assert_true(!result);
      61           1 : }
      62             : 
      63           1 : void test_get_uid_table(void **state)
      64             : {
      65             :     int ret;
      66             :     uid_t uid;
      67             :     TALLOC_CTX *tmp_ctx;
      68             :     hash_table_t *table;
      69             :     hash_key_t key;
      70             :     hash_value_t value;
      71             : 
      72           1 :     tmp_ctx = talloc_new(NULL);
      73           1 :     assert_true(tmp_ctx != NULL);
      74             : 
      75           1 :     ret = get_uid_table(tmp_ctx, &table);
      76           1 :     assert_true(ret == EOK);
      77             : 
      78           1 :     uid = getuid();
      79           1 :     key.type = HASH_KEY_ULONG;
      80           1 :     key.ul = (unsigned long) uid;
      81             : 
      82           1 :     ret = hash_lookup(table, &key, &value);
      83           1 :     assert_true(ret == HASH_SUCCESS);
      84           1 :     assert_true(hash_delete(table, &key) == HASH_SUCCESS);
      85             : 
      86           1 :     uid = (uid_t) -7;
      87           1 :     key.type = HASH_KEY_ULONG;
      88           1 :     key.ul = (unsigned long) uid;
      89             : 
      90           1 :     ret = hash_lookup(table, &key, &value);
      91           1 :     assert_true(ret == HASH_ERROR_KEY_NOT_FOUND);
      92             : 
      93           1 :     talloc_free(tmp_ctx);
      94           1 : }
      95             : 
      96           1 : int main(void)
      97             : {
      98           1 :     const struct CMUnitTest tests[] = {
      99             :         cmocka_unit_test(test_check_if_uid_is_active_success),
     100             :         cmocka_unit_test(test_check_if_uid_is_active_fail),
     101             :         cmocka_unit_test(test_get_uid_table)
     102             :     };
     103             : 
     104           1 :     return cmocka_run_group_tests(tests, NULL, NULL);
     105             : }

Generated by: LCOV version 1.10