LCOV - code coverage report
Current view: top level - tests - direct.c (source / functions) Coverage Total Hit
Test: Code coverage Lines: 87.0 % 23 20
Test Date: 2026-11-03 08:45:29 Functions: 66.7 % 3 2
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 66.7 % 6 4

             Branch data     Line data    Source code
       1                 :             : /*
       2                 :             :  * Test resetting a card of type VCARD_DIRECT
       3                 :             :  *
       4                 :             :  * This code is licensed under the GNU LGPL, version 2.1 or later.
       5                 :             :  * See the COPYING file in the top-level directory.
       6                 :             :  */
       7                 :             : #include <glib.h>
       8                 :             : #include "libcacard.h"
       9                 :             : 
      10                 :             : static const unsigned char test_aid[] = { 0xd2, 0x76, 0x00, 0x01, 0x24, 0x01 };
      11                 :             : 
      12                 :             : static VCardStatus
      13                 :           0 : test_process_apdu(G_GNUC_UNUSED VCard *card, G_GNUC_UNUSED VCardAPDU *apdu,
      14                 :             :                   VCardResponse **response)
      15                 :             : {
      16                 :           0 :     *response = vcard_make_response(VCARD7816_STATUS_SUCCESS);
      17                 :           0 :     return VCARD_DONE;
      18                 :             : }
      19                 :             : 
      20                 :             : /* The applet has no reset function, which vcard_select_applet() accepts */
      21                 :           1 : static void test_reset_applet_without_reset_function(void)
      22                 :             : {
      23                 :             :     VCard *card;
      24                 :             :     VReader *reader;
      25                 :             :     VEvent *event;
      26                 :             :     unsigned char atr[64];
      27                 :           1 :     int atr_len = sizeof(atr);
      28                 :             : 
      29                 :           1 :     card = vcard_new(NULL, NULL);
      30                 :           1 :     vcard_set_type(card, VCARD_DIRECT);
      31                 :           1 :     vcard_add_applet(card, vcard_new_applet(test_process_apdu, NULL,
      32                 :             :                                             test_aid, sizeof(test_aid)));
      33                 :             : 
      34                 :           1 :     vcard_reset(card, VCARD_POWER_ON);
      35                 :             : 
      36                 :           1 :     reader = vreader_new("direct", NULL, NULL);
      37                 :           1 :     vreader_insert_card(reader, card);
      38         [ -  + ]:           1 :     g_assert_cmpint(vreader_power_off(reader), ==, VREADER_OK);
      39         [ -  + ]:           1 :     g_assert_cmpint(vreader_power_on(reader, atr, &atr_len), ==, VREADER_OK);
      40                 :           1 :     vreader_insert_card(reader, NULL);
      41                 :             : 
      42                 :           1 :     vreader_free(reader);
      43                 :           1 :     vcard_free(card);
      44         [ +  + ]:           3 :     while ((event = vevent_get_next_vevent()) != NULL) {
      45                 :           2 :         vevent_delete(event);
      46                 :             :     }
      47                 :           1 : }
      48                 :             : 
      49                 :           1 : int main(int argc, char *argv[])
      50                 :             : {
      51                 :           1 :     g_test_init(&argc, &argv, NULL);
      52                 :             : 
      53                 :           1 :     g_test_add_func("/direct/reset-applet-without-reset-function",
      54                 :             :                     test_reset_applet_without_reset_function);
      55                 :             : 
      56                 :           1 :     return g_test_run();
      57                 :             : }
        

Generated by: LCOV version 2.0-1