Assert that termkey_strpkey's return points to endofstring after parse

This commit is contained in:
Paul LeoNerd Evans 2011-04-07 20:14:44 +01:00
parent 692ae5d6f2
commit c626393aeb
1 changed files with 22 additions and 11 deletions

View File

@ -5,80 +5,91 @@ int main(int argc, char *argv[])
{ {
TermKey *tk; TermKey *tk;
TermKeyKey key; TermKeyKey key;
char *endp;
#define CLEAR_KEY do { key.type = -1; key.code.codepoint = -1; key.modifiers = -1; key.utf8[0] = 0; } while(0) #define CLEAR_KEY do { key.type = -1; key.code.codepoint = -1; key.modifiers = -1; key.utf8[0] = 0; } while(0)
plan_tests(38); plan_tests(48);
tk = termkey_new(0, TERMKEY_FLAG_NOTERMIOS); tk = termkey_new(0, TERMKEY_FLAG_NOTERMIOS);
CLEAR_KEY; CLEAR_KEY;
termkey_strpkey(tk, "A", &key, 0); endp = termkey_strpkey(tk, "A", &key, 0);
is_int(key.type, TERMKEY_TYPE_UNICODE, "key.type for unicode/A/0"); is_int(key.type, TERMKEY_TYPE_UNICODE, "key.type for unicode/A/0");
is_int(key.code.codepoint, 'A', "key.code.codepoint for unicode/A/0"); is_int(key.code.codepoint, 'A', "key.code.codepoint for unicode/A/0");
is_int(key.modifiers, 0, "key.modifiers for unicode/A/0"); is_int(key.modifiers, 0, "key.modifiers for unicode/A/0");
is_str(key.utf8, "A", "key.utf8 for unicode/A/0"); is_str(key.utf8, "A", "key.utf8 for unicode/A/0");
is_str(endp, "", "consumed entire input for unicode/A/0");
CLEAR_KEY; CLEAR_KEY;
termkey_strpkey(tk, "C-b", &key, 0); endp = termkey_strpkey(tk, "C-b", &key, 0);
is_int(key.type, TERMKEY_TYPE_UNICODE, "key.type for unicode/b/CTRL"); is_int(key.type, TERMKEY_TYPE_UNICODE, "key.type for unicode/b/CTRL");
is_int(key.code.codepoint, 'b', "key.code.codepoint for unicode/b/CTRL"); is_int(key.code.codepoint, 'b', "key.code.codepoint for unicode/b/CTRL");
is_int(key.modifiers, TERMKEY_KEYMOD_CTRL, "key.modifiers for unicode/b/CTRL"); is_int(key.modifiers, TERMKEY_KEYMOD_CTRL, "key.modifiers for unicode/b/CTRL");
is_str(key.utf8, "b", "key.utf8 for unicode/b/CTRL"); is_str(key.utf8, "b", "key.utf8 for unicode/b/CTRL");
is_str(endp, "", "consumed entire input for unicode/b/CTRL");
CLEAR_KEY; CLEAR_KEY;
termkey_strpkey(tk, "Ctrl-b", &key, TERMKEY_FORMAT_LONGMOD); endp = termkey_strpkey(tk, "Ctrl-b", &key, TERMKEY_FORMAT_LONGMOD);
is_int(key.type, TERMKEY_TYPE_UNICODE, "key.type for unicode/b/CTRL longmod"); is_int(key.type, TERMKEY_TYPE_UNICODE, "key.type for unicode/b/CTRL longmod");
is_int(key.code.codepoint, 'b', "key.code.codepoint for unicode/b/CTRL longmod"); is_int(key.code.codepoint, 'b', "key.code.codepoint for unicode/b/CTRL longmod");
is_int(key.modifiers, TERMKEY_KEYMOD_CTRL, "key.modifiers for unicode/b/CTRL longmod"); is_int(key.modifiers, TERMKEY_KEYMOD_CTRL, "key.modifiers for unicode/b/CTRL longmod");
is_str(key.utf8, "b", "key.utf8 for unicode/b/CTRL longmod"); is_str(key.utf8, "b", "key.utf8 for unicode/b/CTRL longmod");
is_str(endp, "", "consumed entire input for unicode/b/CTRL longmod");
CLEAR_KEY; CLEAR_KEY;
termkey_strpkey(tk, "^B", &key, TERMKEY_FORMAT_CARETCTRL); endp = termkey_strpkey(tk, "^B", &key, TERMKEY_FORMAT_CARETCTRL);
is_int(key.type, TERMKEY_TYPE_UNICODE, "key.type for unicode/b/CTRL caretctrl"); is_int(key.type, TERMKEY_TYPE_UNICODE, "key.type for unicode/b/CTRL caretctrl");
is_int(key.code.codepoint, 'b', "key.code.codepoint for unicode/b/CTRL caretctrl"); is_int(key.code.codepoint, 'b', "key.code.codepoint for unicode/b/CTRL caretctrl");
is_int(key.modifiers, TERMKEY_KEYMOD_CTRL, "key.modifiers for unicode/b/CTRL caretctrl"); is_int(key.modifiers, TERMKEY_KEYMOD_CTRL, "key.modifiers for unicode/b/CTRL caretctrl");
is_str(key.utf8, "b", "key.utf8 for unicode/b/CTRL caretctrl"); is_str(key.utf8, "b", "key.utf8 for unicode/b/CTRL caretctrl");
is_str(endp, "", "consumed entire input for unicode/b/CTRL caretctrl");
CLEAR_KEY; CLEAR_KEY;
termkey_strpkey(tk, "A-c", &key, 0); endp = termkey_strpkey(tk, "A-c", &key, 0);
is_int(key.type, TERMKEY_TYPE_UNICODE, "key.type for unicode/c/ALT"); is_int(key.type, TERMKEY_TYPE_UNICODE, "key.type for unicode/c/ALT");
is_int(key.code.codepoint, 'c', "key.code.codepoint for unicode/c/ALT"); is_int(key.code.codepoint, 'c', "key.code.codepoint for unicode/c/ALT");
is_int(key.modifiers, TERMKEY_KEYMOD_ALT, "key.modifiers for unicode/c/ALT"); is_int(key.modifiers, TERMKEY_KEYMOD_ALT, "key.modifiers for unicode/c/ALT");
is_str(key.utf8, "c", "key.utf8 for unicode/c/ALT"); is_str(key.utf8, "c", "key.utf8 for unicode/c/ALT");
is_str(endp, "", "consumed entire input for unicode/c/ALT");
CLEAR_KEY; CLEAR_KEY;
termkey_strpkey(tk, "Alt-c", &key, TERMKEY_FORMAT_LONGMOD); endp = termkey_strpkey(tk, "Alt-c", &key, TERMKEY_FORMAT_LONGMOD);
is_int(key.type, TERMKEY_TYPE_UNICODE, "key.type for unicode/c/ALT longmod"); is_int(key.type, TERMKEY_TYPE_UNICODE, "key.type for unicode/c/ALT longmod");
is_int(key.code.codepoint, 'c', "key.code.codepoint for unicode/c/ALT longmod"); is_int(key.code.codepoint, 'c', "key.code.codepoint for unicode/c/ALT longmod");
is_int(key.modifiers, TERMKEY_KEYMOD_ALT, "key.modifiers for unicode/c/ALT longmod"); is_int(key.modifiers, TERMKEY_KEYMOD_ALT, "key.modifiers for unicode/c/ALT longmod");
is_str(key.utf8, "c", "key.utf8 for unicode/c/ALT longmod"); is_str(key.utf8, "c", "key.utf8 for unicode/c/ALT longmod");
is_str(endp, "", "consumed entire input for unicode/c/ALT longmod");
CLEAR_KEY; CLEAR_KEY;
termkey_strpkey(tk, "M-c", &key, TERMKEY_FORMAT_ALTISMETA); endp = termkey_strpkey(tk, "M-c", &key, TERMKEY_FORMAT_ALTISMETA);
is_int(key.type, TERMKEY_TYPE_UNICODE, "key.type for unicode/c/ALT altismeta"); is_int(key.type, TERMKEY_TYPE_UNICODE, "key.type for unicode/c/ALT altismeta");
is_int(key.code.codepoint, 'c', "key.code.codepoint for unicode/c/ALT altismeta"); is_int(key.code.codepoint, 'c', "key.code.codepoint for unicode/c/ALT altismeta");
is_int(key.modifiers, TERMKEY_KEYMOD_ALT, "key.modifiers for unicode/c/ALT altismeta"); is_int(key.modifiers, TERMKEY_KEYMOD_ALT, "key.modifiers for unicode/c/ALT altismeta");
is_str(key.utf8, "c", "key.utf8 for unicode/c/ALT altismeta"); is_str(key.utf8, "c", "key.utf8 for unicode/c/ALT altismeta");
is_str(endp, "", "consumed entire input for unicode/c/ALT altismeta");
CLEAR_KEY; CLEAR_KEY;
termkey_strpkey(tk, "Meta-c", &key, TERMKEY_FORMAT_ALTISMETA|TERMKEY_FORMAT_LONGMOD); endp = termkey_strpkey(tk, "Meta-c", &key, TERMKEY_FORMAT_ALTISMETA|TERMKEY_FORMAT_LONGMOD);
is_int(key.type, TERMKEY_TYPE_UNICODE, "key.type for unicode/c/ALT altismeta+longmod"); is_int(key.type, TERMKEY_TYPE_UNICODE, "key.type for unicode/c/ALT altismeta+longmod");
is_int(key.code.codepoint, 'c', "key.code.codepoint for unicode/c/ALT altismeta+longmod"); is_int(key.code.codepoint, 'c', "key.code.codepoint for unicode/c/ALT altismeta+longmod");
is_int(key.modifiers, TERMKEY_KEYMOD_ALT, "key.modifiers for unicode/c/ALT altismeta+longmod"); is_int(key.modifiers, TERMKEY_KEYMOD_ALT, "key.modifiers for unicode/c/ALT altismeta+longmod");
is_str(key.utf8, "c", "key.utf8 for unicode/c/ALT altismeta+longmod"); is_str(key.utf8, "c", "key.utf8 for unicode/c/ALT altismeta+longmod");
is_str(endp, "", "consumed entire input for unicode/c/ALT altismeta+longmod");
CLEAR_KEY; CLEAR_KEY;
termkey_strpkey(tk, "Up", &key, 0); endp = termkey_strpkey(tk, "Up", &key, 0);
is_int(key.type, TERMKEY_TYPE_KEYSYM, "key.type for sym/Up/0"); is_int(key.type, TERMKEY_TYPE_KEYSYM, "key.type for sym/Up/0");
is_int(key.code.sym, TERMKEY_SYM_UP, "key.code.codepoint for sym/Up/0"); is_int(key.code.sym, TERMKEY_SYM_UP, "key.code.codepoint for sym/Up/0");
is_int(key.modifiers, 0, "key.modifiers for sym/Up/0"); is_int(key.modifiers, 0, "key.modifiers for sym/Up/0");
is_str(endp, "", "consumed entire input for sym/Up/0");
CLEAR_KEY; CLEAR_KEY;
termkey_strpkey(tk, "F5", &key, 0); endp = termkey_strpkey(tk, "F5", &key, 0);
is_int(key.type, TERMKEY_TYPE_FUNCTION, "key.type for func/5/0"); is_int(key.type, TERMKEY_TYPE_FUNCTION, "key.type for func/5/0");
is_int(key.code.number, 5, "key.code.number for func/5/0"); is_int(key.code.number, 5, "key.code.number for func/5/0");
is_int(key.modifiers, 0, "key.modifiers for func/5/0"); is_int(key.modifiers, 0, "key.modifiers for func/5/0");
is_str(endp, "", "consumed entire input for func/5/0");
termkey_destroy(tk); termkey_destroy(tk);