#include "uitoolkit/UIKeyShortcut.h" #include "unittest/TestSuite.h" #include "shell/ShellKeyCodes.h" static void testInit(void) { UIKeyShortcut * shortcut = UIKeyShortcut_single(KEY_CODE_A, 0); TestCase_assertPointerNonNULL(shortcut); TestCase_assertUIntEqual(shortcut->keyCode, KEY_CODE_A); TestCase_assertUIntEqual(shortcut->modifiers, 0); TestCase_assertUIntEqual(shortcut->alternateCount, 0); TestCase_assertPointerNULL(shortcut->alternates); free(shortcut); shortcut = UIKeyShortcut_single(KEY_CODE_B, MODIFIER_CONTROL_BIT); TestCase_assertPointerNonNULL(shortcut); TestCase_assertUIntEqual(shortcut->keyCode, KEY_CODE_B); TestCase_assertUIntEqual(shortcut->modifiers, MODIFIER_CONTROL_BIT); TestCase_assertUIntEqual(shortcut->alternateCount, 0); TestCase_assertPointerNULL(shortcut->alternates); free(shortcut); shortcut = UIKeyShortcut_multiple(KEY_CODE_A, 0, KEY_CODE_B, MODIFIER_CONTROL_BIT, NULL); TestCase_assertPointerNonNULL(shortcut); TestCase_assertUIntEqual(shortcut->keyCode, KEY_CODE_A); TestCase_assertUIntEqual(shortcut->modifiers, 0); TestCase_assertUIntEqual(shortcut->alternateCount, 1); TestCase_assertPointerNonNULL(shortcut->alternates); TestCase_assertUIntEqual(shortcut->alternates[0].keyCode, KEY_CODE_B); TestCase_assertUIntEqual(shortcut->alternates[0].modifiers, MODIFIER_CONTROL_BIT); free(shortcut); shortcut = UIKeyShortcut_multiple(KEY_CODE_B, MODIFIER_CONTROL_BIT, KEY_CODE_C, 0, KEY_CODE_D, MODIFIER_SHIFT_BIT | MODIFIER_ALT_BIT, NULL); TestCase_assertPointerNonNULL(shortcut); TestCase_assertUIntEqual(shortcut->keyCode, KEY_CODE_B); TestCase_assertUIntEqual(shortcut->modifiers, MODIFIER_CONTROL_BIT); TestCase_assertUIntEqual(shortcut->alternateCount, 2); TestCase_assertPointerNonNULL(shortcut->alternates); TestCase_assertUIntEqual(shortcut->alternates[0].keyCode, KEY_CODE_C); TestCase_assertUIntEqual(shortcut->alternates[0].modifiers, 0); TestCase_assertUIntEqual(shortcut->alternates[1].keyCode, KEY_CODE_D); TestCase_assertUIntEqual(shortcut->alternates[1].modifiers, MODIFIER_SHIFT_BIT | MODIFIER_ALT_BIT); free(shortcut); } static void testCopy(void) { UIKeyShortcut * shortcut = UIKeyShortcut_none; UIKeyShortcut * copy = UIKeyShortcut_copy(shortcut); TestCase_assertPointerEqual(copy, UIKeyShortcut_none); shortcut = UIKeyShortcut_single(KEY_CODE_A, 0); copy = UIKeyShortcut_copy(shortcut); TestCase_assertPointerNonNULL(copy); TestCase_assertPointerUnequal(copy, shortcut); TestCase_assertUIntEqual(copy->keyCode, KEY_CODE_A); TestCase_assertUIntEqual(copy->modifiers, 0); TestCase_assertUIntEqual(copy->alternateCount, 0); TestCase_assertPointerNULL(copy->alternates); free(shortcut); free(copy); shortcut = UIKeyShortcut_multiple(KEY_CODE_A, 0, KEY_CODE_B, MODIFIER_CONTROL_BIT, NULL); copy = UIKeyShortcut_copy(shortcut); TestCase_assertPointerNonNULL(copy); TestCase_assertPointerUnequal(copy, shortcut); TestCase_assertUIntEqual(copy->keyCode, KEY_CODE_A); TestCase_assertUIntEqual(copy->modifiers, 0); TestCase_assertUIntEqual(copy->alternateCount, 1); TestCase_assertPointerNonNULL(copy->alternates); TestCase_assertUIntEqual(copy->alternates[0].keyCode, KEY_CODE_B); TestCase_assertUIntEqual(copy->alternates[0].modifiers, MODIFIER_CONTROL_BIT); free(shortcut); free(copy); } static void testIsMatch(void) { UIKeyShortcut * shortcut = UIKeyShortcut_single(KEY_CODE_A, 0); TestCase_assertBoolTrue(UIKeyShortcut_isMatch(shortcut, KEY_CODE_A, 0)); TestCase_assertBoolFalse(UIKeyShortcut_isMatch(shortcut, KEY_CODE_A, MODIFIER_SHIFT_BIT)); TestCase_assertBoolFalse(UIKeyShortcut_isMatch(shortcut, KEY_CODE_B, 0)); shortcut->keyCode = KEY_CODE_B; TestCase_assertBoolTrue(UIKeyShortcut_isMatch(shortcut, KEY_CODE_B, 0)); TestCase_assertBoolFalse(UIKeyShortcut_isMatch(shortcut, KEY_CODE_B, MODIFIER_SHIFT_BIT)); TestCase_assertBoolFalse(UIKeyShortcut_isMatch(shortcut, KEY_CODE_A, 0)); shortcut->modifiers = MODIFIER_CONTROL_BIT; TestCase_assertBoolFalse(UIKeyShortcut_isMatch(shortcut, KEY_CODE_B, 0)); TestCase_assertBoolTrue(UIKeyShortcut_isMatch(shortcut, KEY_CODE_B, MODIFIER_CONTROL_BIT)); TestCase_assertBoolFalse(UIKeyShortcut_isMatch(shortcut, KEY_CODE_B, MODIFIER_SHIFT_BIT)); TestCase_assertBoolFalse(UIKeyShortcut_isMatch(shortcut, KEY_CODE_B, MODIFIER_CONTROL_BIT | MODIFIER_SHIFT_BIT)); TestCase_assertBoolTrue(UIKeyShortcut_isMatch(shortcut, KEY_CODE_B, MODIFIER_CONTROL_BIT | MODIFIER_CAPS_LOCK_BIT)); free(shortcut); shortcut = UIKeyShortcut_multiple(KEY_CODE_A, 0, KEY_CODE_B, MODIFIER_ALT_BIT, NULL); TestCase_assertBoolTrue(UIKeyShortcut_isMatch(shortcut, KEY_CODE_A, 0)); TestCase_assertBoolFalse(UIKeyShortcut_isMatch(shortcut, KEY_CODE_A, MODIFIER_ALT_BIT)); TestCase_assertBoolFalse(UIKeyShortcut_isMatch(shortcut, KEY_CODE_B, 0)); TestCase_assertBoolTrue(UIKeyShortcut_isMatch(shortcut, KEY_CODE_B, MODIFIER_ALT_BIT)); free(shortcut); shortcut = UIKeyShortcut_multiple(KEY_CODE_C, MODIFIER_SHIFT_BIT, KEY_CODE_D, MODIFIER_ALT_BIT, KEY_CODE_D, MODIFIER_ALT_BIT | MODIFIER_CONTROL_BIT, NULL); TestCase_assertBoolFalse(UIKeyShortcut_isMatch(shortcut, KEY_CODE_C, 0)); TestCase_assertBoolTrue(UIKeyShortcut_isMatch(shortcut, KEY_CODE_C, MODIFIER_SHIFT_BIT)); TestCase_assertBoolFalse(UIKeyShortcut_isMatch(shortcut, KEY_CODE_D, 0)); TestCase_assertBoolTrue(UIKeyShortcut_isMatch(shortcut, KEY_CODE_D, MODIFIER_ALT_BIT)); TestCase_assertBoolFalse(UIKeyShortcut_isMatch(shortcut, KEY_CODE_D, MODIFIER_CONTROL_BIT)); TestCase_assertBoolTrue(UIKeyShortcut_isMatch(shortcut, KEY_CODE_D, MODIFIER_ALT_BIT | MODIFIER_CONTROL_BIT)); free(shortcut); } TEST_SUITE(UIKeyShortcutTest, testInit, testCopy, testIsMatch)