OSDN Git Service

enable to resdata update.
authorornse01 <ornse01@users.sourceforge.jp>
Sun, 15 May 2011 07:36:09 +0000 (07:36 +0000)
committerornse01 <ornse01@users.sourceforge.jp>
Sun, 15 May 2011 07:36:09 +0000 (07:36 +0000)
git-svn-id: http://svn.sourceforge.jp/svnroot/bchan/bchan/trunk@274 20a0b8eb-f62a-4a12-8fe1-b598822500fb

src/postres.c
src/test_postres.c

index 7264724..d5e8246 100644 (file)
@@ -69,6 +69,15 @@ LOCAL W tcstrbuffer_appendstring(tcstrbuffer_t *tcstr, TC *str, W len)
        return 0;
 }
 
+LOCAL VOID tcstrbuffer_clear(tcstrbuffer_t *tcstr)
+{
+       if (tcstr->buffer != NULL) {
+               free(tcstr->buffer);
+               tcstr->buffer = NULL;
+               tcstr->strlen = 0;
+       }
+}
+
 LOCAL W tcstrbuffer_initialize(tcstrbuffer_t *tcstr)
 {
        tcstr->buffer = NULL;
@@ -249,6 +258,28 @@ LOCAL W postresdata_convertdata(postresdata_t *post)
        return 0;
 }
 
+LOCAL VOID postresdata_cleardata(postresdata_t *post)
+{
+       tcstrbuffer_clear(&post->from);
+       tcstrbuffer_clear(&post->mail);
+       tcstrbuffer_clear(&post->message);
+       if (post->asc_from != NULL) {
+               free(post->asc_from);
+               post->asc_from = NULL;
+               post->asc_from_len = 0;
+       }
+       if (post->asc_mail != NULL) {
+               free(post->asc_mail);
+               post->asc_mail = NULL;
+               post->asc_mail_len = 0;
+       }
+       if (post->asc_message != NULL) {
+               free(post->asc_message);
+               post->asc_message = NULL;
+               post->asc_message_len = 0;
+       }
+}
+
 EXPORT W postresdata_readfile(postresdata_t *post, VLINK *vlnk)
 {
        W fd, err, size;
@@ -281,6 +312,8 @@ EXPORT W postresdata_readfile(postresdata_t *post, VLINK *vlnk)
        }
        cls_fil(fd);
 
+       postresdata_cleardata(post);
+
        err =  postresdata_readtad(post, (TC *)buf, size/sizeof(TC));
        free(buf);
        if (err < 0) {
index 4b98680..b74d921 100644 (file)
@@ -394,6 +394,114 @@ LOCAL TEST_RESULT test_genrequestbody_5()
        return test_genrequestbody_checkdata(testdata, testdata_len, board, strlen(board), thread, strlen(thread), time, expected, strlen(expected));
 }
 
