LCOV - code coverage report
Current view: top level - pkcs11/wrap-layer - test-init-pin.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 38 38
Test Date: 2024-04-08 13:24:42 Functions: 100.0 % 4 4

            Line data    Source code
       1              : /*
       2              :  * gnome-keyring
       3              :  *
       4              :  * Copyright (C) 2010 Stefan Walter
       5              :  *
       6              :  * This program is free software; you can redistribute it and/or modify
       7              :  * it under the terms of the GNU Lesser General Public License as
       8              :  * published by the Free Software Foundation; either version 2.1 of
       9              :  * the License, or (at your option) any later version.
      10              :  *
      11              :  * This program is distributed in the hope that it will be useful, but
      12              :  * WITHOUT ANY WARRANTY; without even the implied warranty of
      13              :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      14              :  * Lesser General Public License for more details.
      15              :  *
      16              :  * You should have received a copy of the GNU Lesser General Public
      17              :  * License along with this program; if not, see
      18              :  * <http://www.gnu.org/licenses/>.
      19              :  */
      20              : 
      21              : #include "config.h"
      22              : 
      23              : #include "wrap-layer/gkm-wrap-layer.h"
      24              : #include "wrap-layer/gkm-wrap-prompt.h"
      25              : 
      26              : #include "egg/egg-testing.h"
      27              : 
      28              : #include "gkm/gkm-mock.h"
      29              : #include "gkm/gkm-test.h"
      30              : 
      31              : #include <gcr/gcr-base.h>
      32              : 
      33              : #include <string.h>
      34              : 
      35              : typedef struct {
      36              :         CK_FUNCTION_LIST functions;
      37              :         CK_FUNCTION_LIST_PTR module;
      38              :         CK_SESSION_HANDLE session;
      39              : } Test;
      40              : 
      41              : static void
      42            1 : setup (Test *test, gconstpointer unused)
      43              : {
      44              :         CK_FUNCTION_LIST_PTR funcs;
      45              :         CK_SLOT_ID slot_id;
      46            1 :         CK_ULONG n_slots = 1;
      47              :         const gchar *prompter;
      48              :         CK_RV rv;
      49              : 
      50              :         /* Always start off with test test->functions */
      51            1 :         rv = gkm_mock_C_GetFunctionList (&funcs);
      52            1 :         gkm_assert_cmprv (rv, ==, CKR_OK);
      53            1 :         memcpy (&test->functions, funcs, sizeof (test->functions));
      54              : 
      55            1 :         gkm_wrap_layer_reset_modules ();
      56            1 :         gkm_wrap_layer_add_module (&test->functions);
      57            1 :         test->module = gkm_wrap_layer_get_functions ();
      58              : 
      59            1 :         prompter = gcr_mock_prompter_start ();
      60            1 :         gkm_wrap_prompt_set_prompter_name (prompter);
      61              : 
      62              :         /* Open a test->session */
      63            1 :         rv = (test->module->C_Initialize) (NULL);
      64            1 :         gkm_assert_cmprv (rv, ==, CKR_OK);
      65              : 
      66            1 :         rv = (test->module->C_GetSlotList) (CK_TRUE, &slot_id, &n_slots);
      67            1 :         gkm_assert_cmprv (rv, ==, CKR_OK);
      68              : 
      69            1 :         rv = (test->module->C_OpenSession) (slot_id, CKF_SERIAL_SESSION, NULL, NULL, &test->session);
      70            1 :         gkm_assert_cmprv (rv, ==, CKR_OK);
      71            1 : }
      72              : 
      73              : static void
      74            1 : teardown (Test *test, gconstpointer unused)
      75              : {
      76              :         CK_RV rv;
      77              : 
      78            1 :         g_assert (!gcr_mock_prompter_is_expecting ());
      79            1 :         gcr_mock_prompter_stop ();
      80              : 
      81            1 :         rv = (test->module->C_CloseSession) (test->session);
      82            1 :         gkm_assert_cmprv (rv, ==, CKR_OK);
      83            1 :         test->session = 0;
      84              : 
      85            1 :         rv = (test->module->C_Finalize) (NULL);
      86            1 :         gkm_assert_cmprv (rv, ==, CKR_OK);
      87            1 :         test->module = NULL;
      88            1 : }
      89              : 
      90              : static void
      91            1 : test_ok_password (Test *test, gconstpointer unused)
      92              : {
      93              :         CK_RV rv;
      94              : 
      95            1 :         gcr_mock_prompter_expect_password_ok ("new", NULL);
      96              : 
      97            1 :         rv = (test->module->C_InitPIN) (test->session, NULL, 0);
      98            1 :         gkm_assert_cmprv (rv, ==, CKR_OK);
      99              : 
     100            1 :         rv = (test->module->C_Login) (test->session, CKU_USER, (guchar*)"new", 3);
     101            1 :         gkm_assert_cmprv (rv, ==, CKR_OK);
     102            1 : }
     103              : 
     104              : int
     105            1 : main (int argc, char **argv)
     106              : {
     107              : #if !GLIB_CHECK_VERSION(2,35,0)
     108              :         g_type_init ();
     109              : #endif
     110            1 :         g_test_init (&argc, &argv, NULL);
     111              : 
     112            1 :         g_test_add ("/wrap-layer/init-pin/ok_password", Test, NULL, setup, test_ok_password, teardown);
     113              : 
     114            1 :         return egg_tests_run_in_thread_with_loop ();
     115              : }
        

Generated by: LCOV version 2.0-1