LCOV - code coverage report
Current view: top level - tests/cmocka - test_find_uid.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 33 33 100.0 %
Date: 2013-03-18 Functions: 4 4 100.0 %
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : #include <stdarg.h>
       2                 :            : #include <stdlib.h>
       3                 :            : #include <stddef.h>
       4                 :            : #include <setjmp.h>
       5                 :            : #include <unistd.h>
       6                 :            : #include <sys/types.h>
       7                 :            : #include <cmocka.h>
       8                 :            : 
       9                 :            : #include "util/find_uid.h"
      10                 :            : #include "tests/common.h"
      11                 :            : #include "dhash.h"
      12                 :            : 
      13                 :          2 : void test_check_if_uid_is_active_success(void ** state)
      14                 :            : {
      15                 :            :     int ret;
      16                 :            :     uid_t uid;
      17                 :            :     bool result;
      18                 :            : 
      19                 :          2 :     uid = getuid();
      20                 :            : 
      21                 :          2 :     ret = check_if_uid_is_active(uid, &result);
      22                 :          2 :     assert_true(ret == EOK);
      23                 :          2 :     assert_true(result);
      24                 :          2 : }
      25                 :            : 
      26                 :          2 : void test_check_if_uid_is_active_fail(void ** state)
      27                 :            : {
      28                 :            :     
      29                 :            :     int ret;
      30                 :            :     uid_t uid;
      31                 :            :     bool result;
      32                 :            :     
      33                 :          2 :     uid = (uid_t) -7;
      34                 :            : 
      35                 :          2 :     ret = check_if_uid_is_active(uid, &result);
      36                 :          2 :     assert_true(ret == EOK);
      37                 :          2 :     assert_true(!result);
      38                 :          2 : }
      39                 :            : 
      40                 :          2 : void test_get_uid_table(void ** state)
      41                 :            : {
      42                 :            :     int ret;
      43                 :            :     uid_t uid;
      44                 :            :     TALLOC_CTX *tmp_ctx;
      45                 :            :     hash_table_t *table;
      46                 :            :     hash_key_t key;
      47                 :            :     hash_value_t value;
      48                 :            : 
      49                 :          2 :     tmp_ctx = talloc_new(NULL);
      50                 :          2 :     assert_true(tmp_ctx != NULL);
      51                 :            : 
      52                 :          2 :     ret = get_uid_table(tmp_ctx, &table);
      53                 :          2 :     assert_true(ret == EOK);
      54                 :            : 
      55                 :          2 :     uid = getuid();
      56                 :          2 :     key.type = HASH_KEY_ULONG;
      57                 :          2 :     key.ul = (unsigned long) uid;
      58                 :            : 
      59                 :          2 :     ret = hash_lookup(table, &key, &value);
      60                 :          2 :     assert_true(ret == HASH_SUCCESS);
      61                 :          2 :     assert_true(hash_delete(table, &key) == HASH_SUCCESS);
      62                 :            : 
      63                 :          2 :     uid = (uid_t) -7;
      64                 :          2 :     key.type = HASH_KEY_ULONG;
      65                 :          2 :     key.ul = (unsigned long) uid;
      66                 :            : 
      67                 :          2 :     ret = hash_lookup(table, &key, &value);
      68                 :            : 
      69                 :          2 :     assert_true(ret == HASH_ERROR_KEY_NOT_FOUND);
      70                 :            : 
      71                 :          2 :     talloc_free(tmp_ctx);
      72                 :          2 : }
      73                 :            : 
      74                 :          2 : int main(void)
      75                 :            : {
      76                 :          2 :     const UnitTest tests[] = {
      77                 :            :     unit_test(test_check_if_uid_is_active_success), unit_test(test_check_if_uid_is_active_fail),
      78                 :            :     unit_test(test_get_uid_table)};
      79                 :            : 
      80                 :          2 :     return run_tests(tests);
      81                 :            : }

Generated by: LCOV version 1.9