Skip to content

Commit

Permalink
Adding tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chukobyte committed Mar 23, 2024
1 parent b60d400 commit 2e20675
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,6 @@ if (SK_IS_MAIN)
# Create seika test exe
# add_executable(${PROJECT_NAME}_test test/main.c)
# target_link_libraries(${PROJECT_NAME}_test ${PROJECT_NAME} unity)
add_executable(${PROJECT_NAME}_test test/new_main.c)
target_link_libraries(${PROJECT_NAME}_test ${PROJECT_NAME} unity)
endif()
2 changes: 1 addition & 1 deletion new-seika/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ void ska_input_register_input_event(SkaInputSourceType sourceType, SkaInputKey k
} else {
keyState->isJustPressed = false;
}
keyState->isJustPressed = false;
keyState->isPressed = true;
keyState->isJustReleased = false;
keyState->strength = 1.0f;
break;
}
Expand Down
6 changes: 3 additions & 3 deletions new-seika/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
extern "C" {
#endif

#include "new-seika/math.h"
#include "../new-seika/math.h"

typedef int32 SkaInputDeviceIndex;
typedef uint32 SkaInputSubscriberHandle;
Expand Down Expand Up @@ -217,8 +217,8 @@ typedef enum SkaInputKey {
#define SKA_INPUT_KEY_MOUSE_COUNT (SKA_INPUT_KEY_MOUSE_ENUM_END - SKA_INPUT_KEY_MOUSE_ENUM_START)

#define SKA_INPUT_KEY_GAMEPAD_FOR_EACH(KeyName) for(SkaInputKey KeyName = SKA_INPUT_KEY_GAMEPAD_ENUM_START; KeyName <= SKA_INPUT_KEY_GAMEPAD_ENUM_END; KeyName++)
#define SKA_INPUT_KEY_KEYBOARD_FOR_EACH(KeyName) for(SkaInputKey KeyName = SKA_INPUT_KEY_KEYBOARD_ENUM_START; keyName <= SKA_INPUT_KEY_KEYBOARD_ENUM_END; KeyName++)
#define SKA_INPUT_KEY_MOUSE_FOR_EACH(KeyName) for(SkaInputKey KeyName = SKA_INPUT_KEY_MOUSE_ENUM_START; keyName <= SKA_INPUT_KEY_MOUSE_ENUM_END; KeyName++)
#define SKA_INPUT_KEY_KEYBOARD_FOR_EACH(KeyName) for(SkaInputKey KeyName = SKA_INPUT_KEY_KEYBOARD_ENUM_START; KeyName <= SKA_INPUT_KEY_KEYBOARD_ENUM_END; KeyName++)
#define SKA_INPUT_KEY_MOUSE_FOR_EACH(KeyName) for(SkaInputKey KeyName = SKA_INPUT_KEY_MOUSE_ENUM_START; KeyName <= SKA_INPUT_KEY_MOUSE_ENUM_END; KeyName++)

typedef enum SkaInputAxis {
SkaInputAxis_LEFT,
Expand Down
46 changes: 46 additions & 0 deletions test/new_main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include <unity.h>

#include "../new-seika/input.h"

#define RESOURCES_PATH "test/resources"
#define RESOURCES_PACK_PATH "test/resources/test.pck"

void setUp() {}
void tearDown() {}

void seika_input_test(void);

int main(int argv, char** args) {
UNITY_BEGIN();
RUN_TEST(seika_input_test);
return UNITY_END();
}

void seika_input_test(void) {
TEST_MESSAGE("Testing 'for each' and checking input type");
SKA_INPUT_KEY_GAMEPAD_FOR_EACH(key) {
TEST_ASSERT_TRUE(ska_input_is_gamepad_key(key));
}
SKA_INPUT_KEY_KEYBOARD_FOR_EACH(key) {
TEST_ASSERT_TRUE(ska_input_is_keyboard_key(key));
}
SKA_INPUT_KEY_MOUSE_FOR_EACH(key) {
TEST_ASSERT_TRUE(ska_input_is_mouse_key(key));
}

TEST_MESSAGE("Testing events");
ska_input_register_input_event3(SkaInputSourceType_KEYBOARD, SkaInputKey_KEYBOARD_BACKSPACE, SkaInputTriggerType_PRESSED);
TEST_ASSERT_TRUE(ska_input_is_key_pressed(SkaInputKey_KEYBOARD_BACKSPACE, SKA_INPUT_FIRST_PLAYER_DEVICE_INDEX));
TEST_ASSERT_TRUE(ska_input_is_key_just_pressed(SkaInputKey_KEYBOARD_BACKSPACE, SKA_INPUT_FIRST_PLAYER_DEVICE_INDEX));
TEST_ASSERT_FALSE(ska_input_is_key_just_released(SkaInputKey_KEYBOARD_BACKSPACE, SKA_INPUT_FIRST_PLAYER_DEVICE_INDEX));

ska_input_register_input_event3(SkaInputSourceType_KEYBOARD, SkaInputKey_KEYBOARD_BACKSPACE, SkaInputTriggerType_PRESSED);
TEST_ASSERT_TRUE(ska_input_is_key_pressed(SkaInputKey_KEYBOARD_BACKSPACE, SKA_INPUT_FIRST_PLAYER_DEVICE_INDEX));
TEST_ASSERT_FALSE(ska_input_is_key_just_pressed(SkaInputKey_KEYBOARD_BACKSPACE, SKA_INPUT_FIRST_PLAYER_DEVICE_INDEX));
TEST_ASSERT_FALSE(ska_input_is_key_just_released(SkaInputKey_KEYBOARD_BACKSPACE, SKA_INPUT_FIRST_PLAYER_DEVICE_INDEX));

ska_input_register_input_event3(SkaInputSourceType_KEYBOARD, SkaInputKey_KEYBOARD_BACKSPACE, SkaInputTriggerType_RELEASED);
TEST_ASSERT_FALSE(ska_input_is_key_pressed(SkaInputKey_KEYBOARD_BACKSPACE, SKA_INPUT_FIRST_PLAYER_DEVICE_INDEX));
TEST_ASSERT_FALSE(ska_input_is_key_just_pressed(SkaInputKey_KEYBOARD_BACKSPACE, SKA_INPUT_FIRST_PLAYER_DEVICE_INDEX));
TEST_ASSERT_TRUE(ska_input_is_key_just_released(SkaInputKey_KEYBOARD_BACKSPACE, SKA_INPUT_FIRST_PLAYER_DEVICE_INDEX));
}

0 comments on commit 2e20675

Please sign in to comment.