LCOV - code coverage report
Current view: top level - test - keystate.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 58 58
Test Date: 2026-04-03 02:26:39 Functions: 100.0 % 2 2

            Line data    Source code
       1              : #include "catch.hpp"
       2              : #include "KeyState.h"
       3              : 
       4           10 : SCENARIO( "KeyState", "[keystate]" ) {
       5           18 :   GIVEN( "A key state" ) {
       6              :     KeyState ks;
       7              : 
       8           10 :     WHEN( "checking for key presses below bounds" ) {
       9            2 :       THEN( "it cannot confirm" ) {
      10            1 :         REQUIRE_FALSE(ks.testKeyPressed(-1));
      11            1 :       }
      12            1 :     }
      13              : 
      14           10 :     WHEN( "checking for key presses above bounds" ) {
      15            2 :       THEN( "it cannot confirm" ) {
      16            1 :         REQUIRE_FALSE(ks.testKeyPressed(MAX_KEYS + 1));
      17            1 :       }
      18            1 :     }
      19              : 
      20           10 :     WHEN( "checking for key presses that haven't been registered" ) {
      21            2 :       THEN( "it cannot confirm" ) {
      22            1 :         REQUIRE_FALSE(ks.testKeyPressed(0));
      23            1 :       }
      24            1 :     }
      25              : 
      26           10 :     WHEN( "checking for key presses that have been registered" ) {
      27            1 :       ks.keys[0] = KEY_STATE_PRESSED;
      28            2 :       THEN( "it only confirms the key press" ) {
      29            1 :         REQUIRE(ks.testKeyPressed(0));
      30            1 :         REQUIRE_FALSE(ks.testKeyReleased(0));
      31            1 :       }
      32            1 :     }
      33              : 
      34           10 :     WHEN( "checking for released keys below bounds" ) {
      35            2 :       THEN( "it cannot confirm" ) {
      36            1 :         REQUIRE_FALSE(ks.testKeyReleased(-1));
      37            1 :       }
      38            1 :     }
      39              : 
      40           10 :     WHEN( "checking for released keys above bounds" ) {
      41            2 :       THEN( "it cannot confirm" ) {
      42            1 :         REQUIRE_FALSE(ks.testKeyReleased(MAX_KEYS + 1));
      43            1 :       }
      44            1 :     }
      45              : 
      46           10 :     WHEN( "checking for released keys that haven't been registered" ) {
      47            2 :       THEN( "it cannot confirm" ) {
      48            1 :         REQUIRE_FALSE(ks.testKeyReleased(0));
      49            1 :       }
      50            1 :     }
      51              : 
      52           10 :     WHEN( "checking for released keys that have been registered" ) {
      53            1 :       ks.keys[10] = KEY_STATE_RELEASED;
      54            2 :       THEN( "it only confirms the key release" ) {
      55            1 :         REQUIRE(ks.testKeyReleased(10));
      56            1 :         REQUIRE_FALSE(ks.testKeyPressed(10));
      57            1 :       }
      58            1 :     }
      59              : 
      60           10 :     WHEN( "initializing the key states" ) {
      61            1 :       ks.keys[10] = KEY_STATE_RELEASED;
      62            1 :       ks.keys[20] = KEY_STATE_PRESSED;
      63            1 :       ks.initKeyState();
      64              : 
      65            2 :       THEN( "it restores the initial state for all keys" ) {
      66            1 :         REQUIRE(ks.keys[10] == KEY_STATE_INIT);
      67            1 :         REQUIRE(ks.keys[20] == KEY_STATE_INIT);
      68            1 :         REQUIRE(ks.keys[90] == KEY_STATE_INIT);
      69            1 :       }
      70            1 :     }
      71            9 :   }
      72            9 : }
        

Generated by: LCOV version 2.4-0