OSDN Git Service

implement saving and loading residinfo.
authorornse01 <ornse01@users.sourceforge.jp>
Sun, 30 May 2010 13:03:35 +0000 (13:03 +0000)
committerornse01 <ornse01@users.sourceforge.jp>
Sun, 30 May 2010 13:03:35 +0000 (13:03 +0000)
git-svn-id: http://svn.sourceforge.jp/svnroot/bchan/bchan/trunk@119 20a0b8eb-f62a-4a12-8fe1-b598822500fb

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

index 7f8ea2d..a450f75 100644 (file)
@@ -363,11 +363,81 @@ LOCAL W datcache_preparerec_forwritefile(W fd, W rectype, W subtype)
        return 0; /* TODO */
 }
 
+LOCAL W datcache_deleterec_forwritefile(W fd, W rectype, W subtype)
+{
+       W err;
+
+       err = fnd_rec(fd, F_TOPEND, 1 << rectype, subtype, NULL);
+       if (err == ER_REC) {
+               return 0; /* TODO */
+       } else if (err < 0) {
+               return -1; /* TODO */
+       }
+
+       err = del_rec(fd);
+       if (err < 0) {
+               return -1; /* TODO */
+       }
+
+       return 0; /* TODO */
+}
+
 EXPORT W datcache_datasize(datcache_t *cache)
 {
        return cache->s_datsize;
 }
 
+LOCAL W datcache_writefile_residhash(datcache_t *cache)
+{
+       Bool cont;
+       W err, len;
+       residhash_iterator_t iter;
+       TC *idstr;
+       W idstr_len;
+       UW attr;
+       COLOR color;
+       UB bin[10];
+
+       len = residhash_datanum(&cache->residhash);
+       if (len > 0) {
+               err = datcache_preparerec_forwritefile(cache->fd, DATCACHE_RECORDTYPE_INFO, DATCACHE_RECORDSUBTYPE_RESIDINFO);
+               if (err < 0) {
+                       return err;
+               }
+               residhash_iterator_initialize(&iter, &cache->residhash);
+               for (;;) {
+                       cont = residhash_iterator_next(&iter, &idstr, &idstr_len, &attr, &color);
+                       if (cont == False) {
+                               break;
+                       }
+                       *(UH*)bin = idstr_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*)idstr, idstr_len * 2, NULL, NULL, 0);
+                       if (err < 0) {
+                               return err;
+                       }
+                       *(UH*)bin = 8;
+                       *(UW*)(bin + 2) = attr;
+                       *(COLOR*)(bin + 2 + 4) = color;
+                       err = wri_rec(cache->fd, -1, bin, 10, NULL, NULL, 0);
+                       if (err < 0) {
+                               return err;
+                       }
+               }
+               residhash_iterator_finalize(&iter);
+       } else {
+               err = datcache_deleterec_forwritefile(cache->fd, DATCACHE_RECORDTYPE_INFO, DATCACHE_RECORDSUBTYPE_RESIDINFO);
+               if (err < 0) {
+                       return err;
+               }
+       }
+
+       return 0;
+}
+
 EXPORT W datcache_writefile(datcache_t *cache)
 {
        W err;
@@ -403,6 +473,11 @@ EXPORT W datcache_writefile(datcache_t *cache)
                }
        }
 
+       err = datcache_writefile_residhash(cache);
+       if (err < 0) {
+               return err;
+       }
+
        return 0;
 }
 
@@ -475,6 +550,52 @@ LOCAL W datcache_getheader_fromfile(W fd, UB **data, W *size)
        return datcache_getrec_fromfile(fd, DATCACHE_RECORDTYPE_INFO, DATCACHE_RECORDSUBTYPE_HEADER, data, size);
 }
 
