From 57f546f6562c1815fe84816c8ed7a2179f5a9b39 Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Tue, 4 Sep 2012 13:41:03 +0800 Subject: update test cases --- tests/storage/test_chewing_table.cpp | 9 ++++++--- tests/storage/test_phrase_table.cpp | 13 +++++++++---- 2 files changed, 15 insertions(+), 7 deletions(-) (limited to 'tests/storage') diff --git a/tests/storage/test_chewing_table.cpp b/tests/storage/test_chewing_table.cpp index b65b20f..cae766d 100644 --- a/tests/storage/test_chewing_table.cpp +++ b/tests/storage/test_chewing_table.cpp @@ -38,9 +38,12 @@ int main(int argc, char * argv[]) { largetable.store(new_chunk); largetable.load(new_chunk); - char* linebuf = NULL; size_t size = 0; - while( getline(&linebuf, &size, stdin) ){ - linebuf[strlen(linebuf)-1] = '\0'; + char* linebuf = NULL; size_t size = 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/storage/test_phrase_table.cpp b/tests/storage/test_phrase_table.cpp index c657192..eb24382 100644 --- a/tests/storage/test_phrase_table.cpp +++ b/tests/storage/test_phrase_table.cpp @@ -16,16 +16,21 @@ int main(int argc, char * argv[]){ largetable.store(chunk); largetable.load(chunk); - char * linebuf = NULL; - size_t size = 0; - while( getline(&linebuf, &size, stdin) ){ - linebuf[strlen(linebuf) - 1] = '\0'; + char* linebuf = NULL; size_t size = 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; glong phrase_len = g_utf8_strlen(linebuf, -1); ucs4_t * new_phrase = g_utf8_to_ucs4(linebuf, -1, NULL, NULL, NULL); + if (0 == phrase_len) + continue; + PhraseTokens tokens; memset(tokens, 0, sizeof(PhraseTokens)); phrase_index.prepare_tokens(tokens); -- cgit