OSDN Git Service

implement NG word storing to file methods.
authorornse01 <ornse01@users.sourceforge.jp>
Sat, 15 Jan 2011 11:35:25 +0000 (11:35 +0000)
committerornse01 <ornse01@users.sourceforge.jp>
Sat, 15 Jan 2011 11:35:25 +0000 (11:35 +0000)
git-svn-id: http://svn.sourceforge.jp/svnroot/bchan/bchan/trunk@200 20a0b8eb-f62a-4a12-8fe1-b598822500fb

src/cache.c
src/cache.h
src/test_cache.c

index 0c7852b..384881b 100644 (file)
@@ -35,6 +35,7 @@
 #include    "cache.h"
 #include    "residhash.h"
 #include    "resindexhash.h"
+#include    "wordlist.h"
 
 typedef struct datcache_data_t_ datcache_data_t;
 
@@ -49,6 +50,7 @@ struct datcache_data_t_ {
 #define DATCACHE_FLAG_IDINFOUPDATED 0x00000004
 #define DATCACHE_FLAG_INDEXINFOUPDATED 0x00000008
 #define DATCACHE_FLAG_LATESTHEADERUPDATED 0x00000010
+#define DATCACHE_FLAG_NGWORDINFOUPDATED 0x00000020
 
 struct datcache_t_ {
        UW flag;
@@ -71,6 +73,7 @@ struct datcache_t_ {
        W latestheader_len;
        residhash_t residhash;
        resindexhash_t resindexhash;
+       wordlist_t ngwordlist;
 };
 
 struct datcache_datareadcontext_t_ {
@@ -79,6 +82,10 @@ struct datcache_datareadcontext_t_ {
        W index;
 };
 
+struct datcache_ngwordreadcontext_t_ {
+       wordlist_iterator_t iter;
+};
+
 LOCAL datcache_data_t* datcache_data_next(datcache_data_t *data)
 {
        return (datcache_data_t*)data->queue.next;
@@ -169,6 +176,19 @@ LOCAL Bool datcache_issetindexinfoupdatedflag(datcache_t *cache)
        return True;
 }
 
+LOCAL VOID datcache_setngwordinfoupdatedflag(datcache_t *cache)
+{
+       cache->flag = cache->flag | DATCACHE_FLAG_NGWORDINFOUPDATED;
+}
+
+LOCAL Bool datcache_issetngwordinfoupdatedflag(datcache_t *cache)
+{
+       if ((cache->flag & DATCACHE_FLAG_NGWORDINFOUPDATED) == 0) {
+               return False;
+       }
+       return True;
+}
+
 LOCAL VOID datcache_setlatestheaderupdatedflag(datcache_t *cache)
 {
        cache->flag = cache->flag | DATCACHE_FLAG_LATESTHEADERUPDATED;
@@ -612,6 +632,62 @@ LOCAL W datcache_writefile_resindexhash(datcache_t *cache)
        return 0;
 }
 
+LOCAL W datcache_writefile_ngwordlist(datcache_t *cache)
+{
+       Bool cont, updated, empty;
+       W err;
+       wordlist_iterator_t iter;
+       TC *str;
+       W str_len;
+       UB bin[10];
+
+       updated = datcache_issetngwordinfoupdatedflag(cache);
+       if (updated == False) {
+               return 0;
+       }
+
+       empty = wordlist_isempty(&cache->ngwordlist);
+       if (empty == False) {
+               err = datcache_preparerec_forwritefile(cache->fd, DATCACHE_RECORDTYPE_INFO, DATCACHE_RECORDSUBTYPE_NGWORDINFO, True);
+               if (err < 0) {
+                       wordlist_iterator_finalize(&iter);
+                       return err;
+               }
+
+               wordlist_iterator_initialize(&iter, &cache->ngwordlist);
+               for (;;) {
+                       cont = wordlist_iterator_next(&iter, &str, &str_len);
+                       if (cont == False) {
+                               break;
+                       }
+
+                       *(UH*)bin = str_len * 2;
+                       err = wri_rec(cache->fd, -1, bin, 2, NULL, NULL, 0);
+                       if (err < 0) {
+                               return err;
+                       }
+                       err = wri_rec(cache->fd, -1, (UB*)str, str_len * 2, NULL, NULL, 0);
+                       if (err < 0) {
+                               return err;
+                       }
+                       *(UH*)bin = 2;
+                       *(UH*)(bin + 2) = 0;
+                       err = wri_rec(cache->fd, -1, bin, 4, NULL, NULL, 0);
+                       if (err < 0) {
+                               return err;
+                       }
+               }
+               wordlist_iterator_finalize(&iter);
+       } else {
+               err = datcache_deleterec_forwritefile(cache->fd, DATCACHE_RECORDTYPE_INFO, DATCACHE_RECORDSUBTYPE_NGWORDINFO);
+               if (err < 0) {
+                       return err;
+               }
+       }
+
+       return 0;
+}
+
 LOCAL W datcache_writedat_appended(datcache_t *cache)
 {
        W err, size;
@@ -739,6 +815,10 @@ EXPORT W datcache_writefile(datcache_t *cache)
        if (err < 0) {
                return err;
        }
+       err = datcache_writefile_ngwordlist(cache);
+       if (err < 0) {
+               return err;
+       }
 
        return 0;
 }
@@ -777,6 +857,46 @@ EXPORT VOID datcache_removeresindexdata(datcache_t *cache, W index)
        resindexhash_removedata(&cache->resindexhash, index);
 }
 
+EXPORT W datcache_appendngword(datcache_t *cache, TC *str, W len)
+{
+       datcache_setngwordinfoupdatedflag(cache);
+       return wordlist_appendword(&cache->ngwordlist, str, len);
+}
+
+EXPORT VOID datcache_removengword(datcache_t *cache, TC *str, W len)
+{
+       datcache_setngwordinfoupdatedflag(cache);
+       wordlist_removeword(&cache->ngwordlist, str, len);
+}
+
+EXPORT Bool datcache_checkngwordexist(datcache_t *cache, TC *str, W len)
+{
+       return wordlist_checkexistbyword(&cache->ngwordlist, str, len);
+}
+
+EXPORT datcache_ngwordreadcontext_t* datcache_startngwordread(datcache_t *cache)
+{
+       datcache_ngwordreadcontext_t *context;
+
+       context = malloc(sizeof(datcache_ngwordreadcontext_t));
+       if (context == NULL) {
+               return NULL;
+       }
+       wordlist_iterator_initialize(&context->iter, &cache->ngwordlist);
+       return context;
+}
+
+EXPORT VOID datcache_endngwordread(datcache_t *cache, datcache_ngwordreadcontext_t *context)
+{
+       wordlist_iterator_finalize(&context->iter);
+       free(context);
+}
+
+EXPORT Bool datcache_ngwordreadcontext_nextdata(datcache_ngwordreadcontext_t *context, TC **str, W *len)
+{
+       return wordlist_iterator_next(&context->iter, str, len);
+}
+
 LOCAL W datcache_getrec_fromfile(W fd, W rectype, W subtype, UB **data, W *size)
 {
        W err, size0;
@@ -921,6 +1041,42 @@ LOCAL W datcache_readresindexinfo(datcache_t *cache)
        return err;
 }
 
+LOCAL W datcache_readngwordinfo(datcache_t *cache)
+{
+       UB *recdata;
+       W recsize, err = 0, str_len, i;
+       TC *str;
+       UH chunksize;
+
+       err = datcache_getrec_fromfile(cache->fd, DATCACHE_RECORDTYPE_INFO, DATCACHE_RECORDSUBTYPE_NGWORDINFO, &recdata, &recsize);
+       if (err < 0) {
+               return err;
+       }
+
+       if (recsize == 0) {
+               return 0; /* TODO */
+       }
+
+       for (i = 0; i < recsize; ) {
+               chunksize = *(UH*)(recdata + i);
+               i += 2;
+               str = (TC*)(recdata + i);
+               str_len = chunksize / 2;
+               i += chunksize;
+               chunksize = *(UH*)(recdata + i);
+               i += 2;
+               err = wordlist_appendword(&cache->ngwordlist, str, str_len);
+               if (err < 0) {
+                       break;
+               }
+               i += chunksize;
+       }
+
+       free(recdata);
+
+       return err;
+}
+
 EXPORT datcache_t* datcache_new(VID vid)
 {
        datcache_t *cache;
@@ -1013,9 +1169,21 @@ EXPORT datcache_t* datcache_new(VID vid)
                free(cache);
                return NULL;
        }
+       err = wordlist_initialize(&cache->ngwordlist);
+       if (err < 0) {
+               resindexhash_finalize(&cache->resindexhash);
+               residhash_finalize(&cache->residhash);
+               free(retrinfo);
+               free(rawdat);
+               del_sem(semid);
+               cls_fil(fd);
+               free(cache);
+               return NULL;
+       }
 
        err = datcache_readresidinfo(cache);
        if (err < 0) {
+               wordlist_finalize(&cache->ngwordlist);
                resindexhash_finalize(&cache->resindexhash);
                residhash_finalize(&cache->residhash);
                free(retrinfo);
@@ -1027,6 +1195,19 @@ EXPORT datcache_t* datcache_new(VID vid)
        }
        err = datcache_readresindexinfo(cache);
        if (err < 0) {
+               wordlist_finalize(&cache->ngwordlist);
+               resindexhash_finalize(&cache->resindexhash);
+               residhash_finalize(&cache->residhash);
+               free(retrinfo);
+               free(rawdat);
+               del_sem(semid);
+               cls_fil(fd);
+               free(cache);
+               return NULL;
+       }
+       err = datcache_readngwordinfo(cache);
+       if (err < 0) {
+               wordlist_finalize(&cache->ngwordlist);
                resindexhash_finalize(&cache->resindexhash);
                residhash_finalize(&cache->residhash);
                free(retrinfo);
@@ -1045,6 +1226,7 @@ EXPORT VOID datcache_delete(datcache_t *cache)
        datcache_data_t *cache_data;
        Bool ok;
 
+       wordlist_finalize(&cache->ngwordlist);
        resindexhash_finalize(&cache->resindexhash);
        residhash_finalize(&cache->residhash);
 
index f78dcd7..57010fc 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * cache.h
  *
- * Copyright (c) 2009-2010 project bchan
+ * Copyright (c) 2009-2011 project bchan
  *
  * This software is provided 'as-is', without any express or implied
  * warranty. In no event will the authors be held liable for any damages
@@ -36,6 +36,7 @@
 #define DATCACHE_RECORDSUBTYPE_HEADER 0x0002
 #define DATCACHE_RECORDSUBTYPE_RESIDINFO 0x0003
 #define DATCACHE_RECORDSUBTYPE_RESINDEXINFO 0x0004
+#define DATCACHE_RECORDSUBTYPE_NGWORDINFO 0x0005
 
 #define DATCACHE_RESIDDATA_FLAG_NG    0x00000001
 #define DATCACHE_RESIDDATA_FLAG_COLOR 0x00000002
@@ -44,6 +45,7 @@
 
 typedef struct datcache_t_ datcache_t;
 typedef struct datcache_datareadcontext_t_ datcache_datareadcontext_t;
+typedef struct datcache_ngwordreadcontext_t_ datcache_ngwordreadcontext_t;
 
 IMPORT datcache_t* datcache_new(VID vid);
 IMPORT VOID datcache_delete(datcache_t *cache);
@@ -66,10 +68,17 @@ IMPORT W datcache_addresindexdata(datcache_t *cache, W index, UW attr, COLOR col
 #define DATCACHE_SEARCHRESINDEXDATA_FOUND    1 /* RESINDEXHASH_SEARCHDATA_FOUND */
 IMPORT W datcache_searchresindexdata(datcache_t *cache, W index, UW *attr, COLOR *color);
 IMPORT VOID datcache_removeresindexdata(datcache_t *cache, W index);
+IMPORT W datcache_appendngword(datcache_t *cache, TC *str, W len);
+IMPORT VOID datcache_removengword(datcache_t *cache, TC *str, W len);
+IMPORT Bool datcache_checkngwordexist(datcache_t *cache, TC *str, W len);
 
 IMPORT datcache_datareadcontext_t* datcache_startdataread(datcache_t *cache, W start);
 IMPORT VOID datcache_enddataread(datcache_t *cache, datcache_datareadcontext_t *context);
 
 IMPORT Bool datcache_datareadcontext_nextdata(datcache_datareadcontext_t *context, UB **bin, W *len);
 
+IMPORT datcache_ngwordreadcontext_t* datcache_startngwordread(datcache_t *cache);
+IMPORT VOID datcache_endngwordread(datcache_t *cache, datcache_ngwordreadcontext_t *context);
+IMPORT Bool datcache_ngwordreadcontext_nextdata(datcache_ngwordreadcontext_t *context, TC **str, W *len);
+
 #endif
index 6607555..d564d19 100644 (file)
@@ -3002,6 +3002,601 @@ LOCAL TEST_RESULT test_cache_resindexinfo_7()
        return result;
 }
 
+/* test_cache_ngwordinfo_1 */
+
+LOCAL TEST_RESULT test_cache_ngwordinfo_1()
+{
+       LINK test_lnk;
+       W fd, err;
+       VID vid;
+       datcache_t *cache;
+       UB ngword1[] = "yZXmy7Om0", ngword2[] = "GCQJ44Ao", ngword3[] = "V.jwWEDO";
+       TC ngword1_tc[9], ngword2_tc[8], ngword3_tc[8];
+       W ngword1_len = strlen(ngword1), ngword2_len = strlen(ngword2), ngword3_len = strlen(ngword3);
+       Bool found;
+       TEST_RESULT result = TEST_RESULT_PASS;
+
+       sjstotcs(ngword1_tc, ngword1);
+       sjstotcs(ngword2_tc, ngword2);
+       sjstotcs(ngword3_tc, ngword3);
+
+       fd = test_cache_util_gen_file(&test_lnk, &vid);
+       if (fd < 0) {
+               return TEST_RESULT_FAIL;
+       }
+       cls_fil(fd);
+
+       cache = datcache_new(vid);
+
+       err = datcache_appendngword(cache, ngword1_tc, ngword1_len);
+       if (err < 0) {
+               printf("datcache_appendngword fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       err = datcache_appendngword(cache, ngword2_tc, ngword2_len);
+       if (err < 0) {
+               printf("datcache_appendngword fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       err = datcache_appendngword(cache, ngword3_tc, ngword3_len);
+       if (err < 0) {
+               printf("datcache_appendngword fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+
+       err = datcache_writefile(cache);
+       if (err < 0) {
+               printf("datcache_writefile error\n");
+               datcache_delete(cache);
+               return TEST_RESULT_FAIL;
+       }
+
+       datcache_delete(cache);
+
+       cache = datcache_new(vid);
+
+       found = datcache_checkngwordexist(cache, ngword1_tc, ngword1_len);
+       if (found != True) {
+               printf("datcache_checkngwordexist 1 fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       found = datcache_checkngwordexist(cache, ngword2_tc, ngword2_len);
+       if (found != True) {
+               printf("datcache_checkngwordexist 2 fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       found = datcache_checkngwordexist(cache, ngword3_tc, ngword3_len);
+       if (found != True) {
+               printf("datcache_checkngwordexist 3 fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+
+       datcache_delete(cache);
+
+       err = odel_vob(vid, 0);
+       if (err < 0) {
+               printf("error odel_vob:%d\n", err >> 16);
+               result = TEST_RESULT_FAIL;
+       }
+       err = del_fil(NULL, &test_lnk, 0);
+       if (err < 0) {
+               printf("error del_fil:%d\n", err >> 16);
+               result = TEST_RESULT_FAIL;
+       }
+
+       return result;
+}
+
+/* test_cache_ngwordinfo_2 */
+
+LOCAL TEST_RESULT test_cache_ngwordinfo_2()
+{
+       LINK test_lnk;
+       W fd, err;
+       VID vid;
+       datcache_t *cache;
+       UB ngword1[] = "yZXmy7Om0", ngword2[] = "GCQJ44Ao", ngword3[] = "V.jwWEDO";
+       TC ngword1_tc[9], ngword2_tc[8], ngword3_tc[8];
+       W ngword1_len = strlen(ngword1), ngword2_len = strlen(ngword2), ngword3_len = strlen(ngword3);
+       Bool found;
+       TEST_RESULT result = TEST_RESULT_PASS;
+
+       sjstotcs(ngword1_tc, ngword1);
+       sjstotcs(ngword2_tc, ngword2);
+       sjstotcs(ngword3_tc, ngword3);
+
+       fd = test_cache_util_gen_file(&test_lnk, &vid);
+       if (fd < 0) {
+               return TEST_RESULT_FAIL;
+       }
+       cls_fil(fd);
+
+       cache = datcache_new(vid);
+
+       err = datcache_appendngword(cache, ngword1_tc, ngword1_len);
+       if (err < 0) {
+               printf("datcache_addresiddata fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       err = datcache_appendngword(cache, ngword2_tc, ngword2_len);
+       if (err < 0) {
+               printf("datcache_addresiddata fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+
+       err = datcache_writefile(cache);
+       if (err < 0) {
+               printf("datcache_writefile error\n");
+               datcache_delete(cache);
+               return TEST_RESULT_FAIL;
+       }
+
+       datcache_delete(cache);
+
+       cache = datcache_new(vid);
+
+       found = datcache_checkngwordexist(cache, ngword1_tc, ngword1_len);
+       if (found != True) {
+               printf("datcache_checkngwordexist 1 fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       found = datcache_checkngwordexist(cache, ngword2_tc, ngword2_len);
+       if (found != True) {
+               printf("datcache_checkngwordexist 2 fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       found = datcache_checkngwordexist(cache, ngword3_tc, ngword3_len);
+       if (found != False) {
+               printf("datcache_checkngwordexist 3 fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+
+       datcache_delete(cache);
+
+       err = odel_vob(vid, 0);
+       if (err < 0) {
+               printf("error odel_vob:%d\n", err >> 16);
+               result = TEST_RESULT_FAIL;
+       }
+       err = del_fil(NULL, &test_lnk, 0);
+       if (err < 0) {
+               printf("error del_fil:%d\n", err >> 16);
+               result = TEST_RESULT_FAIL;
+       }
+
+       return result;
+}
+
+/* test_cache_ngwordinfo_3 */
+
+LOCAL TEST_RESULT test_cache_ngwordinfo_3()
+{
+       LINK test_lnk;
+       W fd, err;
+       VID vid;
+       datcache_t *cache;
+       UB ngword1[] = "yZXmy7Om0", ngword2[] = "GCQJ44Ao", ngword3[] = "V.jwWEDO";
+       TC ngword1_tc[9], ngword2_tc[8], ngword3_tc[8];
+       W ngword1_len = strlen(ngword1), ngword2_len = strlen(ngword2), ngword3_len = strlen(ngword3);
+       Bool found;
+       TEST_RESULT result = TEST_RESULT_PASS;
+
+       sjstotcs(ngword1_tc, ngword1);
+       sjstotcs(ngword2_tc, ngword2);
+       sjstotcs(ngword3_tc, ngword3);
+
+       fd = test_cache_util_gen_file(&test_lnk, &vid);
+       if (fd < 0) {
+               return TEST_RESULT_FAIL;
+       }
+       cls_fil(fd);
+
+       cache = datcache_new(vid);
+
+       err = datcache_appendngword(cache, ngword1_tc, ngword1_len);
+       if (err < 0) {
+               printf("datcache_appendngword fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+
+       err = datcache_writefile(cache);
+       if (err < 0) {
+               printf("datcache_writefile error\n");
+               datcache_delete(cache);
+               return TEST_RESULT_FAIL;
+       }
+
+       datcache_delete(cache);
+
+       cache = datcache_new(vid);
+
+       found = datcache_checkngwordexist(cache, ngword1_tc, ngword1_len);
+       if (found != True) {
+               printf("datcache_checkngwordexist 1 fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       found = datcache_checkngwordexist(cache, ngword2_tc, ngword2_len);
+       if (found != False) {
+               printf("datcache_checkngwordexist 2 fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       found = datcache_checkngwordexist(cache, ngword3_tc, ngword3_len);
+       if (found != False) {
+               printf("datcache_checkngwordexist 3 fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+
+       datcache_delete(cache);
+
+       err = odel_vob(vid, 0);
+       if (err < 0) {
+               printf("error odel_vob:%d\n", err >> 16);
+               result = TEST_RESULT_FAIL;
+       }
+       err = del_fil(NULL, &test_lnk, 0);
+       if (err < 0) {
+               printf("error del_fil:%d\n", err >> 16);
+               result = TEST_RESULT_FAIL;
+       }
+
+       return result;
+}
+
+/* test_cache_ngwordinfo_4 */
+
+LOCAL TEST_RESULT test_cache_ngwordinfo_4()
+{
+       LINK test_lnk;
+       W fd, err;
+       VID vid;
+       datcache_t *cache;
+       UB ngword1[] = "yZXmy7Om0", ngword2[] = "GCQJ44Ao", ngword3[] = "V.jwWEDO";
+       TC ngword1_tc[9], ngword2_tc[8], ngword3_tc[8];
+       W ngword1_len = strlen(ngword1), ngword2_len = strlen(ngword2), ngword3_len = strlen(ngword3);
+       Bool found;
+       TEST_RESULT result = TEST_RESULT_PASS;
+
+       sjstotcs(ngword1_tc, ngword1);
+       sjstotcs(ngword2_tc, ngword2);
+       sjstotcs(ngword3_tc, ngword3);
+
+       fd = test_cache_util_gen_file(&test_lnk, &vid);
+       if (fd < 0) {
+               return TEST_RESULT_FAIL;
+       }
+       cls_fil(fd);
+
+       cache = datcache_new(vid);
+
+       err = datcache_writefile(cache);
+       if (err < 0) {
+               printf("datcache_writefile error\n");
+               datcache_delete(cache);
+               return TEST_RESULT_FAIL;
+       }
+
+       datcache_delete(cache);
+
+       cache = datcache_new(vid);
+
+       found = datcache_checkngwordexist(cache, ngword1_tc, ngword1_len);
+       if (found != False) {
+               printf("datcache_checkngwordexist 1 fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       found = datcache_checkngwordexist(cache, ngword2_tc, ngword2_len);
+       if (found != False) {
+               printf("datcache_checkngwordexist 2 fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       found = datcache_checkngwordexist(cache, ngword3_tc, ngword3_len);
+       if (found != False) {
+               printf("datcache_checkngwordexist 3 fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+
+       datcache_delete(cache);
+
+       err = odel_vob(vid, 0);
+       if (err < 0) {
+               printf("error odel_vob:%d\n", err >> 16);
+               result = TEST_RESULT_FAIL;
+       }
+       err = del_fil(NULL, &test_lnk, 0);
+       if (err < 0) {
+               printf("error del_fil:%d\n", err >> 16);
+               result = TEST_RESULT_FAIL;
+       }
+
+       return result;
+}
+
+/* test_cache_ngwordinfo_5 */
+
+LOCAL TEST_RESULT test_cache_ngwordinfo_5()
+{
+       LINK test_lnk;
+       W fd, err;
+       VID vid;
+       datcache_t *cache;
+       UB ngword1[] = "yZXmy7Om0", ngword2[] = "GCQJ44Ao", ngword3[] = "V.jwWEDO";
+       TC ngword1_tc[9], ngword2_tc[8], ngword3_tc[8];
+       W ngword1_len = strlen(ngword1), ngword2_len = strlen(ngword2), ngword3_len = strlen(ngword3);
+       Bool found;
+       TEST_RESULT result = TEST_RESULT_PASS;
+
+       sjstotcs(ngword1_tc, ngword1);
+       sjstotcs(ngword2_tc, ngword2);
+       sjstotcs(ngword3_tc, ngword3);
+
+       fd = test_cache_util_gen_file(&test_lnk, &vid);
+       if (fd < 0) {
+               return TEST_RESULT_FAIL;
+       }
+       cls_fil(fd);
+
+       cache = datcache_new(vid);
+
+       err = datcache_appendngword(cache, ngword1_tc, ngword1_len);
+       if (err < 0) {
+               printf("datcache_appendngword fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       err = datcache_appendngword(cache, ngword2_tc, ngword2_len);
+       if (err < 0) {
+               printf("datcache_appendngword fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       err = datcache_appendngword(cache, ngword3_tc, ngword3_len);
+       if (err < 0) {
+               printf("datcache_appendngword fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+
+       err = datcache_writefile(cache);
+       if (err < 0) {
+               printf("datcache_writefile error\n");
+               datcache_delete(cache);
+               return TEST_RESULT_FAIL;
+       }
+
+       datcache_delete(cache);
+
+       cache = datcache_new(vid);
+       datcache_removengword(cache, ngword3_tc, ngword3_len);
+       err = datcache_writefile(cache);
+       if (err < 0) {
+               printf("datcache_writefile error\n");
+               datcache_delete(cache);
+               return TEST_RESULT_FAIL;
+       }
+       datcache_delete(cache);
+
+       cache = datcache_new(vid);
+
+       found = datcache_checkngwordexist(cache, ngword1_tc, ngword1_len);
+       if (found != True) {
+               printf("datcache_checkngwordexist 1 fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       found = datcache_checkngwordexist(cache, ngword2_tc, ngword2_len);
+       if (found != True) {
+               printf("datcache_checkngwordexist 2 fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       found = datcache_checkngwordexist(cache, ngword3_tc, ngword3_len);
+       if (found != False) {
+               printf("datcache_checkngwordexist 3 fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+
+       datcache_delete(cache);
+
+       err = odel_vob(vid, 0);
+       if (err < 0) {
+               printf("error odel_vob:%d\n", err >> 16);
+               result = TEST_RESULT_FAIL;
+       }
+       err = del_fil(NULL, &test_lnk, 0);
+       if (err < 0) {
+               printf("error del_fil:%d\n", err >> 16);
+               result = TEST_RESULT_FAIL;
+       }
+
+       return result;
+}
+
+/* test_cache_ngwordinfo_6 */
+
+LOCAL TEST_RESULT test_cache_ngwordinfo_6()
+{
+       LINK test_lnk;
+       W fd, err;
+       VID vid;
+       datcache_t *cache;
+       UB ngword1[] = "yZXmy7Om0", ngword2[] = "GCQJ44Ao", ngword3[] = "V.jwWEDO";
+       TC ngword1_tc[9], ngword2_tc[8], ngword3_tc[8];
+       W ngword1_len = strlen(ngword1), ngword2_len = strlen(ngword2), ngword3_len = strlen(ngword3);
+       Bool found;
+       TEST_RESULT result = TEST_RESULT_PASS;
+
+       sjstotcs(ngword1_tc, ngword1);
+       sjstotcs(ngword2_tc, ngword2);
+       sjstotcs(ngword3_tc, ngword3);
+
+       fd = test_cache_util_gen_file(&test_lnk, &vid);
+       if (fd < 0) {
+               return TEST_RESULT_FAIL;
+       }
+       cls_fil(fd);
+
+       cache = datcache_new(vid);
+       err = datcache_appendngword(cache, ngword1_tc, ngword1_len);
+       if (err < 0) {
+               printf("datcache_appendngword fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       err = datcache_appendngword(cache, ngword2_tc, ngword2_len);
+       if (err < 0) {
+               printf("datcache_appendngword fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       err = datcache_appendngword(cache, ngword3_tc, ngword3_len);
+       if (err < 0) {
+               printf("datcache_appendngword fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+
+       err = datcache_writefile(cache);
+       if (err < 0) {
+               printf("datcache_writefile error\n");
+               datcache_delete(cache);
+               return TEST_RESULT_FAIL;
+       }
+
+       datcache_delete(cache);
+
+       cache = datcache_new(vid);
+       datcache_removengword(cache, ngword2_tc, ngword2_len);
+       datcache_removengword(cache, ngword3_tc, ngword3_len);
+       err = datcache_writefile(cache);
+       if (err < 0) {
+               printf("datcache_writefile error\n");
+               datcache_delete(cache);
+               return TEST_RESULT_FAIL;
+       }
+       datcache_delete(cache);
+
+       cache = datcache_new(vid);
+
+       found = datcache_checkngwordexist(cache, ngword1_tc, ngword1_len);
+       if (found != True) {
+               printf("datcache_checkngwordexist 1 fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       found = datcache_checkngwordexist(cache, ngword2_tc, ngword2_len);
+       if (found != False) {
+               printf("datcache_checkngwordexist 2 fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       found = datcache_checkngwordexist(cache, ngword3_tc, ngword3_len);
+       if (found != False) {
+               printf("datcache_checkngwordexist 3 fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+
+       datcache_delete(cache);
+
+       err = odel_vob(vid, 0);
+       if (err < 0) {
+               printf("error odel_vob:%d\n", err >> 16);
+               result = TEST_RESULT_FAIL;
+       }
+       err = del_fil(NULL, &test_lnk, 0);
+       if (err < 0) {
+               printf("error del_fil:%d\n", err >> 16);
+               result = TEST_RESULT_FAIL;
+       }
+
+       return result;
+}
+
+/* test_cache_ngwordinfo_7 */
+
+LOCAL TEST_RESULT test_cache_ngwordinfo_7()
+{
+       LINK test_lnk;
+       W fd, err;
+       VID vid;
+       datcache_t *cache;
+       UB ngword1[] = "yZXmy7Om0", ngword2[] = "GCQJ44Ao", ngword3[] = "V.jwWEDO";
+       TC ngword1_tc[9], ngword2_tc[8], ngword3_tc[8];
+       W ngword1_len = strlen(ngword1), ngword2_len = strlen(ngword2), ngword3_len = strlen(ngword3);
+       Bool found;
+       TEST_RESULT result = TEST_RESULT_PASS;
+
+       sjstotcs(ngword1_tc, ngword1);
+       sjstotcs(ngword2_tc, ngword2);
+       sjstotcs(ngword3_tc, ngword3);
+
+       fd = test_cache_util_gen_file(&test_lnk, &vid);
+       if (fd < 0) {
+               return TEST_RESULT_FAIL;
+       }
+       cls_fil(fd);
+
+       cache = datcache_new(vid);
+       err = datcache_appendngword(cache, ngword1_tc, ngword1_len);
+       if (err < 0) {
+               printf("datcache_appendngword fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       err = datcache_appendngword(cache, ngword2_tc, ngword2_len);
+       if (err < 0) {
+               printf("datcache_appendngword fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       err = datcache_appendngword(cache, ngword3_tc, ngword3_len);
+       if (err < 0) {
+               printf("datcache_appendngword fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+
+       err = datcache_writefile(cache);
+       if (err < 0) {
+               printf("datcache_writefile error\n");
+               datcache_delete(cache);
+               return TEST_RESULT_FAIL;
+       }
+
+       datcache_delete(cache);
+
+       cache = datcache_new(vid);
+       datcache_removengword(cache, ngword1_tc, ngword1_len);
+       datcache_removengword(cache, ngword2_tc, ngword2_len);
+       datcache_removengword(cache, ngword3_tc, ngword3_len);
+       err = datcache_writefile(cache);
+       if (err < 0) {
+               printf("datcache_writefile error\n");
+               datcache_delete(cache);
+               return TEST_RESULT_FAIL;
+       }
+       datcache_delete(cache);
+
+       cache = datcache_new(vid);
+
+       found = datcache_checkngwordexist(cache, ngword1_tc, ngword1_len);
+       if (found != False) {
+               printf("datcache_checkngwordexist 1 fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       found = datcache_checkngwordexist(cache, ngword2_tc, ngword2_len);
+       if (found != False) {
+               printf("datcache_checkngwordexist 2 fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       found = datcache_checkngwordexist(cache, ngword3_tc, ngword3_len);
+       if (found != False) {
+               printf("datcache_checkngwordexist 3 fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+
+       datcache_delete(cache);
+
+       err = odel_vob(vid, 0);
+       if (err < 0) {
+               printf("error odel_vob:%d\n", err >> 16);
+               result = TEST_RESULT_FAIL;
+       }
+       err = del_fil(NULL, &test_lnk, 0);
+       if (err < 0) {
+               printf("error del_fil:%d\n", err >> 16);
+               result = TEST_RESULT_FAIL;
+       }
+
+       return result;
+}
+
 LOCAL VOID test_cache_printresult(TEST_RESULT (*proc)(), B *test_name)
 {
        TEST_RESULT result;
@@ -3048,6 +3643,13 @@ IMPORT VOID test_cache_main()
        test_cache_printresult(test_cache_resindexinfo_5, "test_cache_resindexinfo_5");
        test_cache_printresult(test_cache_resindexinfo_6, "test_cache_resindexinfo_6");
        test_cache_printresult(test_cache_resindexinfo_7, "test_cache_resindexinfo_7");
+       test_cache_printresult(test_cache_ngwordinfo_1, "test_cache_ngwordinfo_1");
+       test_cache_printresult(test_cache_ngwordinfo_2, "test_cache_ngwordinfo_2");
+       test_cache_printresult(test_cache_ngwordinfo_3, "test_cache_ngwordinfo_3");
+       test_cache_printresult(test_cache_ngwordinfo_4, "test_cache_ngwordinfo_4");
+       test_cache_printresult(test_cache_ngwordinfo_5, "test_cache_ngwordinfo_5");
+       test_cache_printresult(test_cache_ngwordinfo_6, "test_cache_ngwordinfo_6");
+       test_cache_printresult(test_cache_ngwordinfo_7, "test_cache_ngwordinfo_7");
        test_cache_printresult(test_cache_append_1, "test_cache_append_1");
        test_cache_printresult(test_cache_append_2, "test_cache_append_2");
        test_cache_printresult(test_cache_append_3, "test_cache_append_3");