+LOCAL W datcache_readresidinfo(datcache_t *cache)
+{
+       UB *recdata;
+       W recsize, err = 0, idstr_len, i;
+       TC *idstr;
+       UW attr;
+       COLOR color;
+       UH chunksize;
+
+       err = datcache_getrec_fromfile(cache->fd, DATCACHE_RECORDTYPE_INFO, DATCACHE_RECORDSUBTYPE_RESIDINFO, &recdata, &recsize);
+       if (err < 0) {
+               return err;
+       }
+
+       if (recsize == 0) {
+               return 0; /* TODO */
+       }
+
+       for (i = 0; i < recsize; ) {
+               chunksize = *(UH*)(recdata + i);
+               i += 2;
+               idstr = (TC*)(recdata + i);
+               idstr_len = chunksize / 2;
+               i += chunksize;
+               chunksize = *(UH*)(recdata + i);
+               i += 2;
+               if (chunksize >= 4) {
+                       attr = *(UW*)(recdata + i);
+                       if (chunksize >= 8) {
+                               color = *(COLOR*)(recdata + i + 4);
+                       } else {
+                               color = -1;
+                       }
+                       err = residhash_adddata(&cache->residhash, idstr, idstr_len, attr, color);
+                       if (err < 0) {
+                               break;
+                       }
+               }
+               i += chunksize;
+       }
+
+       free(recdata);
+
+       return err;
+}
+
 EXPORT datcache_t* datcache_new(VID vid)
 {
        datcache_t *cache;
@@ -549,6 +670,16 @@ EXPORT datcache_t* datcache_new(VID vid)
                free(cache);
                return NULL;
        }
+       err = datcache_readresidinfo(cache);
+       if (err < 0) {
+               residhash_finalize(&cache->residhash);
+               free(retrinfo);
+               free(rawdat);
+               del_sem(semid);
+               cls_fil(fd);
+               free(cache);
+               return NULL;
+       }
 
        return cache;
 }
index f750479..51877e5 100644 (file)
@@ -34,6 +34,7 @@
 #define DATCACHE_RECORDTYPE_INFO 30
 #define DATCACHE_RECORDSUBTYPE_RETRIEVE 0x0001
 #define DATCACHE_RECORDSUBTYPE_HEADER 0x0002
+#define DATCACHE_RECORDSUBTYPE_RESIDINFO 0x0003
 
 #define DATCACHE_RESIDDATA_FLAG_NG    0x00000001
 #define DATCACHE_RESIDDATA_FLAG_COLOR 0x00000002
index acbd577..c6056e9 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * test_cache.c
  *
- * Copyright (c) 2009 project bchan
+ * Copyright (c) 2009-2010 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
@@ -29,6 +29,7 @@
 #include    <bstdio.h>
 #include    <bstring.h>
 #include    <bstdlib.h>
+#include    <tstring.h>
 #include       <errcode.h>
 
 #include    "test.h"
@@ -1393,6 +1394,682 @@ LOCAL TEST_RESULT test_cache_15()
        return result;
 }
 