+LOCAL TEST_RESULT test_genrequestbody_checkdata_update(UB *testdata1, W testdata1_len, UB *testdata2, W testdata2_len, UB *board, W board_len, UB *thread, W thread_len, STIME time, UB *expected, W expected_len)
+{
+       LINK test_lnk1, test_lnk2;
+       W fd, err;
+       postresdata_t *postres;
+       UB *body = NULL;
+       W body_len = 0;
+       TEST_RESULT result;
+
+       fd = test_postres_util_gen_file(&test_lnk1);
+       if (fd < 0) {
+               return TEST_RESULT_FAIL;
+       }
+       err = ins_rec(fd, testdata1, testdata1_len, RT_TADDATA, 0, 0);
+       if (err < 0) {
+               cls_fil(fd);
+               del_fil(NULL, &test_lnk1, 0);
+               return TEST_RESULT_FAIL;
+       }
+       cls_fil(fd);
+
+       fd = test_postres_util_gen_file(&test_lnk2);
+       if (fd < 0) {
+               del_fil(NULL, &test_lnk1, 0);
+               return TEST_RESULT_FAIL;
+       }
+       err = ins_rec(fd, testdata2, testdata2_len, RT_TADDATA, 0, 0);
+       if (err < 0) {
+               cls_fil(fd);
+               del_fil(NULL, &test_lnk2, 0);
+               del_fil(NULL, &test_lnk1, 0);
+               return TEST_RESULT_FAIL;
+       }
+       cls_fil(fd);
+
+       postres = postresdata_new();
+       if (postres == NULL) {
+               del_fil(NULL, &test_lnk2, 0);
+               del_fil(NULL, &test_lnk1, 0);
+               return TEST_RESULT_FAIL;
+       }
+       err = postresdata_readfile(postres, (VLINK *)&test_lnk1);
+       if (err < 0) {
+               postresdata_delete(postres);
+               del_fil(NULL, &test_lnk2, 0);
+               del_fil(NULL, &test_lnk1, 0);
+               return TEST_RESULT_FAIL;
+       }
+       err = postresdata_readfile(postres, (VLINK *)&test_lnk2);
+       if (err < 0) {
+               postresdata_delete(postres);
+               del_fil(NULL, &test_lnk2, 0);
+               del_fil(NULL, &test_lnk1, 0);
+               return TEST_RESULT_FAIL;
+       }
+       err = postresdata_genrequestbody(postres, board, board_len, thread, thread_len, time, &body, &body_len);
+       if (err < 0) {
+               postresdata_delete(postres);
+               del_fil(NULL, &test_lnk2, 0);
+               del_fil(NULL, &test_lnk1, 0);
+               return TEST_RESULT_FAIL;
+       }
+       postresdata_delete(postres);
+
+       if (body_len != expected_len) {
+               printf("length different\n");
+               result = TEST_RESULT_FAIL;
+       } else {
+               if (strncmp(body, expected, expected_len) != 0) {
+                       printf("string different\n");
+                       result = TEST_RESULT_FAIL;
+               } else {
+                       result = TEST_RESULT_PASS;
+               }
+       }
+       if (result != TEST_RESULT_PASS) {
+               printf("length: generated = %d, expected = %d\n", body_len, expected_len);
+               printf("string\n");
+               printf("  generated:  ");
+               SJSTRING_DP(body, body_len);
+               printf("\n");
+               printf("  expected:   ");
+               SJSTRING_DP(expected, expected_len);
+               printf("\n");
+       }
+
+       free(body);
+
+       del_fil(NULL, &test_lnk2, 0);
+       del_fil(NULL, &test_lnk1, 0);
+
+       return result;
+}
+
+LOCAL TEST_RESULT test_genrequestbody_6()
+{
+       UB *testdata1 = test_genrequestbody_testdata01;
+       W testdata1_len = sizeof(test_genrequestbody_testdata01);
+       UB *testdata2 = test_genrequestbody_testdata04;
+       W testdata2_len = sizeof(test_genrequestbody_testdata04);
+       UB board[] = "test";
+       UB thread[] = "000000000";
+       STIME time = 1234567890;
+       UB expected[] = "bbs=test&key=000000000&time=1707953490&FROM=&mail=&MESSAGE=%82%82%82%8F%82%84%82%99&submit=%8F%91%82%AB%8D%9E%82%DE";
+
+       return test_genrequestbody_checkdata_update(testdata1, testdata1_len, testdata2, testdata2_len, board, strlen(board), thread, strlen(thread), time, expected, strlen(expected));
+}
+
 LOCAL TEST_RESULT test_gennamemail_checkdata(UB *testdata, W testdata_len, UB *expected_name, W expected_name_len, UB *expected_mail, W expected_mail_len)
 {
        LINK test_lnk;
@@ -545,6 +653,7 @@ EXPORT VOID test_postres_main()
        test_postres_printresult(test_genrequestbody_3, "test_genrequestbody_3");
        test_postres_printresult(test_genrequestbody_4, "test_genrequestbody_4");
        test_postres_printresult(test_genrequestbody_5, "test_genrequestbody_5");
+       test_postres_printresult(test_genrequestbody_6, "test_genrequestbody_6");
        test_postres_printresult(test_gennamemail_1, "test_gennamemail_1");
        test_postres_printresult(test_gennamemail_2, "test_gennamemail_2");
        test_postres_printresult(test_gennamemail_3, "test_gennamemail_3");