summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2011-08-23 18:36:30 +0800
committerPeng Wu <alexepico@gmail.com>2011-08-23 18:36:30 +0800
commit40c82f591553e94f21816b2d940aab1d47f2b3d3 (patch)
tree91653cacc4690ca15a1de77548b5df9e3b3a0eec /tests
parentc108fa57f1e265a6682c9fdb267e7b2c1653a401 (diff)
downloadlibpinyin-40c82f591553e94f21816b2d940aab1d47f2b3d3.tar.gz
libpinyin-40c82f591553e94f21816b2d940aab1d47f2b3d3.tar.xz
libpinyin-40c82f591553e94f21816b2d940aab1d47f2b3d3.zip
write test pinyin
Diffstat (limited to 'tests')
-rw-r--r--tests/lookup/test_simple_lookup.cpp4
-rw-r--r--tests/test_pinyin.cpp28
2 files changed, 30 insertions, 2 deletions
diff --git a/tests/lookup/test_simple_lookup.cpp b/tests/lookup/test_simple_lookup.cpp
index 96c512a..6a2ebcf 100644
--- a/tests/lookup/test_simple_lookup.cpp
+++ b/tests/lookup/test_simple_lookup.cpp
@@ -52,8 +52,8 @@ int main( int argc, char * argv[]){
PinyinLookup pinyin_lookup(&custom, &largetable, &phrase_index,
&system_bigram, &user_bigram);
- char* linebuf = (char *)malloc ( 1024 * sizeof (char) );
- size_t size = 1024;
+ char* linebuf = NULL;
+ size_t size = 0;
while( getline(&linebuf, &size, stdin) ){
linebuf[strlen(linebuf)-1] = '\0';
if ( strcmp ( linebuf, "quit" ) == 0)
diff --git a/tests/test_pinyin.cpp b/tests/test_pinyin.cpp
index 2212534..ee8f9d2 100644
--- a/tests/test_pinyin.cpp
+++ b/tests/test_pinyin.cpp
@@ -23,5 +23,33 @@
#include "pinyin.h"
int main(int argc, char * argv[]){
+ pinyin_context_t * context =
+ pinyin_init("../data", "../data");
+
+ PinyinKeyVector pinyin_keys =
+ g_array_new(FALSE, FALSE, sizeof(PinyinKey));
+
+ char* linebuf = NULL;
+ size_t size = 0;
+ while( getline(&linebuf, &size, stdin) ){
+ linebuf[strlen(linebuf)-1] = '\0';
+ if ( strcmp ( linebuf, "quit" ) == 0)
+ break;
+
+ pinyin_parse_more_fulls(context, linebuf, pinyin_keys);
+ pinyin_set_pinyin_keys(context, pinyin_keys);
+ char * sentence = NULL;
+ pinyin_get_guessed_sentence(context, &sentence);
+ printf("%s\n", sentence);
+ g_free(sentence);
+
+ pinyin_train(context);
+ pinyin_reset(context);
+ pinyin_save(context);
+ }
+
+ pinyin_fini(context);
+ g_array_free(pinyin_keys, TRUE);
+ free(linebuf);
return 0;
}