+/* test_cache_residinfo_1 */
+
+LOCAL TEST_RESULT test_cache_residinfo_1()
+{
+       LINK test_lnk;
+       W fd, err;
+       VID vid;
+       datcache_t *cache;
+       UB idstr1[] = "yZXmy7Om0", idstr2[] = "GCQJ44Ao", idstr3[] = "V.jwWEDO";
+       TC idstr1_tc[9], idstr2_tc[8], idstr3_tc[8];
+       W ret, idstr1_len = strlen(idstr1), idstr2_len = strlen(idstr2), idstr3_len = strlen(idstr3);
+       UW attr, attr1 = 0x01010101, attr2 = 0x10101010, attr3 = 0x00001111;
+       COLOR color, color1 = 0x10FF00FF, color2 = 0x1000FF00, color3 = 0x10000000;
+       TEST_RESULT result = TEST_RESULT_PASS;
+
+       sjstotcs(idstr1_tc, idstr1);
+       sjstotcs(idstr2_tc, idstr2);
+       sjstotcs(idstr3_tc, idstr3);
+
+       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_addresiddata(cache, idstr1_tc, idstr1_len, attr1, color1);
+       if (err < 0) {
+               printf("datcache_addresiddata fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       err = datcache_addresiddata(cache, idstr2_tc, idstr2_len, attr2, color2);
+       if (err < 0) {
+               printf("datcache_addresiddata fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       err = datcache_addresiddata(cache, idstr3_tc, idstr3_len, attr3, color3);
+       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);
+
+       ret = datcache_searchresiddata(cache, idstr1_tc, idstr1_len, &attr, &color);
+       if (ret != DATCACHE_SEARCHRESIDDATA_FOUND) {
+               printf("residhash_searchdata 1 fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       if (attr != attr1) {
+               printf("residhash_searchdata 1 result fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       if (color != color1) {
+               printf("residhash_searchdata 1 result fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       ret = datcache_searchresiddata(cache, idstr2_tc, idstr2_len, &attr, &color);
+       if (ret != DATCACHE_SEARCHRESIDDATA_FOUND) {
+               printf("residhash_searchdata 2 fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       if (attr != attr2) {
+               printf("residhash_searchdata 2 result fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       if (color != color2) {
+               printf("residhash_searchdata 2 result fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       ret = datcache_searchresiddata(cache, idstr3_tc, idstr3_len, &attr, &color);
+       if (ret != DATCACHE_SEARCHRESIDDATA_FOUND) {
+               printf("residhash_searchdata 3 fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       if (attr != attr3) {
+               printf("residhash_searchdata 3 result fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       if (color != color3) {
+               printf("residhash_searchdata 3 result 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_residinfo_2 */
+
+LOCAL TEST_RESULT test_cache_residinfo_2()
+{
+       LINK test_lnk;
+       W fd, err;
+       VID vid;
+       datcache_t *cache;
+       UB idstr1[] = "yZXmy7Om0", idstr2[] = "GCQJ44Ao", idstr3[] = "V.jwWEDO";
+       TC idstr1_tc[9], idstr2_tc[8], idstr3_tc[8];
+       W ret, idstr1_len = strlen(idstr1), idstr2_len = strlen(idstr2), idstr3_len = strlen(idstr3);
+       UW attr, attr1 = 0x01010101, attr2 = 0x10101010;
+       COLOR color, color1 = 0x10FF00FF, color2 = 0x1000FF00;
+       TEST_RESULT result = TEST_RESULT_PASS;
+
+       sjstotcs(idstr1_tc, idstr1);
+       sjstotcs(idstr2_tc, idstr2);
+       sjstotcs(idstr3_tc, idstr3);
+
+       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_addresiddata(cache, idstr1_tc, idstr1_len, attr1, color1);
+       if (err < 0) {
+               printf("datcache_addresiddata fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       err = datcache_addresiddata(cache, idstr2_tc, idstr2_len, attr2, color2);
+       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);
+
+       ret = datcache_searchresiddata(cache, idstr1_tc, idstr1_len, &attr, &color);
+       if (ret != DATCACHE_SEARCHRESIDDATA_FOUND) {
+               printf("residhash_searchdata 1 fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       if (attr != attr1) {
+               printf("residhash_searchdata 1 result fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       if (color != color1) {
+               printf("residhash_searchdata 1 result fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       ret = datcache_searchresiddata(cache, idstr2_tc, idstr2_len, &attr, &color);
+       if (ret != DATCACHE_SEARCHRESIDDATA_FOUND) {
+               printf("residhash_searchdata 2 fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       if (attr != attr2) {
+               printf("residhash_searchdata 2 result fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       if (color != color2) {
+               printf("residhash_searchdata 2 result fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       ret = datcache_searchresiddata(cache, idstr3_tc, idstr3_len, &attr, &color);
+       if (ret != DATCACHE_SEARCHRESIDDATA_NOTFOUND) {
+               printf("residhash_searchdata 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_residinfo_3 */
+
+LOCAL TEST_RESULT test_cache_residinfo_3()
+{
+       LINK test_lnk;
+       W fd, err;
+       VID vid;
+       datcache_t *cache;
+       UB idstr1[] = "yZXmy7Om0", idstr2[] = "GCQJ44Ao", idstr3[] = "V.jwWEDO";
+       TC idstr1_tc[9], idstr2_tc[8], idstr3_tc[8];
+       W ret, idstr1_len = strlen(idstr1), idstr2_len = strlen(idstr2), idstr3_len = strlen(idstr3);
+       UW attr, attr1 = 0x01010101;
+       COLOR color, color1 = 0x10FF00FF;
+       TEST_RESULT result = TEST_RESULT_PASS;
+
+       sjstotcs(idstr1_tc, idstr1);
+       sjstotcs(idstr2_tc, idstr2);
+       sjstotcs(idstr3_tc, idstr3);
+
+       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_addresiddata(cache, idstr1_tc, idstr1_len, attr1, color1);
+       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);
+
+       ret = datcache_searchresiddata(cache, idstr1_tc, idstr1_len, &attr, &color);
+       if (ret != DATCACHE_SEARCHRESIDDATA_FOUND) {
+               printf("residhash_searchdata 1 fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       if (attr != attr1) {
+               printf("residhash_searchdata 1 result fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       if (color != color1) {
+               printf("residhash_searchdata 1 result fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       ret = datcache_searchresiddata(cache, idstr2_tc, idstr2_len, &attr, &color);
+       if (ret != DATCACHE_SEARCHRESIDDATA_NOTFOUND) {
+               printf("residhash_searchdata 2 fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       ret = datcache_searchresiddata(cache, idstr3_tc, idstr3_len, &attr, &color);
+       if (ret != DATCACHE_SEARCHRESIDDATA_NOTFOUND) {
+               printf("residhash_searchdata 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_residinfo_4 */
+
+LOCAL TEST_RESULT test_cache_residinfo_4()
+{
+       LINK test_lnk;
+       W fd, err;
+       VID vid;
+       datcache_t *cache;
+       UB idstr1[] = "yZXmy7Om0", idstr2[] = "GCQJ44Ao", idstr3[] = "V.jwWEDO";
+       TC idstr1_tc[9], idstr2_tc[8], idstr3_tc[8];
+       W ret, idstr1_len = strlen(idstr1), idstr2_len = strlen(idstr2), idstr3_len = strlen(idstr3);
+       UW attr;
+       COLOR color;
+       TEST_RESULT result = TEST_RESULT_PASS;
+
+       sjstotcs(idstr1_tc, idstr1);
+       sjstotcs(idstr2_tc, idstr2);
+       sjstotcs(idstr3_tc, idstr3);
+
+       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);
+
+       ret = datcache_searchresiddata(cache, idstr1_tc, idstr1_len, &attr, &color);
+       if (ret != DATCACHE_SEARCHRESIDDATA_NOTFOUND) {
+               printf("residhash_searchdata 1 fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       ret = datcache_searchresiddata(cache, idstr2_tc, idstr2_len, &attr, &color);
+       if (ret != DATCACHE_SEARCHRESIDDATA_NOTFOUND) {
+               printf("residhash_searchdata 2 fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       ret = datcache_searchresiddata(cache, idstr3_tc, idstr3_len, &attr, &color);
+       if (ret != DATCACHE_SEARCHRESIDDATA_NOTFOUND) {
+               printf("residhash_searchdata 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_residinfo_5 */
+
+LOCAL TEST_RESULT test_cache_residinfo_5()
+{
+       LINK test_lnk;
+       W fd, err;
+       VID vid;
+       datcache_t *cache;
+       UB idstr1[] = "yZXmy7Om0", idstr2[] = "GCQJ44Ao", idstr3[] = "V.jwWEDO";
+       TC idstr1_tc[9], idstr2_tc[8], idstr3_tc[8];
+       W ret, idstr1_len = strlen(idstr1), idstr2_len = strlen(idstr2), idstr3_len = strlen(idstr3);
+       UW attr, attr1 = 0x01010101, attr2 = 0x10101010, attr3 = 0x00001111;
+       COLOR color, color1 = 0x10FF00FF, color2 = 0x1000FF00, color3 = 0x10000000;
+       TEST_RESULT result = TEST_RESULT_PASS;
+
+       sjstotcs(idstr1_tc, idstr1);
+       sjstotcs(idstr2_tc, idstr2);
+       sjstotcs(idstr3_tc, idstr3);
+
+       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_addresiddata(cache, idstr1_tc, idstr1_len, attr1, color1);
+       if (err < 0) {
+               printf("datcache_addresiddata fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       err = datcache_addresiddata(cache, idstr2_tc, idstr2_len, attr2, color2);
+       if (err < 0) {
+               printf("datcache_addresiddata fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       err = datcache_addresiddata(cache, idstr3_tc, idstr3_len, attr3, color3);
+       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);
+       datcache_removeresiddata(cache, idstr3_tc, idstr3_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);
+
+       ret = datcache_searchresiddata(cache, idstr1_tc, idstr1_len, &attr, &color);
+       if (ret != DATCACHE_SEARCHRESIDDATA_FOUND) {
+               printf("residhash_searchdata 1 fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       if (attr != attr1) {
+               printf("residhash_searchdata 1 result fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       if (color != color1) {
+               printf("residhash_searchdata 1 result fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       ret = datcache_searchresiddata(cache, idstr2_tc, idstr2_len, &attr, &color);
+       if (ret != DATCACHE_SEARCHRESIDDATA_FOUND) {
+               printf("residhash_searchdata 2 fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       if (attr != attr2) {
+               printf("residhash_searchdata 2 result fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       if (color != color2) {
+               printf("residhash_searchdata 2 result fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       ret = datcache_searchresiddata(cache, idstr3_tc, idstr3_len, &attr, &color);
+       if (ret != DATCACHE_SEARCHRESIDDATA_NOTFOUND) {
+               printf("residhash_searchdata 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_residinfo_6 */
+
+LOCAL TEST_RESULT test_cache_residinfo_6()
+{
+       LINK test_lnk;
+       W fd, err;
+       VID vid;
+       datcache_t *cache;
+       UB idstr1[] = "yZXmy7Om0", idstr2[] = "GCQJ44Ao", idstr3[] = "V.jwWEDO";
+       TC idstr1_tc[9], idstr2_tc[8], idstr3_tc[8];
+       W ret, idstr1_len = strlen(idstr1), idstr2_len = strlen(idstr2), idstr3_len = strlen(idstr3);
+       UW attr, attr1 = 0x01010101, attr2 = 0x10101010, attr3 = 0x00001111;
+       COLOR color, color1 = 0x10FF00FF, color2 = 0x1000FF00, color3 = 0x10000000;
+       TEST_RESULT result = TEST_RESULT_PASS;
+
+       sjstotcs(idstr1_tc, idstr1);
+       sjstotcs(idstr2_tc, idstr2);
+       sjstotcs(idstr3_tc, idstr3);
+
+       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_addresiddata(cache, idstr1_tc, idstr1_len, attr1, color1);
+       if (err < 0) {
+               printf("datcache_addresiddata fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       err = datcache_addresiddata(cache, idstr2_tc, idstr2_len, attr2, color2);
+       if (err < 0) {
+               printf("datcache_addresiddata fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       err = datcache_addresiddata(cache, idstr3_tc, idstr3_len, attr3, color3);
+       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);
+       datcache_removeresiddata(cache, idstr2_tc, idstr2_len);
+       datcache_removeresiddata(cache, idstr3_tc, idstr3_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);
+
+       ret = datcache_searchresiddata(cache, idstr1_tc, idstr1_len, &attr, &color);
+       if (ret != DATCACHE_SEARCHRESIDDATA_FOUND) {
+               printf("residhash_searchdata 1 fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       if (attr != attr1) {
+               printf("residhash_searchdata 1 result fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       if (color != color1) {
+               printf("residhash_searchdata 1 result fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       ret = datcache_searchresiddata(cache, idstr2_tc, idstr2_len, &attr, &color);
+       if (ret != DATCACHE_SEARCHRESIDDATA_NOTFOUND) {
+               printf("residhash_searchdata 2 fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       ret = datcache_searchresiddata(cache, idstr3_tc, idstr3_len, &attr, &color);
+       if (ret != DATCACHE_SEARCHRESIDDATA_NOTFOUND) {
+               printf("residhash_searchdata 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_residinfo_7 */
+
+LOCAL TEST_RESULT test_cache_residinfo_7()
+{
+       LINK test_lnk;
+       W fd, err;
+       VID vid;
+       datcache_t *cache;
+       UB idstr1[] = "yZXmy7Om0", idstr2[] = "GCQJ44Ao", idstr3[] = "V.jwWEDO";
+       TC idstr1_tc[9], idstr2_tc[8], idstr3_tc[8];
+       W ret, idstr1_len = strlen(idstr1), idstr2_len = strlen(idstr2), idstr3_len = strlen(idstr3);
+       UW attr, attr1 = 0x01010101, attr2 = 0x10101010, attr3 = 0x00001111;
+       COLOR color, color1 = 0x10FF00FF, color2 = 0x1000FF00, color3 = 0x10000000;
+       TEST_RESULT result = TEST_RESULT_PASS;
+
+       sjstotcs(idstr1_tc, idstr1);
+       sjstotcs(idstr2_tc, idstr2);
+       sjstotcs(idstr3_tc, idstr3);
+
+       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_addresiddata(cache, idstr1_tc, idstr1_len, attr1, color1);
+       if (err < 0) {
+               printf("datcache_addresiddata fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       err = datcache_addresiddata(cache, idstr2_tc, idstr2_len, attr2, color2);
+       if (err < 0) {
+               printf("datcache_addresiddata fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       err = datcache_addresiddata(cache, idstr3_tc, idstr3_len, attr3, color3);
+       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);
+       datcache_removeresiddata(cache, idstr1_tc, idstr1_len);
+       datcache_removeresiddata(cache, idstr2_tc, idstr2_len);
+       datcache_removeresiddata(cache, idstr3_tc, idstr3_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);
+
+       ret = datcache_searchresiddata(cache, idstr1_tc, idstr1_len, &attr, &color);
+       if (ret != DATCACHE_SEARCHRESIDDATA_NOTFOUND) {
+               printf("residhash_searchdata 1 fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       ret = datcache_searchresiddata(cache, idstr2_tc, idstr2_len, &attr, &color);
+       if (ret != DATCACHE_SEARCHRESIDDATA_NOTFOUND) {
+               printf("residhash_searchdata 2 fail\n");
+               result = TEST_RESULT_FAIL;
+       }
+       ret = datcache_searchresiddata(cache, idstr3_tc, idstr3_len, &attr, &color);
+       if (ret != DATCACHE_SEARCHRESIDDATA_NOTFOUND) {
+               printf("residhash_searchdata 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;
@@ -1425,4 +2102,11 @@ IMPORT VOID test_cache_main()
        test_cache_printresult(test_cache_13, "test_cache_13");
        test_cache_printresult(test_cache_14, "test_cache_14");
        test_cache_printresult(test_cache_15, "test_cache_15");
+       test_cache_printresult(test_cache_residinfo_1, "test_cache_residinfo_1");
+       test_cache_printresult(test_cache_residinfo_2, "test_cache_residinfo_2");
+       test_cache_printresult(test_cache_residinfo_3, "test_cache_residinfo_3");
+       test_cache_printresult(test_cache_residinfo_4, "test_cache_residinfo_4");
+       test_cache_printresult(test_cache_residinfo_5, "test_cache_residinfo_5");
+       test_cache_printresult(test_cache_residinfo_6, "test_cache_residinfo_6");
+       test_cache_printresult(test_cache_residinfo_7, "test_cache_residinfo_7");
 }