summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2012-03-05 16:14:20 +0800
committerPeng Wu <alexepico@gmail.com>2012-03-05 16:24:20 +0800
commit5f3b3345937e33438fb505635f2543038fc30cba (patch)
tree0452b91878f21d84381c696708b25ccdaa743ac2 /tests
parentda7323a57cb89ca385676b9566f5b70e4a42e1a3 (diff)
downloadlibpinyin-5f3b3345937e33438fb505635f2543038fc30cba.tar.gz
libpinyin-5f3b3345937e33438fb505635f2543038fc30cba.tar.xz
libpinyin-5f3b3345937e33438fb505635f2543038fc30cba.zip
update test_pinyin.cpp
Diffstat (limited to 'tests')
-rw-r--r--tests/test_pinyin.cpp26
1 files changed, 20 insertions, 6 deletions
diff --git a/tests/test_pinyin.cpp b/tests/test_pinyin.cpp
index f965bdf..afde14f 100644
--- a/tests/test_pinyin.cpp
+++ b/tests/test_pinyin.cpp
@@ -30,19 +30,33 @@ int main(int argc, char * argv[]){
pinyin_instance_t * instance = pinyin_alloc_instance(context);
- char* linebuf = NULL;
- size_t size = 0;
+ char * linebuf = NULL; char * prefixbuf = NULL;
+ size_t linesize = 0; size_t prefixsize = 0;
ssize_t read;
- while( (read = getline(&linebuf, &size, stdin)) != -1 ){
+
+ while( TRUE ){
+ fprintf(stdout, "prefix:");
+ fflush(stdout);
+
+ if ((read = getline(&prefixbuf, &prefixsize, stdin)) == -1)
+ break;
+
+ if ( '\n' == prefixbuf[strlen(prefixbuf) - 1] ) {
+ prefixbuf[strlen(prefixbuf) - 1] = '\0';
+ }
+
+ if ((read = getline(&linebuf, &linesize, stdin)) == -1)
+ break;
+
if ( '\n' == linebuf[strlen(linebuf) - 1] ) {
linebuf[strlen(linebuf) - 1] = '\0';
}
if ( strcmp ( linebuf, "quit" ) == 0)
break;
-
+
pinyin_parse_more_full_pinyins(instance, linebuf);
- pinyin_guess_sentence(instance);
+ pinyin_guess_sentence_with_prefix(instance, prefixbuf);
char * sentence = NULL;
pinyin_get_sentence (instance, &sentence);
@@ -57,6 +71,6 @@ int main(int argc, char * argv[]){
pinyin_free_instance(instance);
pinyin_fini(context);
- free(linebuf);
+ free(prefixbuf); free(linebuf);
return 0;
}