summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2011-08-24 10:41:12 +0800
committerPeng Wu <alexepico@gmail.com>2011-08-24 10:41:12 +0800
commitc0a3bc04c7963f8a53447acec77497f28646fdf9 (patch)
tree4601fb303a847e8bd786f9012cfedf3ee1954b8f /tests
parent51b8bf1f01b64cb8c22dd25e9ac636b80ba8cd18 (diff)
downloadlibpinyin-c0a3bc04c7963f8a53447acec77497f28646fdf9.tar.gz
libpinyin-c0a3bc04c7963f8a53447acec77497f28646fdf9.tar.xz
libpinyin-c0a3bc04c7963f8a53447acec77497f28646fdf9.zip
refine test cases
Diffstat (limited to 'tests')
-rw-r--r--tests/lookup/test_simple_lookup.cpp8
-rw-r--r--tests/test_pinyin.cpp10
2 files changed, 13 insertions, 5 deletions
diff --git a/tests/lookup/test_simple_lookup.cpp b/tests/lookup/test_simple_lookup.cpp
index 6a2ebcf..b58f248 100644
--- a/tests/lookup/test_simple_lookup.cpp
+++ b/tests/lookup/test_simple_lookup.cpp
@@ -54,8 +54,12 @@ int main( int argc, char * argv[]){
char* linebuf = NULL;
size_t size = 0;
- while( getline(&linebuf, &size, stdin) ){
- linebuf[strlen(linebuf)-1] = '\0';
+ ssize_t read;
+ while( (read = getline(&linebuf, &size, stdin)) != -1 ){
+ if ( '\n' == linebuf[strlen(linebuf) - 1] ) {
+ linebuf[strlen(linebuf) - 1] = '\0';
+ }
+
if ( strcmp ( linebuf, "quit" ) == 0)
break;
diff --git a/tests/test_pinyin.cpp b/tests/test_pinyin.cpp
index ee8f9d2..d335f77 100644
--- a/tests/test_pinyin.cpp
+++ b/tests/test_pinyin.cpp
@@ -31,9 +31,13 @@ int main(int argc, char * argv[]){
char* linebuf = NULL;
size_t size = 0;
- while( getline(&linebuf, &size, stdin) ){
- linebuf[strlen(linebuf)-1] = '\0';
- if ( strcmp ( linebuf, "quit" ) == 0)
+ ssize_t read;
+ while( (read = getline(&linebuf, &size, stdin)) != -1 ){
+ if ( '\n' == linebuf[strlen(linebuf) - 1] ) {
+ linebuf[strlen(linebuf) - 1] = '\0';
+ }
+
+ if ( strcmp ( linebuf, "quit" ) == 0)
break;
pinyin_parse_more_fulls(context, linebuf, pinyin_keys);