#include "cache.h"
#include "residhash.h"
#include "resindexhash.h"
+#include "wordlist.h"
typedef struct datcache_data_t_ 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;
W latestheader_len;
residhash_t residhash;
resindexhash_t resindexhash;
+ wordlist_t ngwordlist;
};
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;
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;
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;
if (err < 0) {
return err;
}
+ err = datcache_writefile_ngwordlist(cache);
+ if (err < 0) {
+ return err;
+ }
return 0;
}
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;
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;
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);
}
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);
datcache_data_t *cache_data;
Bool ok;
+ wordlist_finalize(&cache->ngwordlist);
resindexhash_finalize(&cache->resindexhash);
residhash_finalize(&cache->residhash);
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;
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");