LCOV - code coverage report
Current view: top level - pkcs11/wrap-layer - test-set-pin.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 39 39
Test Date: 2024-09-14 11:48:09 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 <glib-object.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_passwords (Test *test, gconstpointer unused)
      92              : {
      93              :         CK_RV rv;
      94              : 
      95            1 :         gcr_mock_prompter_expect_password_ok ("booo", NULL);
      96            1 :         gcr_mock_prompter_expect_password_ok ("new", NULL);
      97              : 
      98            1 :         rv = (test->module->C_SetPIN) (test->session, NULL, 0, NULL, 0);
      99            1 :         gkm_assert_cmprv (rv, ==, CKR_OK);
     100              : 
     101            1 :         rv = (test->module->C_Login) (test->session, CKU_USER, (guchar*)"new", 3);
     102            1 :         gkm_assert_cmprv (rv, ==, CKR_OK);
     103            1 : }
     104              : 
     105              : int
     106            1 : main (int argc, char **argv)
     107              : {
     108              : #if !GLIB_CHECK_VERSION(2,35,0)
     109              :         g_type_init ();
     110              : #endif
     111            1 :         g_test_init (&argc, &argv, NULL);
     112              : 
     113            1 :         g_test_add ("/wrap-layer/set-pin/ok_passwords", Test, NULL, setup, test_ok_passwords, teardown);
     114              : 
     115            1 :         return egg_tests_run_in_thread_with_loop ();
     116              : }
        

Generated by: LCOV version 2.0-1