void internal_ok_candidate( const char *file, int line, ChewingContext *ctx, const char *cand[], size_t cand_len ) { size_t i; char *buf; assert( ctx ); chewing_cand_Enumerate( ctx ); for ( i = 0; i < cand_len; ++i ) { internal_ok( file, line, chewing_cand_hasNext( ctx ), __func__, "shall has next candidate" ); buf = chewing_cand_String( ctx ); internal_ok( file, line, strcmp( buf, cand[i] ) == 0, __func__, "candidate `%s' shall be `%s'", buf, cand[i] ); chewing_free( buf ); buf = chewing_cand_string_by_index( ctx, i ); internal_ok( file, line, strcmp( buf, cand[i] ) == 0, __func__, "candndate `%s' shall be `%s'", buf, cand[i] ); chewing_free( buf ); } internal_ok( file, line , !chewing_cand_hasNext( ctx ), __func__, "shall not have next candidate" ); buf = chewing_cand_String( ctx ); internal_ok( file, line, strcmp( buf, "" ) == 0, __func__, "candndate `%s' shall be `%s'", buf, "" ); chewing_free( buf ); }
void internal_ok_keystroke_rtn( const char *file, int line, ChewingContext *ctx, int rtn ) { const struct { int rtn; int (*func)(ChewingContext* ctx); } TABLE[] = { { KEYSTROKE_IGNORE, chewing_keystroke_CheckIgnore }, { KEYSTROKE_COMMIT, chewing_commit_Check }, // No function to check KEYSTROKE_BELL { KEYSTROKE_ABSORB, chewing_keystroke_CheckAbsorb }, }; size_t i; int actual; int expected; assert( ctx ); for ( i = 0; i < ARRAY_SIZE( TABLE ); ++i ) { actual = TABLE[i].func( ctx ); expected = !!( rtn & TABLE[i].rtn ); internal_ok( file, line, actual == expected, __func__, "keystroke rtn `%d' shall be `%d'", actual, expected ); } }
void internal_ok_candidate_len(const char *file, int line, ChewingContext *ctx, size_t expected_len) { const char *buf; size_t actual_len; assert(ctx); buf = chewing_cand_string_by_index_static(ctx, 0); actual_len = ueStrLen(buf); internal_ok(file, line, actual_len == expected_len, __func__, "candidate length `%d' shall be `%d'", actual_len, expected_len); }
void internal_ok_buffer( const char *file, int line, ChewingContext *ctx, const char *expected, const BufferType *buffer ) { char *buf; int actual_ret; int expected_ret; int expected_len; assert( ctx ); assert( expected ); assert( buffer ); expected_len = ueStrLen( expected ); if ( buffer->check ) { actual_ret = buffer->check( ctx ); expected_ret = !!expected_len; internal_ok( file, line, actual_ret == expected_ret, "actual_ret == expected_ret", "%s check function returned `%d' shall be `%d'", buffer->name, actual_ret, expected_ret ); } if ( buffer->check_alt ) { actual_ret = buffer->check_alt( ctx ); expected_ret = !expected_len; internal_ok( file, line, actual_ret == expected_ret, "actual_ret == expected_ret", "%s check function returned `%d' shall be `%d'", buffer->name, actual_ret, expected_ret ); } if ( buffer->get_length ) { actual_ret = buffer->get_length( ctx ); expected_ret = expected_len; internal_ok( file, line, actual_ret == expected_ret, "actual_ret == expected_ret", "%s get length function returned `%d' shall be `%d'", buffer->name, actual_ret, expected_ret ); } if ( buffer->get_string ) { buf = buffer->get_string( ctx ); internal_ok( file, line, !strcmp( buf, expected ), "!strcmp( buf, expected )", "%s string function returned `%s' shall be `%s'", buffer->name, buf, expected ); chewing_free( buf ); } if ( buffer->get_string_alt ) { buf = buffer->get_string_alt( ctx, &actual_ret ); expected_ret = expected_len; internal_ok( file, line, actual_ret == expected_ret, "actual_ret == expected_ret", "%s string function returned parameter `%d' shall be `%d'", buffer->name, actual_ret, expected_ret ); internal_ok( file, line, !strcmp( buf, expected ), "!strcmp( buf, expected )", "%s string function returned `%s' shall be `%s'", buffer->name, buf, expected ); chewing_free( buf ); } }