summaryrefslogtreecommitdiffstats
path: root/tests/storage
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2012-09-04 12:32:15 +0800
committerPeng Wu <alexepico@gmail.com>2012-09-04 12:32:15 +0800
commit9569248cb69d52a57cbb227c9312953545cea35a (patch)
treecc7f0b28ad2b423c88c99e5a03990bf4c53e21e1 /tests/storage
parente5cd53d3416a500480db25c2363eabf6877ec67a (diff)
downloadlibpinyin-9569248cb69d52a57cbb227c9312953545cea35a.tar.gz
libpinyin-9569248cb69d52a57cbb227c9312953545cea35a.tar.xz
libpinyin-9569248cb69d52a57cbb227c9312953545cea35a.zip
enhance test_phrase_table.cpp
Diffstat (limited to 'tests/storage')
-rw-r--r--tests/storage/test_phrase_table.cpp24
1 files changed, 16 insertions, 8 deletions
diff --git a/tests/storage/test_phrase_table.cpp b/tests/storage/test_phrase_table.cpp
index 706d6bf..c657192 100644
--- a/tests/storage/test_phrase_table.cpp
+++ b/tests/storage/test_phrase_table.cpp
@@ -25,14 +25,13 @@ int main(int argc, char * argv[]){
glong phrase_len = g_utf8_strlen(linebuf, -1);
ucs4_t * new_phrase = g_utf8_to_ucs4(linebuf, -1, NULL, NULL, NULL);
- phrase_token_t token = null_token;
PhraseTokens tokens;
memset(tokens, 0, sizeof(PhraseTokens));
phrase_index.prepare_tokens(tokens);
guint32 start = record_time();
- for ( size_t i = 0; i < bench_times; ++i){
+ for (size_t i = 0; i < bench_times; ++i){
phrase_index.clear_tokens(tokens);
largetable.search(phrase_len, new_phrase, tokens);
}
@@ -40,15 +39,24 @@ int main(int argc, char * argv[]){
phrase_index.clear_tokens(tokens);
int retval = largetable.search(phrase_len, new_phrase, tokens);
- int num = get_first_token(tokens, token);
- phrase_index.destroy_tokens(tokens);
+ if (retval & SEARCH_OK) {
+ for (size_t i = 0; i < PHRASE_INDEX_LIBRARY_COUNT; ++i) {
+ GArray * array = tokens[i];
+ if (NULL == array)
+ continue;
+
+ for (size_t k = 0; k < array->len; ++k) {
+ phrase_token_t token = g_array_index
+ (array, phrase_token_t, k);
- if ( retval & SEARCH_OK )
- printf("%s: num:%d token:%d\n", linebuf, num, token);
- else
- printf("phrase %s not found.\n", linebuf);
+ printf("token:%d\t", token);
+ }
+ }
+ printf("\n");
+ }
+ phrase_index.destroy_tokens(tokens);
g_free(new_phrase);
}