LCOV - code coverage report
Current view: top level - pkcs11/secret-store - test-secret-compat.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 60 60
Test Date: 2024-04-08 13:24:42 Functions: 100.0 % 5 5

            Line data    Source code
       1              : /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
       2              : /* test-secret-compat.c: Test secret compat files
       3              : 
       4              :    Copyright (C) 2008 Stefan Walter
       5              : 
       6              :    The Gnome Keyring Library is free software; you can redistribute it and/or
       7              :    modify it under the terms of the GNU Library General Public License as
       8              :    published by the Free Software Foundation; either version 2 of the
       9              :    License, or (at your option) any later version.
      10              : 
      11              :    The Gnome Keyring Library is distributed in the hope that it will be useful,
      12              :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      13              :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      14              :    Library General Public License for more details.
      15              : 
      16              :    You should have received a copy of the GNU Library General Public
      17              :    License along with the Gnome Library; see the file COPYING.LIB.  If not,
      18              :    <http://www.gnu.org/licenses/>.
      19              : 
      20              :    Author: Stef Walter <stef@memberwebs.com>
      21              : */
      22              : 
      23              : #include "config.h"
      24              : 
      25              : #include "secret-store/gkm-secret-compat.h"
      26              : 
      27              : #include <glib.h>
      28              : 
      29              : #include <stdlib.h>
      30              : #include <stdio.h>
      31              : #include <string.h>
      32              : 
      33              : static void
      34            1 : test_access_free (void)
      35              : {
      36              :         GkmSecretAccess *ac;
      37              : 
      38            1 :         ac = g_new0 (GkmSecretAccess, 1);
      39            1 :         ac->pathname = g_strdup ("/path");
      40            1 :         ac->display_name = g_strdup ("Display");
      41            1 :         ac->types_allowed = GKM_SECRET_ACCESS_READ;
      42              : 
      43            1 :         gkm_secret_compat_access_free (ac);
      44            1 : }
      45              : 
      46              : static void
      47            1 : test_acl_free (void)
      48              : {
      49              :         GkmSecretAccess *ac;
      50            1 :         GList *acl = NULL;
      51              :         int i;
      52              : 
      53           11 :         for (i = 0; i < 10; ++i) {
      54           10 :                 ac = g_new0 (GkmSecretAccess, 1);
      55           10 :                 ac->pathname = g_strdup ("/path");
      56           10 :                 ac->display_name = g_strdup ("Display");
      57           10 :                 ac->types_allowed = GKM_SECRET_ACCESS_READ;
      58           10 :                 acl = g_list_prepend (acl, ac);
      59              :         }
      60              : 
      61            1 :         gkm_secret_compat_acl_free (acl);
      62            1 : }
      63              : 
      64              : static void
      65            1 : test_parse_item_type (void)
      66              : {
      67              :         guint type;
      68              : 
      69            1 :         type = gkm_secret_compat_parse_item_type ("org.freedesktop.Secret.Generic");
      70            1 :         g_assert_cmpuint (type, ==, 0);
      71            1 :         type = gkm_secret_compat_parse_item_type ("org.gnome.keyring.NetworkPassword");
      72            1 :         g_assert_cmpuint (type, ==, 1);
      73            1 :         type = gkm_secret_compat_parse_item_type ("org.gnome.keyring.Note");
      74            1 :         g_assert_cmpuint (type, ==, 2);
      75            1 :         type = gkm_secret_compat_parse_item_type ("org.gnome.keyring.ChainedKeyring");
      76            1 :         g_assert_cmpuint (type, ==, 3);
      77            1 :         type = gkm_secret_compat_parse_item_type ("org.gnome.keyring.EncryptionKey");
      78            1 :         g_assert_cmpuint (type, ==, 4);
      79            1 :         type = gkm_secret_compat_parse_item_type ("org.gnome.keyring.PkStorage");
      80            1 :         g_assert_cmpuint (type, ==, 0x100);
      81              : 
      82              :         /* Invalid returns generic secret */
      83            1 :         type = gkm_secret_compat_parse_item_type ("invalid");
      84            1 :         g_assert_cmpuint (type, ==, 0);
      85              : 
      86              :         /* Null returns generic secret */
      87            1 :         type = gkm_secret_compat_parse_item_type (NULL);
      88            1 :         g_assert_cmpuint (type, ==, 0);
      89            1 : }
      90              : 
      91              : static void
      92            1 : test_format_item_type (void)
      93              : {
      94              :         const gchar *type;
      95              : 
      96            1 :         type = gkm_secret_compat_format_item_type (0);
      97            1 :         g_assert_cmpstr (type, ==, "org.freedesktop.Secret.Generic");
      98            1 :         type = gkm_secret_compat_format_item_type (1);
      99            1 :         g_assert_cmpstr (type, ==, "org.gnome.keyring.NetworkPassword");
     100            1 :         type = gkm_secret_compat_format_item_type (2);
     101            1 :         g_assert_cmpstr (type, ==, "org.gnome.keyring.Note");
     102            1 :         type = gkm_secret_compat_format_item_type (3);
     103            1 :         g_assert_cmpstr (type, ==, "org.gnome.keyring.ChainedKeyring");
     104            1 :         type = gkm_secret_compat_format_item_type (4);
     105            1 :         g_assert_cmpstr (type, ==, "org.gnome.keyring.EncryptionKey");
     106            1 :         type = gkm_secret_compat_format_item_type (0x100);
     107            1 :         g_assert_cmpstr (type, ==, "org.gnome.keyring.PkStorage");
     108              : 
     109              :         /* Higher bits shouldn't make a difference */
     110            1 :         type = gkm_secret_compat_format_item_type (0xF0000001);
     111            1 :         g_assert_cmpstr (type, ==, "org.gnome.keyring.NetworkPassword");
     112              : 
     113              :         /* Unrecognized should be null */
     114            1 :         type = gkm_secret_compat_format_item_type (32);
     115            1 :         g_assert (type == NULL);
     116            1 : }
     117              : 
     118              : int
     119            1 : main (int argc, char **argv)
     120              : {
     121            1 :         g_test_init (&argc, &argv, NULL);
     122              : 
     123            1 :         g_test_add_func ("/secret-store/compat/access_free", test_access_free);
     124            1 :         g_test_add_func ("/secret-store/compat/acl_free", test_acl_free);
     125            1 :         g_test_add_func ("/secret-store/compat/parse_item_type", test_parse_item_type);
     126            1 :         g_test_add_func ("/secret-store/compat/format_item_type", test_format_item_type);
     127              : 
     128            1 :         return g_test_run ();
     129              : }
        

Generated by: LCOV version 2.0-1