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

          Line data    Source code
       1             : /*
       2             :     Authors:
       3             :         Pavel Reichl <preichl@redhat.com>
       4             : 
       5             :     Copyright (C) 2015 Red Hat
       6             : 
       7             :     SSSD tests - sdap access
       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 <stdarg.h>
      24             : #include <stdlib.h>
      25             : #include <stddef.h>
      26             : #include <setjmp.h>
      27             : #include <unistd.h>
      28             : #include <sys/types.h>
      29             : #include <cmocka.h>
      30             : 
      31             : #include "tests/common_check.h"
      32             : #include "tests/cmocka/test_expire_common.h"
      33             : 
      34             : /* linking against function from sdap_access.c module */
      35             : extern bool nds_check_expired(const char *exp_time_str);
      36             : 
      37           2 : static void nds_check_expired_wrap(void *in, void *_out)
      38             : {
      39           2 :     *(bool*)_out = nds_check_expired((const char*)in);
      40           2 : }
      41             : 
      42           1 : void test_nds_check_expire(void **state)
      43             : {
      44             :     struct expire_test_ctx *tc;
      45             :     bool res;
      46             : 
      47           1 :     tc = talloc_get_type(*state, struct expire_test_ctx);
      48           1 :     assert_non_null(tc);
      49             : 
      50           1 :     assert_false(nds_check_expired(NULL));
      51           1 :     assert_true(nds_check_expired(tc->invalid_longer_format));
      52           1 :     assert_true(nds_check_expired(tc->invalid_format));
      53           1 :     assert_true(nds_check_expired(tc->past_time));
      54           1 :     assert_false(nds_check_expired(tc->future_time));
      55             : 
      56             :     /* changing time zone has no effect as time of expiration is in UTC */
      57           1 :     expire_test_tz("GST+2", nds_check_expired_wrap, (void*)tc->future_time,
      58             :                    (void*)&res);
      59           1 :     assert_false(res);
      60           1 :     expire_test_tz("GST-2", nds_check_expired_wrap, (void*)tc->future_time,
      61             :                    (void*)&res);
      62           1 :     assert_false(res);
      63           1 : }
      64             : 
      65           1 : int main(void)
      66             : {
      67           1 :     const struct CMUnitTest tests[] = {
      68             :         cmocka_unit_test_setup_teardown(test_nds_check_expire,
      69             :                                         expire_test_setup,
      70             :                                         expire_test_teardown)
      71             :     };
      72             : 
      73           1 :     return cmocka_run_group_tests(tests, NULL, NULL);
      74             : }

Generated by: LCOV version 1.10