update test cases
authorPeng Wu <alexepico@gmail.com>
Tue, 4 Sep 2012 05:41:03 +0000 (13:41 +0800)
committerPeng Wu <alexepico@gmail.com>
Tue, 4 Sep 2012 05:41:03 +0000 (13:41 +0800)
tests/storage/test_chewing_table.cpp
tests/storage/test_phrase_table.cpp

index b65b20f..cae766d 100644 (file)
@@ -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;
 
index c657192..eb24382 100644 (file)
@@ -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);